]> git.ipfire.org Git - thirdparty/grsecurity-scrape.git/blame - test/grsecurity-3.0-3.14.4-201405141623.patch
Auto commit, 1 new patch{es}.
[thirdparty/grsecurity-scrape.git] / test / grsecurity-3.0-3.14.4-201405141623.patch
CommitLineData
aca9faf7
PK
1diff --git a/Documentation/dontdiff b/Documentation/dontdiff
2index b89a739..e289b9b 100644
3--- a/Documentation/dontdiff
4+++ b/Documentation/dontdiff
5@@ -2,9 +2,11 @@
6 *.aux
7 *.bin
8 *.bz2
9+*.c.[012]*.*
10 *.cis
11 *.cpio
12 *.csp
13+*.dbg
14 *.dsp
15 *.dvi
16 *.elf
17@@ -14,6 +16,7 @@
18 *.gcov
19 *.gen.S
20 *.gif
21+*.gmo
22 *.grep
23 *.grp
24 *.gz
25@@ -48,14 +51,17 @@
26 *.tab.h
27 *.tex
28 *.ver
29+*.vim
30 *.xml
31 *.xz
32 *_MODULES
33+*_reg_safe.h
34 *_vga16.c
35 *~
36 \#*#
37 *.9
38-.*
39+.[^g]*
40+.gen*
41 .*.d
42 .mm
43 53c700_d.h
44@@ -69,9 +75,11 @@ Image
45 Module.markers
46 Module.symvers
47 PENDING
48+PERF*
49 SCCS
50 System.map*
51 TAGS
52+TRACEEVENT-CFLAGS
53 aconf
54 af_names.h
55 aic7*reg.h*
56@@ -80,6 +88,7 @@ aic7*seq.h*
57 aicasm
58 aicdb.h*
59 altivec*.c
60+ashldi3.S
61 asm-offsets.h
62 asm_offsets.h
63 autoconf.h*
64@@ -92,32 +101,40 @@ bounds.h
65 bsetup
66 btfixupprep
67 build
68+builtin-policy.h
69 bvmlinux
70 bzImage*
71 capability_names.h
72 capflags.c
73 classlist.h*
74+clut_vga16.c
75+common-cmds.h
76 comp*.log
77 compile.h*
78 conf
79 config
80 config-*
81 config_data.h*
82+config.c
83 config.mak
84 config.mak.autogen
85+config.tmp
86 conmakehash
87 consolemap_deftbl.c*
88 cpustr.h
89 crc32table.h*
90 cscope.*
91 defkeymap.c
92+devicetable-offsets.h
93 devlist.h*
94 dnotify_test
95 docproc
96 dslm
97+dtc-lexer.lex.c
98 elf2ecoff
99 elfconfig.h*
100 evergreen_reg_safe.h
101+exception_policy.conf
102 fixdep
103 flask.h
104 fore200e_mkfirm
105@@ -125,12 +142,15 @@ fore200e_pca_fw.c*
106 gconf
107 gconf.glade.h
108 gen-devlist
109+gen-kdb_cmds.c
110 gen_crc32table
111 gen_init_cpio
112 generated
113 genheaders
114 genksyms
115 *_gray256.c
116+hash
117+hid-example
118 hpet_example
119 hugepage-mmap
120 hugepage-shm
121@@ -145,14 +165,14 @@ int32.c
122 int4.c
123 int8.c
124 kallsyms
125-kconfig
126+kern_constants.h
127 keywords.c
128 ksym.c*
129 ksym.h*
130 kxgettext
131 lex.c
132 lex.*.c
133-linux
134+lib1funcs.S
135 logo_*.c
136 logo_*_clut224.c
137 logo_*_mono.c
138@@ -162,14 +182,15 @@ mach-types.h
139 machtypes.h
140 map
141 map_hugetlb
142-media
143 mconf
144+mdp
145 miboot*
146 mk_elfconfig
147 mkboot
148 mkbugboot
149 mkcpustr
150 mkdep
151+mkpiggy
152 mkprep
153 mkregtable
154 mktables
155@@ -185,6 +206,8 @@ oui.c*
156 page-types
157 parse.c
158 parse.h
159+parse-events*
160+pasyms.h
161 patches*
162 pca200e.bin
163 pca200e_ecd.bin2
164@@ -194,6 +217,7 @@ perf-archive
165 piggyback
166 piggy.gzip
167 piggy.S
168+pmu-*
169 pnmtologo
170 ppc_defs.h*
171 pss_boot.h
172@@ -203,7 +227,12 @@ r200_reg_safe.h
173 r300_reg_safe.h
174 r420_reg_safe.h
175 r600_reg_safe.h
176+randomize_layout_hash.h
177+randomize_layout_seed.h
178+realmode.lds
179+realmode.relocs
180 recordmcount
181+regdb.c
182 relocs
183 rlim_names.h
184 rn50_reg_safe.h
185@@ -213,8 +242,12 @@ series
186 setup
187 setup.bin
188 setup.elf
189+signing_key*
190+size_overflow_hash.h
191 sImage
192+slabinfo
193 sm_tbl*
194+sortextable
195 split-include
196 syscalltab.h
197 tables.c
198@@ -224,6 +257,7 @@ tftpboot.img
199 timeconst.h
200 times.h*
201 trix_boot.h
202+user_constants.h
203 utsrelease.h*
204 vdso-syms.lds
205 vdso.lds
206@@ -235,13 +269,17 @@ vdso32.lds
207 vdso32.so.dbg
208 vdso64.lds
209 vdso64.so.dbg
210+vdsox32.lds
211+vdsox32-syms.lds
212 version.h*
213 vmImage
214 vmlinux
215 vmlinux-*
216 vmlinux.aout
217 vmlinux.bin.all
218+vmlinux.bin.bz2
219 vmlinux.lds
220+vmlinux.relocs
221 vmlinuz
222 voffset.h
223 vsyscall.lds
224@@ -249,9 +287,12 @@ vsyscall_32.lds
225 wanxlfw.inc
226 uImage
227 unifdef
228+utsrelease.h
229 wakeup.bin
230 wakeup.elf
231 wakeup.lds
232+x509*
233 zImage*
234 zconf.hash.c
235+zconf.lex.c
236 zoffset.h
237diff --git a/Documentation/kernel-parameters.txt b/Documentation/kernel-parameters.txt
238index 7116fda..d8ed6e8 100644
239--- a/Documentation/kernel-parameters.txt
240+++ b/Documentation/kernel-parameters.txt
241@@ -1084,6 +1084,10 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
242 Format: <unsigned int> such that (rxsize & ~0x1fffc0) == 0.
243 Default: 1024
244
245+ grsec_proc_gid= [GRKERNSEC_PROC_USERGROUP] Chooses GID to
246+ ignore grsecurity's /proc restrictions
247+
248+
249 hashdist= [KNL,NUMA] Large hashes allocated during boot
250 are distributed across NUMA nodes. Defaults on
251 for 64-bit NUMA, off otherwise.
252@@ -2080,6 +2084,10 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
253 noexec=on: enable non-executable mappings (default)
254 noexec=off: disable non-executable mappings
255
256+ nopcid [X86-64]
257+ Disable PCID (Process-Context IDentifier) even if it
258+ is supported by the processor.
259+
260 nosmap [X86]
261 Disable SMAP (Supervisor Mode Access Prevention)
262 even if it is supported by processor.
263@@ -2347,6 +2355,25 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
264 the specified number of seconds. This is to be used if
265 your oopses keep scrolling off the screen.
266
267+ pax_nouderef [X86] disables UDEREF. Most likely needed under certain
268+ virtualization environments that don't cope well with the
269+ expand down segment used by UDEREF on X86-32 or the frequent
270+ page table updates on X86-64.
271+
272+ pax_sanitize_slab=
273+ 0/1 to disable/enable slab object sanitization (enabled by
274+ default).
275+
276+ pax_softmode= 0/1 to disable/enable PaX softmode on boot already.
277+
278+ pax_extra_latent_entropy
279+ Enable a very simple form of latent entropy extraction
280+ from the first 4GB of memory as the bootmem allocator
281+ passes the memory pages to the buddy allocator.
282+
283+ pax_weakuderef [X86-64] enables the weaker but faster form of UDEREF
284+ when the processor supports PCID.
285+
286 pcbit= [HW,ISDN]
287
288 pcd. [PARIDE]
289diff --git a/Makefile b/Makefile
290index d7c07fd..d6d4bfa 100644
291--- a/Makefile
292+++ b/Makefile
293@@ -244,8 +244,9 @@ CONFIG_SHELL := $(shell if [ -x "$$BASH" ]; then echo $$BASH; \
294
295 HOSTCC = gcc
296 HOSTCXX = g++
297-HOSTCFLAGS = -Wall -Wmissing-prototypes -Wstrict-prototypes -O2 -fomit-frame-pointer
298-HOSTCXXFLAGS = -O2
299+HOSTCFLAGS = -Wall -W -Wmissing-prototypes -Wstrict-prototypes -Wno-unused-parameter -Wno-missing-field-initializers -O2 -fomit-frame-pointer -fno-delete-null-pointer-checks
300+HOSTCFLAGS += $(call cc-option, -Wno-empty-body)
301+HOSTCXXFLAGS = -O2 -Wall -W -Wno-array-bounds
302
303 # Decide whether to build built-in, modular, or both.
304 # Normally, just do built-in.
305@@ -423,8 +424,8 @@ export RCS_TAR_IGNORE := --exclude SCCS --exclude BitKeeper --exclude .svn \
306 # Rules shared between *config targets and build targets
307
308 # Basic helpers built in scripts/
309-PHONY += scripts_basic
310-scripts_basic:
311+PHONY += scripts_basic gcc-plugins
312+scripts_basic: gcc-plugins
313 $(Q)$(MAKE) $(build)=scripts/basic
314 $(Q)rm -f .tmp_quiet_recordmcount
315
316@@ -585,6 +586,72 @@ else
317 KBUILD_CFLAGS += -O2
318 endif
319
320+ifndef DISABLE_PAX_PLUGINS
321+ifeq ($(call cc-ifversion, -ge, 0408, y), y)
322+PLUGINCC := $(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-plugin.sh "$(HOSTCXX)" "$(HOSTCXX)" "$(CC)")
323+else
324+PLUGINCC := $(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-plugin.sh "$(HOSTCC)" "$(HOSTCXX)" "$(CC)")
325+endif
326+ifneq ($(PLUGINCC),)
327+ifdef CONFIG_PAX_CONSTIFY_PLUGIN
328+CONSTIFY_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/constify_plugin.so -DCONSTIFY_PLUGIN
329+endif
330+ifdef CONFIG_PAX_MEMORY_STACKLEAK
331+STACKLEAK_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/stackleak_plugin.so -DSTACKLEAK_PLUGIN
332+STACKLEAK_PLUGIN_CFLAGS += -fplugin-arg-stackleak_plugin-track-lowest-sp=100
333+endif
334+ifdef CONFIG_KALLOCSTAT_PLUGIN
335+KALLOCSTAT_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/kallocstat_plugin.so
336+endif
337+ifdef CONFIG_PAX_KERNEXEC_PLUGIN
338+KERNEXEC_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/kernexec_plugin.so
339+KERNEXEC_PLUGIN_CFLAGS += -fplugin-arg-kernexec_plugin-method=$(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD) -DKERNEXEC_PLUGIN
340+KERNEXEC_PLUGIN_AFLAGS := -DKERNEXEC_PLUGIN
341+endif
342+ifdef CONFIG_GRKERNSEC_RANDSTRUCT
343+RANDSTRUCT_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/randomize_layout_plugin.so -DRANDSTRUCT_PLUGIN
344+ifdef CONFIG_GRKERNSEC_RANDSTRUCT_PERFORMANCE
345+RANDSTRUCT_PLUGIN_CFLAGS += -fplugin-arg-randomize_layout_plugin-performance-mode
346+endif
347+endif
348+ifdef CONFIG_CHECKER_PLUGIN
349+ifeq ($(call cc-ifversion, -ge, 0406, y), y)
350+CHECKER_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/checker_plugin.so -DCHECKER_PLUGIN
351+endif
352+endif
353+COLORIZE_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/colorize_plugin.so
354+ifdef CONFIG_PAX_SIZE_OVERFLOW
355+SIZE_OVERFLOW_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/size_overflow_plugin/size_overflow_plugin.so -DSIZE_OVERFLOW_PLUGIN
356+endif
357+ifdef CONFIG_PAX_LATENT_ENTROPY
358+LATENT_ENTROPY_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/latent_entropy_plugin.so -DLATENT_ENTROPY_PLUGIN
359+endif
360+ifdef CONFIG_PAX_MEMORY_STRUCTLEAK
361+STRUCTLEAK_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/structleak_plugin.so -DSTRUCTLEAK_PLUGIN
362+endif
363+GCC_PLUGINS_CFLAGS := $(CONSTIFY_PLUGIN_CFLAGS) $(STACKLEAK_PLUGIN_CFLAGS) $(KALLOCSTAT_PLUGIN_CFLAGS)
364+GCC_PLUGINS_CFLAGS += $(KERNEXEC_PLUGIN_CFLAGS) $(CHECKER_PLUGIN_CFLAGS) $(COLORIZE_PLUGIN_CFLAGS)
365+GCC_PLUGINS_CFLAGS += $(SIZE_OVERFLOW_PLUGIN_CFLAGS) $(LATENT_ENTROPY_PLUGIN_CFLAGS) $(STRUCTLEAK_PLUGIN_CFLAGS)
366+GCC_PLUGINS_CFLAGS += $(RANDSTRUCT_PLUGIN_CFLAGS)
367+GCC_PLUGINS_AFLAGS := $(KERNEXEC_PLUGIN_AFLAGS)
368+export PLUGINCC GCC_PLUGINS_CFLAGS GCC_PLUGINS_AFLAGS CONSTIFY_PLUGIN LATENT_ENTROPY_PLUGIN_CFLAGS
369+ifeq ($(KBUILD_EXTMOD),)
370+gcc-plugins:
371+ $(Q)$(MAKE) $(build)=tools/gcc
372+else
373+gcc-plugins: ;
374+endif
375+else
376+gcc-plugins:
377+ifeq ($(call cc-ifversion, -ge, 0405, y), y)
378+ $(error Your gcc installation does not support plugins. If the necessary headers for plugin support are missing, they should be installed. On Debian, apt-get install gcc-<ver>-plugin-dev. If you choose to ignore this error and lessen the improvements provided by this patch, re-run make with the DISABLE_PAX_PLUGINS=y argument.))
379+else
380+ $(Q)echo "warning, your gcc version does not support plugins, you should upgrade it to gcc 4.5 at least"
381+endif
382+ $(Q)echo "PAX_MEMORY_STACKLEAK, constification, PAX_LATENT_ENTROPY and other features will be less secure. PAX_SIZE_OVERFLOW will not be active."
383+endif
384+endif
385+
386 include $(srctree)/arch/$(SRCARCH)/Makefile
387
388 ifdef CONFIG_READABLE_ASM
389@@ -779,7 +846,7 @@ export mod_sign_cmd
390
391
392 ifeq ($(KBUILD_EXTMOD),)
393-core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/
394+core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/ grsecurity/
395
396 vmlinux-dirs := $(patsubst %/,%,$(filter %/, $(init-y) $(init-m) \
397 $(core-y) $(core-m) $(drivers-y) $(drivers-m) \
398@@ -828,6 +895,8 @@ endif
399
400 # The actual objects are generated when descending,
401 # make sure no implicit rule kicks in
402+$(filter-out $(init-y),$(vmlinux-deps)): KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
403+$(filter-out $(init-y),$(vmlinux-deps)): KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
404 $(sort $(vmlinux-deps)): $(vmlinux-dirs) ;
405
406 # Handle descending into subdirectories listed in $(vmlinux-dirs)
407@@ -837,7 +906,7 @@ $(sort $(vmlinux-deps)): $(vmlinux-dirs) ;
408 # Error messages still appears in the original language
409
410 PHONY += $(vmlinux-dirs)
411-$(vmlinux-dirs): prepare scripts
412+$(vmlinux-dirs): gcc-plugins prepare scripts
413 $(Q)$(MAKE) $(build)=$@
414
415 define filechk_kernel.release
416@@ -880,10 +949,13 @@ prepare1: prepare2 $(version_h) include/generated/utsrelease.h \
417
418 archprepare: archheaders archscripts prepare1 scripts_basic
419
420+prepare0: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
421+prepare0: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
422 prepare0: archprepare FORCE
423 $(Q)$(MAKE) $(build)=.
424
425 # All the preparing..
426+prepare: KBUILD_CFLAGS := $(filter-out $(GCC_PLUGINS_CFLAGS),$(KBUILD_CFLAGS))
427 prepare: prepare0
428
429 # Generate some files
430@@ -991,6 +1063,8 @@ all: modules
431 # using awk while concatenating to the final file.
432
433 PHONY += modules
434+modules: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
435+modules: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
436 modules: $(vmlinux-dirs) $(if $(KBUILD_BUILTIN),vmlinux) modules.builtin
437 $(Q)$(AWK) '!x[$$0]++' $(vmlinux-dirs:%=$(objtree)/%/modules.order) > $(objtree)/modules.order
438 @$(kecho) ' Building modules, stage 2.';
439@@ -1006,7 +1080,7 @@ modules.builtin: $(vmlinux-dirs:%=%/modules.builtin)
440
441 # Target to prepare building external modules
442 PHONY += modules_prepare
443-modules_prepare: prepare scripts
444+modules_prepare: gcc-plugins prepare scripts
445
446 # Target to install modules
447 PHONY += modules_install
448@@ -1072,7 +1146,8 @@ MRPROPER_FILES += .config .config.old .version .old_version $(version_h) \
449 Module.symvers tags TAGS cscope* GPATH GTAGS GRTAGS GSYMS \
450 signing_key.priv signing_key.x509 x509.genkey \
451 extra_certificates signing_key.x509.keyid \
452- signing_key.x509.signer
453+ signing_key.x509.signer tools/gcc/size_overflow_hash.h \
454+ tools/gcc/randomize_layout_seed.h
455
456 # clean - Delete most, but leave enough to build external modules
457 #
458@@ -1112,6 +1187,7 @@ distclean: mrproper
459 \( -name '*.orig' -o -name '*.rej' -o -name '*~' \
460 -o -name '*.bak' -o -name '#*#' -o -name '.*.orig' \
461 -o -name '.*.rej' \
462+ -o -name '.*.rej' -o -name '*.so' \
463 -o -name '*%' -o -name '.*.cmd' -o -name 'core' \) \
464 -type f -print | xargs rm -f
465
466@@ -1273,6 +1349,8 @@ PHONY += $(module-dirs) modules
467 $(module-dirs): crmodverdir $(objtree)/Module.symvers
468 $(Q)$(MAKE) $(build)=$(patsubst _module_%,%,$@)
469
470+modules: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
471+modules: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
472 modules: $(module-dirs)
473 @$(kecho) ' Building modules, stage 2.';
474 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost
475@@ -1412,17 +1490,21 @@ else
476 target-dir = $(if $(KBUILD_EXTMOD),$(dir $<),$(dir $@))
477 endif
478
479-%.s: %.c prepare scripts FORCE
480+%.s: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
481+%.s: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
482+%.s: %.c gcc-plugins prepare scripts FORCE
483 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
484 %.i: %.c prepare scripts FORCE
485 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
486-%.o: %.c prepare scripts FORCE
487+%.o: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
488+%.o: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
489+%.o: %.c gcc-plugins prepare scripts FORCE
490 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
491 %.lst: %.c prepare scripts FORCE
492 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
493-%.s: %.S prepare scripts FORCE
494+%.s: %.S gcc-plugins prepare scripts FORCE
495 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
496-%.o: %.S prepare scripts FORCE
497+%.o: %.S gcc-plugins prepare scripts FORCE
498 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
499 %.symtypes: %.c prepare scripts FORCE
500 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
501@@ -1432,11 +1514,15 @@ endif
502 $(cmd_crmodverdir)
503 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
504 $(build)=$(build-dir)
505-%/: prepare scripts FORCE
506+%/: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
507+%/: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
508+%/: gcc-plugins prepare scripts FORCE
509 $(cmd_crmodverdir)
510 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
511 $(build)=$(build-dir)
512-%.ko: prepare scripts FORCE
513+%.ko: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
514+%.ko: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
515+%.ko: gcc-plugins prepare scripts FORCE
516 $(cmd_crmodverdir)
517 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
518 $(build)=$(build-dir) $(@:.ko=.o)
519diff --git a/arch/alpha/include/asm/atomic.h b/arch/alpha/include/asm/atomic.h
520index 78b03ef..da28a51 100644
521--- a/arch/alpha/include/asm/atomic.h
522+++ b/arch/alpha/include/asm/atomic.h
523@@ -292,6 +292,16 @@ static inline long atomic64_dec_if_positive(atomic64_t *v)
524 #define atomic_dec(v) atomic_sub(1,(v))
525 #define atomic64_dec(v) atomic64_sub(1,(v))
526
527+#define atomic64_read_unchecked(v) atomic64_read(v)
528+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
529+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
530+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
531+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
532+#define atomic64_inc_unchecked(v) atomic64_inc(v)
533+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
534+#define atomic64_dec_unchecked(v) atomic64_dec(v)
535+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
536+
537 #define smp_mb__before_atomic_dec() smp_mb()
538 #define smp_mb__after_atomic_dec() smp_mb()
539 #define smp_mb__before_atomic_inc() smp_mb()
540diff --git a/arch/alpha/include/asm/cache.h b/arch/alpha/include/asm/cache.h
541index ad368a9..fbe0f25 100644
542--- a/arch/alpha/include/asm/cache.h
543+++ b/arch/alpha/include/asm/cache.h
544@@ -4,19 +4,19 @@
545 #ifndef __ARCH_ALPHA_CACHE_H
546 #define __ARCH_ALPHA_CACHE_H
547
548+#include <linux/const.h>
549
550 /* Bytes per L1 (data) cache line. */
551 #if defined(CONFIG_ALPHA_GENERIC) || defined(CONFIG_ALPHA_EV6)
552-# define L1_CACHE_BYTES 64
553 # define L1_CACHE_SHIFT 6
554 #else
555 /* Both EV4 and EV5 are write-through, read-allocate,
556 direct-mapped, physical.
557 */
558-# define L1_CACHE_BYTES 32
559 # define L1_CACHE_SHIFT 5
560 #endif
561
562+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
563 #define SMP_CACHE_BYTES L1_CACHE_BYTES
564
565 #endif
566diff --git a/arch/alpha/include/asm/elf.h b/arch/alpha/include/asm/elf.h
567index 968d999..d36b2df 100644
568--- a/arch/alpha/include/asm/elf.h
569+++ b/arch/alpha/include/asm/elf.h
570@@ -91,6 +91,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
571
572 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x1000000)
573
574+#ifdef CONFIG_PAX_ASLR
575+#define PAX_ELF_ET_DYN_BASE (current->personality & ADDR_LIMIT_32BIT ? 0x10000 : 0x120000000UL)
576+
577+#define PAX_DELTA_MMAP_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 28)
578+#define PAX_DELTA_STACK_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 19)
579+#endif
580+
581 /* $0 is set by ld.so to a pointer to a function which might be
582 registered using atexit. This provides a mean for the dynamic
583 linker to call DT_FINI functions for shared libraries that have
584diff --git a/arch/alpha/include/asm/pgalloc.h b/arch/alpha/include/asm/pgalloc.h
585index aab14a0..b4fa3e7 100644
586--- a/arch/alpha/include/asm/pgalloc.h
587+++ b/arch/alpha/include/asm/pgalloc.h
588@@ -29,6 +29,12 @@ pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
589 pgd_set(pgd, pmd);
590 }
591
592+static inline void
593+pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
594+{
595+ pgd_populate(mm, pgd, pmd);
596+}
597+
598 extern pgd_t *pgd_alloc(struct mm_struct *mm);
599
600 static inline void
601diff --git a/arch/alpha/include/asm/pgtable.h b/arch/alpha/include/asm/pgtable.h
602index d8f9b7e..f6222fa 100644
603--- a/arch/alpha/include/asm/pgtable.h
604+++ b/arch/alpha/include/asm/pgtable.h
605@@ -102,6 +102,17 @@ struct vm_area_struct;
606 #define PAGE_SHARED __pgprot(_PAGE_VALID | __ACCESS_BITS)
607 #define PAGE_COPY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
608 #define PAGE_READONLY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
609+
610+#ifdef CONFIG_PAX_PAGEEXEC
611+# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOE)
612+# define PAGE_COPY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
613+# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
614+#else
615+# define PAGE_SHARED_NOEXEC PAGE_SHARED
616+# define PAGE_COPY_NOEXEC PAGE_COPY
617+# define PAGE_READONLY_NOEXEC PAGE_READONLY
618+#endif
619+
620 #define PAGE_KERNEL __pgprot(_PAGE_VALID | _PAGE_ASM | _PAGE_KRE | _PAGE_KWE)
621
622 #define _PAGE_NORMAL(x) __pgprot(_PAGE_VALID | __ACCESS_BITS | (x))
623diff --git a/arch/alpha/kernel/module.c b/arch/alpha/kernel/module.c
624index 2fd00b7..cfd5069 100644
625--- a/arch/alpha/kernel/module.c
626+++ b/arch/alpha/kernel/module.c
627@@ -160,7 +160,7 @@ apply_relocate_add(Elf64_Shdr *sechdrs, const char *strtab,
628
629 /* The small sections were sorted to the end of the segment.
630 The following should definitely cover them. */
631- gp = (u64)me->module_core + me->core_size - 0x8000;
632+ gp = (u64)me->module_core_rw + me->core_size_rw - 0x8000;
633 got = sechdrs[me->arch.gotsecindex].sh_addr;
634
635 for (i = 0; i < n; i++) {
636diff --git a/arch/alpha/kernel/osf_sys.c b/arch/alpha/kernel/osf_sys.c
637index 1402fcc..0b1abd2 100644
638--- a/arch/alpha/kernel/osf_sys.c
639+++ b/arch/alpha/kernel/osf_sys.c
640@@ -1298,10 +1298,11 @@ SYSCALL_DEFINE1(old_adjtimex, struct timex32 __user *, txc_p)
641 generic version except that we know how to honor ADDR_LIMIT_32BIT. */
642
643 static unsigned long
644-arch_get_unmapped_area_1(unsigned long addr, unsigned long len,
645- unsigned long limit)
646+arch_get_unmapped_area_1(struct file *filp, unsigned long addr, unsigned long len,
647+ unsigned long limit, unsigned long flags)
648 {
649 struct vm_unmapped_area_info info;
650+ unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
651
652 info.flags = 0;
653 info.length = len;
654@@ -1309,6 +1310,7 @@ arch_get_unmapped_area_1(unsigned long addr, unsigned long len,
655 info.high_limit = limit;
656 info.align_mask = 0;
657 info.align_offset = 0;
658+ info.threadstack_offset = offset;
659 return vm_unmapped_area(&info);
660 }
661
662@@ -1341,20 +1343,24 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
663 merely specific addresses, but regions of memory -- perhaps
664 this feature should be incorporated into all ports? */
665
666+#ifdef CONFIG_PAX_RANDMMAP
667+ if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
668+#endif
669+
670 if (addr) {
671- addr = arch_get_unmapped_area_1 (PAGE_ALIGN(addr), len, limit);
672+ addr = arch_get_unmapped_area_1 (filp, PAGE_ALIGN(addr), len, limit, flags);
673 if (addr != (unsigned long) -ENOMEM)
674 return addr;
675 }
676
677 /* Next, try allocating at TASK_UNMAPPED_BASE. */
678- addr = arch_get_unmapped_area_1 (PAGE_ALIGN(TASK_UNMAPPED_BASE),
679- len, limit);
680+ addr = arch_get_unmapped_area_1 (filp, PAGE_ALIGN(current->mm->mmap_base), len, limit, flags);
681+
682 if (addr != (unsigned long) -ENOMEM)
683 return addr;
684
685 /* Finally, try allocating in low memory. */
686- addr = arch_get_unmapped_area_1 (PAGE_SIZE, len, limit);
687+ addr = arch_get_unmapped_area_1 (filp, PAGE_SIZE, len, limit, flags);
688
689 return addr;
690 }
691diff --git a/arch/alpha/mm/fault.c b/arch/alpha/mm/fault.c
692index 98838a0..b304fb4 100644
693--- a/arch/alpha/mm/fault.c
694+++ b/arch/alpha/mm/fault.c
695@@ -53,6 +53,124 @@ __load_new_mm_context(struct mm_struct *next_mm)
696 __reload_thread(pcb);
697 }
698
699+#ifdef CONFIG_PAX_PAGEEXEC
700+/*
701+ * PaX: decide what to do with offenders (regs->pc = fault address)
702+ *
703+ * returns 1 when task should be killed
704+ * 2 when patched PLT trampoline was detected
705+ * 3 when unpatched PLT trampoline was detected
706+ */
707+static int pax_handle_fetch_fault(struct pt_regs *regs)
708+{
709+
710+#ifdef CONFIG_PAX_EMUPLT
711+ int err;
712+
713+ do { /* PaX: patched PLT emulation #1 */
714+ unsigned int ldah, ldq, jmp;
715+
716+ err = get_user(ldah, (unsigned int *)regs->pc);
717+ err |= get_user(ldq, (unsigned int *)(regs->pc+4));
718+ err |= get_user(jmp, (unsigned int *)(regs->pc+8));
719+
720+ if (err)
721+ break;
722+
723+ if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
724+ (ldq & 0xFFFF0000U) == 0xA77B0000U &&
725+ jmp == 0x6BFB0000U)
726+ {
727+ unsigned long r27, addr;
728+ unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
729+ unsigned long addrl = ldq | 0xFFFFFFFFFFFF0000UL;
730+
731+ addr = regs->r27 + ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
732+ err = get_user(r27, (unsigned long *)addr);
733+ if (err)
734+ break;
735+
736+ regs->r27 = r27;
737+ regs->pc = r27;
738+ return 2;
739+ }
740+ } while (0);
741+
742+ do { /* PaX: patched PLT emulation #2 */
743+ unsigned int ldah, lda, br;
744+
745+ err = get_user(ldah, (unsigned int *)regs->pc);
746+ err |= get_user(lda, (unsigned int *)(regs->pc+4));
747+ err |= get_user(br, (unsigned int *)(regs->pc+8));
748+
749+ if (err)
750+ break;
751+
752+ if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
753+ (lda & 0xFFFF0000U) == 0xA77B0000U &&
754+ (br & 0xFFE00000U) == 0xC3E00000U)
755+ {
756+ unsigned long addr = br | 0xFFFFFFFFFFE00000UL;
757+ unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
758+ unsigned long addrl = lda | 0xFFFFFFFFFFFF0000UL;
759+
760+ regs->r27 += ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
761+ regs->pc += 12 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
762+ return 2;
763+ }
764+ } while (0);
765+
766+ do { /* PaX: unpatched PLT emulation */
767+ unsigned int br;
768+
769+ err = get_user(br, (unsigned int *)regs->pc);
770+
771+ if (!err && (br & 0xFFE00000U) == 0xC3800000U) {
772+ unsigned int br2, ldq, nop, jmp;
773+ unsigned long addr = br | 0xFFFFFFFFFFE00000UL, resolver;
774+
775+ addr = regs->pc + 4 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
776+ err = get_user(br2, (unsigned int *)addr);
777+ err |= get_user(ldq, (unsigned int *)(addr+4));
778+ err |= get_user(nop, (unsigned int *)(addr+8));
779+ err |= get_user(jmp, (unsigned int *)(addr+12));
780+ err |= get_user(resolver, (unsigned long *)(addr+16));
781+
782+ if (err)
783+ break;
784+
785+ if (br2 == 0xC3600000U &&
786+ ldq == 0xA77B000CU &&
787+ nop == 0x47FF041FU &&
788+ jmp == 0x6B7B0000U)
789+ {
790+ regs->r28 = regs->pc+4;
791+ regs->r27 = addr+16;
792+ regs->pc = resolver;
793+ return 3;
794+ }
795+ }
796+ } while (0);
797+#endif
798+
799+ return 1;
800+}
801+
802+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
803+{
804+ unsigned long i;
805+
806+ printk(KERN_ERR "PAX: bytes at PC: ");
807+ for (i = 0; i < 5; i++) {
808+ unsigned int c;
809+ if (get_user(c, (unsigned int *)pc+i))
810+ printk(KERN_CONT "???????? ");
811+ else
812+ printk(KERN_CONT "%08x ", c);
813+ }
814+ printk("\n");
815+}
816+#endif
817
818 /*
819 * This routine handles page faults. It determines the address,
820@@ -133,8 +251,29 @@ retry:
821 good_area:
822 si_code = SEGV_ACCERR;
823 if (cause < 0) {
824- if (!(vma->vm_flags & VM_EXEC))
825+ if (!(vma->vm_flags & VM_EXEC)) {
826+
827+#ifdef CONFIG_PAX_PAGEEXEC
828+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->pc)
829+ goto bad_area;
830+
831+ up_read(&mm->mmap_sem);
832+ switch (pax_handle_fetch_fault(regs)) {
833+
834+#ifdef CONFIG_PAX_EMUPLT
835+ case 2:
836+ case 3:
837+ return;
838+#endif
839+
840+ }
841+ pax_report_fault(regs, (void *)regs->pc, (void *)rdusp());
842+ do_group_exit(SIGKILL);
843+#else
844 goto bad_area;
845+#endif
846+
847+ }
848 } else if (!cause) {
849 /* Allow reads even for write-only mappings */
850 if (!(vma->vm_flags & (VM_READ | VM_WRITE)))
851diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
852index 44298ad..29a20c0 100644
853--- a/arch/arm/Kconfig
854+++ b/arch/arm/Kconfig
855@@ -1862,7 +1862,7 @@ config ALIGNMENT_TRAP
856
857 config UACCESS_WITH_MEMCPY
858 bool "Use kernel mem{cpy,set}() for {copy_to,clear}_user()"
859- depends on MMU
860+ depends on MMU && !PAX_MEMORY_UDEREF
861 default y if CPU_FEROCEON
862 help
863 Implement faster copy_to_user and clear_user methods for CPU
864@@ -2125,6 +2125,7 @@ config XIP_PHYS_ADDR
865 config KEXEC
866 bool "Kexec system call (EXPERIMENTAL)"
867 depends on (!SMP || PM_SLEEP_SMP)
868+ depends on !GRKERNSEC_KMEM
869 help
870 kexec is a system call that implements the ability to shutdown your
871 current kernel, and to start another kernel. It is like a reboot
872diff --git a/arch/arm/include/asm/atomic.h b/arch/arm/include/asm/atomic.h
873index 62d2cb5..09d45e3 100644
874--- a/arch/arm/include/asm/atomic.h
875+++ b/arch/arm/include/asm/atomic.h
876@@ -18,17 +18,35 @@
877 #include <asm/barrier.h>
878 #include <asm/cmpxchg.h>
879
880+#ifdef CONFIG_GENERIC_ATOMIC64
881+#include <asm-generic/atomic64.h>
882+#endif
883+
884 #define ATOMIC_INIT(i) { (i) }
885
886 #ifdef __KERNEL__
887
888+#define _ASM_EXTABLE(from, to) \
889+" .pushsection __ex_table,\"a\"\n"\
890+" .align 3\n" \
891+" .long " #from ", " #to"\n" \
892+" .popsection"
893+
894 /*
895 * On ARM, ordinary assignment (str instruction) doesn't clear the local
896 * strex/ldrex monitor on some implementations. The reason we can use it for
897 * atomic_set() is the clrex or dummy strex done on every exception return.
898 */
899 #define atomic_read(v) (*(volatile int *)&(v)->counter)
900+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
901+{
902+ return v->counter;
903+}
904 #define atomic_set(v,i) (((v)->counter) = (i))
905+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
906+{
907+ v->counter = i;
908+}
909
910 #if __LINUX_ARM_ARCH__ >= 6
911
912@@ -44,6 +62,36 @@ static inline void atomic_add(int i, atomic_t *v)
913
914 prefetchw(&v->counter);
915 __asm__ __volatile__("@ atomic_add\n"
916+"1: ldrex %1, [%3]\n"
917+" adds %0, %1, %4\n"
918+
919+#ifdef CONFIG_PAX_REFCOUNT
920+" bvc 3f\n"
921+"2: bkpt 0xf103\n"
922+"3:\n"
923+#endif
924+
925+" strex %1, %0, [%3]\n"
926+" teq %1, #0\n"
927+" bne 1b"
928+
929+#ifdef CONFIG_PAX_REFCOUNT
930+"\n4:\n"
931+ _ASM_EXTABLE(2b, 4b)
932+#endif
933+
934+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
935+ : "r" (&v->counter), "Ir" (i)
936+ : "cc");
937+}
938+
939+static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
940+{
941+ unsigned long tmp;
942+ int result;
943+
944+ prefetchw(&v->counter);
945+ __asm__ __volatile__("@ atomic_add_unchecked\n"
946 "1: ldrex %0, [%3]\n"
947 " add %0, %0, %4\n"
948 " strex %1, %0, [%3]\n"
949@@ -62,6 +110,42 @@ static inline int atomic_add_return(int i, atomic_t *v)
950 smp_mb();
951
952 __asm__ __volatile__("@ atomic_add_return\n"
953+"1: ldrex %1, [%3]\n"
954+" adds %0, %1, %4\n"
955+
956+#ifdef CONFIG_PAX_REFCOUNT
957+" bvc 3f\n"
958+" mov %0, %1\n"
959+"2: bkpt 0xf103\n"
960+"3:\n"
961+#endif
962+
963+" strex %1, %0, [%3]\n"
964+" teq %1, #0\n"
965+" bne 1b"
966+
967+#ifdef CONFIG_PAX_REFCOUNT
968+"\n4:\n"
969+ _ASM_EXTABLE(2b, 4b)
970+#endif
971+
972+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
973+ : "r" (&v->counter), "Ir" (i)
974+ : "cc");
975+
976+ smp_mb();
977+
978+ return result;
979+}
980+
981+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
982+{
983+ unsigned long tmp;
984+ int result;
985+
986+ smp_mb();
987+
988+ __asm__ __volatile__("@ atomic_add_return_unchecked\n"
989 "1: ldrex %0, [%3]\n"
990 " add %0, %0, %4\n"
991 " strex %1, %0, [%3]\n"
992@@ -83,6 +167,36 @@ static inline void atomic_sub(int i, atomic_t *v)
993
994 prefetchw(&v->counter);
995 __asm__ __volatile__("@ atomic_sub\n"
996+"1: ldrex %1, [%3]\n"
997+" subs %0, %1, %4\n"
998+
999+#ifdef CONFIG_PAX_REFCOUNT
1000+" bvc 3f\n"
1001+"2: bkpt 0xf103\n"
1002+"3:\n"
1003+#endif
1004+
1005+" strex %1, %0, [%3]\n"
1006+" teq %1, #0\n"
1007+" bne 1b"
1008+
1009+#ifdef CONFIG_PAX_REFCOUNT
1010+"\n4:\n"
1011+ _ASM_EXTABLE(2b, 4b)
1012+#endif
1013+
1014+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1015+ : "r" (&v->counter), "Ir" (i)
1016+ : "cc");
1017+}
1018+
1019+static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
1020+{
1021+ unsigned long tmp;
1022+ int result;
1023+
1024+ prefetchw(&v->counter);
1025+ __asm__ __volatile__("@ atomic_sub_unchecked\n"
1026 "1: ldrex %0, [%3]\n"
1027 " sub %0, %0, %4\n"
1028 " strex %1, %0, [%3]\n"
1029@@ -101,11 +215,25 @@ static inline int atomic_sub_return(int i, atomic_t *v)
1030 smp_mb();
1031
1032 __asm__ __volatile__("@ atomic_sub_return\n"
1033-"1: ldrex %0, [%3]\n"
1034-" sub %0, %0, %4\n"
1035+"1: ldrex %1, [%3]\n"
1036+" subs %0, %1, %4\n"
1037+
1038+#ifdef CONFIG_PAX_REFCOUNT
1039+" bvc 3f\n"
1040+" mov %0, %1\n"
1041+"2: bkpt 0xf103\n"
1042+"3:\n"
1043+#endif
1044+
1045 " strex %1, %0, [%3]\n"
1046 " teq %1, #0\n"
1047 " bne 1b"
1048+
1049+#ifdef CONFIG_PAX_REFCOUNT
1050+"\n4:\n"
1051+ _ASM_EXTABLE(2b, 4b)
1052+#endif
1053+
1054 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1055 : "r" (&v->counter), "Ir" (i)
1056 : "cc");
1057@@ -138,6 +266,28 @@ static inline int atomic_cmpxchg(atomic_t *ptr, int old, int new)
1058 return oldval;
1059 }
1060
1061+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *ptr, int old, int new)
1062+{
1063+ unsigned long oldval, res;
1064+
1065+ smp_mb();
1066+
1067+ do {
1068+ __asm__ __volatile__("@ atomic_cmpxchg_unchecked\n"
1069+ "ldrex %1, [%3]\n"
1070+ "mov %0, #0\n"
1071+ "teq %1, %4\n"
1072+ "strexeq %0, %5, [%3]\n"
1073+ : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
1074+ : "r" (&ptr->counter), "Ir" (old), "r" (new)
1075+ : "cc");
1076+ } while (res);
1077+
1078+ smp_mb();
1079+
1080+ return oldval;
1081+}
1082+
1083 #else /* ARM_ARCH_6 */
1084
1085 #ifdef CONFIG_SMP
1086@@ -156,7 +306,17 @@ static inline int atomic_add_return(int i, atomic_t *v)
1087
1088 return val;
1089 }
1090+
1091+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
1092+{
1093+ return atomic_add_return(i, v);
1094+}
1095+
1096 #define atomic_add(i, v) (void) atomic_add_return(i, v)
1097+static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
1098+{
1099+ (void) atomic_add_return(i, v);
1100+}
1101
1102 static inline int atomic_sub_return(int i, atomic_t *v)
1103 {
1104@@ -171,6 +331,10 @@ static inline int atomic_sub_return(int i, atomic_t *v)
1105 return val;
1106 }
1107 #define atomic_sub(i, v) (void) atomic_sub_return(i, v)
1108+static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
1109+{
1110+ (void) atomic_sub_return(i, v);
1111+}
1112
1113 static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
1114 {
1115@@ -186,9 +350,18 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
1116 return ret;
1117 }
1118
1119+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
1120+{
1121+ return atomic_cmpxchg(v, old, new);
1122+}
1123+
1124 #endif /* __LINUX_ARM_ARCH__ */
1125
1126 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
1127+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
1128+{
1129+ return xchg(&v->counter, new);
1130+}
1131
1132 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1133 {
1134@@ -201,11 +374,27 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1135 }
1136
1137 #define atomic_inc(v) atomic_add(1, v)
1138+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
1139+{
1140+ atomic_add_unchecked(1, v);
1141+}
1142 #define atomic_dec(v) atomic_sub(1, v)
1143+static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
1144+{
1145+ atomic_sub_unchecked(1, v);
1146+}
1147
1148 #define atomic_inc_and_test(v) (atomic_add_return(1, v) == 0)
1149+static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
1150+{
1151+ return atomic_add_return_unchecked(1, v) == 0;
1152+}
1153 #define atomic_dec_and_test(v) (atomic_sub_return(1, v) == 0)
1154 #define atomic_inc_return(v) (atomic_add_return(1, v))
1155+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
1156+{
1157+ return atomic_add_return_unchecked(1, v);
1158+}
1159 #define atomic_dec_return(v) (atomic_sub_return(1, v))
1160 #define atomic_sub_and_test(i, v) (atomic_sub_return(i, v) == 0)
1161
1162@@ -221,6 +410,14 @@ typedef struct {
1163 long long counter;
1164 } atomic64_t;
1165
1166+#ifdef CONFIG_PAX_REFCOUNT
1167+typedef struct {
1168+ long long counter;
1169+} atomic64_unchecked_t;
1170+#else
1171+typedef atomic64_t atomic64_unchecked_t;
1172+#endif
1173+
1174 #define ATOMIC64_INIT(i) { (i) }
1175
1176 #ifdef CONFIG_ARM_LPAE
1177@@ -237,6 +434,19 @@ static inline long long atomic64_read(const atomic64_t *v)
1178 return result;
1179 }
1180
1181+static inline long long atomic64_read_unchecked(const atomic64_unchecked_t *v)
1182+{
1183+ long long result;
1184+
1185+ __asm__ __volatile__("@ atomic64_read_unchecked\n"
1186+" ldrd %0, %H0, [%1]"
1187+ : "=&r" (result)
1188+ : "r" (&v->counter), "Qo" (v->counter)
1189+ );
1190+
1191+ return result;
1192+}
1193+
1194 static inline void atomic64_set(atomic64_t *v, long long i)
1195 {
1196 __asm__ __volatile__("@ atomic64_set\n"
1197@@ -245,6 +455,15 @@ static inline void atomic64_set(atomic64_t *v, long long i)
1198 : "r" (&v->counter), "r" (i)
1199 );
1200 }
1201+
1202+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
1203+{
1204+ __asm__ __volatile__("@ atomic64_set_unchecked\n"
1205+" strd %2, %H2, [%1]"
1206+ : "=Qo" (v->counter)
1207+ : "r" (&v->counter), "r" (i)
1208+ );
1209+}
1210 #else
1211 static inline long long atomic64_read(const atomic64_t *v)
1212 {
1213@@ -259,6 +478,19 @@ static inline long long atomic64_read(const atomic64_t *v)
1214 return result;
1215 }
1216
1217+static inline long long atomic64_read_unchecked(const atomic64_unchecked_t *v)
1218+{
1219+ long long result;
1220+
1221+ __asm__ __volatile__("@ atomic64_read_unchecked\n"
1222+" ldrexd %0, %H0, [%1]"
1223+ : "=&r" (result)
1224+ : "r" (&v->counter), "Qo" (v->counter)
1225+ );
1226+
1227+ return result;
1228+}
1229+
1230 static inline void atomic64_set(atomic64_t *v, long long i)
1231 {
1232 long long tmp;
1233@@ -273,6 +505,21 @@ static inline void atomic64_set(atomic64_t *v, long long i)
1234 : "r" (&v->counter), "r" (i)
1235 : "cc");
1236 }
1237+
1238+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
1239+{
1240+ long long tmp;
1241+
1242+ prefetchw(&v->counter);
1243+ __asm__ __volatile__("@ atomic64_set_unchecked\n"
1244+"1: ldrexd %0, %H0, [%2]\n"
1245+" strexd %0, %3, %H3, [%2]\n"
1246+" teq %0, #0\n"
1247+" bne 1b"
1248+ : "=&r" (tmp), "=Qo" (v->counter)
1249+ : "r" (&v->counter), "r" (i)
1250+ : "cc");
1251+}
1252 #endif
1253
1254 static inline void atomic64_add(long long i, atomic64_t *v)
1255@@ -284,6 +531,37 @@ static inline void atomic64_add(long long i, atomic64_t *v)
1256 __asm__ __volatile__("@ atomic64_add\n"
1257 "1: ldrexd %0, %H0, [%3]\n"
1258 " adds %Q0, %Q0, %Q4\n"
1259+" adcs %R0, %R0, %R4\n"
1260+
1261+#ifdef CONFIG_PAX_REFCOUNT
1262+" bvc 3f\n"
1263+"2: bkpt 0xf103\n"
1264+"3:\n"
1265+#endif
1266+
1267+" strexd %1, %0, %H0, [%3]\n"
1268+" teq %1, #0\n"
1269+" bne 1b"
1270+
1271+#ifdef CONFIG_PAX_REFCOUNT
1272+"\n4:\n"
1273+ _ASM_EXTABLE(2b, 4b)
1274+#endif
1275+
1276+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1277+ : "r" (&v->counter), "r" (i)
1278+ : "cc");
1279+}
1280+
1281+static inline void atomic64_add_unchecked(long long i, atomic64_unchecked_t *v)
1282+{
1283+ long long result;
1284+ unsigned long tmp;
1285+
1286+ prefetchw(&v->counter);
1287+ __asm__ __volatile__("@ atomic64_add_unchecked\n"
1288+"1: ldrexd %0, %H0, [%3]\n"
1289+" adds %Q0, %Q0, %Q4\n"
1290 " adc %R0, %R0, %R4\n"
1291 " strexd %1, %0, %H0, [%3]\n"
1292 " teq %1, #0\n"
1293@@ -303,6 +581,44 @@ static inline long long atomic64_add_return(long long i, atomic64_t *v)
1294 __asm__ __volatile__("@ atomic64_add_return\n"
1295 "1: ldrexd %0, %H0, [%3]\n"
1296 " adds %Q0, %Q0, %Q4\n"
1297+" adcs %R0, %R0, %R4\n"
1298+
1299+#ifdef CONFIG_PAX_REFCOUNT
1300+" bvc 3f\n"
1301+" mov %0, %1\n"
1302+" mov %H0, %H1\n"
1303+"2: bkpt 0xf103\n"
1304+"3:\n"
1305+#endif
1306+
1307+" strexd %1, %0, %H0, [%3]\n"
1308+" teq %1, #0\n"
1309+" bne 1b"
1310+
1311+#ifdef CONFIG_PAX_REFCOUNT
1312+"\n4:\n"
1313+ _ASM_EXTABLE(2b, 4b)
1314+#endif
1315+
1316+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1317+ : "r" (&v->counter), "r" (i)
1318+ : "cc");
1319+
1320+ smp_mb();
1321+
1322+ return result;
1323+}
1324+
1325+static inline long long atomic64_add_return_unchecked(long long i, atomic64_unchecked_t *v)
1326+{
1327+ long long result;
1328+ unsigned long tmp;
1329+
1330+ smp_mb();
1331+
1332+ __asm__ __volatile__("@ atomic64_add_return_unchecked\n"
1333+"1: ldrexd %0, %H0, [%3]\n"
1334+" adds %Q0, %Q0, %Q4\n"
1335 " adc %R0, %R0, %R4\n"
1336 " strexd %1, %0, %H0, [%3]\n"
1337 " teq %1, #0\n"
1338@@ -325,6 +641,37 @@ static inline void atomic64_sub(long long i, atomic64_t *v)
1339 __asm__ __volatile__("@ atomic64_sub\n"
1340 "1: ldrexd %0, %H0, [%3]\n"
1341 " subs %Q0, %Q0, %Q4\n"
1342+" sbcs %R0, %R0, %R4\n"
1343+
1344+#ifdef CONFIG_PAX_REFCOUNT
1345+" bvc 3f\n"
1346+"2: bkpt 0xf103\n"
1347+"3:\n"
1348+#endif
1349+
1350+" strexd %1, %0, %H0, [%3]\n"
1351+" teq %1, #0\n"
1352+" bne 1b"
1353+
1354+#ifdef CONFIG_PAX_REFCOUNT
1355+"\n4:\n"
1356+ _ASM_EXTABLE(2b, 4b)
1357+#endif
1358+
1359+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1360+ : "r" (&v->counter), "r" (i)
1361+ : "cc");
1362+}
1363+
1364+static inline void atomic64_sub_unchecked(long long i, atomic64_unchecked_t *v)
1365+{
1366+ long long result;
1367+ unsigned long tmp;
1368+
1369+ prefetchw(&v->counter);
1370+ __asm__ __volatile__("@ atomic64_sub_unchecked\n"
1371+"1: ldrexd %0, %H0, [%3]\n"
1372+" subs %Q0, %Q0, %Q4\n"
1373 " sbc %R0, %R0, %R4\n"
1374 " strexd %1, %0, %H0, [%3]\n"
1375 " teq %1, #0\n"
1376@@ -344,16 +691,29 @@ static inline long long atomic64_sub_return(long long i, atomic64_t *v)
1377 __asm__ __volatile__("@ atomic64_sub_return\n"
1378 "1: ldrexd %0, %H0, [%3]\n"
1379 " subs %Q0, %Q0, %Q4\n"
1380-" sbc %R0, %R0, %R4\n"
1381+" sbcs %R0, %R0, %R4\n"
1382+
1383+#ifdef CONFIG_PAX_REFCOUNT
1384+" bvc 3f\n"
1385+" mov %0, %1\n"
1386+" mov %H0, %H1\n"
1387+"2: bkpt 0xf103\n"
1388+"3:\n"
1389+#endif
1390+
1391 " strexd %1, %0, %H0, [%3]\n"
1392 " teq %1, #0\n"
1393 " bne 1b"
1394+
1395+#ifdef CONFIG_PAX_REFCOUNT
1396+"\n4:\n"
1397+ _ASM_EXTABLE(2b, 4b)
1398+#endif
1399+
1400 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1401 : "r" (&v->counter), "r" (i)
1402 : "cc");
1403
1404- smp_mb();
1405-
1406 return result;
1407 }
1408
1409@@ -382,6 +742,31 @@ static inline long long atomic64_cmpxchg(atomic64_t *ptr, long long old,
1410 return oldval;
1411 }
1412
1413+static inline long long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *ptr, long long old,
1414+ long long new)
1415+{
1416+ long long oldval;
1417+ unsigned long res;
1418+
1419+ smp_mb();
1420+
1421+ do {
1422+ __asm__ __volatile__("@ atomic64_cmpxchg_unchecked\n"
1423+ "ldrexd %1, %H1, [%3]\n"
1424+ "mov %0, #0\n"
1425+ "teq %1, %4\n"
1426+ "teqeq %H1, %H4\n"
1427+ "strexdeq %0, %5, %H5, [%3]"
1428+ : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
1429+ : "r" (&ptr->counter), "r" (old), "r" (new)
1430+ : "cc");
1431+ } while (res);
1432+
1433+ smp_mb();
1434+
1435+ return oldval;
1436+}
1437+
1438 static inline long long atomic64_xchg(atomic64_t *ptr, long long new)
1439 {
1440 long long result;
1441@@ -406,20 +791,34 @@ static inline long long atomic64_xchg(atomic64_t *ptr, long long new)
1442 static inline long long atomic64_dec_if_positive(atomic64_t *v)
1443 {
1444 long long result;
1445- unsigned long tmp;
1446+ u64 tmp;
1447
1448 smp_mb();
1449
1450 __asm__ __volatile__("@ atomic64_dec_if_positive\n"
1451-"1: ldrexd %0, %H0, [%3]\n"
1452-" subs %Q0, %Q0, #1\n"
1453-" sbc %R0, %R0, #0\n"
1454+"1: ldrexd %1, %H1, [%3]\n"
1455+" subs %Q0, %Q1, #1\n"
1456+" sbcs %R0, %R1, #0\n"
1457+
1458+#ifdef CONFIG_PAX_REFCOUNT
1459+" bvc 3f\n"
1460+" mov %Q0, %Q1\n"
1461+" mov %R0, %R1\n"
1462+"2: bkpt 0xf103\n"
1463+"3:\n"
1464+#endif
1465+
1466 " teq %R0, #0\n"
1467-" bmi 2f\n"
1468+" bmi 4f\n"
1469 " strexd %1, %0, %H0, [%3]\n"
1470 " teq %1, #0\n"
1471 " bne 1b\n"
1472-"2:"
1473+"4:\n"
1474+
1475+#ifdef CONFIG_PAX_REFCOUNT
1476+ _ASM_EXTABLE(2b, 4b)
1477+#endif
1478+
1479 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1480 : "r" (&v->counter)
1481 : "cc");
1482@@ -442,13 +841,25 @@ static inline int atomic64_add_unless(atomic64_t *v, long long a, long long u)
1483 " teq %0, %5\n"
1484 " teqeq %H0, %H5\n"
1485 " moveq %1, #0\n"
1486-" beq 2f\n"
1487+" beq 4f\n"
1488 " adds %Q0, %Q0, %Q6\n"
1489-" adc %R0, %R0, %R6\n"
1490+" adcs %R0, %R0, %R6\n"
1491+
1492+#ifdef CONFIG_PAX_REFCOUNT
1493+" bvc 3f\n"
1494+"2: bkpt 0xf103\n"
1495+"3:\n"
1496+#endif
1497+
1498 " strexd %2, %0, %H0, [%4]\n"
1499 " teq %2, #0\n"
1500 " bne 1b\n"
1501-"2:"
1502+"4:\n"
1503+
1504+#ifdef CONFIG_PAX_REFCOUNT
1505+ _ASM_EXTABLE(2b, 4b)
1506+#endif
1507+
1508 : "=&r" (val), "+r" (ret), "=&r" (tmp), "+Qo" (v->counter)
1509 : "r" (&v->counter), "r" (u), "r" (a)
1510 : "cc");
1511@@ -461,10 +872,13 @@ static inline int atomic64_add_unless(atomic64_t *v, long long a, long long u)
1512
1513 #define atomic64_add_negative(a, v) (atomic64_add_return((a), (v)) < 0)
1514 #define atomic64_inc(v) atomic64_add(1LL, (v))
1515+#define atomic64_inc_unchecked(v) atomic64_add_unchecked(1LL, (v))
1516 #define atomic64_inc_return(v) atomic64_add_return(1LL, (v))
1517+#define atomic64_inc_return_unchecked(v) atomic64_add_return_unchecked(1LL, (v))
1518 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
1519 #define atomic64_sub_and_test(a, v) (atomic64_sub_return((a), (v)) == 0)
1520 #define atomic64_dec(v) atomic64_sub(1LL, (v))
1521+#define atomic64_dec_unchecked(v) atomic64_sub_unchecked(1LL, (v))
1522 #define atomic64_dec_return(v) atomic64_sub_return(1LL, (v))
1523 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
1524 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
1525diff --git a/arch/arm/include/asm/cache.h b/arch/arm/include/asm/cache.h
1526index 75fe66b..ba3dee4 100644
1527--- a/arch/arm/include/asm/cache.h
1528+++ b/arch/arm/include/asm/cache.h
1529@@ -4,8 +4,10 @@
1530 #ifndef __ASMARM_CACHE_H
1531 #define __ASMARM_CACHE_H
1532
1533+#include <linux/const.h>
1534+
1535 #define L1_CACHE_SHIFT CONFIG_ARM_L1_CACHE_SHIFT
1536-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
1537+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
1538
1539 /*
1540 * Memory returned by kmalloc() may be used for DMA, so we must make
1541@@ -24,5 +26,6 @@
1542 #endif
1543
1544 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
1545+#define __read_only __attribute__ ((__section__(".data..read_only")))
1546
1547 #endif
1548diff --git a/arch/arm/include/asm/cacheflush.h b/arch/arm/include/asm/cacheflush.h
1549index 8b8b616..d973d24 100644
1550--- a/arch/arm/include/asm/cacheflush.h
1551+++ b/arch/arm/include/asm/cacheflush.h
1552@@ -116,7 +116,7 @@ struct cpu_cache_fns {
1553 void (*dma_unmap_area)(const void *, size_t, int);
1554
1555 void (*dma_flush_range)(const void *, const void *);
1556-};
1557+} __no_const;
1558
1559 /*
1560 * Select the calling method
1561diff --git a/arch/arm/include/asm/checksum.h b/arch/arm/include/asm/checksum.h
1562index 5233151..87a71fa 100644
1563--- a/arch/arm/include/asm/checksum.h
1564+++ b/arch/arm/include/asm/checksum.h
1565@@ -37,7 +37,19 @@ __wsum
1566 csum_partial_copy_nocheck(const void *src, void *dst, int len, __wsum sum);
1567
1568 __wsum
1569-csum_partial_copy_from_user(const void __user *src, void *dst, int len, __wsum sum, int *err_ptr);
1570+__csum_partial_copy_from_user(const void __user *src, void *dst, int len, __wsum sum, int *err_ptr);
1571+
1572+static inline __wsum
1573+csum_partial_copy_from_user(const void __user *src, void *dst, int len, __wsum sum, int *err_ptr)
1574+{
1575+ __wsum ret;
1576+ pax_open_userland();
1577+ ret = __csum_partial_copy_from_user(src, dst, len, sum, err_ptr);
1578+ pax_close_userland();
1579+ return ret;
1580+}
1581+
1582+
1583
1584 /*
1585 * Fold a partial checksum without adding pseudo headers
1586diff --git a/arch/arm/include/asm/cmpxchg.h b/arch/arm/include/asm/cmpxchg.h
1587index df2fbba..63fe3e1 100644
1588--- a/arch/arm/include/asm/cmpxchg.h
1589+++ b/arch/arm/include/asm/cmpxchg.h
1590@@ -102,6 +102,8 @@ static inline unsigned long __xchg(unsigned long x, volatile void *ptr, int size
1591
1592 #define xchg(ptr,x) \
1593 ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
1594+#define xchg_unchecked(ptr,x) \
1595+ ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
1596
1597 #include <asm-generic/cmpxchg-local.h>
1598
1599diff --git a/arch/arm/include/asm/domain.h b/arch/arm/include/asm/domain.h
1600index 6ddbe44..b5e38b1 100644
1601--- a/arch/arm/include/asm/domain.h
1602+++ b/arch/arm/include/asm/domain.h
1603@@ -48,18 +48,37 @@
1604 * Domain types
1605 */
1606 #define DOMAIN_NOACCESS 0
1607-#define DOMAIN_CLIENT 1
1608 #ifdef CONFIG_CPU_USE_DOMAINS
1609+#define DOMAIN_USERCLIENT 1
1610+#define DOMAIN_KERNELCLIENT 1
1611 #define DOMAIN_MANAGER 3
1612+#define DOMAIN_VECTORS DOMAIN_USER
1613 #else
1614+
1615+#ifdef CONFIG_PAX_KERNEXEC
1616 #define DOMAIN_MANAGER 1
1617+#define DOMAIN_KERNEXEC 3
1618+#else
1619+#define DOMAIN_MANAGER 1
1620+#endif
1621+
1622+#ifdef CONFIG_PAX_MEMORY_UDEREF
1623+#define DOMAIN_USERCLIENT 0
1624+#define DOMAIN_UDEREF 1
1625+#define DOMAIN_VECTORS DOMAIN_KERNEL
1626+#else
1627+#define DOMAIN_USERCLIENT 1
1628+#define DOMAIN_VECTORS DOMAIN_USER
1629+#endif
1630+#define DOMAIN_KERNELCLIENT 1
1631+
1632 #endif
1633
1634 #define domain_val(dom,type) ((type) << (2*(dom)))
1635
1636 #ifndef __ASSEMBLY__
1637
1638-#ifdef CONFIG_CPU_USE_DOMAINS
1639+#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
1640 static inline void set_domain(unsigned val)
1641 {
1642 asm volatile(
1643@@ -68,15 +87,7 @@ static inline void set_domain(unsigned val)
1644 isb();
1645 }
1646
1647-#define modify_domain(dom,type) \
1648- do { \
1649- struct thread_info *thread = current_thread_info(); \
1650- unsigned int domain = thread->cpu_domain; \
1651- domain &= ~domain_val(dom, DOMAIN_MANAGER); \
1652- thread->cpu_domain = domain | domain_val(dom, type); \
1653- set_domain(thread->cpu_domain); \
1654- } while (0)
1655-
1656+extern void modify_domain(unsigned int dom, unsigned int type);
1657 #else
1658 static inline void set_domain(unsigned val) { }
1659 static inline void modify_domain(unsigned dom, unsigned type) { }
1660diff --git a/arch/arm/include/asm/elf.h b/arch/arm/include/asm/elf.h
1661index f4b46d3..abc9b2b 100644
1662--- a/arch/arm/include/asm/elf.h
1663+++ b/arch/arm/include/asm/elf.h
1664@@ -114,7 +114,14 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1665 the loader. We need to make sure that it is out of the way of the program
1666 that it will "exec", and that there is sufficient room for the brk. */
1667
1668-#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
1669+#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
1670+
1671+#ifdef CONFIG_PAX_ASLR
1672+#define PAX_ELF_ET_DYN_BASE 0x00008000UL
1673+
1674+#define PAX_DELTA_MMAP_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1675+#define PAX_DELTA_STACK_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1676+#endif
1677
1678 /* When the program starts, a1 contains a pointer to a function to be
1679 registered with atexit, as per the SVR4 ABI. A value of 0 means we
1680@@ -124,10 +131,6 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1681 extern void elf_set_personality(const struct elf32_hdr *);
1682 #define SET_PERSONALITY(ex) elf_set_personality(&(ex))
1683
1684-struct mm_struct;
1685-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
1686-#define arch_randomize_brk arch_randomize_brk
1687-
1688 #ifdef CONFIG_MMU
1689 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
1690 struct linux_binprm;
1691diff --git a/arch/arm/include/asm/fncpy.h b/arch/arm/include/asm/fncpy.h
1692index de53547..52b9a28 100644
1693--- a/arch/arm/include/asm/fncpy.h
1694+++ b/arch/arm/include/asm/fncpy.h
1695@@ -81,7 +81,9 @@
1696 BUG_ON((uintptr_t)(dest_buf) & (FNCPY_ALIGN - 1) || \
1697 (__funcp_address & ~(uintptr_t)1 & (FNCPY_ALIGN - 1))); \
1698 \
1699+ pax_open_kernel(); \
1700 memcpy(dest_buf, (void const *)(__funcp_address & ~1), size); \
1701+ pax_close_kernel(); \
1702 flush_icache_range((unsigned long)(dest_buf), \
1703 (unsigned long)(dest_buf) + (size)); \
1704 \
1705diff --git a/arch/arm/include/asm/futex.h b/arch/arm/include/asm/futex.h
1706index 2aff798..099eb15 100644
1707--- a/arch/arm/include/asm/futex.h
1708+++ b/arch/arm/include/asm/futex.h
1709@@ -45,6 +45,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1710 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
1711 return -EFAULT;
1712
1713+ pax_open_userland();
1714+
1715 smp_mb();
1716 __asm__ __volatile__("@futex_atomic_cmpxchg_inatomic\n"
1717 "1: ldrex %1, [%4]\n"
1718@@ -60,6 +62,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1719 : "cc", "memory");
1720 smp_mb();
1721
1722+ pax_close_userland();
1723+
1724 *uval = val;
1725 return ret;
1726 }
1727@@ -90,6 +94,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1728 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
1729 return -EFAULT;
1730
1731+ pax_open_userland();
1732+
1733 __asm__ __volatile__("@futex_atomic_cmpxchg_inatomic\n"
1734 "1: " TUSER(ldr) " %1, [%4]\n"
1735 " teq %1, %2\n"
1736@@ -100,6 +106,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1737 : "r" (oldval), "r" (newval), "r" (uaddr), "Ir" (-EFAULT)
1738 : "cc", "memory");
1739
1740+ pax_close_userland();
1741+
1742 *uval = val;
1743 return ret;
1744 }
1745@@ -122,6 +130,7 @@ futex_atomic_op_inuser (int encoded_op, u32 __user *uaddr)
1746 return -EFAULT;
1747
1748 pagefault_disable(); /* implies preempt_disable() */
1749+ pax_open_userland();
1750
1751 switch (op) {
1752 case FUTEX_OP_SET:
1753@@ -143,6 +152,7 @@ futex_atomic_op_inuser (int encoded_op, u32 __user *uaddr)
1754 ret = -ENOSYS;
1755 }
1756
1757+ pax_close_userland();
1758 pagefault_enable(); /* subsumes preempt_enable() */
1759
1760 if (!ret) {
1761diff --git a/arch/arm/include/asm/kmap_types.h b/arch/arm/include/asm/kmap_types.h
1762index 83eb2f7..ed77159 100644
1763--- a/arch/arm/include/asm/kmap_types.h
1764+++ b/arch/arm/include/asm/kmap_types.h
1765@@ -4,6 +4,6 @@
1766 /*
1767 * This is the "bare minimum". AIO seems to require this.
1768 */
1769-#define KM_TYPE_NR 16
1770+#define KM_TYPE_NR 17
1771
1772 #endif
1773diff --git a/arch/arm/include/asm/mach/dma.h b/arch/arm/include/asm/mach/dma.h
1774index 9e614a1..3302cca 100644
1775--- a/arch/arm/include/asm/mach/dma.h
1776+++ b/arch/arm/include/asm/mach/dma.h
1777@@ -22,7 +22,7 @@ struct dma_ops {
1778 int (*residue)(unsigned int, dma_t *); /* optional */
1779 int (*setspeed)(unsigned int, dma_t *, int); /* optional */
1780 const char *type;
1781-};
1782+} __do_const;
1783
1784 struct dma_struct {
1785 void *addr; /* single DMA address */
1786diff --git a/arch/arm/include/asm/mach/map.h b/arch/arm/include/asm/mach/map.h
1787index f98c7f3..e5c626d 100644
1788--- a/arch/arm/include/asm/mach/map.h
1789+++ b/arch/arm/include/asm/mach/map.h
1790@@ -23,17 +23,19 @@ struct map_desc {
1791
1792 /* types 0-3 are defined in asm/io.h */
1793 enum {
1794- MT_UNCACHED = 4,
1795- MT_CACHECLEAN,
1796- MT_MINICLEAN,
1797+ MT_UNCACHED_RW = 4,
1798+ MT_CACHECLEAN_RO,
1799+ MT_MINICLEAN_RO,
1800 MT_LOW_VECTORS,
1801 MT_HIGH_VECTORS,
1802- MT_MEMORY_RWX,
1803+ __MT_MEMORY_RWX,
1804 MT_MEMORY_RW,
1805- MT_ROM,
1806- MT_MEMORY_RWX_NONCACHED,
1807+ MT_MEMORY_RX,
1808+ MT_ROM_RX,
1809+ MT_MEMORY_RW_NONCACHED,
1810+ MT_MEMORY_RX_NONCACHED,
1811 MT_MEMORY_RW_DTCM,
1812- MT_MEMORY_RWX_ITCM,
1813+ MT_MEMORY_RX_ITCM,
1814 MT_MEMORY_RW_SO,
1815 MT_MEMORY_DMA_READY,
1816 };
1817diff --git a/arch/arm/include/asm/outercache.h b/arch/arm/include/asm/outercache.h
1818index f94784f..9a09a4a 100644
1819--- a/arch/arm/include/asm/outercache.h
1820+++ b/arch/arm/include/asm/outercache.h
1821@@ -35,7 +35,7 @@ struct outer_cache_fns {
1822 #endif
1823 void (*set_debug)(unsigned long);
1824 void (*resume)(void);
1825-};
1826+} __no_const;
1827
1828 extern struct outer_cache_fns outer_cache;
1829
1830diff --git a/arch/arm/include/asm/page.h b/arch/arm/include/asm/page.h
1831index 4355f0e..cd9168e 100644
1832--- a/arch/arm/include/asm/page.h
1833+++ b/arch/arm/include/asm/page.h
1834@@ -23,6 +23,7 @@
1835
1836 #else
1837
1838+#include <linux/compiler.h>
1839 #include <asm/glue.h>
1840
1841 /*
1842@@ -114,7 +115,7 @@ struct cpu_user_fns {
1843 void (*cpu_clear_user_highpage)(struct page *page, unsigned long vaddr);
1844 void (*cpu_copy_user_highpage)(struct page *to, struct page *from,
1845 unsigned long vaddr, struct vm_area_struct *vma);
1846-};
1847+} __no_const;
1848
1849 #ifdef MULTI_USER
1850 extern struct cpu_user_fns cpu_user;
1851diff --git a/arch/arm/include/asm/pgalloc.h b/arch/arm/include/asm/pgalloc.h
1852index 78a7793..e3dc06c 100644
1853--- a/arch/arm/include/asm/pgalloc.h
1854+++ b/arch/arm/include/asm/pgalloc.h
1855@@ -17,6 +17,7 @@
1856 #include <asm/processor.h>
1857 #include <asm/cacheflush.h>
1858 #include <asm/tlbflush.h>
1859+#include <asm/system_info.h>
1860
1861 #define check_pgt_cache() do { } while (0)
1862
1863@@ -43,6 +44,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1864 set_pud(pud, __pud(__pa(pmd) | PMD_TYPE_TABLE));
1865 }
1866
1867+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1868+{
1869+ pud_populate(mm, pud, pmd);
1870+}
1871+
1872 #else /* !CONFIG_ARM_LPAE */
1873
1874 /*
1875@@ -51,6 +57,7 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1876 #define pmd_alloc_one(mm,addr) ({ BUG(); ((pmd_t *)2); })
1877 #define pmd_free(mm, pmd) do { } while (0)
1878 #define pud_populate(mm,pmd,pte) BUG()
1879+#define pud_populate_kernel(mm,pmd,pte) BUG()
1880
1881 #endif /* CONFIG_ARM_LPAE */
1882
1883@@ -128,6 +135,19 @@ static inline void pte_free(struct mm_struct *mm, pgtable_t pte)
1884 __free_page(pte);
1885 }
1886
1887+static inline void __section_update(pmd_t *pmdp, unsigned long addr, pmdval_t prot)
1888+{
1889+#ifdef CONFIG_ARM_LPAE
1890+ pmdp[0] = __pmd(pmd_val(pmdp[0]) | prot);
1891+#else
1892+ if (addr & SECTION_SIZE)
1893+ pmdp[1] = __pmd(pmd_val(pmdp[1]) | prot);
1894+ else
1895+ pmdp[0] = __pmd(pmd_val(pmdp[0]) | prot);
1896+#endif
1897+ flush_pmd_entry(pmdp);
1898+}
1899+
1900 static inline void __pmd_populate(pmd_t *pmdp, phys_addr_t pte,
1901 pmdval_t prot)
1902 {
1903@@ -157,7 +177,7 @@ pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmdp, pte_t *ptep)
1904 static inline void
1905 pmd_populate(struct mm_struct *mm, pmd_t *pmdp, pgtable_t ptep)
1906 {
1907- __pmd_populate(pmdp, page_to_phys(ptep), _PAGE_USER_TABLE);
1908+ __pmd_populate(pmdp, page_to_phys(ptep), _PAGE_USER_TABLE | __supported_pmd_mask);
1909 }
1910 #define pmd_pgtable(pmd) pmd_page(pmd)
1911
1912diff --git a/arch/arm/include/asm/pgtable-2level-hwdef.h b/arch/arm/include/asm/pgtable-2level-hwdef.h
1913index 5cfba15..f415e1a 100644
1914--- a/arch/arm/include/asm/pgtable-2level-hwdef.h
1915+++ b/arch/arm/include/asm/pgtable-2level-hwdef.h
1916@@ -20,12 +20,15 @@
1917 #define PMD_TYPE_FAULT (_AT(pmdval_t, 0) << 0)
1918 #define PMD_TYPE_TABLE (_AT(pmdval_t, 1) << 0)
1919 #define PMD_TYPE_SECT (_AT(pmdval_t, 2) << 0)
1920+#define PMD_PXNTABLE (_AT(pmdval_t, 1) << 2) /* v7 */
1921 #define PMD_BIT4 (_AT(pmdval_t, 1) << 4)
1922 #define PMD_DOMAIN(x) (_AT(pmdval_t, (x)) << 5)
1923 #define PMD_PROTECTION (_AT(pmdval_t, 1) << 9) /* v5 */
1924+
1925 /*
1926 * - section
1927 */
1928+#define PMD_SECT_PXN (_AT(pmdval_t, 1) << 0) /* v7 */
1929 #define PMD_SECT_BUFFERABLE (_AT(pmdval_t, 1) << 2)
1930 #define PMD_SECT_CACHEABLE (_AT(pmdval_t, 1) << 3)
1931 #define PMD_SECT_XN (_AT(pmdval_t, 1) << 4) /* v6 */
1932@@ -37,6 +40,7 @@
1933 #define PMD_SECT_nG (_AT(pmdval_t, 1) << 17) /* v6 */
1934 #define PMD_SECT_SUPER (_AT(pmdval_t, 1) << 18) /* v6 */
1935 #define PMD_SECT_AF (_AT(pmdval_t, 0))
1936+#define PMD_SECT_RDONLY (_AT(pmdval_t, 0))
1937
1938 #define PMD_SECT_UNCACHED (_AT(pmdval_t, 0))
1939 #define PMD_SECT_BUFFERED (PMD_SECT_BUFFERABLE)
1940@@ -66,6 +70,7 @@
1941 * - extended small page/tiny page
1942 */
1943 #define PTE_EXT_XN (_AT(pteval_t, 1) << 0) /* v6 */
1944+#define PTE_EXT_PXN (_AT(pteval_t, 1) << 2) /* v7 */
1945 #define PTE_EXT_AP_MASK (_AT(pteval_t, 3) << 4)
1946 #define PTE_EXT_AP0 (_AT(pteval_t, 1) << 4)
1947 #define PTE_EXT_AP1 (_AT(pteval_t, 2) << 4)
1948diff --git a/arch/arm/include/asm/pgtable-2level.h b/arch/arm/include/asm/pgtable-2level.h
1949index 219ac88..73ec32a 100644
1950--- a/arch/arm/include/asm/pgtable-2level.h
1951+++ b/arch/arm/include/asm/pgtable-2level.h
1952@@ -126,6 +126,9 @@
1953 #define L_PTE_SHARED (_AT(pteval_t, 1) << 10) /* shared(v6), coherent(xsc3) */
1954 #define L_PTE_NONE (_AT(pteval_t, 1) << 11)
1955
1956+/* Two-level page tables only have PXN in the PGD, not in the PTE. */
1957+#define L_PTE_PXN (_AT(pteval_t, 0))
1958+
1959 /*
1960 * These are the memory types, defined to be compatible with
1961 * pre-ARMv6 CPUs cacheable and bufferable bits: XXCB
1962diff --git a/arch/arm/include/asm/pgtable-3level-hwdef.h b/arch/arm/include/asm/pgtable-3level-hwdef.h
1963index 626989f..9d67a33 100644
1964--- a/arch/arm/include/asm/pgtable-3level-hwdef.h
1965+++ b/arch/arm/include/asm/pgtable-3level-hwdef.h
1966@@ -75,6 +75,7 @@
1967 #define PTE_EXT_SHARED (_AT(pteval_t, 3) << 8) /* SH[1:0], inner shareable */
1968 #define PTE_EXT_AF (_AT(pteval_t, 1) << 10) /* Access Flag */
1969 #define PTE_EXT_NG (_AT(pteval_t, 1) << 11) /* nG */
1970+#define PTE_EXT_PXN (_AT(pteval_t, 1) << 53) /* PXN */
1971 #define PTE_EXT_XN (_AT(pteval_t, 1) << 54) /* XN */
1972
1973 /*
1974diff --git a/arch/arm/include/asm/pgtable-3level.h b/arch/arm/include/asm/pgtable-3level.h
1975index 85c60ad..b0bbd7e 100644
1976--- a/arch/arm/include/asm/pgtable-3level.h
1977+++ b/arch/arm/include/asm/pgtable-3level.h
1978@@ -82,6 +82,7 @@
1979 #define L_PTE_RDONLY (_AT(pteval_t, 1) << 7) /* AP[2] */
1980 #define L_PTE_SHARED (_AT(pteval_t, 3) << 8) /* SH[1:0], inner shareable */
1981 #define L_PTE_YOUNG (_AT(pteval_t, 1) << 10) /* AF */
1982+#define L_PTE_PXN (_AT(pteval_t, 1) << 53) /* PXN */
1983 #define L_PTE_XN (_AT(pteval_t, 1) << 54) /* XN */
1984 #define L_PTE_DIRTY (_AT(pteval_t, 1) << 55) /* unused */
1985 #define L_PTE_SPECIAL (_AT(pteval_t, 1) << 56) /* unused */
1986@@ -95,6 +96,7 @@
1987 /*
1988 * To be used in assembly code with the upper page attributes.
1989 */
1990+#define L_PTE_PXN_HIGH (1 << (53 - 32))
1991 #define L_PTE_XN_HIGH (1 << (54 - 32))
1992 #define L_PTE_DIRTY_HIGH (1 << (55 - 32))
1993
1994diff --git a/arch/arm/include/asm/pgtable.h b/arch/arm/include/asm/pgtable.h
1995index 7d59b52..27a12f8 100644
1996--- a/arch/arm/include/asm/pgtable.h
1997+++ b/arch/arm/include/asm/pgtable.h
1998@@ -33,6 +33,9 @@
1999 #include <asm/pgtable-2level.h>
2000 #endif
2001
2002+#define ktla_ktva(addr) (addr)
2003+#define ktva_ktla(addr) (addr)
2004+
2005 /*
2006 * Just any arbitrary offset to the start of the vmalloc VM area: the
2007 * current 8MB value just means that there will be a 8MB "hole" after the
2008@@ -48,6 +51,9 @@
2009 #define LIBRARY_TEXT_START 0x0c000000
2010
2011 #ifndef __ASSEMBLY__
2012+extern pteval_t __supported_pte_mask;
2013+extern pmdval_t __supported_pmd_mask;
2014+
2015 extern void __pte_error(const char *file, int line, pte_t);
2016 extern void __pmd_error(const char *file, int line, pmd_t);
2017 extern void __pgd_error(const char *file, int line, pgd_t);
2018@@ -56,6 +62,48 @@ extern void __pgd_error(const char *file, int line, pgd_t);
2019 #define pmd_ERROR(pmd) __pmd_error(__FILE__, __LINE__, pmd)
2020 #define pgd_ERROR(pgd) __pgd_error(__FILE__, __LINE__, pgd)
2021
2022+#define __HAVE_ARCH_PAX_OPEN_KERNEL
2023+#define __HAVE_ARCH_PAX_CLOSE_KERNEL
2024+
2025+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2026+#include <asm/domain.h>
2027+#include <linux/thread_info.h>
2028+#include <linux/preempt.h>
2029+
2030+static inline int test_domain(int domain, int domaintype)
2031+{
2032+ return ((current_thread_info()->cpu_domain) & domain_val(domain, 3)) == domain_val(domain, domaintype);
2033+}
2034+#endif
2035+
2036+#ifdef CONFIG_PAX_KERNEXEC
2037+static inline unsigned long pax_open_kernel(void) {
2038+#ifdef CONFIG_ARM_LPAE
2039+ /* TODO */
2040+#else
2041+ preempt_disable();
2042+ BUG_ON(test_domain(DOMAIN_KERNEL, DOMAIN_KERNEXEC));
2043+ modify_domain(DOMAIN_KERNEL, DOMAIN_KERNEXEC);
2044+#endif
2045+ return 0;
2046+}
2047+
2048+static inline unsigned long pax_close_kernel(void) {
2049+#ifdef CONFIG_ARM_LPAE
2050+ /* TODO */
2051+#else
2052+ BUG_ON(test_domain(DOMAIN_KERNEL, DOMAIN_MANAGER));
2053+ /* DOMAIN_MANAGER = "client" under KERNEXEC */
2054+ modify_domain(DOMAIN_KERNEL, DOMAIN_MANAGER);
2055+ preempt_enable_no_resched();
2056+#endif
2057+ return 0;
2058+}
2059+#else
2060+static inline unsigned long pax_open_kernel(void) { return 0; }
2061+static inline unsigned long pax_close_kernel(void) { return 0; }
2062+#endif
2063+
2064 /*
2065 * This is the lowest virtual address we can permit any user space
2066 * mapping to be mapped at. This is particularly important for
2067@@ -75,8 +123,8 @@ extern void __pgd_error(const char *file, int line, pgd_t);
2068 /*
2069 * The pgprot_* and protection_map entries will be fixed up in runtime
2070 * to include the cachable and bufferable bits based on memory policy,
2071- * as well as any architecture dependent bits like global/ASID and SMP
2072- * shared mapping bits.
2073+ * as well as any architecture dependent bits like global/ASID, PXN,
2074+ * and SMP shared mapping bits.
2075 */
2076 #define _L_PTE_DEFAULT L_PTE_PRESENT | L_PTE_YOUNG
2077
2078@@ -262,7 +310,7 @@ static inline pte_t pte_mkspecial(pte_t pte) { return pte; }
2079 static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
2080 {
2081 const pteval_t mask = L_PTE_XN | L_PTE_RDONLY | L_PTE_USER |
2082- L_PTE_NONE | L_PTE_VALID;
2083+ L_PTE_NONE | L_PTE_VALID | __supported_pte_mask;
2084 pte_val(pte) = (pte_val(pte) & ~mask) | (pgprot_val(newprot) & mask);
2085 return pte;
2086 }
2087diff --git a/arch/arm/include/asm/psci.h b/arch/arm/include/asm/psci.h
2088index c4ae171..ea0c0c2 100644
2089--- a/arch/arm/include/asm/psci.h
2090+++ b/arch/arm/include/asm/psci.h
2091@@ -29,7 +29,7 @@ struct psci_operations {
2092 int (*cpu_off)(struct psci_power_state state);
2093 int (*cpu_on)(unsigned long cpuid, unsigned long entry_point);
2094 int (*migrate)(unsigned long cpuid);
2095-};
2096+} __no_const;
2097
2098 extern struct psci_operations psci_ops;
2099 extern struct smp_operations psci_smp_ops;
2100diff --git a/arch/arm/include/asm/smp.h b/arch/arm/include/asm/smp.h
2101index 22a3b9b..7f214ee 100644
2102--- a/arch/arm/include/asm/smp.h
2103+++ b/arch/arm/include/asm/smp.h
2104@@ -112,7 +112,7 @@ struct smp_operations {
2105 int (*cpu_disable)(unsigned int cpu);
2106 #endif
2107 #endif
2108-};
2109+} __no_const;
2110
2111 /*
2112 * set platform specific SMP operations
2113diff --git a/arch/arm/include/asm/thread_info.h b/arch/arm/include/asm/thread_info.h
2114index 71a06b2..8bb9ae1 100644
2115--- a/arch/arm/include/asm/thread_info.h
2116+++ b/arch/arm/include/asm/thread_info.h
2117@@ -88,9 +88,9 @@ struct thread_info {
2118 .flags = 0, \
2119 .preempt_count = INIT_PREEMPT_COUNT, \
2120 .addr_limit = KERNEL_DS, \
2121- .cpu_domain = domain_val(DOMAIN_USER, DOMAIN_MANAGER) | \
2122- domain_val(DOMAIN_KERNEL, DOMAIN_MANAGER) | \
2123- domain_val(DOMAIN_IO, DOMAIN_CLIENT), \
2124+ .cpu_domain = domain_val(DOMAIN_USER, DOMAIN_USERCLIENT) | \
2125+ domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT) | \
2126+ domain_val(DOMAIN_IO, DOMAIN_KERNELCLIENT), \
2127 .restart_block = { \
2128 .fn = do_no_restart_syscall, \
2129 }, \
2130@@ -157,7 +157,11 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
2131 #define TIF_SYSCALL_AUDIT 9
2132 #define TIF_SYSCALL_TRACEPOINT 10
2133 #define TIF_SECCOMP 11 /* seccomp syscall filtering active */
2134-#define TIF_NOHZ 12 /* in adaptive nohz mode */
2135+/* within 8 bits of TIF_SYSCALL_TRACE
2136+ * to meet flexible second operand requirements
2137+ */
2138+#define TIF_GRSEC_SETXID 12
2139+#define TIF_NOHZ 13 /* in adaptive nohz mode */
2140 #define TIF_USING_IWMMXT 17
2141 #define TIF_MEMDIE 18 /* is terminating due to OOM killer */
2142 #define TIF_RESTORE_SIGMASK 20
2143@@ -170,10 +174,11 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
2144 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
2145 #define _TIF_SECCOMP (1 << TIF_SECCOMP)
2146 #define _TIF_USING_IWMMXT (1 << TIF_USING_IWMMXT)
2147+#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
2148
2149 /* Checks for any syscall work in entry-common.S */
2150 #define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
2151- _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP)
2152+ _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP | _TIF_GRSEC_SETXID)
2153
2154 /*
2155 * Change these and you break ASM code in entry-common.S
2156diff --git a/arch/arm/include/asm/uaccess.h b/arch/arm/include/asm/uaccess.h
2157index 72abdc5..35acac1 100644
2158--- a/arch/arm/include/asm/uaccess.h
2159+++ b/arch/arm/include/asm/uaccess.h
2160@@ -18,6 +18,7 @@
2161 #include <asm/domain.h>
2162 #include <asm/unified.h>
2163 #include <asm/compiler.h>
2164+#include <asm/pgtable.h>
2165
2166 #if __LINUX_ARM_ARCH__ < 6
2167 #include <asm-generic/uaccess-unaligned.h>
2168@@ -70,11 +71,38 @@ extern int __put_user_bad(void);
2169 static inline void set_fs(mm_segment_t fs)
2170 {
2171 current_thread_info()->addr_limit = fs;
2172- modify_domain(DOMAIN_KERNEL, fs ? DOMAIN_CLIENT : DOMAIN_MANAGER);
2173+ modify_domain(DOMAIN_KERNEL, fs ? DOMAIN_KERNELCLIENT : DOMAIN_MANAGER);
2174 }
2175
2176 #define segment_eq(a,b) ((a) == (b))
2177
2178+#define __HAVE_ARCH_PAX_OPEN_USERLAND
2179+#define __HAVE_ARCH_PAX_CLOSE_USERLAND
2180+
2181+static inline void pax_open_userland(void)
2182+{
2183+
2184+#ifdef CONFIG_PAX_MEMORY_UDEREF
2185+ if (segment_eq(get_fs(), USER_DS)) {
2186+ BUG_ON(test_domain(DOMAIN_USER, DOMAIN_UDEREF));
2187+ modify_domain(DOMAIN_USER, DOMAIN_UDEREF);
2188+ }
2189+#endif
2190+
2191+}
2192+
2193+static inline void pax_close_userland(void)
2194+{
2195+
2196+#ifdef CONFIG_PAX_MEMORY_UDEREF
2197+ if (segment_eq(get_fs(), USER_DS)) {
2198+ BUG_ON(test_domain(DOMAIN_USER, DOMAIN_NOACCESS));
2199+ modify_domain(DOMAIN_USER, DOMAIN_NOACCESS);
2200+ }
2201+#endif
2202+
2203+}
2204+
2205 #define __addr_ok(addr) ({ \
2206 unsigned long flag; \
2207 __asm__("cmp %2, %0; movlo %0, #0" \
2208@@ -150,8 +178,12 @@ extern int __get_user_4(void *);
2209
2210 #define get_user(x,p) \
2211 ({ \
2212+ int __e; \
2213 might_fault(); \
2214- __get_user_check(x,p); \
2215+ pax_open_userland(); \
2216+ __e = __get_user_check(x,p); \
2217+ pax_close_userland(); \
2218+ __e; \
2219 })
2220
2221 extern int __put_user_1(void *, unsigned int);
2222@@ -195,8 +227,12 @@ extern int __put_user_8(void *, unsigned long long);
2223
2224 #define put_user(x,p) \
2225 ({ \
2226+ int __e; \
2227 might_fault(); \
2228- __put_user_check(x,p); \
2229+ pax_open_userland(); \
2230+ __e = __put_user_check(x,p); \
2231+ pax_close_userland(); \
2232+ __e; \
2233 })
2234
2235 #else /* CONFIG_MMU */
2236@@ -220,6 +256,7 @@ static inline void set_fs(mm_segment_t fs)
2237
2238 #endif /* CONFIG_MMU */
2239
2240+#define access_ok_noprefault(type,addr,size) access_ok((type),(addr),(size))
2241 #define access_ok(type,addr,size) (__range_ok(addr,size) == 0)
2242
2243 #define user_addr_max() \
2244@@ -237,13 +274,17 @@ static inline void set_fs(mm_segment_t fs)
2245 #define __get_user(x,ptr) \
2246 ({ \
2247 long __gu_err = 0; \
2248+ pax_open_userland(); \
2249 __get_user_err((x),(ptr),__gu_err); \
2250+ pax_close_userland(); \
2251 __gu_err; \
2252 })
2253
2254 #define __get_user_error(x,ptr,err) \
2255 ({ \
2256+ pax_open_userland(); \
2257 __get_user_err((x),(ptr),err); \
2258+ pax_close_userland(); \
2259 (void) 0; \
2260 })
2261
2262@@ -319,13 +360,17 @@ do { \
2263 #define __put_user(x,ptr) \
2264 ({ \
2265 long __pu_err = 0; \
2266+ pax_open_userland(); \
2267 __put_user_err((x),(ptr),__pu_err); \
2268+ pax_close_userland(); \
2269 __pu_err; \
2270 })
2271
2272 #define __put_user_error(x,ptr,err) \
2273 ({ \
2274+ pax_open_userland(); \
2275 __put_user_err((x),(ptr),err); \
2276+ pax_close_userland(); \
2277 (void) 0; \
2278 })
2279
2280@@ -425,11 +470,44 @@ do { \
2281
2282
2283 #ifdef CONFIG_MMU
2284-extern unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n);
2285-extern unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n);
2286+extern unsigned long __must_check ___copy_from_user(void *to, const void __user *from, unsigned long n);
2287+extern unsigned long __must_check ___copy_to_user(void __user *to, const void *from, unsigned long n);
2288+
2289+static inline unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n)
2290+{
2291+ unsigned long ret;
2292+
2293+ check_object_size(to, n, false);
2294+ pax_open_userland();
2295+ ret = ___copy_from_user(to, from, n);
2296+ pax_close_userland();
2297+ return ret;
2298+}
2299+
2300+static inline unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n)
2301+{
2302+ unsigned long ret;
2303+
2304+ check_object_size(from, n, true);
2305+ pax_open_userland();
2306+ ret = ___copy_to_user(to, from, n);
2307+ pax_close_userland();
2308+ return ret;
2309+}
2310+
2311 extern unsigned long __must_check __copy_to_user_std(void __user *to, const void *from, unsigned long n);
2312-extern unsigned long __must_check __clear_user(void __user *addr, unsigned long n);
2313+extern unsigned long __must_check ___clear_user(void __user *addr, unsigned long n);
2314 extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned long n);
2315+
2316+static inline unsigned long __must_check __clear_user(void __user *addr, unsigned long n)
2317+{
2318+ unsigned long ret;
2319+ pax_open_userland();
2320+ ret = ___clear_user(addr, n);
2321+ pax_close_userland();
2322+ return ret;
2323+}
2324+
2325 #else
2326 #define __copy_from_user(to,from,n) (memcpy(to, (void __force *)from, n), 0)
2327 #define __copy_to_user(to,from,n) (memcpy((void __force *)to, from, n), 0)
2328@@ -438,6 +516,9 @@ extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned l
2329
2330 static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
2331 {
2332+ if ((long)n < 0)
2333+ return n;
2334+
2335 if (access_ok(VERIFY_READ, from, n))
2336 n = __copy_from_user(to, from, n);
2337 else /* security hole - plug it */
2338@@ -447,6 +528,9 @@ static inline unsigned long __must_check copy_from_user(void *to, const void __u
2339
2340 static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
2341 {
2342+ if ((long)n < 0)
2343+ return n;
2344+
2345 if (access_ok(VERIFY_WRITE, to, n))
2346 n = __copy_to_user(to, from, n);
2347 return n;
2348diff --git a/arch/arm/include/uapi/asm/ptrace.h b/arch/arm/include/uapi/asm/ptrace.h
2349index 5af0ed1..cea83883 100644
2350--- a/arch/arm/include/uapi/asm/ptrace.h
2351+++ b/arch/arm/include/uapi/asm/ptrace.h
2352@@ -92,7 +92,7 @@
2353 * ARMv7 groups of PSR bits
2354 */
2355 #define APSR_MASK 0xf80f0000 /* N, Z, C, V, Q and GE flags */
2356-#define PSR_ISET_MASK 0x01000010 /* ISA state (J, T) mask */
2357+#define PSR_ISET_MASK 0x01000020 /* ISA state (J, T) mask */
2358 #define PSR_IT_MASK 0x0600fc00 /* If-Then execution state mask */
2359 #define PSR_ENDIAN_MASK 0x00000200 /* Endianness state mask */
2360
2361diff --git a/arch/arm/kernel/armksyms.c b/arch/arm/kernel/armksyms.c
2362index 85e664b..419a1cd 100644
2363--- a/arch/arm/kernel/armksyms.c
2364+++ b/arch/arm/kernel/armksyms.c
2365@@ -55,7 +55,7 @@ EXPORT_SYMBOL(arm_delay_ops);
2366
2367 /* networking */
2368 EXPORT_SYMBOL(csum_partial);
2369-EXPORT_SYMBOL(csum_partial_copy_from_user);
2370+EXPORT_SYMBOL(__csum_partial_copy_from_user);
2371 EXPORT_SYMBOL(csum_partial_copy_nocheck);
2372 EXPORT_SYMBOL(__csum_ipv6_magic);
2373
2374@@ -91,9 +91,9 @@ EXPORT_SYMBOL(__memzero);
2375 #ifdef CONFIG_MMU
2376 EXPORT_SYMBOL(copy_page);
2377
2378-EXPORT_SYMBOL(__copy_from_user);
2379-EXPORT_SYMBOL(__copy_to_user);
2380-EXPORT_SYMBOL(__clear_user);
2381+EXPORT_SYMBOL(___copy_from_user);
2382+EXPORT_SYMBOL(___copy_to_user);
2383+EXPORT_SYMBOL(___clear_user);
2384
2385 EXPORT_SYMBOL(__get_user_1);
2386 EXPORT_SYMBOL(__get_user_2);
2387diff --git a/arch/arm/kernel/entry-armv.S b/arch/arm/kernel/entry-armv.S
2388index 1879e8d..b2207fc 100644
2389--- a/arch/arm/kernel/entry-armv.S
2390+++ b/arch/arm/kernel/entry-armv.S
2391@@ -47,6 +47,87 @@
2392 9997:
2393 .endm
2394
2395+ .macro pax_enter_kernel
2396+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2397+ @ make aligned space for saved DACR
2398+ sub sp, sp, #8
2399+ @ save regs
2400+ stmdb sp!, {r1, r2}
2401+ @ read DACR from cpu_domain into r1
2402+ mov r2, sp
2403+ @ assume 8K pages, since we have to split the immediate in two
2404+ bic r2, r2, #(0x1fc0)
2405+ bic r2, r2, #(0x3f)
2406+ ldr r1, [r2, #TI_CPU_DOMAIN]
2407+ @ store old DACR on stack
2408+ str r1, [sp, #8]
2409+#ifdef CONFIG_PAX_KERNEXEC
2410+ @ set type of DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2411+ bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2412+ orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2413+#endif
2414+#ifdef CONFIG_PAX_MEMORY_UDEREF
2415+ @ set current DOMAIN_USER to DOMAIN_NOACCESS
2416+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2417+#endif
2418+ @ write r1 to current_thread_info()->cpu_domain
2419+ str r1, [r2, #TI_CPU_DOMAIN]
2420+ @ write r1 to DACR
2421+ mcr p15, 0, r1, c3, c0, 0
2422+ @ instruction sync
2423+ instr_sync
2424+ @ restore regs
2425+ ldmia sp!, {r1, r2}
2426+#endif
2427+ .endm
2428+
2429+ .macro pax_open_userland
2430+#ifdef CONFIG_PAX_MEMORY_UDEREF
2431+ @ save regs
2432+ stmdb sp!, {r0, r1}
2433+ @ read DACR from cpu_domain into r1
2434+ mov r0, sp
2435+ @ assume 8K pages, since we have to split the immediate in two
2436+ bic r0, r0, #(0x1fc0)
2437+ bic r0, r0, #(0x3f)
2438+ ldr r1, [r0, #TI_CPU_DOMAIN]
2439+ @ set current DOMAIN_USER to DOMAIN_CLIENT
2440+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2441+ orr r1, r1, #(domain_val(DOMAIN_USER, DOMAIN_UDEREF))
2442+ @ write r1 to current_thread_info()->cpu_domain
2443+ str r1, [r0, #TI_CPU_DOMAIN]
2444+ @ write r1 to DACR
2445+ mcr p15, 0, r1, c3, c0, 0
2446+ @ instruction sync
2447+ instr_sync
2448+ @ restore regs
2449+ ldmia sp!, {r0, r1}
2450+#endif
2451+ .endm
2452+
2453+ .macro pax_close_userland
2454+#ifdef CONFIG_PAX_MEMORY_UDEREF
2455+ @ save regs
2456+ stmdb sp!, {r0, r1}
2457+ @ read DACR from cpu_domain into r1
2458+ mov r0, sp
2459+ @ assume 8K pages, since we have to split the immediate in two
2460+ bic r0, r0, #(0x1fc0)
2461+ bic r0, r0, #(0x3f)
2462+ ldr r1, [r0, #TI_CPU_DOMAIN]
2463+ @ set current DOMAIN_USER to DOMAIN_NOACCESS
2464+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2465+ @ write r1 to current_thread_info()->cpu_domain
2466+ str r1, [r0, #TI_CPU_DOMAIN]
2467+ @ write r1 to DACR
2468+ mcr p15, 0, r1, c3, c0, 0
2469+ @ instruction sync
2470+ instr_sync
2471+ @ restore regs
2472+ ldmia sp!, {r0, r1}
2473+#endif
2474+ .endm
2475+
2476 .macro pabt_helper
2477 @ PABORT handler takes pt_regs in r2, fault address in r4 and psr in r5
2478 #ifdef MULTI_PABORT
2479@@ -89,11 +170,15 @@
2480 * Invalid mode handlers
2481 */
2482 .macro inv_entry, reason
2483+
2484+ pax_enter_kernel
2485+
2486 sub sp, sp, #S_FRAME_SIZE
2487 ARM( stmib sp, {r1 - lr} )
2488 THUMB( stmia sp, {r0 - r12} )
2489 THUMB( str sp, [sp, #S_SP] )
2490 THUMB( str lr, [sp, #S_LR] )
2491+
2492 mov r1, #\reason
2493 .endm
2494
2495@@ -149,7 +234,11 @@ ENDPROC(__und_invalid)
2496 .macro svc_entry, stack_hole=0
2497 UNWIND(.fnstart )
2498 UNWIND(.save {r0 - pc} )
2499+
2500+ pax_enter_kernel
2501+
2502 sub sp, sp, #(S_FRAME_SIZE + \stack_hole - 4)
2503+
2504 #ifdef CONFIG_THUMB2_KERNEL
2505 SPFIX( str r0, [sp] ) @ temporarily saved
2506 SPFIX( mov r0, sp )
2507@@ -164,7 +253,12 @@ ENDPROC(__und_invalid)
2508 ldmia r0, {r3 - r5}
2509 add r7, sp, #S_SP - 4 @ here for interlock avoidance
2510 mov r6, #-1 @ "" "" "" ""
2511+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2512+ @ offset sp by 8 as done in pax_enter_kernel
2513+ add r2, sp, #(S_FRAME_SIZE + \stack_hole + 4)
2514+#else
2515 add r2, sp, #(S_FRAME_SIZE + \stack_hole - 4)
2516+#endif
2517 SPFIX( addeq r2, r2, #4 )
2518 str r3, [sp, #-4]! @ save the "real" r0 copied
2519 @ from the exception stack
2520@@ -317,6 +411,9 @@ ENDPROC(__pabt_svc)
2521 .macro usr_entry
2522 UNWIND(.fnstart )
2523 UNWIND(.cantunwind ) @ don't unwind the user space
2524+
2525+ pax_enter_kernel_user
2526+
2527 sub sp, sp, #S_FRAME_SIZE
2528 ARM( stmib sp, {r1 - r12} )
2529 THUMB( stmia sp, {r0 - r12} )
2530@@ -416,7 +513,9 @@ __und_usr:
2531 tst r3, #PSR_T_BIT @ Thumb mode?
2532 bne __und_usr_thumb
2533 sub r4, r2, #4 @ ARM instr at LR - 4
2534+ pax_open_userland
2535 1: ldrt r0, [r4]
2536+ pax_close_userland
2537 ARM_BE8(rev r0, r0) @ little endian instruction
2538
2539 @ r0 = 32-bit ARM instruction which caused the exception
2540@@ -450,11 +549,15 @@ __und_usr_thumb:
2541 */
2542 .arch armv6t2
2543 #endif
2544+ pax_open_userland
2545 2: ldrht r5, [r4]
2546+ pax_close_userland
2547 ARM_BE8(rev16 r5, r5) @ little endian instruction
2548 cmp r5, #0xe800 @ 32bit instruction if xx != 0
2549 blo __und_usr_fault_16 @ 16bit undefined instruction
2550+ pax_open_userland
2551 3: ldrht r0, [r2]
2552+ pax_close_userland
2553 ARM_BE8(rev16 r0, r0) @ little endian instruction
2554 add r2, r2, #2 @ r2 is PC + 2, make it PC + 4
2555 str r2, [sp, #S_PC] @ it's a 2x16bit instr, update
2556@@ -484,7 +587,8 @@ ENDPROC(__und_usr)
2557 */
2558 .pushsection .fixup, "ax"
2559 .align 2
2560-4: mov pc, r9
2561+4: pax_close_userland
2562+ mov pc, r9
2563 .popsection
2564 .pushsection __ex_table,"a"
2565 .long 1b, 4b
2566@@ -694,7 +798,7 @@ ENTRY(__switch_to)
2567 THUMB( str lr, [ip], #4 )
2568 ldr r4, [r2, #TI_TP_VALUE]
2569 ldr r5, [r2, #TI_TP_VALUE + 4]
2570-#ifdef CONFIG_CPU_USE_DOMAINS
2571+#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2572 ldr r6, [r2, #TI_CPU_DOMAIN]
2573 #endif
2574 switch_tls r1, r4, r5, r3, r7
2575@@ -703,7 +807,7 @@ ENTRY(__switch_to)
2576 ldr r8, =__stack_chk_guard
2577 ldr r7, [r7, #TSK_STACK_CANARY]
2578 #endif
2579-#ifdef CONFIG_CPU_USE_DOMAINS
2580+#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2581 mcr p15, 0, r6, c3, c0, 0 @ Set domain register
2582 #endif
2583 mov r5, r0
2584diff --git a/arch/arm/kernel/entry-common.S b/arch/arm/kernel/entry-common.S
2585index a2dcafd..1048b5a 100644
2586--- a/arch/arm/kernel/entry-common.S
2587+++ b/arch/arm/kernel/entry-common.S
2588@@ -10,18 +10,46 @@
2589
2590 #include <asm/unistd.h>
2591 #include <asm/ftrace.h>
2592+#include <asm/domain.h>
2593 #include <asm/unwind.h>
2594
2595+#include "entry-header.S"
2596+
2597 #ifdef CONFIG_NEED_RET_TO_USER
2598 #include <mach/entry-macro.S>
2599 #else
2600 .macro arch_ret_to_user, tmp1, tmp2
2601+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2602+ @ save regs
2603+ stmdb sp!, {r1, r2}
2604+ @ read DACR from cpu_domain into r1
2605+ mov r2, sp
2606+ @ assume 8K pages, since we have to split the immediate in two
2607+ bic r2, r2, #(0x1fc0)
2608+ bic r2, r2, #(0x3f)
2609+ ldr r1, [r2, #TI_CPU_DOMAIN]
2610+#ifdef CONFIG_PAX_KERNEXEC
2611+ @ set type of DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2612+ bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2613+ orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2614+#endif
2615+#ifdef CONFIG_PAX_MEMORY_UDEREF
2616+ @ set current DOMAIN_USER to DOMAIN_UDEREF
2617+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2618+ orr r1, r1, #(domain_val(DOMAIN_USER, DOMAIN_UDEREF))
2619+#endif
2620+ @ write r1 to current_thread_info()->cpu_domain
2621+ str r1, [r2, #TI_CPU_DOMAIN]
2622+ @ write r1 to DACR
2623+ mcr p15, 0, r1, c3, c0, 0
2624+ @ instruction sync
2625+ instr_sync
2626+ @ restore regs
2627+ ldmia sp!, {r1, r2}
2628+#endif
2629 .endm
2630 #endif
2631
2632-#include "entry-header.S"
2633-
2634-
2635 .align 5
2636 /*
2637 * This is the fast syscall return path. We do as little as
2638@@ -411,6 +439,12 @@ ENTRY(vector_swi)
2639 USER( ldr scno, [lr, #-4] ) @ get SWI instruction
2640 #endif
2641
2642+ /*
2643+ * do this here to avoid a performance hit of wrapping the code above
2644+ * that directly dereferences userland to parse the SWI instruction
2645+ */
2646+ pax_enter_kernel_user
2647+
2648 adr tbl, sys_call_table @ load syscall table pointer
2649
2650 #if defined(CONFIG_OABI_COMPAT)
2651diff --git a/arch/arm/kernel/entry-header.S b/arch/arm/kernel/entry-header.S
2652index 39f89fb..d612bd9 100644
2653--- a/arch/arm/kernel/entry-header.S
2654+++ b/arch/arm/kernel/entry-header.S
2655@@ -184,6 +184,60 @@
2656 msr cpsr_c, \rtemp @ switch back to the SVC mode
2657 .endm
2658
2659+ .macro pax_enter_kernel_user
2660+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2661+ @ save regs
2662+ stmdb sp!, {r0, r1}
2663+ @ read DACR from cpu_domain into r1
2664+ mov r0, sp
2665+ @ assume 8K pages, since we have to split the immediate in two
2666+ bic r0, r0, #(0x1fc0)
2667+ bic r0, r0, #(0x3f)
2668+ ldr r1, [r0, #TI_CPU_DOMAIN]
2669+#ifdef CONFIG_PAX_MEMORY_UDEREF
2670+ @ set current DOMAIN_USER to DOMAIN_NOACCESS
2671+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2672+#endif
2673+#ifdef CONFIG_PAX_KERNEXEC
2674+ @ set current DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2675+ bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2676+ orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2677+#endif
2678+ @ write r1 to current_thread_info()->cpu_domain
2679+ str r1, [r0, #TI_CPU_DOMAIN]
2680+ @ write r1 to DACR
2681+ mcr p15, 0, r1, c3, c0, 0
2682+ @ instruction sync
2683+ instr_sync
2684+ @ restore regs
2685+ ldmia sp!, {r0, r1}
2686+#endif
2687+ .endm
2688+
2689+ .macro pax_exit_kernel
2690+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2691+ @ save regs
2692+ stmdb sp!, {r0, r1}
2693+ @ read old DACR from stack into r1
2694+ ldr r1, [sp, #(8 + S_SP)]
2695+ sub r1, r1, #8
2696+ ldr r1, [r1]
2697+
2698+ @ write r1 to current_thread_info()->cpu_domain
2699+ mov r0, sp
2700+ @ assume 8K pages, since we have to split the immediate in two
2701+ bic r0, r0, #(0x1fc0)
2702+ bic r0, r0, #(0x3f)
2703+ str r1, [r0, #TI_CPU_DOMAIN]
2704+ @ write r1 to DACR
2705+ mcr p15, 0, r1, c3, c0, 0
2706+ @ instruction sync
2707+ instr_sync
2708+ @ restore regs
2709+ ldmia sp!, {r0, r1}
2710+#endif
2711+ .endm
2712+
2713 #ifndef CONFIG_THUMB2_KERNEL
2714 .macro svc_exit, rpsr, irq = 0
2715 .if \irq != 0
2716@@ -203,6 +257,9 @@
2717 blne trace_hardirqs_off
2718 #endif
2719 .endif
2720+
2721+ pax_exit_kernel
2722+
2723 msr spsr_cxsf, \rpsr
2724 #if defined(CONFIG_CPU_V6)
2725 ldr r0, [sp]
2726@@ -266,6 +323,9 @@
2727 blne trace_hardirqs_off
2728 #endif
2729 .endif
2730+
2731+ pax_exit_kernel
2732+
2733 ldr lr, [sp, #S_SP] @ top of the stack
2734 ldrd r0, r1, [sp, #S_LR] @ calling lr and pc
2735 clrex @ clear the exclusive monitor
2736diff --git a/arch/arm/kernel/fiq.c b/arch/arm/kernel/fiq.c
2737index 918875d..cd5fa27 100644
2738--- a/arch/arm/kernel/fiq.c
2739+++ b/arch/arm/kernel/fiq.c
2740@@ -87,7 +87,10 @@ void set_fiq_handler(void *start, unsigned int length)
2741 void *base = vectors_page;
2742 unsigned offset = FIQ_OFFSET;
2743
2744+ pax_open_kernel();
2745 memcpy(base + offset, start, length);
2746+ pax_close_kernel();
2747+
2748 if (!cache_is_vipt_nonaliasing())
2749 flush_icache_range((unsigned long)base + offset, offset +
2750 length);
2751diff --git a/arch/arm/kernel/head.S b/arch/arm/kernel/head.S
2752index f5f381d..a6f36a1 100644
2753--- a/arch/arm/kernel/head.S
2754+++ b/arch/arm/kernel/head.S
2755@@ -437,7 +437,7 @@ __enable_mmu:
2756 mov r5, #(domain_val(DOMAIN_USER, DOMAIN_MANAGER) | \
2757 domain_val(DOMAIN_KERNEL, DOMAIN_MANAGER) | \
2758 domain_val(DOMAIN_TABLE, DOMAIN_MANAGER) | \
2759- domain_val(DOMAIN_IO, DOMAIN_CLIENT))
2760+ domain_val(DOMAIN_IO, DOMAIN_KERNELCLIENT))
2761 mcr p15, 0, r5, c3, c0, 0 @ load domain access register
2762 mcr p15, 0, r4, c2, c0, 0 @ load page table pointer
2763 #endif
2764diff --git a/arch/arm/kernel/module.c b/arch/arm/kernel/module.c
2765index 45e4781..8eac93d 100644
2766--- a/arch/arm/kernel/module.c
2767+++ b/arch/arm/kernel/module.c
2768@@ -38,12 +38,39 @@
2769 #endif
2770
2771 #ifdef CONFIG_MMU
2772-void *module_alloc(unsigned long size)
2773+static inline void *__module_alloc(unsigned long size, pgprot_t prot)
2774 {
2775+ if (!size || PAGE_ALIGN(size) > MODULES_END - MODULES_VADDR)
2776+ return NULL;
2777 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
2778- GFP_KERNEL, PAGE_KERNEL_EXEC, NUMA_NO_NODE,
2779+ GFP_KERNEL, prot, NUMA_NO_NODE,
2780 __builtin_return_address(0));
2781 }
2782+
2783+void *module_alloc(unsigned long size)
2784+{
2785+
2786+#ifdef CONFIG_PAX_KERNEXEC
2787+ return __module_alloc(size, PAGE_KERNEL);
2788+#else
2789+ return __module_alloc(size, PAGE_KERNEL_EXEC);
2790+#endif
2791+
2792+}
2793+
2794+#ifdef CONFIG_PAX_KERNEXEC
2795+void module_free_exec(struct module *mod, void *module_region)
2796+{
2797+ module_free(mod, module_region);
2798+}
2799+EXPORT_SYMBOL(module_free_exec);
2800+
2801+void *module_alloc_exec(unsigned long size)
2802+{
2803+ return __module_alloc(size, PAGE_KERNEL_EXEC);
2804+}
2805+EXPORT_SYMBOL(module_alloc_exec);
2806+#endif
2807 #endif
2808
2809 int
2810diff --git a/arch/arm/kernel/patch.c b/arch/arm/kernel/patch.c
2811index 07314af..c46655c 100644
2812--- a/arch/arm/kernel/patch.c
2813+++ b/arch/arm/kernel/patch.c
2814@@ -18,6 +18,7 @@ void __kprobes __patch_text(void *addr, unsigned int insn)
2815 bool thumb2 = IS_ENABLED(CONFIG_THUMB2_KERNEL);
2816 int size;
2817
2818+ pax_open_kernel();
2819 if (thumb2 && __opcode_is_thumb16(insn)) {
2820 *(u16 *)addr = __opcode_to_mem_thumb16(insn);
2821 size = sizeof(u16);
2822@@ -39,6 +40,7 @@ void __kprobes __patch_text(void *addr, unsigned int insn)
2823 *(u32 *)addr = insn;
2824 size = sizeof(u32);
2825 }
2826+ pax_close_kernel();
2827
2828 flush_icache_range((uintptr_t)(addr),
2829 (uintptr_t)(addr) + size);
2830diff --git a/arch/arm/kernel/process.c b/arch/arm/kernel/process.c
2831index 92f7b15..7048500 100644
2832--- a/arch/arm/kernel/process.c
2833+++ b/arch/arm/kernel/process.c
2834@@ -217,6 +217,7 @@ void machine_power_off(void)
2835
2836 if (pm_power_off)
2837 pm_power_off();
2838+ BUG();
2839 }
2840
2841 /*
2842@@ -230,7 +231,7 @@ void machine_power_off(void)
2843 * executing pre-reset code, and using RAM that the primary CPU's code wishes
2844 * to use. Implementing such co-ordination would be essentially impossible.
2845 */
2846-void machine_restart(char *cmd)
2847+__noreturn void machine_restart(char *cmd)
2848 {
2849 local_irq_disable();
2850 smp_send_stop();
2851@@ -253,8 +254,8 @@ void __show_regs(struct pt_regs *regs)
2852
2853 show_regs_print_info(KERN_DEFAULT);
2854
2855- print_symbol("PC is at %s\n", instruction_pointer(regs));
2856- print_symbol("LR is at %s\n", regs->ARM_lr);
2857+ printk("PC is at %pA\n", (void *)instruction_pointer(regs));
2858+ printk("LR is at %pA\n", (void *)regs->ARM_lr);
2859 printk("pc : [<%08lx>] lr : [<%08lx>] psr: %08lx\n"
2860 "sp : %08lx ip : %08lx fp : %08lx\n",
2861 regs->ARM_pc, regs->ARM_lr, regs->ARM_cpsr,
2862@@ -425,12 +426,6 @@ unsigned long get_wchan(struct task_struct *p)
2863 return 0;
2864 }
2865
2866-unsigned long arch_randomize_brk(struct mm_struct *mm)
2867-{
2868- unsigned long range_end = mm->brk + 0x02000000;
2869- return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
2870-}
2871-
2872 #ifdef CONFIG_MMU
2873 #ifdef CONFIG_KUSER_HELPERS
2874 /*
2875@@ -446,7 +441,7 @@ static struct vm_area_struct gate_vma = {
2876
2877 static int __init gate_vma_init(void)
2878 {
2879- gate_vma.vm_page_prot = PAGE_READONLY_EXEC;
2880+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
2881 return 0;
2882 }
2883 arch_initcall(gate_vma_init);
2884@@ -472,41 +467,16 @@ int in_gate_area_no_mm(unsigned long addr)
2885
2886 const char *arch_vma_name(struct vm_area_struct *vma)
2887 {
2888- return is_gate_vma(vma) ? "[vectors]" :
2889- (vma->vm_mm && vma->vm_start == vma->vm_mm->context.sigpage) ?
2890- "[sigpage]" : NULL;
2891+ return is_gate_vma(vma) ? "[vectors]" : NULL;
2892 }
2893
2894-static struct page *signal_page;
2895-extern struct page *get_signal_page(void);
2896-
2897 int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
2898 {
2899 struct mm_struct *mm = current->mm;
2900- unsigned long addr;
2901- int ret;
2902-
2903- if (!signal_page)
2904- signal_page = get_signal_page();
2905- if (!signal_page)
2906- return -ENOMEM;
2907
2908 down_write(&mm->mmap_sem);
2909- addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
2910- if (IS_ERR_VALUE(addr)) {
2911- ret = addr;
2912- goto up_fail;
2913- }
2914-
2915- ret = install_special_mapping(mm, addr, PAGE_SIZE,
2916- VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC,
2917- &signal_page);
2918-
2919- if (ret == 0)
2920- mm->context.sigpage = addr;
2921-
2922- up_fail:
2923+ mm->context.sigpage = (PAGE_OFFSET + (get_random_int() % 0x3FFEFFE0)) & 0xFFFFFFFC;
2924 up_write(&mm->mmap_sem);
2925- return ret;
2926+ return 0;
2927 }
2928 #endif
2929diff --git a/arch/arm/kernel/psci.c b/arch/arm/kernel/psci.c
2930index 4693188..4596c5e 100644
2931--- a/arch/arm/kernel/psci.c
2932+++ b/arch/arm/kernel/psci.c
2933@@ -24,7 +24,7 @@
2934 #include <asm/opcodes-virt.h>
2935 #include <asm/psci.h>
2936
2937-struct psci_operations psci_ops;
2938+struct psci_operations psci_ops __read_only;
2939
2940 static int (*invoke_psci_fn)(u32, u32, u32, u32);
2941
2942diff --git a/arch/arm/kernel/ptrace.c b/arch/arm/kernel/ptrace.c
2943index 0dd3b79..e018f64 100644
2944--- a/arch/arm/kernel/ptrace.c
2945+++ b/arch/arm/kernel/ptrace.c
2946@@ -929,10 +929,19 @@ static int tracehook_report_syscall(struct pt_regs *regs,
2947 return current_thread_info()->syscall;
2948 }
2949
2950+#ifdef CONFIG_GRKERNSEC_SETXID
2951+extern void gr_delayed_cred_worker(void);
2952+#endif
2953+
2954 asmlinkage int syscall_trace_enter(struct pt_regs *regs, int scno)
2955 {
2956 current_thread_info()->syscall = scno;
2957
2958+#ifdef CONFIG_GRKERNSEC_SETXID
2959+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
2960+ gr_delayed_cred_worker();
2961+#endif
2962+
2963 /* Do the secure computing check first; failures should be fast. */
2964 if (secure_computing(scno) == -1)
2965 return -1;
2966diff --git a/arch/arm/kernel/setup.c b/arch/arm/kernel/setup.c
2967index 1e8b030..37c3022 100644
2968--- a/arch/arm/kernel/setup.c
2969+++ b/arch/arm/kernel/setup.c
2970@@ -100,21 +100,23 @@ EXPORT_SYMBOL(system_serial_high);
2971 unsigned int elf_hwcap __read_mostly;
2972 EXPORT_SYMBOL(elf_hwcap);
2973
2974+pteval_t __supported_pte_mask __read_only;
2975+pmdval_t __supported_pmd_mask __read_only;
2976
2977 #ifdef MULTI_CPU
2978-struct processor processor __read_mostly;
2979+struct processor processor __read_only;
2980 #endif
2981 #ifdef MULTI_TLB
2982-struct cpu_tlb_fns cpu_tlb __read_mostly;
2983+struct cpu_tlb_fns cpu_tlb __read_only;
2984 #endif
2985 #ifdef MULTI_USER
2986-struct cpu_user_fns cpu_user __read_mostly;
2987+struct cpu_user_fns cpu_user __read_only;
2988 #endif
2989 #ifdef MULTI_CACHE
2990-struct cpu_cache_fns cpu_cache __read_mostly;
2991+struct cpu_cache_fns cpu_cache __read_only;
2992 #endif
2993 #ifdef CONFIG_OUTER_CACHE
2994-struct outer_cache_fns outer_cache __read_mostly;
2995+struct outer_cache_fns outer_cache __read_only;
2996 EXPORT_SYMBOL(outer_cache);
2997 #endif
2998
2999@@ -247,9 +249,13 @@ static int __get_cpu_architecture(void)
3000 asm("mrc p15, 0, %0, c0, c1, 4"
3001 : "=r" (mmfr0));
3002 if ((mmfr0 & 0x0000000f) >= 0x00000003 ||
3003- (mmfr0 & 0x000000f0) >= 0x00000030)
3004+ (mmfr0 & 0x000000f0) >= 0x00000030) {
3005 cpu_arch = CPU_ARCH_ARMv7;
3006- else if ((mmfr0 & 0x0000000f) == 0x00000002 ||
3007+ if ((mmfr0 & 0x0000000f) == 0x00000005 || (mmfr0 & 0x0000000f) == 0x00000004) {
3008+ __supported_pte_mask |= L_PTE_PXN;
3009+ __supported_pmd_mask |= PMD_PXNTABLE;
3010+ }
3011+ } else if ((mmfr0 & 0x0000000f) == 0x00000002 ||
3012 (mmfr0 & 0x000000f0) == 0x00000020)
3013 cpu_arch = CPU_ARCH_ARMv6;
3014 else
3015diff --git a/arch/arm/kernel/signal.c b/arch/arm/kernel/signal.c
3016index 04d6388..5115238 100644
3017--- a/arch/arm/kernel/signal.c
3018+++ b/arch/arm/kernel/signal.c
3019@@ -23,8 +23,6 @@
3020
3021 extern const unsigned long sigreturn_codes[7];
3022
3023-static unsigned long signal_return_offset;
3024-
3025 #ifdef CONFIG_CRUNCH
3026 static int preserve_crunch_context(struct crunch_sigframe __user *frame)
3027 {
3028@@ -395,8 +393,7 @@ setup_return(struct pt_regs *regs, struct ksignal *ksig,
3029 * except when the MPU has protected the vectors
3030 * page from PL0
3031 */
3032- retcode = mm->context.sigpage + signal_return_offset +
3033- (idx << 2) + thumb;
3034+ retcode = mm->context.sigpage + (idx << 2) + thumb;
3035 } else
3036 #endif
3037 {
3038@@ -600,33 +597,3 @@ do_work_pending(struct pt_regs *regs, unsigned int thread_flags, int syscall)
3039 } while (thread_flags & _TIF_WORK_MASK);
3040 return 0;
3041 }
3042-
3043-struct page *get_signal_page(void)
3044-{
3045- unsigned long ptr;
3046- unsigned offset;
3047- struct page *page;
3048- void *addr;
3049-
3050- page = alloc_pages(GFP_KERNEL, 0);
3051-
3052- if (!page)
3053- return NULL;
3054-
3055- addr = page_address(page);
3056-
3057- /* Give the signal return code some randomness */
3058- offset = 0x200 + (get_random_int() & 0x7fc);
3059- signal_return_offset = offset;
3060-
3061- /*
3062- * Copy signal return handlers into the vector page, and
3063- * set sigreturn to be a pointer to these.
3064- */
3065- memcpy(addr + offset, sigreturn_codes, sizeof(sigreturn_codes));
3066-
3067- ptr = (unsigned long)addr + offset;
3068- flush_icache_range(ptr, ptr + sizeof(sigreturn_codes));
3069-
3070- return page;
3071-}
3072diff --git a/arch/arm/kernel/smp.c b/arch/arm/kernel/smp.c
3073index b7b4c86..47c4f77 100644
3074--- a/arch/arm/kernel/smp.c
3075+++ b/arch/arm/kernel/smp.c
3076@@ -73,7 +73,7 @@ enum ipi_msg_type {
3077
3078 static DECLARE_COMPLETION(cpu_running);
3079
3080-static struct smp_operations smp_ops;
3081+static struct smp_operations smp_ops __read_only;
3082
3083 void __init smp_set_ops(struct smp_operations *ops)
3084 {
3085diff --git a/arch/arm/kernel/tcm.c b/arch/arm/kernel/tcm.c
3086index 7a3be1d..b00c7de 100644
3087--- a/arch/arm/kernel/tcm.c
3088+++ b/arch/arm/kernel/tcm.c
3089@@ -61,7 +61,7 @@ static struct map_desc itcm_iomap[] __initdata = {
3090 .virtual = ITCM_OFFSET,
3091 .pfn = __phys_to_pfn(ITCM_OFFSET),
3092 .length = 0,
3093- .type = MT_MEMORY_RWX_ITCM,
3094+ .type = MT_MEMORY_RX_ITCM,
3095 }
3096 };
3097
3098@@ -267,7 +267,9 @@ no_dtcm:
3099 start = &__sitcm_text;
3100 end = &__eitcm_text;
3101 ram = &__itcm_start;
3102+ pax_open_kernel();
3103 memcpy(start, ram, itcm_code_sz);
3104+ pax_close_kernel();
3105 pr_debug("CPU ITCM: copied code from %p - %p\n",
3106 start, end);
3107 itcm_present = true;
3108diff --git a/arch/arm/kernel/traps.c b/arch/arm/kernel/traps.c
3109index 172ee18..ce4ec3d 100644
3110--- a/arch/arm/kernel/traps.c
3111+++ b/arch/arm/kernel/traps.c
3112@@ -62,7 +62,7 @@ static void dump_mem(const char *, const char *, unsigned long, unsigned long);
3113 void dump_backtrace_entry(unsigned long where, unsigned long from, unsigned long frame)
3114 {
3115 #ifdef CONFIG_KALLSYMS
3116- printk("[<%08lx>] (%ps) from [<%08lx>] (%pS)\n", where, (void *)where, from, (void *)from);
3117+ printk("[<%08lx>] (%pA) from [<%08lx>] (%pA)\n", where, (void *)where, from, (void *)from);
3118 #else
3119 printk("Function entered at [<%08lx>] from [<%08lx>]\n", where, from);
3120 #endif
3121@@ -264,6 +264,8 @@ static arch_spinlock_t die_lock = __ARCH_SPIN_LOCK_UNLOCKED;
3122 static int die_owner = -1;
3123 static unsigned int die_nest_count;
3124
3125+extern void gr_handle_kernel_exploit(void);
3126+
3127 static unsigned long oops_begin(void)
3128 {
3129 int cpu;
3130@@ -306,6 +308,9 @@ static void oops_end(unsigned long flags, struct pt_regs *regs, int signr)
3131 panic("Fatal exception in interrupt");
3132 if (panic_on_oops)
3133 panic("Fatal exception");
3134+
3135+ gr_handle_kernel_exploit();
3136+
3137 if (signr)
3138 do_exit(signr);
3139 }
3140@@ -642,7 +647,9 @@ asmlinkage int arm_syscall(int no, struct pt_regs *regs)
3141 * The user helper at 0xffff0fe0 must be used instead.
3142 * (see entry-armv.S for details)
3143 */
3144+ pax_open_kernel();
3145 *((unsigned int *)0xffff0ff0) = regs->ARM_r0;
3146+ pax_close_kernel();
3147 }
3148 return 0;
3149
3150@@ -899,7 +906,11 @@ void __init early_trap_init(void *vectors_base)
3151 kuser_init(vectors_base);
3152
3153 flush_icache_range(vectors, vectors + PAGE_SIZE * 2);
3154- modify_domain(DOMAIN_USER, DOMAIN_CLIENT);
3155+
3156+#ifndef CONFIG_PAX_MEMORY_UDEREF
3157+ modify_domain(DOMAIN_USER, DOMAIN_USERCLIENT);
3158+#endif
3159+
3160 #else /* ifndef CONFIG_CPU_V7M */
3161 /*
3162 * on V7-M there is no need to copy the vector table to a dedicated
3163diff --git a/arch/arm/kernel/vmlinux.lds.S b/arch/arm/kernel/vmlinux.lds.S
3164index 7bcee5c..e2f3249 100644
3165--- a/arch/arm/kernel/vmlinux.lds.S
3166+++ b/arch/arm/kernel/vmlinux.lds.S
3167@@ -8,7 +8,11 @@
3168 #include <asm/thread_info.h>
3169 #include <asm/memory.h>
3170 #include <asm/page.h>
3171-
3172+
3173+#ifdef CONFIG_PAX_KERNEXEC
3174+#include <asm/pgtable.h>
3175+#endif
3176+
3177 #define PROC_INFO \
3178 . = ALIGN(4); \
3179 VMLINUX_SYMBOL(__proc_info_begin) = .; \
3180@@ -34,7 +38,7 @@
3181 #endif
3182
3183 #if (defined(CONFIG_SMP_ON_UP) && !defined(CONFIG_DEBUG_SPINLOCK)) || \
3184- defined(CONFIG_GENERIC_BUG)
3185+ defined(CONFIG_GENERIC_BUG) || defined(CONFIG_PAX_REFCOUNT)
3186 #define ARM_EXIT_KEEP(x) x
3187 #define ARM_EXIT_DISCARD(x)
3188 #else
3189@@ -90,6 +94,11 @@ SECTIONS
3190 _text = .;
3191 HEAD_TEXT
3192 }
3193+
3194+#ifdef CONFIG_PAX_KERNEXEC
3195+ . = ALIGN(1<<SECTION_SHIFT);
3196+#endif
3197+
3198 .text : { /* Real text segment */
3199 _stext = .; /* Text and read-only data */
3200 __exception_text_start = .;
3201@@ -112,6 +121,8 @@ SECTIONS
3202 ARM_CPU_KEEP(PROC_INFO)
3203 }
3204
3205+ _etext = .; /* End of text section */
3206+
3207 RO_DATA(PAGE_SIZE)
3208
3209 . = ALIGN(4);
3210@@ -142,7 +153,9 @@ SECTIONS
3211
3212 NOTES
3213
3214- _etext = .; /* End of text and rodata section */
3215+#ifdef CONFIG_PAX_KERNEXEC
3216+ . = ALIGN(1<<SECTION_SHIFT);
3217+#endif
3218
3219 #ifndef CONFIG_XIP_KERNEL
3220 . = ALIGN(PAGE_SIZE);
3221@@ -220,6 +233,11 @@ SECTIONS
3222 . = PAGE_OFFSET + TEXT_OFFSET;
3223 #else
3224 __init_end = .;
3225+
3226+#ifdef CONFIG_PAX_KERNEXEC
3227+ . = ALIGN(1<<SECTION_SHIFT);
3228+#endif
3229+
3230 . = ALIGN(THREAD_SIZE);
3231 __data_loc = .;
3232 #endif
3233diff --git a/arch/arm/kvm/arm.c b/arch/arm/kvm/arm.c
3234index bd18bb8..87ede26 100644
3235--- a/arch/arm/kvm/arm.c
3236+++ b/arch/arm/kvm/arm.c
3237@@ -57,7 +57,7 @@ static unsigned long hyp_default_vectors;
3238 static DEFINE_PER_CPU(struct kvm_vcpu *, kvm_arm_running_vcpu);
3239
3240 /* The VMID used in the VTTBR */
3241-static atomic64_t kvm_vmid_gen = ATOMIC64_INIT(1);
3242+static atomic64_unchecked_t kvm_vmid_gen = ATOMIC64_INIT(1);
3243 static u8 kvm_next_vmid;
3244 static DEFINE_SPINLOCK(kvm_vmid_lock);
3245
3246@@ -408,7 +408,7 @@ void force_vm_exit(const cpumask_t *mask)
3247 */
3248 static bool need_new_vmid_gen(struct kvm *kvm)
3249 {
3250- return unlikely(kvm->arch.vmid_gen != atomic64_read(&kvm_vmid_gen));
3251+ return unlikely(kvm->arch.vmid_gen != atomic64_read_unchecked(&kvm_vmid_gen));
3252 }
3253
3254 /**
3255@@ -441,7 +441,7 @@ static void update_vttbr(struct kvm *kvm)
3256
3257 /* First user of a new VMID generation? */
3258 if (unlikely(kvm_next_vmid == 0)) {
3259- atomic64_inc(&kvm_vmid_gen);
3260+ atomic64_inc_unchecked(&kvm_vmid_gen);
3261 kvm_next_vmid = 1;
3262
3263 /*
3264@@ -458,7 +458,7 @@ static void update_vttbr(struct kvm *kvm)
3265 kvm_call_hyp(__kvm_flush_vm_context);
3266 }
3267
3268- kvm->arch.vmid_gen = atomic64_read(&kvm_vmid_gen);
3269+ kvm->arch.vmid_gen = atomic64_read_unchecked(&kvm_vmid_gen);
3270 kvm->arch.vmid = kvm_next_vmid;
3271 kvm_next_vmid++;
3272
3273diff --git a/arch/arm/lib/clear_user.S b/arch/arm/lib/clear_user.S
3274index 14a0d98..7771a7d 100644
3275--- a/arch/arm/lib/clear_user.S
3276+++ b/arch/arm/lib/clear_user.S
3277@@ -12,14 +12,14 @@
3278
3279 .text
3280
3281-/* Prototype: int __clear_user(void *addr, size_t sz)
3282+/* Prototype: int ___clear_user(void *addr, size_t sz)
3283 * Purpose : clear some user memory
3284 * Params : addr - user memory address to clear
3285 * : sz - number of bytes to clear
3286 * Returns : number of bytes NOT cleared
3287 */
3288 ENTRY(__clear_user_std)
3289-WEAK(__clear_user)
3290+WEAK(___clear_user)
3291 stmfd sp!, {r1, lr}
3292 mov r2, #0
3293 cmp r1, #4
3294@@ -44,7 +44,7 @@ WEAK(__clear_user)
3295 USER( strnebt r2, [r0])
3296 mov r0, #0
3297 ldmfd sp!, {r1, pc}
3298-ENDPROC(__clear_user)
3299+ENDPROC(___clear_user)
3300 ENDPROC(__clear_user_std)
3301
3302 .pushsection .fixup,"ax"
3303diff --git a/arch/arm/lib/copy_from_user.S b/arch/arm/lib/copy_from_user.S
3304index 66a477a..bee61d3 100644
3305--- a/arch/arm/lib/copy_from_user.S
3306+++ b/arch/arm/lib/copy_from_user.S
3307@@ -16,7 +16,7 @@
3308 /*
3309 * Prototype:
3310 *
3311- * size_t __copy_from_user(void *to, const void *from, size_t n)
3312+ * size_t ___copy_from_user(void *to, const void *from, size_t n)
3313 *
3314 * Purpose:
3315 *
3316@@ -84,11 +84,11 @@
3317
3318 .text
3319
3320-ENTRY(__copy_from_user)
3321+ENTRY(___copy_from_user)
3322
3323 #include "copy_template.S"
3324
3325-ENDPROC(__copy_from_user)
3326+ENDPROC(___copy_from_user)
3327
3328 .pushsection .fixup,"ax"
3329 .align 0
3330diff --git a/arch/arm/lib/copy_page.S b/arch/arm/lib/copy_page.S
3331index 6ee2f67..d1cce76 100644
3332--- a/arch/arm/lib/copy_page.S
3333+++ b/arch/arm/lib/copy_page.S
3334@@ -10,6 +10,7 @@
3335 * ASM optimised string functions
3336 */
3337 #include <linux/linkage.h>
3338+#include <linux/const.h>
3339 #include <asm/assembler.h>
3340 #include <asm/asm-offsets.h>
3341 #include <asm/cache.h>
3342diff --git a/arch/arm/lib/copy_to_user.S b/arch/arm/lib/copy_to_user.S
3343index d066df6..df28194 100644
3344--- a/arch/arm/lib/copy_to_user.S
3345+++ b/arch/arm/lib/copy_to_user.S
3346@@ -16,7 +16,7 @@
3347 /*
3348 * Prototype:
3349 *
3350- * size_t __copy_to_user(void *to, const void *from, size_t n)
3351+ * size_t ___copy_to_user(void *to, const void *from, size_t n)
3352 *
3353 * Purpose:
3354 *
3355@@ -88,11 +88,11 @@
3356 .text
3357
3358 ENTRY(__copy_to_user_std)
3359-WEAK(__copy_to_user)
3360+WEAK(___copy_to_user)
3361
3362 #include "copy_template.S"
3363
3364-ENDPROC(__copy_to_user)
3365+ENDPROC(___copy_to_user)
3366 ENDPROC(__copy_to_user_std)
3367
3368 .pushsection .fixup,"ax"
3369diff --git a/arch/arm/lib/csumpartialcopyuser.S b/arch/arm/lib/csumpartialcopyuser.S
3370index 7d08b43..f7ca7ea 100644
3371--- a/arch/arm/lib/csumpartialcopyuser.S
3372+++ b/arch/arm/lib/csumpartialcopyuser.S
3373@@ -57,8 +57,8 @@
3374 * Returns : r0 = checksum, [[sp, #0], #0] = 0 or -EFAULT
3375 */
3376
3377-#define FN_ENTRY ENTRY(csum_partial_copy_from_user)
3378-#define FN_EXIT ENDPROC(csum_partial_copy_from_user)
3379+#define FN_ENTRY ENTRY(__csum_partial_copy_from_user)
3380+#define FN_EXIT ENDPROC(__csum_partial_copy_from_user)
3381
3382 #include "csumpartialcopygeneric.S"
3383
3384diff --git a/arch/arm/lib/delay.c b/arch/arm/lib/delay.c
3385index 5306de3..aed6d03 100644
3386--- a/arch/arm/lib/delay.c
3387+++ b/arch/arm/lib/delay.c
3388@@ -28,7 +28,7 @@
3389 /*
3390 * Default to the loop-based delay implementation.
3391 */
3392-struct arm_delay_ops arm_delay_ops = {
3393+struct arm_delay_ops arm_delay_ops __read_only = {
3394 .delay = __loop_delay,
3395 .const_udelay = __loop_const_udelay,
3396 .udelay = __loop_udelay,
3397diff --git a/arch/arm/lib/uaccess_with_memcpy.c b/arch/arm/lib/uaccess_with_memcpy.c
3398index 3e58d71..029817c 100644
3399--- a/arch/arm/lib/uaccess_with_memcpy.c
3400+++ b/arch/arm/lib/uaccess_with_memcpy.c
3401@@ -136,7 +136,7 @@ out:
3402 }
3403
3404 unsigned long
3405-__copy_to_user(void __user *to, const void *from, unsigned long n)
3406+___copy_to_user(void __user *to, const void *from, unsigned long n)
3407 {
3408 /*
3409 * This test is stubbed out of the main function above to keep
3410@@ -190,7 +190,7 @@ out:
3411 return n;
3412 }
3413
3414-unsigned long __clear_user(void __user *addr, unsigned long n)
3415+unsigned long ___clear_user(void __user *addr, unsigned long n)
3416 {
3417 /* See rational for this in __copy_to_user() above. */
3418 if (n < 64)
3419diff --git a/arch/arm/mach-at91/setup.c b/arch/arm/mach-at91/setup.c
3420index f7ca97b..3d7e719 100644
3421--- a/arch/arm/mach-at91/setup.c
3422+++ b/arch/arm/mach-at91/setup.c
3423@@ -81,7 +81,7 @@ void __init at91_init_sram(int bank, unsigned long base, unsigned int length)
3424
3425 desc->pfn = __phys_to_pfn(base);
3426 desc->length = length;
3427- desc->type = MT_MEMORY_RWX_NONCACHED;
3428+ desc->type = MT_MEMORY_RW_NONCACHED;
3429
3430 pr_info("AT91: sram at 0x%lx of 0x%x mapped at 0x%lx\n",
3431 base, length, desc->virtual);
3432diff --git a/arch/arm/mach-kirkwood/common.c b/arch/arm/mach-kirkwood/common.c
3433index f3407a5..bd4256f 100644
3434--- a/arch/arm/mach-kirkwood/common.c
3435+++ b/arch/arm/mach-kirkwood/common.c
3436@@ -156,7 +156,16 @@ static void clk_gate_fn_disable(struct clk_hw *hw)
3437 clk_gate_ops.disable(hw);
3438 }
3439
3440-static struct clk_ops clk_gate_fn_ops;
3441+static int clk_gate_fn_is_enabled(struct clk_hw *hw)
3442+{
3443+ return clk_gate_ops.is_enabled(hw);
3444+}
3445+
3446+static struct clk_ops clk_gate_fn_ops = {
3447+ .enable = clk_gate_fn_enable,
3448+ .disable = clk_gate_fn_disable,
3449+ .is_enabled = clk_gate_fn_is_enabled,
3450+};
3451
3452 static struct clk __init *clk_register_gate_fn(struct device *dev,
3453 const char *name,
3454@@ -190,14 +199,6 @@ static struct clk __init *clk_register_gate_fn(struct device *dev,
3455 gate_fn->fn_en = fn_en;
3456 gate_fn->fn_dis = fn_dis;
3457
3458- /* ops is the gate ops, but with our enable/disable functions */
3459- if (clk_gate_fn_ops.enable != clk_gate_fn_enable ||
3460- clk_gate_fn_ops.disable != clk_gate_fn_disable) {
3461- clk_gate_fn_ops = clk_gate_ops;
3462- clk_gate_fn_ops.enable = clk_gate_fn_enable;
3463- clk_gate_fn_ops.disable = clk_gate_fn_disable;
3464- }
3465-
3466 clk = clk_register(dev, &gate_fn->gate.hw);
3467
3468 if (IS_ERR(clk))
3469diff --git a/arch/arm/mach-omap2/board-n8x0.c b/arch/arm/mach-omap2/board-n8x0.c
3470index aead77a..a2253fa 100644
3471--- a/arch/arm/mach-omap2/board-n8x0.c
3472+++ b/arch/arm/mach-omap2/board-n8x0.c
3473@@ -568,7 +568,7 @@ static int n8x0_menelaus_late_init(struct device *dev)
3474 }
3475 #endif
3476
3477-static struct menelaus_platform_data n8x0_menelaus_platform_data __initdata = {
3478+static struct menelaus_platform_data n8x0_menelaus_platform_data __initconst = {
3479 .late_init = n8x0_menelaus_late_init,
3480 };
3481
3482diff --git a/arch/arm/mach-omap2/gpmc.c b/arch/arm/mach-omap2/gpmc.c
3483index ab43755..ccfa231 100644
3484--- a/arch/arm/mach-omap2/gpmc.c
3485+++ b/arch/arm/mach-omap2/gpmc.c
3486@@ -148,7 +148,6 @@ struct omap3_gpmc_regs {
3487 };
3488
3489 static struct gpmc_client_irq gpmc_client_irq[GPMC_NR_IRQ];
3490-static struct irq_chip gpmc_irq_chip;
3491 static int gpmc_irq_start;
3492
3493 static struct resource gpmc_mem_root;
3494@@ -716,6 +715,18 @@ static void gpmc_irq_noop(struct irq_data *data) { }
3495
3496 static unsigned int gpmc_irq_noop_ret(struct irq_data *data) { return 0; }
3497
3498+static struct irq_chip gpmc_irq_chip = {
3499+ .name = "gpmc",
3500+ .irq_startup = gpmc_irq_noop_ret,
3501+ .irq_enable = gpmc_irq_enable,
3502+ .irq_disable = gpmc_irq_disable,
3503+ .irq_shutdown = gpmc_irq_noop,
3504+ .irq_ack = gpmc_irq_noop,
3505+ .irq_mask = gpmc_irq_noop,
3506+ .irq_unmask = gpmc_irq_noop,
3507+
3508+};
3509+
3510 static int gpmc_setup_irq(void)
3511 {
3512 int i;
3513@@ -730,15 +741,6 @@ static int gpmc_setup_irq(void)
3514 return gpmc_irq_start;
3515 }
3516
3517- gpmc_irq_chip.name = "gpmc";
3518- gpmc_irq_chip.irq_startup = gpmc_irq_noop_ret;
3519- gpmc_irq_chip.irq_enable = gpmc_irq_enable;
3520- gpmc_irq_chip.irq_disable = gpmc_irq_disable;
3521- gpmc_irq_chip.irq_shutdown = gpmc_irq_noop;
3522- gpmc_irq_chip.irq_ack = gpmc_irq_noop;
3523- gpmc_irq_chip.irq_mask = gpmc_irq_noop;
3524- gpmc_irq_chip.irq_unmask = gpmc_irq_noop;
3525-
3526 gpmc_client_irq[0].bitmask = GPMC_IRQ_FIFOEVENTENABLE;
3527 gpmc_client_irq[1].bitmask = GPMC_IRQ_COUNT_EVENT;
3528
3529diff --git a/arch/arm/mach-omap2/omap-mpuss-lowpower.c b/arch/arm/mach-omap2/omap-mpuss-lowpower.c
3530index 667915d..2ee1219 100644
3531--- a/arch/arm/mach-omap2/omap-mpuss-lowpower.c
3532+++ b/arch/arm/mach-omap2/omap-mpuss-lowpower.c
3533@@ -84,7 +84,7 @@ struct cpu_pm_ops {
3534 int (*finish_suspend)(unsigned long cpu_state);
3535 void (*resume)(void);
3536 void (*scu_prepare)(unsigned int cpu_id, unsigned int cpu_state);
3537-};
3538+} __no_const;
3539
3540 static DEFINE_PER_CPU(struct omap4_cpu_pm_info, omap4_pm_info);
3541 static struct powerdomain *mpuss_pd;
3542@@ -102,7 +102,7 @@ static void dummy_cpu_resume(void)
3543 static void dummy_scu_prepare(unsigned int cpu_id, unsigned int cpu_state)
3544 {}
3545
3546-struct cpu_pm_ops omap_pm_ops = {
3547+static struct cpu_pm_ops omap_pm_ops __read_only = {
3548 .finish_suspend = default_finish_suspend,
3549 .resume = dummy_cpu_resume,
3550 .scu_prepare = dummy_scu_prepare,
3551diff --git a/arch/arm/mach-omap2/omap-wakeupgen.c b/arch/arm/mach-omap2/omap-wakeupgen.c
3552index 3664562..72f85c6 100644
3553--- a/arch/arm/mach-omap2/omap-wakeupgen.c
3554+++ b/arch/arm/mach-omap2/omap-wakeupgen.c
3555@@ -343,7 +343,7 @@ static int irq_cpu_hotplug_notify(struct notifier_block *self,
3556 return NOTIFY_OK;
3557 }
3558
3559-static struct notifier_block __refdata irq_hotplug_notifier = {
3560+static struct notifier_block irq_hotplug_notifier = {
3561 .notifier_call = irq_cpu_hotplug_notify,
3562 };
3563
3564diff --git a/arch/arm/mach-omap2/omap_device.c b/arch/arm/mach-omap2/omap_device.c
3565index 01ef59d..32ae28a8 100644
3566--- a/arch/arm/mach-omap2/omap_device.c
3567+++ b/arch/arm/mach-omap2/omap_device.c
3568@@ -510,7 +510,7 @@ void omap_device_delete(struct omap_device *od)
3569 struct platform_device __init *omap_device_build(const char *pdev_name,
3570 int pdev_id,
3571 struct omap_hwmod *oh,
3572- void *pdata, int pdata_len)
3573+ const void *pdata, int pdata_len)
3574 {
3575 struct omap_hwmod *ohs[] = { oh };
3576
3577@@ -538,7 +538,7 @@ struct platform_device __init *omap_device_build(const char *pdev_name,
3578 struct platform_device __init *omap_device_build_ss(const char *pdev_name,
3579 int pdev_id,
3580 struct omap_hwmod **ohs,
3581- int oh_cnt, void *pdata,
3582+ int oh_cnt, const void *pdata,
3583 int pdata_len)
3584 {
3585 int ret = -ENOMEM;
3586diff --git a/arch/arm/mach-omap2/omap_device.h b/arch/arm/mach-omap2/omap_device.h
3587index 78c02b3..c94109a 100644
3588--- a/arch/arm/mach-omap2/omap_device.h
3589+++ b/arch/arm/mach-omap2/omap_device.h
3590@@ -72,12 +72,12 @@ int omap_device_idle(struct platform_device *pdev);
3591 /* Core code interface */
3592
3593 struct platform_device *omap_device_build(const char *pdev_name, int pdev_id,
3594- struct omap_hwmod *oh, void *pdata,
3595+ struct omap_hwmod *oh, const void *pdata,
3596 int pdata_len);
3597
3598 struct platform_device *omap_device_build_ss(const char *pdev_name, int pdev_id,
3599 struct omap_hwmod **oh, int oh_cnt,
3600- void *pdata, int pdata_len);
3601+ const void *pdata, int pdata_len);
3602
3603 struct omap_device *omap_device_alloc(struct platform_device *pdev,
3604 struct omap_hwmod **ohs, int oh_cnt);
3605diff --git a/arch/arm/mach-omap2/omap_hwmod.c b/arch/arm/mach-omap2/omap_hwmod.c
3606index 66c60fe..c78950d 100644
3607--- a/arch/arm/mach-omap2/omap_hwmod.c
3608+++ b/arch/arm/mach-omap2/omap_hwmod.c
3609@@ -194,10 +194,10 @@ struct omap_hwmod_soc_ops {
3610 int (*init_clkdm)(struct omap_hwmod *oh);
3611 void (*update_context_lost)(struct omap_hwmod *oh);
3612 int (*get_context_lost)(struct omap_hwmod *oh);
3613-};
3614+} __no_const;
3615
3616 /* soc_ops: adapts the omap_hwmod code to the currently-booted SoC */
3617-static struct omap_hwmod_soc_ops soc_ops;
3618+static struct omap_hwmod_soc_ops soc_ops __read_only;
3619
3620 /* omap_hwmod_list contains all registered struct omap_hwmods */
3621 static LIST_HEAD(omap_hwmod_list);
3622diff --git a/arch/arm/mach-omap2/powerdomains43xx_data.c b/arch/arm/mach-omap2/powerdomains43xx_data.c
3623index 95fee54..cfa9cf1 100644
3624--- a/arch/arm/mach-omap2/powerdomains43xx_data.c
3625+++ b/arch/arm/mach-omap2/powerdomains43xx_data.c
3626@@ -10,6 +10,7 @@
3627
3628 #include <linux/kernel.h>
3629 #include <linux/init.h>
3630+#include <asm/pgtable.h>
3631
3632 #include "powerdomain.h"
3633
3634@@ -129,7 +130,9 @@ static int am43xx_check_vcvp(void)
3635
3636 void __init am43xx_powerdomains_init(void)
3637 {
3638- omap4_pwrdm_operations.pwrdm_has_voltdm = am43xx_check_vcvp;
3639+ pax_open_kernel();
3640+ *(void **)&omap4_pwrdm_operations.pwrdm_has_voltdm = am43xx_check_vcvp;
3641+ pax_close_kernel();
3642 pwrdm_register_platform_funcs(&omap4_pwrdm_operations);
3643 pwrdm_register_pwrdms(powerdomains_am43xx);
3644 pwrdm_complete_init();
3645diff --git a/arch/arm/mach-omap2/wd_timer.c b/arch/arm/mach-omap2/wd_timer.c
3646index d15c7bb..b2d1f0c 100644
3647--- a/arch/arm/mach-omap2/wd_timer.c
3648+++ b/arch/arm/mach-omap2/wd_timer.c
3649@@ -110,7 +110,9 @@ static int __init omap_init_wdt(void)
3650 struct omap_hwmod *oh;
3651 char *oh_name = "wd_timer2";
3652 char *dev_name = "omap_wdt";
3653- struct omap_wd_timer_platform_data pdata;
3654+ static struct omap_wd_timer_platform_data pdata = {
3655+ .read_reset_sources = prm_read_reset_sources
3656+ };
3657
3658 if (!cpu_class_is_omap2() || of_have_populated_dt())
3659 return 0;
3660@@ -121,8 +123,6 @@ static int __init omap_init_wdt(void)
3661 return -EINVAL;
3662 }
3663
3664- pdata.read_reset_sources = prm_read_reset_sources;
3665-
3666 pdev = omap_device_build(dev_name, id, oh, &pdata,
3667 sizeof(struct omap_wd_timer_platform_data));
3668 WARN(IS_ERR(pdev), "Can't build omap_device for %s:%s.\n",
3669diff --git a/arch/arm/mach-tegra/cpuidle-tegra20.c b/arch/arm/mach-tegra/cpuidle-tegra20.c
3670index b82dcae..44ee5b6 100644
3671--- a/arch/arm/mach-tegra/cpuidle-tegra20.c
3672+++ b/arch/arm/mach-tegra/cpuidle-tegra20.c
3673@@ -180,7 +180,7 @@ static int tegra20_idle_lp2_coupled(struct cpuidle_device *dev,
3674 bool entered_lp2 = false;
3675
3676 if (tegra_pending_sgi())
3677- ACCESS_ONCE(abort_flag) = true;
3678+ ACCESS_ONCE_RW(abort_flag) = true;
3679
3680 cpuidle_coupled_parallel_barrier(dev, &abort_barrier);
3681
3682diff --git a/arch/arm/mach-ux500/setup.h b/arch/arm/mach-ux500/setup.h
3683index 2dea8b5..6499da2 100644
3684--- a/arch/arm/mach-ux500/setup.h
3685+++ b/arch/arm/mach-ux500/setup.h
3686@@ -33,13 +33,6 @@ extern void ux500_timer_init(void);
3687 .type = MT_DEVICE, \
3688 }
3689
3690-#define __MEM_DEV_DESC(x, sz) { \
3691- .virtual = IO_ADDRESS(x), \
3692- .pfn = __phys_to_pfn(x), \
3693- .length = sz, \
3694- .type = MT_MEMORY_RWX, \
3695-}
3696-
3697 extern struct smp_operations ux500_smp_ops;
3698 extern void ux500_cpu_die(unsigned int cpu);
3699
3700diff --git a/arch/arm/mm/Kconfig b/arch/arm/mm/Kconfig
3701index ca8ecde..58ba893 100644
3702--- a/arch/arm/mm/Kconfig
3703+++ b/arch/arm/mm/Kconfig
3704@@ -446,6 +446,7 @@ config CPU_32v5
3705
3706 config CPU_32v6
3707 bool
3708+ select CPU_USE_DOMAINS if CPU_V6 && MMU && !PAX_KERNEXEC && !PAX_MEMORY_UDEREF
3709 select TLS_REG_EMUL if !CPU_32v6K && !MMU
3710
3711 config CPU_32v6K
3712@@ -600,6 +601,7 @@ config CPU_CP15_MPU
3713
3714 config CPU_USE_DOMAINS
3715 bool
3716+ depends on !ARM_LPAE && !PAX_KERNEXEC && !PAX_MEMORY_UDEREF
3717 help
3718 This option enables or disables the use of domain switching
3719 via the set_fs() function.
3720@@ -799,6 +801,7 @@ config NEED_KUSER_HELPERS
3721 config KUSER_HELPERS
3722 bool "Enable kuser helpers in vector page" if !NEED_KUSER_HELPERS
3723 default y
3724+ depends on !(CPU_V6 || CPU_V6K || CPU_V7) || GRKERNSEC_OLD_ARM_USERLAND
3725 help
3726 Warning: disabling this option may break user programs.
3727
3728@@ -811,7 +814,7 @@ config KUSER_HELPERS
3729 See Documentation/arm/kernel_user_helpers.txt for details.
3730
3731 However, the fixed address nature of these helpers can be used
3732- by ROP (return orientated programming) authors when creating
3733+ by ROP (Return Oriented Programming) authors when creating
3734 exploits.
3735
3736 If all of the binaries and libraries which run on your platform
3737diff --git a/arch/arm/mm/alignment.c b/arch/arm/mm/alignment.c
3738index 9240364..a2b8cf3 100644
3739--- a/arch/arm/mm/alignment.c
3740+++ b/arch/arm/mm/alignment.c
3741@@ -212,10 +212,12 @@ union offset_union {
3742 #define __get16_unaligned_check(ins,val,addr) \
3743 do { \
3744 unsigned int err = 0, v, a = addr; \
3745+ pax_open_userland(); \
3746 __get8_unaligned_check(ins,v,a,err); \
3747 val = v << ((BE) ? 8 : 0); \
3748 __get8_unaligned_check(ins,v,a,err); \
3749 val |= v << ((BE) ? 0 : 8); \
3750+ pax_close_userland(); \
3751 if (err) \
3752 goto fault; \
3753 } while (0)
3754@@ -229,6 +231,7 @@ union offset_union {
3755 #define __get32_unaligned_check(ins,val,addr) \
3756 do { \
3757 unsigned int err = 0, v, a = addr; \
3758+ pax_open_userland(); \
3759 __get8_unaligned_check(ins,v,a,err); \
3760 val = v << ((BE) ? 24 : 0); \
3761 __get8_unaligned_check(ins,v,a,err); \
3762@@ -237,6 +240,7 @@ union offset_union {
3763 val |= v << ((BE) ? 8 : 16); \
3764 __get8_unaligned_check(ins,v,a,err); \
3765 val |= v << ((BE) ? 0 : 24); \
3766+ pax_close_userland(); \
3767 if (err) \
3768 goto fault; \
3769 } while (0)
3770@@ -250,6 +254,7 @@ union offset_union {
3771 #define __put16_unaligned_check(ins,val,addr) \
3772 do { \
3773 unsigned int err = 0, v = val, a = addr; \
3774+ pax_open_userland(); \
3775 __asm__( FIRST_BYTE_16 \
3776 ARM( "1: "ins" %1, [%2], #1\n" ) \
3777 THUMB( "1: "ins" %1, [%2]\n" ) \
3778@@ -269,6 +274,7 @@ union offset_union {
3779 " .popsection\n" \
3780 : "=r" (err), "=&r" (v), "=&r" (a) \
3781 : "0" (err), "1" (v), "2" (a)); \
3782+ pax_close_userland(); \
3783 if (err) \
3784 goto fault; \
3785 } while (0)
3786@@ -282,6 +288,7 @@ union offset_union {
3787 #define __put32_unaligned_check(ins,val,addr) \
3788 do { \
3789 unsigned int err = 0, v = val, a = addr; \
3790+ pax_open_userland(); \
3791 __asm__( FIRST_BYTE_32 \
3792 ARM( "1: "ins" %1, [%2], #1\n" ) \
3793 THUMB( "1: "ins" %1, [%2]\n" ) \
3794@@ -311,6 +318,7 @@ union offset_union {
3795 " .popsection\n" \
3796 : "=r" (err), "=&r" (v), "=&r" (a) \
3797 : "0" (err), "1" (v), "2" (a)); \
3798+ pax_close_userland(); \
3799 if (err) \
3800 goto fault; \
3801 } while (0)
3802diff --git a/arch/arm/mm/cache-l2x0.c b/arch/arm/mm/cache-l2x0.c
3803index 7abde2c..9df495f 100644
3804--- a/arch/arm/mm/cache-l2x0.c
3805+++ b/arch/arm/mm/cache-l2x0.c
3806@@ -46,7 +46,7 @@ struct l2x0_of_data {
3807 void (*setup)(const struct device_node *, u32 *, u32 *);
3808 void (*save)(void);
3809 struct outer_cache_fns outer_cache;
3810-};
3811+} __do_const;
3812
3813 static bool of_init = false;
3814
3815diff --git a/arch/arm/mm/context.c b/arch/arm/mm/context.c
3816index 6eb97b3..ac509f6 100644
3817--- a/arch/arm/mm/context.c
3818+++ b/arch/arm/mm/context.c
3819@@ -43,7 +43,7 @@
3820 #define NUM_USER_ASIDS ASID_FIRST_VERSION
3821
3822 static DEFINE_RAW_SPINLOCK(cpu_asid_lock);
3823-static atomic64_t asid_generation = ATOMIC64_INIT(ASID_FIRST_VERSION);
3824+static atomic64_unchecked_t asid_generation = ATOMIC64_INIT(ASID_FIRST_VERSION);
3825 static DECLARE_BITMAP(asid_map, NUM_USER_ASIDS);
3826
3827 static DEFINE_PER_CPU(atomic64_t, active_asids);
3828@@ -182,7 +182,7 @@ static u64 new_context(struct mm_struct *mm, unsigned int cpu)
3829 {
3830 static u32 cur_idx = 1;
3831 u64 asid = atomic64_read(&mm->context.id);
3832- u64 generation = atomic64_read(&asid_generation);
3833+ u64 generation = atomic64_read_unchecked(&asid_generation);
3834
3835 if (asid != 0 && is_reserved_asid(asid)) {
3836 /*
3837@@ -203,7 +203,7 @@ static u64 new_context(struct mm_struct *mm, unsigned int cpu)
3838 */
3839 asid = find_next_zero_bit(asid_map, NUM_USER_ASIDS, cur_idx);
3840 if (asid == NUM_USER_ASIDS) {
3841- generation = atomic64_add_return(ASID_FIRST_VERSION,
3842+ generation = atomic64_add_return_unchecked(ASID_FIRST_VERSION,
3843 &asid_generation);
3844 flush_context(cpu);
3845 asid = find_next_zero_bit(asid_map, NUM_USER_ASIDS, 1);
3846@@ -234,14 +234,14 @@ void check_and_switch_context(struct mm_struct *mm, struct task_struct *tsk)
3847 cpu_set_reserved_ttbr0();
3848
3849 asid = atomic64_read(&mm->context.id);
3850- if (!((asid ^ atomic64_read(&asid_generation)) >> ASID_BITS)
3851+ if (!((asid ^ atomic64_read_unchecked(&asid_generation)) >> ASID_BITS)
3852 && atomic64_xchg(&per_cpu(active_asids, cpu), asid))
3853 goto switch_mm_fastpath;
3854
3855 raw_spin_lock_irqsave(&cpu_asid_lock, flags);
3856 /* Check that our ASID belongs to the current generation. */
3857 asid = atomic64_read(&mm->context.id);
3858- if ((asid ^ atomic64_read(&asid_generation)) >> ASID_BITS) {
3859+ if ((asid ^ atomic64_read_unchecked(&asid_generation)) >> ASID_BITS) {
3860 asid = new_context(mm, cpu);
3861 atomic64_set(&mm->context.id, asid);
3862 }
3863diff --git a/arch/arm/mm/fault.c b/arch/arm/mm/fault.c
3864index eb8830a..5360ce7 100644
3865--- a/arch/arm/mm/fault.c
3866+++ b/arch/arm/mm/fault.c
3867@@ -25,6 +25,7 @@
3868 #include <asm/system_misc.h>
3869 #include <asm/system_info.h>
3870 #include <asm/tlbflush.h>
3871+#include <asm/sections.h>
3872
3873 #include "fault.h"
3874
3875@@ -138,6 +139,31 @@ __do_kernel_fault(struct mm_struct *mm, unsigned long addr, unsigned int fsr,
3876 if (fixup_exception(regs))
3877 return;
3878
3879+#ifdef CONFIG_PAX_MEMORY_UDEREF
3880+ if (addr < TASK_SIZE) {
3881+ if (current->signal->curr_ip)
3882+ printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to access userland memory at %08lx\n", &current->signal->curr_ip, current->comm, task_pid_nr(current),
3883+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
3884+ else
3885+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to access userland memory at %08lx\n", current->comm, task_pid_nr(current),
3886+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
3887+ }
3888+#endif
3889+
3890+#ifdef CONFIG_PAX_KERNEXEC
3891+ if ((fsr & FSR_WRITE) &&
3892+ (((unsigned long)_stext <= addr && addr < init_mm.end_code) ||
3893+ (MODULES_VADDR <= addr && addr < MODULES_END)))
3894+ {
3895+ if (current->signal->curr_ip)
3896+ printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n", &current->signal->curr_ip, current->comm, task_pid_nr(current),
3897+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
3898+ else
3899+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n", current->comm, task_pid_nr(current),
3900+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
3901+ }
3902+#endif
3903+
3904 /*
3905 * No handler, we'll have to terminate things with extreme prejudice.
3906 */
3907@@ -174,6 +200,13 @@ __do_user_fault(struct task_struct *tsk, unsigned long addr,
3908 }
3909 #endif
3910
3911+#ifdef CONFIG_PAX_PAGEEXEC
3912+ if (fsr & FSR_LNX_PF) {
3913+ pax_report_fault(regs, (void *)regs->ARM_pc, (void *)regs->ARM_sp);
3914+ do_group_exit(SIGKILL);
3915+ }
3916+#endif
3917+
3918 tsk->thread.address = addr;
3919 tsk->thread.error_code = fsr;
3920 tsk->thread.trap_no = 14;
3921@@ -401,6 +434,33 @@ do_page_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
3922 }
3923 #endif /* CONFIG_MMU */
3924
3925+#ifdef CONFIG_PAX_PAGEEXEC
3926+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
3927+{
3928+ long i;
3929+
3930+ printk(KERN_ERR "PAX: bytes at PC: ");
3931+ for (i = 0; i < 20; i++) {
3932+ unsigned char c;
3933+ if (get_user(c, (__force unsigned char __user *)pc+i))
3934+ printk(KERN_CONT "?? ");
3935+ else
3936+ printk(KERN_CONT "%02x ", c);
3937+ }
3938+ printk("\n");
3939+
3940+ printk(KERN_ERR "PAX: bytes at SP-4: ");
3941+ for (i = -1; i < 20; i++) {
3942+ unsigned long c;
3943+ if (get_user(c, (__force unsigned long __user *)sp+i))
3944+ printk(KERN_CONT "???????? ");
3945+ else
3946+ printk(KERN_CONT "%08lx ", c);
3947+ }
3948+ printk("\n");
3949+}
3950+#endif
3951+
3952 /*
3953 * First Level Translation Fault Handler
3954 *
3955@@ -548,9 +608,22 @@ do_DataAbort(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
3956 const struct fsr_info *inf = fsr_info + fsr_fs(fsr);
3957 struct siginfo info;
3958
3959+#ifdef CONFIG_PAX_MEMORY_UDEREF
3960+ if (addr < TASK_SIZE && is_domain_fault(fsr)) {
3961+ if (current->signal->curr_ip)
3962+ printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to access userland memory at %08lx\n", &current->signal->curr_ip, current->comm, task_pid_nr(current),
3963+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
3964+ else
3965+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to access userland memory at %08lx\n", current->comm, task_pid_nr(current),
3966+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
3967+ goto die;
3968+ }
3969+#endif
3970+
3971 if (!inf->fn(addr, fsr & ~FSR_LNX_PF, regs))
3972 return;
3973
3974+die:
3975 printk(KERN_ALERT "Unhandled fault: %s (0x%03x) at 0x%08lx\n",
3976 inf->name, fsr, addr);
3977
3978@@ -574,15 +647,98 @@ hook_ifault_code(int nr, int (*fn)(unsigned long, unsigned int, struct pt_regs *
3979 ifsr_info[nr].name = name;
3980 }
3981
3982+asmlinkage int sys_sigreturn(struct pt_regs *regs);
3983+asmlinkage int sys_rt_sigreturn(struct pt_regs *regs);
3984+
3985 asmlinkage void __exception
3986 do_PrefetchAbort(unsigned long addr, unsigned int ifsr, struct pt_regs *regs)
3987 {
3988 const struct fsr_info *inf = ifsr_info + fsr_fs(ifsr);
3989 struct siginfo info;
3990+ unsigned long pc = instruction_pointer(regs);
3991+
3992+ if (user_mode(regs)) {
3993+ unsigned long sigpage = current->mm->context.sigpage;
3994+
3995+ if (sigpage <= pc && pc < sigpage + 7*4) {
3996+ if (pc < sigpage + 3*4)
3997+ sys_sigreturn(regs);
3998+ else
3999+ sys_rt_sigreturn(regs);
4000+ return;
4001+ }
4002+ if (pc == 0xffff0f60UL) {
4003+ /*
4004+ * PaX: __kuser_cmpxchg64 emulation
4005+ */
4006+ // TODO
4007+ //regs->ARM_pc = regs->ARM_lr;
4008+ //return;
4009+ }
4010+ if (pc == 0xffff0fa0UL) {
4011+ /*
4012+ * PaX: __kuser_memory_barrier emulation
4013+ */
4014+ // dmb(); implied by the exception
4015+ regs->ARM_pc = regs->ARM_lr;
4016+ return;
4017+ }
4018+ if (pc == 0xffff0fc0UL) {
4019+ /*
4020+ * PaX: __kuser_cmpxchg emulation
4021+ */
4022+ // TODO
4023+ //long new;
4024+ //int op;
4025+
4026+ //op = FUTEX_OP_SET << 28;
4027+ //new = futex_atomic_op_inuser(op, regs->ARM_r2);
4028+ //regs->ARM_r0 = old != new;
4029+ //regs->ARM_pc = regs->ARM_lr;
4030+ //return;
4031+ }
4032+ if (pc == 0xffff0fe0UL) {
4033+ /*
4034+ * PaX: __kuser_get_tls emulation
4035+ */
4036+ regs->ARM_r0 = current_thread_info()->tp_value[0];
4037+ regs->ARM_pc = regs->ARM_lr;
4038+ return;
4039+ }
4040+ }
4041+
4042+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
4043+ else if (is_domain_fault(ifsr) || is_xn_fault(ifsr)) {
4044+ if (current->signal->curr_ip)
4045+ printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to execute %s memory at %08lx\n", &current->signal->curr_ip, current->comm, task_pid_nr(current),
4046+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()),
4047+ pc >= TASK_SIZE ? "non-executable kernel" : "userland", pc);
4048+ else
4049+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to execute %s memory at %08lx\n", current->comm, task_pid_nr(current),
4050+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()),
4051+ pc >= TASK_SIZE ? "non-executable kernel" : "userland", pc);
4052+ goto die;
4053+ }
4054+#endif
4055+
4056+#ifdef CONFIG_PAX_REFCOUNT
4057+ if (fsr_fs(ifsr) == FAULT_CODE_DEBUG) {
4058+ unsigned int bkpt;
4059+
4060+ if (!probe_kernel_address(pc, bkpt) && cpu_to_le32(bkpt) == 0xe12f1073) {
4061+ current->thread.error_code = ifsr;
4062+ current->thread.trap_no = 0;
4063+ pax_report_refcount_overflow(regs);
4064+ fixup_exception(regs);
4065+ return;
4066+ }
4067+ }
4068+#endif
4069
4070 if (!inf->fn(addr, ifsr | FSR_LNX_PF, regs))
4071 return;
4072
4073+die:
4074 printk(KERN_ALERT "Unhandled prefetch abort: %s (0x%03x) at 0x%08lx\n",
4075 inf->name, ifsr, addr);
4076
4077diff --git a/arch/arm/mm/fault.h b/arch/arm/mm/fault.h
4078index cf08bdf..772656c 100644
4079--- a/arch/arm/mm/fault.h
4080+++ b/arch/arm/mm/fault.h
4081@@ -3,6 +3,7 @@
4082
4083 /*
4084 * Fault status register encodings. We steal bit 31 for our own purposes.
4085+ * Set when the FSR value is from an instruction fault.
4086 */
4087 #define FSR_LNX_PF (1 << 31)
4088 #define FSR_WRITE (1 << 11)
4089@@ -22,6 +23,17 @@ static inline int fsr_fs(unsigned int fsr)
4090 }
4091 #endif
4092
4093+/* valid for LPAE and !LPAE */
4094+static inline int is_xn_fault(unsigned int fsr)
4095+{
4096+ return ((fsr_fs(fsr) & 0x3c) == 0xc);
4097+}
4098+
4099+static inline int is_domain_fault(unsigned int fsr)
4100+{
4101+ return ((fsr_fs(fsr) & 0xD) == 0x9);
4102+}
4103+
4104 void do_bad_area(unsigned long addr, unsigned int fsr, struct pt_regs *regs);
4105 unsigned long search_exception_table(unsigned long addr);
4106
4107diff --git a/arch/arm/mm/init.c b/arch/arm/mm/init.c
4108index 804d615..fcec50a 100644
4109--- a/arch/arm/mm/init.c
4110+++ b/arch/arm/mm/init.c
4111@@ -30,6 +30,8 @@
4112 #include <asm/setup.h>
4113 #include <asm/tlb.h>
4114 #include <asm/fixmap.h>
4115+#include <asm/system_info.h>
4116+#include <asm/cp15.h>
4117
4118 #include <asm/mach/arch.h>
4119 #include <asm/mach/map.h>
4120@@ -625,7 +627,46 @@ void free_initmem(void)
4121 {
4122 #ifdef CONFIG_HAVE_TCM
4123 extern char __tcm_start, __tcm_end;
4124+#endif
4125
4126+#ifdef CONFIG_PAX_KERNEXEC
4127+ unsigned long addr;
4128+ pgd_t *pgd;
4129+ pud_t *pud;
4130+ pmd_t *pmd;
4131+ int cpu_arch = cpu_architecture();
4132+ unsigned int cr = get_cr();
4133+
4134+ if (cpu_arch >= CPU_ARCH_ARMv6 && (cr & CR_XP)) {
4135+ /* make pages tables, etc before .text NX */
4136+ for (addr = PAGE_OFFSET; addr < (unsigned long)_stext; addr += SECTION_SIZE) {
4137+ pgd = pgd_offset_k(addr);
4138+ pud = pud_offset(pgd, addr);
4139+ pmd = pmd_offset(pud, addr);
4140+ __section_update(pmd, addr, PMD_SECT_XN);
4141+ }
4142+ /* make init NX */
4143+ for (addr = (unsigned long)__init_begin; addr < (unsigned long)_sdata; addr += SECTION_SIZE) {
4144+ pgd = pgd_offset_k(addr);
4145+ pud = pud_offset(pgd, addr);
4146+ pmd = pmd_offset(pud, addr);
4147+ __section_update(pmd, addr, PMD_SECT_XN);
4148+ }
4149+ /* make kernel code/rodata RX */
4150+ for (addr = (unsigned long)_stext; addr < (unsigned long)__init_begin; addr += SECTION_SIZE) {
4151+ pgd = pgd_offset_k(addr);
4152+ pud = pud_offset(pgd, addr);
4153+ pmd = pmd_offset(pud, addr);
4154+#ifdef CONFIG_ARM_LPAE
4155+ __section_update(pmd, addr, PMD_SECT_RDONLY);
4156+#else
4157+ __section_update(pmd, addr, PMD_SECT_APX|PMD_SECT_AP_WRITE);
4158+#endif
4159+ }
4160+ }
4161+#endif
4162+
4163+#ifdef CONFIG_HAVE_TCM
4164 poison_init_mem(&__tcm_start, &__tcm_end - &__tcm_start);
4165 free_reserved_area(&__tcm_start, &__tcm_end, -1, "TCM link");
4166 #endif
4167diff --git a/arch/arm/mm/ioremap.c b/arch/arm/mm/ioremap.c
4168index f9c32ba..8540068 100644
4169--- a/arch/arm/mm/ioremap.c
4170+++ b/arch/arm/mm/ioremap.c
4171@@ -392,9 +392,9 @@ __arm_ioremap_exec(phys_addr_t phys_addr, size_t size, bool cached)
4172 unsigned int mtype;
4173
4174 if (cached)
4175- mtype = MT_MEMORY_RWX;
4176+ mtype = MT_MEMORY_RX;
4177 else
4178- mtype = MT_MEMORY_RWX_NONCACHED;
4179+ mtype = MT_MEMORY_RX_NONCACHED;
4180
4181 return __arm_ioremap_caller(phys_addr, size, mtype,
4182 __builtin_return_address(0));
4183diff --git a/arch/arm/mm/mmap.c b/arch/arm/mm/mmap.c
4184index 5e85ed3..b10a7ed 100644
4185--- a/arch/arm/mm/mmap.c
4186+++ b/arch/arm/mm/mmap.c
4187@@ -59,6 +59,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4188 struct vm_area_struct *vma;
4189 int do_align = 0;
4190 int aliasing = cache_is_vipt_aliasing();
4191+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
4192 struct vm_unmapped_area_info info;
4193
4194 /*
4195@@ -81,6 +82,10 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4196 if (len > TASK_SIZE)
4197 return -ENOMEM;
4198
4199+#ifdef CONFIG_PAX_RANDMMAP
4200+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
4201+#endif
4202+
4203 if (addr) {
4204 if (do_align)
4205 addr = COLOUR_ALIGN(addr, pgoff);
4206@@ -88,8 +93,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4207 addr = PAGE_ALIGN(addr);
4208
4209 vma = find_vma(mm, addr);
4210- if (TASK_SIZE - len >= addr &&
4211- (!vma || addr + len <= vma->vm_start))
4212+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
4213 return addr;
4214 }
4215
4216@@ -99,6 +103,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4217 info.high_limit = TASK_SIZE;
4218 info.align_mask = do_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
4219 info.align_offset = pgoff << PAGE_SHIFT;
4220+ info.threadstack_offset = offset;
4221 return vm_unmapped_area(&info);
4222 }
4223
4224@@ -112,6 +117,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4225 unsigned long addr = addr0;
4226 int do_align = 0;
4227 int aliasing = cache_is_vipt_aliasing();
4228+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
4229 struct vm_unmapped_area_info info;
4230
4231 /*
4232@@ -132,6 +138,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4233 return addr;
4234 }
4235
4236+#ifdef CONFIG_PAX_RANDMMAP
4237+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
4238+#endif
4239+
4240 /* requesting a specific address */
4241 if (addr) {
4242 if (do_align)
4243@@ -139,8 +149,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4244 else
4245 addr = PAGE_ALIGN(addr);
4246 vma = find_vma(mm, addr);
4247- if (TASK_SIZE - len >= addr &&
4248- (!vma || addr + len <= vma->vm_start))
4249+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
4250 return addr;
4251 }
4252
4253@@ -150,6 +159,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4254 info.high_limit = mm->mmap_base;
4255 info.align_mask = do_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
4256 info.align_offset = pgoff << PAGE_SHIFT;
4257+ info.threadstack_offset = offset;
4258 addr = vm_unmapped_area(&info);
4259
4260 /*
4261@@ -173,6 +183,10 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4262 {
4263 unsigned long random_factor = 0UL;
4264
4265+#ifdef CONFIG_PAX_RANDMMAP
4266+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
4267+#endif
4268+
4269 /* 8 bits of randomness in 20 address space bits */
4270 if ((current->flags & PF_RANDOMIZE) &&
4271 !(current->personality & ADDR_NO_RANDOMIZE))
4272@@ -180,9 +194,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4273
4274 if (mmap_is_legacy()) {
4275 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
4276+
4277+#ifdef CONFIG_PAX_RANDMMAP
4278+ if (mm->pax_flags & MF_PAX_RANDMMAP)
4279+ mm->mmap_base += mm->delta_mmap;
4280+#endif
4281+
4282 mm->get_unmapped_area = arch_get_unmapped_area;
4283 } else {
4284 mm->mmap_base = mmap_base(random_factor);
4285+
4286+#ifdef CONFIG_PAX_RANDMMAP
4287+ if (mm->pax_flags & MF_PAX_RANDMMAP)
4288+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
4289+#endif
4290+
4291 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
4292 }
4293 }
4294diff --git a/arch/arm/mm/mmu.c b/arch/arm/mm/mmu.c
4295index b68c6b2..f66c492 100644
4296--- a/arch/arm/mm/mmu.c
4297+++ b/arch/arm/mm/mmu.c
4298@@ -39,6 +39,22 @@
4299 #include "mm.h"
4300 #include "tcm.h"
4301
4302+#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
4303+void modify_domain(unsigned int dom, unsigned int type)
4304+{
4305+ struct thread_info *thread = current_thread_info();
4306+ unsigned int domain = thread->cpu_domain;
4307+ /*
4308+ * DOMAIN_MANAGER might be defined to some other value,
4309+ * use the arch-defined constant
4310+ */
4311+ domain &= ~domain_val(dom, 3);
4312+ thread->cpu_domain = domain | domain_val(dom, type);
4313+ set_domain(thread->cpu_domain);
4314+}
4315+EXPORT_SYMBOL(modify_domain);
4316+#endif
4317+
4318 /*
4319 * empty_zero_page is a special page that is used for
4320 * zero-initialized data and COW.
4321@@ -235,7 +251,15 @@ __setup("noalign", noalign_setup);
4322 #define PROT_PTE_S2_DEVICE PROT_PTE_DEVICE
4323 #define PROT_SECT_DEVICE PMD_TYPE_SECT|PMD_SECT_AP_WRITE
4324
4325-static struct mem_type mem_types[] = {
4326+#ifdef CONFIG_PAX_KERNEXEC
4327+#define L_PTE_KERNEXEC L_PTE_RDONLY
4328+#define PMD_SECT_KERNEXEC PMD_SECT_RDONLY
4329+#else
4330+#define L_PTE_KERNEXEC L_PTE_DIRTY
4331+#define PMD_SECT_KERNEXEC PMD_SECT_AP_WRITE
4332+#endif
4333+
4334+static struct mem_type mem_types[] __read_only = {
4335 [MT_DEVICE] = { /* Strongly ordered / ARMv6 shared device */
4336 .prot_pte = PROT_PTE_DEVICE | L_PTE_MT_DEV_SHARED |
4337 L_PTE_SHARED,
4338@@ -264,19 +288,19 @@ static struct mem_type mem_types[] = {
4339 .prot_sect = PROT_SECT_DEVICE,
4340 .domain = DOMAIN_IO,
4341 },
4342- [MT_UNCACHED] = {
4343+ [MT_UNCACHED_RW] = {
4344 .prot_pte = PROT_PTE_DEVICE,
4345 .prot_l1 = PMD_TYPE_TABLE,
4346 .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
4347 .domain = DOMAIN_IO,
4348 },
4349- [MT_CACHECLEAN] = {
4350- .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
4351+ [MT_CACHECLEAN_RO] = {
4352+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN | PMD_SECT_RDONLY,
4353 .domain = DOMAIN_KERNEL,
4354 },
4355 #ifndef CONFIG_ARM_LPAE
4356- [MT_MINICLEAN] = {
4357- .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN | PMD_SECT_MINICACHE,
4358+ [MT_MINICLEAN_RO] = {
4359+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_MINICACHE | PMD_SECT_XN | PMD_SECT_RDONLY,
4360 .domain = DOMAIN_KERNEL,
4361 },
4362 #endif
4363@@ -284,15 +308,15 @@ static struct mem_type mem_types[] = {
4364 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4365 L_PTE_RDONLY,
4366 .prot_l1 = PMD_TYPE_TABLE,
4367- .domain = DOMAIN_USER,
4368+ .domain = DOMAIN_VECTORS,
4369 },
4370 [MT_HIGH_VECTORS] = {
4371 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4372 L_PTE_USER | L_PTE_RDONLY,
4373 .prot_l1 = PMD_TYPE_TABLE,
4374- .domain = DOMAIN_USER,
4375+ .domain = DOMAIN_VECTORS,
4376 },
4377- [MT_MEMORY_RWX] = {
4378+ [__MT_MEMORY_RWX] = {
4379 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
4380 .prot_l1 = PMD_TYPE_TABLE,
4381 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
4382@@ -305,17 +329,30 @@ static struct mem_type mem_types[] = {
4383 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
4384 .domain = DOMAIN_KERNEL,
4385 },
4386- [MT_ROM] = {
4387- .prot_sect = PMD_TYPE_SECT,
4388+ [MT_MEMORY_RX] = {
4389+ .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_KERNEXEC,
4390+ .prot_l1 = PMD_TYPE_TABLE,
4391+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_KERNEXEC,
4392+ .domain = DOMAIN_KERNEL,
4393+ },
4394+ [MT_ROM_RX] = {
4395+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_RDONLY,
4396 .domain = DOMAIN_KERNEL,
4397 },
4398- [MT_MEMORY_RWX_NONCACHED] = {
4399+ [MT_MEMORY_RW_NONCACHED] = {
4400 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4401 L_PTE_MT_BUFFERABLE,
4402 .prot_l1 = PMD_TYPE_TABLE,
4403 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
4404 .domain = DOMAIN_KERNEL,
4405 },
4406+ [MT_MEMORY_RX_NONCACHED] = {
4407+ .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_KERNEXEC |
4408+ L_PTE_MT_BUFFERABLE,
4409+ .prot_l1 = PMD_TYPE_TABLE,
4410+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_KERNEXEC,
4411+ .domain = DOMAIN_KERNEL,
4412+ },
4413 [MT_MEMORY_RW_DTCM] = {
4414 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4415 L_PTE_XN,
4416@@ -323,9 +360,10 @@ static struct mem_type mem_types[] = {
4417 .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
4418 .domain = DOMAIN_KERNEL,
4419 },
4420- [MT_MEMORY_RWX_ITCM] = {
4421- .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
4422+ [MT_MEMORY_RX_ITCM] = {
4423+ .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_KERNEXEC,
4424 .prot_l1 = PMD_TYPE_TABLE,
4425+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_KERNEXEC,
4426 .domain = DOMAIN_KERNEL,
4427 },
4428 [MT_MEMORY_RW_SO] = {
4429@@ -534,9 +572,14 @@ static void __init build_mem_type_table(void)
4430 * Mark cache clean areas and XIP ROM read only
4431 * from SVC mode and no access from userspace.
4432 */
4433- mem_types[MT_ROM].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4434- mem_types[MT_MINICLEAN].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4435- mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4436+ mem_types[MT_ROM_RX].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4437+#ifdef CONFIG_PAX_KERNEXEC
4438+ mem_types[MT_MEMORY_RX].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4439+ mem_types[MT_MEMORY_RX_NONCACHED].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4440+ mem_types[MT_MEMORY_RX_ITCM].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4441+#endif
4442+ mem_types[MT_MINICLEAN_RO].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4443+ mem_types[MT_CACHECLEAN_RO].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4444 #endif
4445
4446 if (is_smp()) {
4447@@ -552,13 +595,17 @@ static void __init build_mem_type_table(void)
4448 mem_types[MT_DEVICE_WC].prot_pte |= L_PTE_SHARED;
4449 mem_types[MT_DEVICE_CACHED].prot_sect |= PMD_SECT_S;
4450 mem_types[MT_DEVICE_CACHED].prot_pte |= L_PTE_SHARED;
4451- mem_types[MT_MEMORY_RWX].prot_sect |= PMD_SECT_S;
4452- mem_types[MT_MEMORY_RWX].prot_pte |= L_PTE_SHARED;
4453+ mem_types[__MT_MEMORY_RWX].prot_sect |= PMD_SECT_S;
4454+ mem_types[__MT_MEMORY_RWX].prot_pte |= L_PTE_SHARED;
4455 mem_types[MT_MEMORY_RW].prot_sect |= PMD_SECT_S;
4456 mem_types[MT_MEMORY_RW].prot_pte |= L_PTE_SHARED;
4457+ mem_types[MT_MEMORY_RX].prot_sect |= PMD_SECT_S;
4458+ mem_types[MT_MEMORY_RX].prot_pte |= L_PTE_SHARED;
4459 mem_types[MT_MEMORY_DMA_READY].prot_pte |= L_PTE_SHARED;
4460- mem_types[MT_MEMORY_RWX_NONCACHED].prot_sect |= PMD_SECT_S;
4461- mem_types[MT_MEMORY_RWX_NONCACHED].prot_pte |= L_PTE_SHARED;
4462+ mem_types[MT_MEMORY_RW_NONCACHED].prot_sect |= PMD_SECT_S;
4463+ mem_types[MT_MEMORY_RW_NONCACHED].prot_pte |= L_PTE_SHARED;
4464+ mem_types[MT_MEMORY_RX_NONCACHED].prot_sect |= PMD_SECT_S;
4465+ mem_types[MT_MEMORY_RX_NONCACHED].prot_pte |= L_PTE_SHARED;
4466 }
4467 }
4468
4469@@ -569,15 +616,20 @@ static void __init build_mem_type_table(void)
4470 if (cpu_arch >= CPU_ARCH_ARMv6) {
4471 if (cpu_arch >= CPU_ARCH_ARMv7 && (cr & CR_TRE)) {
4472 /* Non-cacheable Normal is XCB = 001 */
4473- mem_types[MT_MEMORY_RWX_NONCACHED].prot_sect |=
4474+ mem_types[MT_MEMORY_RW_NONCACHED].prot_sect |=
4475+ PMD_SECT_BUFFERED;
4476+ mem_types[MT_MEMORY_RX_NONCACHED].prot_sect |=
4477 PMD_SECT_BUFFERED;
4478 } else {
4479 /* For both ARMv6 and non-TEX-remapping ARMv7 */
4480- mem_types[MT_MEMORY_RWX_NONCACHED].prot_sect |=
4481+ mem_types[MT_MEMORY_RW_NONCACHED].prot_sect |=
4482+ PMD_SECT_TEX(1);
4483+ mem_types[MT_MEMORY_RX_NONCACHED].prot_sect |=
4484 PMD_SECT_TEX(1);
4485 }
4486 } else {
4487- mem_types[MT_MEMORY_RWX_NONCACHED].prot_sect |= PMD_SECT_BUFFERABLE;
4488+ mem_types[MT_MEMORY_RW_NONCACHED].prot_sect |= PMD_SECT_BUFFERABLE;
4489+ mem_types[MT_MEMORY_RX_NONCACHED].prot_sect |= PMD_SECT_BUFFERABLE;
4490 }
4491
4492 #ifdef CONFIG_ARM_LPAE
4493@@ -593,6 +645,8 @@ static void __init build_mem_type_table(void)
4494 vecs_pgprot |= PTE_EXT_AF;
4495 #endif
4496
4497+ user_pgprot |= __supported_pte_mask;
4498+
4499 for (i = 0; i < 16; i++) {
4500 pteval_t v = pgprot_val(protection_map[i]);
4501 protection_map[i] = __pgprot(v | user_pgprot);
4502@@ -610,21 +664,24 @@ static void __init build_mem_type_table(void)
4503
4504 mem_types[MT_LOW_VECTORS].prot_l1 |= ecc_mask;
4505 mem_types[MT_HIGH_VECTORS].prot_l1 |= ecc_mask;
4506- mem_types[MT_MEMORY_RWX].prot_sect |= ecc_mask | cp->pmd;
4507- mem_types[MT_MEMORY_RWX].prot_pte |= kern_pgprot;
4508+ mem_types[__MT_MEMORY_RWX].prot_sect |= ecc_mask | cp->pmd;
4509+ mem_types[__MT_MEMORY_RWX].prot_pte |= kern_pgprot;
4510 mem_types[MT_MEMORY_RW].prot_sect |= ecc_mask | cp->pmd;
4511 mem_types[MT_MEMORY_RW].prot_pte |= kern_pgprot;
4512+ mem_types[MT_MEMORY_RX].prot_sect |= ecc_mask | cp->pmd;
4513+ mem_types[MT_MEMORY_RX].prot_pte |= kern_pgprot;
4514 mem_types[MT_MEMORY_DMA_READY].prot_pte |= kern_pgprot;
4515- mem_types[MT_MEMORY_RWX_NONCACHED].prot_sect |= ecc_mask;
4516- mem_types[MT_ROM].prot_sect |= cp->pmd;
4517+ mem_types[MT_MEMORY_RW_NONCACHED].prot_sect |= ecc_mask;
4518+ mem_types[MT_MEMORY_RX_NONCACHED].prot_sect |= ecc_mask;
4519+ mem_types[MT_ROM_RX].prot_sect |= cp->pmd;
4520
4521 switch (cp->pmd) {
4522 case PMD_SECT_WT:
4523- mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_WT;
4524+ mem_types[MT_CACHECLEAN_RO].prot_sect |= PMD_SECT_WT;
4525 break;
4526 case PMD_SECT_WB:
4527 case PMD_SECT_WBWA:
4528- mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_WB;
4529+ mem_types[MT_CACHECLEAN_RO].prot_sect |= PMD_SECT_WB;
4530 break;
4531 }
4532 pr_info("Memory policy: %sData cache %s\n",
4533@@ -842,7 +899,7 @@ static void __init create_mapping(struct map_desc *md)
4534 return;
4535 }
4536
4537- if ((md->type == MT_DEVICE || md->type == MT_ROM) &&
4538+ if ((md->type == MT_DEVICE || md->type == MT_ROM_RX) &&
4539 md->virtual >= PAGE_OFFSET &&
4540 (md->virtual < VMALLOC_START || md->virtual >= VMALLOC_END)) {
4541 printk(KERN_WARNING "BUG: mapping for 0x%08llx"
4542@@ -1257,18 +1314,15 @@ void __init arm_mm_memblock_reserve(void)
4543 * called function. This means you can't use any function or debugging
4544 * method which may touch any device, otherwise the kernel _will_ crash.
4545 */
4546+
4547+static char vectors[PAGE_SIZE * 2] __read_only __aligned(PAGE_SIZE);
4548+
4549 static void __init devicemaps_init(const struct machine_desc *mdesc)
4550 {
4551 struct map_desc map;
4552 unsigned long addr;
4553- void *vectors;
4554
4555- /*
4556- * Allocate the vector page early.
4557- */
4558- vectors = early_alloc(PAGE_SIZE * 2);
4559-
4560- early_trap_init(vectors);
4561+ early_trap_init(&vectors);
4562
4563 for (addr = VMALLOC_START; addr; addr += PMD_SIZE)
4564 pmd_clear(pmd_off_k(addr));
4565@@ -1281,7 +1335,7 @@ static void __init devicemaps_init(const struct machine_desc *mdesc)
4566 map.pfn = __phys_to_pfn(CONFIG_XIP_PHYS_ADDR & SECTION_MASK);
4567 map.virtual = MODULES_VADDR;
4568 map.length = ((unsigned long)_etext - map.virtual + ~SECTION_MASK) & SECTION_MASK;
4569- map.type = MT_ROM;
4570+ map.type = MT_ROM_RX;
4571 create_mapping(&map);
4572 #endif
4573
4574@@ -1292,14 +1346,14 @@ static void __init devicemaps_init(const struct machine_desc *mdesc)
4575 map.pfn = __phys_to_pfn(FLUSH_BASE_PHYS);
4576 map.virtual = FLUSH_BASE;
4577 map.length = SZ_1M;
4578- map.type = MT_CACHECLEAN;
4579+ map.type = MT_CACHECLEAN_RO;
4580 create_mapping(&map);
4581 #endif
4582 #ifdef FLUSH_BASE_MINICACHE
4583 map.pfn = __phys_to_pfn(FLUSH_BASE_PHYS + SZ_1M);
4584 map.virtual = FLUSH_BASE_MINICACHE;
4585 map.length = SZ_1M;
4586- map.type = MT_MINICLEAN;
4587+ map.type = MT_MINICLEAN_RO;
4588 create_mapping(&map);
4589 #endif
4590
4591@@ -1308,7 +1362,7 @@ static void __init devicemaps_init(const struct machine_desc *mdesc)
4592 * location (0xffff0000). If we aren't using high-vectors, also
4593 * create a mapping at the low-vectors virtual address.
4594 */
4595- map.pfn = __phys_to_pfn(virt_to_phys(vectors));
4596+ map.pfn = __phys_to_pfn(virt_to_phys(&vectors));
4597 map.virtual = 0xffff0000;
4598 map.length = PAGE_SIZE;
4599 #ifdef CONFIG_KUSER_HELPERS
4600@@ -1365,8 +1419,10 @@ static void __init kmap_init(void)
4601 static void __init map_lowmem(void)
4602 {
4603 struct memblock_region *reg;
4604+#ifndef CONFIG_PAX_KERNEXEC
4605 unsigned long kernel_x_start = round_down(__pa(_stext), SECTION_SIZE);
4606 unsigned long kernel_x_end = round_up(__pa(__init_end), SECTION_SIZE);
4607+#endif
4608
4609 /* Map all the lowmem memory banks. */
4610 for_each_memblock(memory, reg) {
4611@@ -1379,11 +1435,48 @@ static void __init map_lowmem(void)
4612 if (start >= end)
4613 break;
4614
4615+#ifdef CONFIG_PAX_KERNEXEC
4616+ map.pfn = __phys_to_pfn(start);
4617+ map.virtual = __phys_to_virt(start);
4618+ map.length = end - start;
4619+
4620+ if (map.virtual <= (unsigned long)_stext && ((unsigned long)_end < (map.virtual + map.length))) {
4621+ struct map_desc kernel;
4622+ struct map_desc initmap;
4623+
4624+ /* when freeing initmem we will make this RW */
4625+ initmap.pfn = __phys_to_pfn(__pa(__init_begin));
4626+ initmap.virtual = (unsigned long)__init_begin;
4627+ initmap.length = _sdata - __init_begin;
4628+ initmap.type = __MT_MEMORY_RWX;
4629+ create_mapping(&initmap);
4630+
4631+ /* when freeing initmem we will make this RX */
4632+ kernel.pfn = __phys_to_pfn(__pa(_stext));
4633+ kernel.virtual = (unsigned long)_stext;
4634+ kernel.length = __init_begin - _stext;
4635+ kernel.type = __MT_MEMORY_RWX;
4636+ create_mapping(&kernel);
4637+
4638+ if (map.virtual < (unsigned long)_stext) {
4639+ map.length = (unsigned long)_stext - map.virtual;
4640+ map.type = __MT_MEMORY_RWX;
4641+ create_mapping(&map);
4642+ }
4643+
4644+ map.pfn = __phys_to_pfn(__pa(_sdata));
4645+ map.virtual = (unsigned long)_sdata;
4646+ map.length = end - __pa(_sdata);
4647+ }
4648+
4649+ map.type = MT_MEMORY_RW;
4650+ create_mapping(&map);
4651+#else
4652 if (end < kernel_x_start || start >= kernel_x_end) {
4653 map.pfn = __phys_to_pfn(start);
4654 map.virtual = __phys_to_virt(start);
4655 map.length = end - start;
4656- map.type = MT_MEMORY_RWX;
4657+ map.type = __MT_MEMORY_RWX;
4658
4659 create_mapping(&map);
4660 } else {
4661@@ -1400,7 +1493,7 @@ static void __init map_lowmem(void)
4662 map.pfn = __phys_to_pfn(kernel_x_start);
4663 map.virtual = __phys_to_virt(kernel_x_start);
4664 map.length = kernel_x_end - kernel_x_start;
4665- map.type = MT_MEMORY_RWX;
4666+ map.type = __MT_MEMORY_RWX;
4667
4668 create_mapping(&map);
4669
4670@@ -1413,6 +1506,7 @@ static void __init map_lowmem(void)
4671 create_mapping(&map);
4672 }
4673 }
4674+#endif
4675 }
4676 }
4677
4678diff --git a/arch/arm/plat-iop/setup.c b/arch/arm/plat-iop/setup.c
4679index 5b217f4..c23f40e 100644
4680--- a/arch/arm/plat-iop/setup.c
4681+++ b/arch/arm/plat-iop/setup.c
4682@@ -24,7 +24,7 @@ static struct map_desc iop3xx_std_desc[] __initdata = {
4683 .virtual = IOP3XX_PERIPHERAL_VIRT_BASE,
4684 .pfn = __phys_to_pfn(IOP3XX_PERIPHERAL_PHYS_BASE),
4685 .length = IOP3XX_PERIPHERAL_SIZE,
4686- .type = MT_UNCACHED,
4687+ .type = MT_UNCACHED_RW,
4688 },
4689 };
4690
4691diff --git a/arch/arm/plat-omap/sram.c b/arch/arm/plat-omap/sram.c
4692index a5bc92d..0bb4730 100644
4693--- a/arch/arm/plat-omap/sram.c
4694+++ b/arch/arm/plat-omap/sram.c
4695@@ -93,6 +93,8 @@ void __init omap_map_sram(unsigned long start, unsigned long size,
4696 * Looks like we need to preserve some bootloader code at the
4697 * beginning of SRAM for jumping to flash for reboot to work...
4698 */
4699+ pax_open_kernel();
4700 memset_io(omap_sram_base + omap_sram_skip, 0,
4701 omap_sram_size - omap_sram_skip);
4702+ pax_close_kernel();
4703 }
4704diff --git a/arch/arm/plat-samsung/include/plat/dma-ops.h b/arch/arm/plat-samsung/include/plat/dma-ops.h
4705index ce6d763..cfea917 100644
4706--- a/arch/arm/plat-samsung/include/plat/dma-ops.h
4707+++ b/arch/arm/plat-samsung/include/plat/dma-ops.h
4708@@ -47,7 +47,7 @@ struct samsung_dma_ops {
4709 int (*started)(unsigned ch);
4710 int (*flush)(unsigned ch);
4711 int (*stop)(unsigned ch);
4712-};
4713+} __no_const;
4714
4715 extern void *samsung_dmadev_get_ops(void);
4716 extern void *s3c_dma_get_ops(void);
4717diff --git a/arch/arm64/include/asm/uaccess.h b/arch/arm64/include/asm/uaccess.h
4718index 6c0f684..5faea9d 100644
4719--- a/arch/arm64/include/asm/uaccess.h
4720+++ b/arch/arm64/include/asm/uaccess.h
4721@@ -99,6 +99,7 @@ static inline void set_fs(mm_segment_t fs)
4722 flag; \
4723 })
4724
4725+#define access_ok_noprefault(type, addr, size) access_ok((type), (addr), (size))
4726 #define access_ok(type, addr, size) __range_ok(addr, size)
4727 #define user_addr_max get_fs
4728
4729diff --git a/arch/avr32/include/asm/cache.h b/arch/avr32/include/asm/cache.h
4730index c3a58a1..78fbf54 100644
4731--- a/arch/avr32/include/asm/cache.h
4732+++ b/arch/avr32/include/asm/cache.h
4733@@ -1,8 +1,10 @@
4734 #ifndef __ASM_AVR32_CACHE_H
4735 #define __ASM_AVR32_CACHE_H
4736
4737+#include <linux/const.h>
4738+
4739 #define L1_CACHE_SHIFT 5
4740-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4741+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4742
4743 /*
4744 * Memory returned by kmalloc() may be used for DMA, so we must make
4745diff --git a/arch/avr32/include/asm/elf.h b/arch/avr32/include/asm/elf.h
4746index d232888..87c8df1 100644
4747--- a/arch/avr32/include/asm/elf.h
4748+++ b/arch/avr32/include/asm/elf.h
4749@@ -84,8 +84,14 @@ typedef struct user_fpu_struct elf_fpregset_t;
4750 the loader. We need to make sure that it is out of the way of the program
4751 that it will "exec", and that there is sufficient room for the brk. */
4752
4753-#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
4754+#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
4755
4756+#ifdef CONFIG_PAX_ASLR
4757+#define PAX_ELF_ET_DYN_BASE 0x00001000UL
4758+
4759+#define PAX_DELTA_MMAP_LEN 15
4760+#define PAX_DELTA_STACK_LEN 15
4761+#endif
4762
4763 /* This yields a mask that user programs can use to figure out what
4764 instruction set this CPU supports. This could be done in user space,
4765diff --git a/arch/avr32/include/asm/kmap_types.h b/arch/avr32/include/asm/kmap_types.h
4766index 479330b..53717a8 100644
4767--- a/arch/avr32/include/asm/kmap_types.h
4768+++ b/arch/avr32/include/asm/kmap_types.h
4769@@ -2,9 +2,9 @@
4770 #define __ASM_AVR32_KMAP_TYPES_H
4771
4772 #ifdef CONFIG_DEBUG_HIGHMEM
4773-# define KM_TYPE_NR 29
4774+# define KM_TYPE_NR 30
4775 #else
4776-# define KM_TYPE_NR 14
4777+# define KM_TYPE_NR 15
4778 #endif
4779
4780 #endif /* __ASM_AVR32_KMAP_TYPES_H */
4781diff --git a/arch/avr32/mm/fault.c b/arch/avr32/mm/fault.c
4782index 0eca933..eb78c7b 100644
4783--- a/arch/avr32/mm/fault.c
4784+++ b/arch/avr32/mm/fault.c
4785@@ -41,6 +41,23 @@ static inline int notify_page_fault(struct pt_regs *regs, int trap)
4786
4787 int exception_trace = 1;
4788
4789+#ifdef CONFIG_PAX_PAGEEXEC
4790+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
4791+{
4792+ unsigned long i;
4793+
4794+ printk(KERN_ERR "PAX: bytes at PC: ");
4795+ for (i = 0; i < 20; i++) {
4796+ unsigned char c;
4797+ if (get_user(c, (unsigned char *)pc+i))
4798+ printk(KERN_CONT "???????? ");
4799+ else
4800+ printk(KERN_CONT "%02x ", c);
4801+ }
4802+ printk("\n");
4803+}
4804+#endif
4805+
4806 /*
4807 * This routine handles page faults. It determines the address and the
4808 * problem, and then passes it off to one of the appropriate routines.
4809@@ -176,6 +193,16 @@ bad_area:
4810 up_read(&mm->mmap_sem);
4811
4812 if (user_mode(regs)) {
4813+
4814+#ifdef CONFIG_PAX_PAGEEXEC
4815+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
4816+ if (ecr == ECR_PROTECTION_X || ecr == ECR_TLB_MISS_X) {
4817+ pax_report_fault(regs, (void *)regs->pc, (void *)regs->sp);
4818+ do_group_exit(SIGKILL);
4819+ }
4820+ }
4821+#endif
4822+
4823 if (exception_trace && printk_ratelimit())
4824 printk("%s%s[%d]: segfault at %08lx pc %08lx "
4825 "sp %08lx ecr %lu\n",
4826diff --git a/arch/blackfin/include/asm/cache.h b/arch/blackfin/include/asm/cache.h
4827index 568885a..f8008df 100644
4828--- a/arch/blackfin/include/asm/cache.h
4829+++ b/arch/blackfin/include/asm/cache.h
4830@@ -7,6 +7,7 @@
4831 #ifndef __ARCH_BLACKFIN_CACHE_H
4832 #define __ARCH_BLACKFIN_CACHE_H
4833
4834+#include <linux/const.h>
4835 #include <linux/linkage.h> /* for asmlinkage */
4836
4837 /*
4838@@ -14,7 +15,7 @@
4839 * Blackfin loads 32 bytes for cache
4840 */
4841 #define L1_CACHE_SHIFT 5
4842-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4843+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4844 #define SMP_CACHE_BYTES L1_CACHE_BYTES
4845
4846 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
4847diff --git a/arch/cris/include/arch-v10/arch/cache.h b/arch/cris/include/arch-v10/arch/cache.h
4848index aea2718..3639a60 100644
4849--- a/arch/cris/include/arch-v10/arch/cache.h
4850+++ b/arch/cris/include/arch-v10/arch/cache.h
4851@@ -1,8 +1,9 @@
4852 #ifndef _ASM_ARCH_CACHE_H
4853 #define _ASM_ARCH_CACHE_H
4854
4855+#include <linux/const.h>
4856 /* Etrax 100LX have 32-byte cache-lines. */
4857-#define L1_CACHE_BYTES 32
4858 #define L1_CACHE_SHIFT 5
4859+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4860
4861 #endif /* _ASM_ARCH_CACHE_H */
4862diff --git a/arch/cris/include/arch-v32/arch/cache.h b/arch/cris/include/arch-v32/arch/cache.h
4863index 7caf25d..ee65ac5 100644
4864--- a/arch/cris/include/arch-v32/arch/cache.h
4865+++ b/arch/cris/include/arch-v32/arch/cache.h
4866@@ -1,11 +1,12 @@
4867 #ifndef _ASM_CRIS_ARCH_CACHE_H
4868 #define _ASM_CRIS_ARCH_CACHE_H
4869
4870+#include <linux/const.h>
4871 #include <arch/hwregs/dma.h>
4872
4873 /* A cache-line is 32 bytes. */
4874-#define L1_CACHE_BYTES 32
4875 #define L1_CACHE_SHIFT 5
4876+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4877
4878 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
4879
4880diff --git a/arch/frv/include/asm/atomic.h b/arch/frv/include/asm/atomic.h
4881index b86329d..6709906 100644
4882--- a/arch/frv/include/asm/atomic.h
4883+++ b/arch/frv/include/asm/atomic.h
4884@@ -186,6 +186,16 @@ static inline void atomic64_dec(atomic64_t *v)
4885 #define atomic64_cmpxchg(v, old, new) (__cmpxchg_64(old, new, &(v)->counter))
4886 #define atomic64_xchg(v, new) (__xchg_64(new, &(v)->counter))
4887
4888+#define atomic64_read_unchecked(v) atomic64_read(v)
4889+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
4890+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
4891+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
4892+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
4893+#define atomic64_inc_unchecked(v) atomic64_inc(v)
4894+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
4895+#define atomic64_dec_unchecked(v) atomic64_dec(v)
4896+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
4897+
4898 static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
4899 {
4900 int c, old;
4901diff --git a/arch/frv/include/asm/cache.h b/arch/frv/include/asm/cache.h
4902index 2797163..c2a401d 100644
4903--- a/arch/frv/include/asm/cache.h
4904+++ b/arch/frv/include/asm/cache.h
4905@@ -12,10 +12,11 @@
4906 #ifndef __ASM_CACHE_H
4907 #define __ASM_CACHE_H
4908
4909+#include <linux/const.h>
4910
4911 /* bytes per L1 cache line */
4912 #define L1_CACHE_SHIFT (CONFIG_FRV_L1_CACHE_SHIFT)
4913-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4914+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4915
4916 #define __cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
4917 #define ____cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
4918diff --git a/arch/frv/include/asm/kmap_types.h b/arch/frv/include/asm/kmap_types.h
4919index 43901f2..0d8b865 100644
4920--- a/arch/frv/include/asm/kmap_types.h
4921+++ b/arch/frv/include/asm/kmap_types.h
4922@@ -2,6 +2,6 @@
4923 #ifndef _ASM_KMAP_TYPES_H
4924 #define _ASM_KMAP_TYPES_H
4925
4926-#define KM_TYPE_NR 17
4927+#define KM_TYPE_NR 18
4928
4929 #endif
4930diff --git a/arch/frv/mm/elf-fdpic.c b/arch/frv/mm/elf-fdpic.c
4931index 836f147..4cf23f5 100644
4932--- a/arch/frv/mm/elf-fdpic.c
4933+++ b/arch/frv/mm/elf-fdpic.c
4934@@ -61,6 +61,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
4935 {
4936 struct vm_area_struct *vma;
4937 struct vm_unmapped_area_info info;
4938+ unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
4939
4940 if (len > TASK_SIZE)
4941 return -ENOMEM;
4942@@ -73,8 +74,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
4943 if (addr) {
4944 addr = PAGE_ALIGN(addr);
4945 vma = find_vma(current->mm, addr);
4946- if (TASK_SIZE - len >= addr &&
4947- (!vma || addr + len <= vma->vm_start))
4948+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
4949 goto success;
4950 }
4951
4952@@ -85,6 +85,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
4953 info.high_limit = (current->mm->start_stack - 0x00200000);
4954 info.align_mask = 0;
4955 info.align_offset = 0;
4956+ info.threadstack_offset = offset;
4957 addr = vm_unmapped_area(&info);
4958 if (!(addr & ~PAGE_MASK))
4959 goto success;
4960diff --git a/arch/hexagon/include/asm/cache.h b/arch/hexagon/include/asm/cache.h
4961index f4ca594..adc72fd6 100644
4962--- a/arch/hexagon/include/asm/cache.h
4963+++ b/arch/hexagon/include/asm/cache.h
4964@@ -21,9 +21,11 @@
4965 #ifndef __ASM_CACHE_H
4966 #define __ASM_CACHE_H
4967
4968+#include <linux/const.h>
4969+
4970 /* Bytes per L1 cache line */
4971-#define L1_CACHE_SHIFT (5)
4972-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4973+#define L1_CACHE_SHIFT 5
4974+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4975
4976 #define __cacheline_aligned __aligned(L1_CACHE_BYTES)
4977 #define ____cacheline_aligned __aligned(L1_CACHE_BYTES)
4978diff --git a/arch/ia64/Kconfig b/arch/ia64/Kconfig
4979index 0c8e553..112d734 100644
4980--- a/arch/ia64/Kconfig
4981+++ b/arch/ia64/Kconfig
4982@@ -544,6 +544,7 @@ source "drivers/sn/Kconfig"
4983 config KEXEC
4984 bool "kexec system call"
4985 depends on !IA64_HP_SIM && (!SMP || HOTPLUG_CPU)
4986+ depends on !GRKERNSEC_KMEM
4987 help
4988 kexec is a system call that implements the ability to shutdown your
4989 current kernel, and to start another kernel. It is like a reboot
4990diff --git a/arch/ia64/include/asm/atomic.h b/arch/ia64/include/asm/atomic.h
4991index 6e6fe18..a6ae668 100644
4992--- a/arch/ia64/include/asm/atomic.h
4993+++ b/arch/ia64/include/asm/atomic.h
4994@@ -208,6 +208,16 @@ atomic64_add_negative (__s64 i, atomic64_t *v)
4995 #define atomic64_inc(v) atomic64_add(1, (v))
4996 #define atomic64_dec(v) atomic64_sub(1, (v))
4997
4998+#define atomic64_read_unchecked(v) atomic64_read(v)
4999+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
5000+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
5001+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
5002+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
5003+#define atomic64_inc_unchecked(v) atomic64_inc(v)
5004+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
5005+#define atomic64_dec_unchecked(v) atomic64_dec(v)
5006+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
5007+
5008 /* Atomic operations are already serializing */
5009 #define smp_mb__before_atomic_dec() barrier()
5010 #define smp_mb__after_atomic_dec() barrier()
5011diff --git a/arch/ia64/include/asm/cache.h b/arch/ia64/include/asm/cache.h
5012index 988254a..e1ee885 100644
5013--- a/arch/ia64/include/asm/cache.h
5014+++ b/arch/ia64/include/asm/cache.h
5015@@ -1,6 +1,7 @@
5016 #ifndef _ASM_IA64_CACHE_H
5017 #define _ASM_IA64_CACHE_H
5018
5019+#include <linux/const.h>
5020
5021 /*
5022 * Copyright (C) 1998-2000 Hewlett-Packard Co
5023@@ -9,7 +10,7 @@
5024
5025 /* Bytes per L1 (data) cache line. */
5026 #define L1_CACHE_SHIFT CONFIG_IA64_L1_CACHE_SHIFT
5027-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5028+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5029
5030 #ifdef CONFIG_SMP
5031 # define SMP_CACHE_SHIFT L1_CACHE_SHIFT
5032diff --git a/arch/ia64/include/asm/elf.h b/arch/ia64/include/asm/elf.h
5033index 5a83c5c..4d7f553 100644
5034--- a/arch/ia64/include/asm/elf.h
5035+++ b/arch/ia64/include/asm/elf.h
5036@@ -42,6 +42,13 @@
5037 */
5038 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x800000000UL)
5039
5040+#ifdef CONFIG_PAX_ASLR
5041+#define PAX_ELF_ET_DYN_BASE (current->personality == PER_LINUX32 ? 0x08048000UL : 0x4000000000000000UL)
5042+
5043+#define PAX_DELTA_MMAP_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
5044+#define PAX_DELTA_STACK_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
5045+#endif
5046+
5047 #define PT_IA_64_UNWIND 0x70000001
5048
5049 /* IA-64 relocations: */
5050diff --git a/arch/ia64/include/asm/pgalloc.h b/arch/ia64/include/asm/pgalloc.h
5051index 5767cdf..7462574 100644
5052--- a/arch/ia64/include/asm/pgalloc.h
5053+++ b/arch/ia64/include/asm/pgalloc.h
5054@@ -39,6 +39,12 @@ pgd_populate(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
5055 pgd_val(*pgd_entry) = __pa(pud);
5056 }
5057
5058+static inline void
5059+pgd_populate_kernel(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
5060+{
5061+ pgd_populate(mm, pgd_entry, pud);
5062+}
5063+
5064 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
5065 {
5066 return quicklist_alloc(0, GFP_KERNEL, NULL);
5067@@ -57,6 +63,12 @@ pud_populate(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
5068 pud_val(*pud_entry) = __pa(pmd);
5069 }
5070
5071+static inline void
5072+pud_populate_kernel(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
5073+{
5074+ pud_populate(mm, pud_entry, pmd);
5075+}
5076+
5077 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
5078 {
5079 return quicklist_alloc(0, GFP_KERNEL, NULL);
5080diff --git a/arch/ia64/include/asm/pgtable.h b/arch/ia64/include/asm/pgtable.h
5081index 7935115..c0eca6a 100644
5082--- a/arch/ia64/include/asm/pgtable.h
5083+++ b/arch/ia64/include/asm/pgtable.h
5084@@ -12,7 +12,7 @@
5085 * David Mosberger-Tang <davidm@hpl.hp.com>
5086 */
5087
5088-
5089+#include <linux/const.h>
5090 #include <asm/mman.h>
5091 #include <asm/page.h>
5092 #include <asm/processor.h>
5093@@ -142,6 +142,17 @@
5094 #define PAGE_READONLY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
5095 #define PAGE_COPY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
5096 #define PAGE_COPY_EXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RX)
5097+
5098+#ifdef CONFIG_PAX_PAGEEXEC
5099+# define PAGE_SHARED_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RW)
5100+# define PAGE_READONLY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
5101+# define PAGE_COPY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
5102+#else
5103+# define PAGE_SHARED_NOEXEC PAGE_SHARED
5104+# define PAGE_READONLY_NOEXEC PAGE_READONLY
5105+# define PAGE_COPY_NOEXEC PAGE_COPY
5106+#endif
5107+
5108 #define PAGE_GATE __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_X_RX)
5109 #define PAGE_KERNEL __pgprot(__DIRTY_BITS | _PAGE_PL_0 | _PAGE_AR_RWX)
5110 #define PAGE_KERNELRX __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_RX)
5111diff --git a/arch/ia64/include/asm/spinlock.h b/arch/ia64/include/asm/spinlock.h
5112index 45698cd..e8e2dbc 100644
5113--- a/arch/ia64/include/asm/spinlock.h
5114+++ b/arch/ia64/include/asm/spinlock.h
5115@@ -71,7 +71,7 @@ static __always_inline void __ticket_spin_unlock(arch_spinlock_t *lock)
5116 unsigned short *p = (unsigned short *)&lock->lock + 1, tmp;
5117
5118 asm volatile ("ld2.bias %0=[%1]" : "=r"(tmp) : "r"(p));
5119- ACCESS_ONCE(*p) = (tmp + 2) & ~1;
5120+ ACCESS_ONCE_RW(*p) = (tmp + 2) & ~1;
5121 }
5122
5123 static __always_inline void __ticket_spin_unlock_wait(arch_spinlock_t *lock)
5124diff --git a/arch/ia64/include/asm/uaccess.h b/arch/ia64/include/asm/uaccess.h
5125index 449c8c0..3d4b1e9 100644
5126--- a/arch/ia64/include/asm/uaccess.h
5127+++ b/arch/ia64/include/asm/uaccess.h
5128@@ -70,6 +70,7 @@
5129 && ((segment).seg == KERNEL_DS.seg \
5130 || likely(REGION_OFFSET((unsigned long) (addr)) < RGN_MAP_LIMIT))); \
5131 })
5132+#define access_ok_noprefault(type, addr, size) access_ok((type), (addr), (size))
5133 #define access_ok(type, addr, size) __access_ok((addr), (size), get_fs())
5134
5135 /*
5136@@ -240,12 +241,24 @@ extern unsigned long __must_check __copy_user (void __user *to, const void __use
5137 static inline unsigned long
5138 __copy_to_user (void __user *to, const void *from, unsigned long count)
5139 {
5140+ if (count > INT_MAX)
5141+ return count;
5142+
5143+ if (!__builtin_constant_p(count))
5144+ check_object_size(from, count, true);
5145+
5146 return __copy_user(to, (__force void __user *) from, count);
5147 }
5148
5149 static inline unsigned long
5150 __copy_from_user (void *to, const void __user *from, unsigned long count)
5151 {
5152+ if (count > INT_MAX)
5153+ return count;
5154+
5155+ if (!__builtin_constant_p(count))
5156+ check_object_size(to, count, false);
5157+
5158 return __copy_user((__force void __user *) to, from, count);
5159 }
5160
5161@@ -255,10 +268,13 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
5162 ({ \
5163 void __user *__cu_to = (to); \
5164 const void *__cu_from = (from); \
5165- long __cu_len = (n); \
5166+ unsigned long __cu_len = (n); \
5167 \
5168- if (__access_ok(__cu_to, __cu_len, get_fs())) \
5169+ if (__cu_len <= INT_MAX && __access_ok(__cu_to, __cu_len, get_fs())) { \
5170+ if (!__builtin_constant_p(n)) \
5171+ check_object_size(__cu_from, __cu_len, true); \
5172 __cu_len = __copy_user(__cu_to, (__force void __user *) __cu_from, __cu_len); \
5173+ } \
5174 __cu_len; \
5175 })
5176
5177@@ -266,11 +282,14 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
5178 ({ \
5179 void *__cu_to = (to); \
5180 const void __user *__cu_from = (from); \
5181- long __cu_len = (n); \
5182+ unsigned long __cu_len = (n); \
5183 \
5184 __chk_user_ptr(__cu_from); \
5185- if (__access_ok(__cu_from, __cu_len, get_fs())) \
5186+ if (__cu_len <= INT_MAX && __access_ok(__cu_from, __cu_len, get_fs())) { \
5187+ if (!__builtin_constant_p(n)) \
5188+ check_object_size(__cu_to, __cu_len, false); \
5189 __cu_len = __copy_user((__force void __user *) __cu_to, __cu_from, __cu_len); \
5190+ } \
5191 __cu_len; \
5192 })
5193
5194diff --git a/arch/ia64/kernel/module.c b/arch/ia64/kernel/module.c
5195index 24603be..948052d 100644
5196--- a/arch/ia64/kernel/module.c
5197+++ b/arch/ia64/kernel/module.c
5198@@ -307,8 +307,7 @@ plt_target (struct plt_entry *plt)
5199 void
5200 module_free (struct module *mod, void *module_region)
5201 {
5202- if (mod && mod->arch.init_unw_table &&
5203- module_region == mod->module_init) {
5204+ if (mod && mod->arch.init_unw_table && module_region == mod->module_init_rx) {
5205 unw_remove_unwind_table(mod->arch.init_unw_table);
5206 mod->arch.init_unw_table = NULL;
5207 }
5208@@ -494,15 +493,39 @@ module_frob_arch_sections (Elf_Ehdr *ehdr, Elf_Shdr *sechdrs, char *secstrings,
5209 }
5210
5211 static inline int
5212+in_init_rx (const struct module *mod, uint64_t addr)
5213+{
5214+ return addr - (uint64_t) mod->module_init_rx < mod->init_size_rx;
5215+}
5216+
5217+static inline int
5218+in_init_rw (const struct module *mod, uint64_t addr)
5219+{
5220+ return addr - (uint64_t) mod->module_init_rw < mod->init_size_rw;
5221+}
5222+
5223+static inline int
5224 in_init (const struct module *mod, uint64_t addr)
5225 {
5226- return addr - (uint64_t) mod->module_init < mod->init_size;
5227+ return in_init_rx(mod, addr) || in_init_rw(mod, addr);
5228+}
5229+
5230+static inline int
5231+in_core_rx (const struct module *mod, uint64_t addr)
5232+{
5233+ return addr - (uint64_t) mod->module_core_rx < mod->core_size_rx;
5234+}
5235+
5236+static inline int
5237+in_core_rw (const struct module *mod, uint64_t addr)
5238+{
5239+ return addr - (uint64_t) mod->module_core_rw < mod->core_size_rw;
5240 }
5241
5242 static inline int
5243 in_core (const struct module *mod, uint64_t addr)
5244 {
5245- return addr - (uint64_t) mod->module_core < mod->core_size;
5246+ return in_core_rx(mod, addr) || in_core_rw(mod, addr);
5247 }
5248
5249 static inline int
5250@@ -685,7 +708,14 @@ do_reloc (struct module *mod, uint8_t r_type, Elf64_Sym *sym, uint64_t addend,
5251 break;
5252
5253 case RV_BDREL:
5254- val -= (uint64_t) (in_init(mod, val) ? mod->module_init : mod->module_core);
5255+ if (in_init_rx(mod, val))
5256+ val -= (uint64_t) mod->module_init_rx;
5257+ else if (in_init_rw(mod, val))
5258+ val -= (uint64_t) mod->module_init_rw;
5259+ else if (in_core_rx(mod, val))
5260+ val -= (uint64_t) mod->module_core_rx;
5261+ else if (in_core_rw(mod, val))
5262+ val -= (uint64_t) mod->module_core_rw;
5263 break;
5264
5265 case RV_LTV:
5266@@ -820,15 +850,15 @@ apply_relocate_add (Elf64_Shdr *sechdrs, const char *strtab, unsigned int symind
5267 * addresses have been selected...
5268 */
5269 uint64_t gp;
5270- if (mod->core_size > MAX_LTOFF)
5271+ if (mod->core_size_rx + mod->core_size_rw > MAX_LTOFF)
5272 /*
5273 * This takes advantage of fact that SHF_ARCH_SMALL gets allocated
5274 * at the end of the module.
5275 */
5276- gp = mod->core_size - MAX_LTOFF / 2;
5277+ gp = mod->core_size_rx + mod->core_size_rw - MAX_LTOFF / 2;
5278 else
5279- gp = mod->core_size / 2;
5280- gp = (uint64_t) mod->module_core + ((gp + 7) & -8);
5281+ gp = (mod->core_size_rx + mod->core_size_rw) / 2;
5282+ gp = (uint64_t) mod->module_core_rx + ((gp + 7) & -8);
5283 mod->arch.gp = gp;
5284 DEBUGP("%s: placing gp at 0x%lx\n", __func__, gp);
5285 }
5286diff --git a/arch/ia64/kernel/palinfo.c b/arch/ia64/kernel/palinfo.c
5287index ab33328..f39506c 100644
5288--- a/arch/ia64/kernel/palinfo.c
5289+++ b/arch/ia64/kernel/palinfo.c
5290@@ -980,7 +980,7 @@ static int palinfo_cpu_callback(struct notifier_block *nfb,
5291 return NOTIFY_OK;
5292 }
5293
5294-static struct notifier_block __refdata palinfo_cpu_notifier =
5295+static struct notifier_block palinfo_cpu_notifier =
5296 {
5297 .notifier_call = palinfo_cpu_callback,
5298 .priority = 0,
5299diff --git a/arch/ia64/kernel/sys_ia64.c b/arch/ia64/kernel/sys_ia64.c
5300index 41e33f8..65180b2a 100644
5301--- a/arch/ia64/kernel/sys_ia64.c
5302+++ b/arch/ia64/kernel/sys_ia64.c
5303@@ -28,6 +28,7 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
5304 unsigned long align_mask = 0;
5305 struct mm_struct *mm = current->mm;
5306 struct vm_unmapped_area_info info;
5307+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
5308
5309 if (len > RGN_MAP_LIMIT)
5310 return -ENOMEM;
5311@@ -43,6 +44,13 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
5312 if (REGION_NUMBER(addr) == RGN_HPAGE)
5313 addr = 0;
5314 #endif
5315+
5316+#ifdef CONFIG_PAX_RANDMMAP
5317+ if (mm->pax_flags & MF_PAX_RANDMMAP)
5318+ addr = mm->free_area_cache;
5319+ else
5320+#endif
5321+
5322 if (!addr)
5323 addr = TASK_UNMAPPED_BASE;
5324
5325@@ -61,6 +69,7 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
5326 info.high_limit = TASK_SIZE;
5327 info.align_mask = align_mask;
5328 info.align_offset = 0;
5329+ info.threadstack_offset = offset;
5330 return vm_unmapped_area(&info);
5331 }
5332
5333diff --git a/arch/ia64/kernel/vmlinux.lds.S b/arch/ia64/kernel/vmlinux.lds.S
5334index 84f8a52..7c76178 100644
5335--- a/arch/ia64/kernel/vmlinux.lds.S
5336+++ b/arch/ia64/kernel/vmlinux.lds.S
5337@@ -192,7 +192,7 @@ SECTIONS {
5338 /* Per-cpu data: */
5339 . = ALIGN(PERCPU_PAGE_SIZE);
5340 PERCPU_VADDR(SMP_CACHE_BYTES, PERCPU_ADDR, :percpu)
5341- __phys_per_cpu_start = __per_cpu_load;
5342+ __phys_per_cpu_start = per_cpu_load;
5343 /*
5344 * ensure percpu data fits
5345 * into percpu page size
5346diff --git a/arch/ia64/mm/fault.c b/arch/ia64/mm/fault.c
5347index 7225dad..2a7c8256 100644
5348--- a/arch/ia64/mm/fault.c
5349+++ b/arch/ia64/mm/fault.c
5350@@ -72,6 +72,23 @@ mapped_kernel_page_is_present (unsigned long address)
5351 return pte_present(pte);
5352 }
5353
5354+#ifdef CONFIG_PAX_PAGEEXEC
5355+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
5356+{
5357+ unsigned long i;
5358+
5359+ printk(KERN_ERR "PAX: bytes at PC: ");
5360+ for (i = 0; i < 8; i++) {
5361+ unsigned int c;
5362+ if (get_user(c, (unsigned int *)pc+i))
5363+ printk(KERN_CONT "???????? ");
5364+ else
5365+ printk(KERN_CONT "%08x ", c);
5366+ }
5367+ printk("\n");
5368+}
5369+#endif
5370+
5371 # define VM_READ_BIT 0
5372 # define VM_WRITE_BIT 1
5373 # define VM_EXEC_BIT 2
5374@@ -151,8 +168,21 @@ retry:
5375 if (((isr >> IA64_ISR_R_BIT) & 1UL) && (!(vma->vm_flags & (VM_READ | VM_WRITE))))
5376 goto bad_area;
5377
5378- if ((vma->vm_flags & mask) != mask)
5379+ if ((vma->vm_flags & mask) != mask) {
5380+
5381+#ifdef CONFIG_PAX_PAGEEXEC
5382+ if (!(vma->vm_flags & VM_EXEC) && (mask & VM_EXEC)) {
5383+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->cr_iip)
5384+ goto bad_area;
5385+
5386+ up_read(&mm->mmap_sem);
5387+ pax_report_fault(regs, (void *)regs->cr_iip, (void *)regs->r12);
5388+ do_group_exit(SIGKILL);
5389+ }
5390+#endif
5391+
5392 goto bad_area;
5393+ }
5394
5395 /*
5396 * If for any reason at all we couldn't handle the fault, make
5397diff --git a/arch/ia64/mm/hugetlbpage.c b/arch/ia64/mm/hugetlbpage.c
5398index 68232db..6ca80af 100644
5399--- a/arch/ia64/mm/hugetlbpage.c
5400+++ b/arch/ia64/mm/hugetlbpage.c
5401@@ -154,6 +154,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
5402 unsigned long pgoff, unsigned long flags)
5403 {
5404 struct vm_unmapped_area_info info;
5405+ unsigned long offset = gr_rand_threadstack_offset(current->mm, file, flags);
5406
5407 if (len > RGN_MAP_LIMIT)
5408 return -ENOMEM;
5409@@ -177,6 +178,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
5410 info.high_limit = HPAGE_REGION_BASE + RGN_MAP_LIMIT;
5411 info.align_mask = PAGE_MASK & (HPAGE_SIZE - 1);
5412 info.align_offset = 0;
5413+ info.threadstack_offset = offset;
5414 return vm_unmapped_area(&info);
5415 }
5416
5417diff --git a/arch/ia64/mm/init.c b/arch/ia64/mm/init.c
5418index 25c3502..560dae7 100644
5419--- a/arch/ia64/mm/init.c
5420+++ b/arch/ia64/mm/init.c
5421@@ -120,6 +120,19 @@ ia64_init_addr_space (void)
5422 vma->vm_start = current->thread.rbs_bot & PAGE_MASK;
5423 vma->vm_end = vma->vm_start + PAGE_SIZE;
5424 vma->vm_flags = VM_DATA_DEFAULT_FLAGS|VM_GROWSUP|VM_ACCOUNT;
5425+
5426+#ifdef CONFIG_PAX_PAGEEXEC
5427+ if (current->mm->pax_flags & MF_PAX_PAGEEXEC) {
5428+ vma->vm_flags &= ~VM_EXEC;
5429+
5430+#ifdef CONFIG_PAX_MPROTECT
5431+ if (current->mm->pax_flags & MF_PAX_MPROTECT)
5432+ vma->vm_flags &= ~VM_MAYEXEC;
5433+#endif
5434+
5435+ }
5436+#endif
5437+
5438 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
5439 down_write(&current->mm->mmap_sem);
5440 if (insert_vm_struct(current->mm, vma)) {
5441diff --git a/arch/m32r/include/asm/cache.h b/arch/m32r/include/asm/cache.h
5442index 40b3ee9..8c2c112 100644
5443--- a/arch/m32r/include/asm/cache.h
5444+++ b/arch/m32r/include/asm/cache.h
5445@@ -1,8 +1,10 @@
5446 #ifndef _ASM_M32R_CACHE_H
5447 #define _ASM_M32R_CACHE_H
5448
5449+#include <linux/const.h>
5450+
5451 /* L1 cache line size */
5452 #define L1_CACHE_SHIFT 4
5453-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5454+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5455
5456 #endif /* _ASM_M32R_CACHE_H */
5457diff --git a/arch/m32r/lib/usercopy.c b/arch/m32r/lib/usercopy.c
5458index 82abd15..d95ae5d 100644
5459--- a/arch/m32r/lib/usercopy.c
5460+++ b/arch/m32r/lib/usercopy.c
5461@@ -14,6 +14,9 @@
5462 unsigned long
5463 __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
5464 {
5465+ if ((long)n < 0)
5466+ return n;
5467+
5468 prefetch(from);
5469 if (access_ok(VERIFY_WRITE, to, n))
5470 __copy_user(to,from,n);
5471@@ -23,6 +26,9 @@ __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
5472 unsigned long
5473 __generic_copy_from_user(void *to, const void __user *from, unsigned long n)
5474 {
5475+ if ((long)n < 0)
5476+ return n;
5477+
5478 prefetchw(to);
5479 if (access_ok(VERIFY_READ, from, n))
5480 __copy_user_zeroing(to,from,n);
5481diff --git a/arch/m68k/include/asm/cache.h b/arch/m68k/include/asm/cache.h
5482index 0395c51..5f26031 100644
5483--- a/arch/m68k/include/asm/cache.h
5484+++ b/arch/m68k/include/asm/cache.h
5485@@ -4,9 +4,11 @@
5486 #ifndef __ARCH_M68K_CACHE_H
5487 #define __ARCH_M68K_CACHE_H
5488
5489+#include <linux/const.h>
5490+
5491 /* bytes per L1 cache line */
5492 #define L1_CACHE_SHIFT 4
5493-#define L1_CACHE_BYTES (1<< L1_CACHE_SHIFT)
5494+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5495
5496 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
5497
5498diff --git a/arch/metag/mm/hugetlbpage.c b/arch/metag/mm/hugetlbpage.c
5499index 0424315..defcca9 100644
5500--- a/arch/metag/mm/hugetlbpage.c
5501+++ b/arch/metag/mm/hugetlbpage.c
5502@@ -205,6 +205,7 @@ hugetlb_get_unmapped_area_new_pmd(unsigned long len)
5503 info.high_limit = TASK_SIZE;
5504 info.align_mask = PAGE_MASK & HUGEPT_MASK;
5505 info.align_offset = 0;
5506+ info.threadstack_offset = 0;
5507 return vm_unmapped_area(&info);
5508 }
5509
5510diff --git a/arch/microblaze/include/asm/cache.h b/arch/microblaze/include/asm/cache.h
5511index 4efe96a..60e8699 100644
5512--- a/arch/microblaze/include/asm/cache.h
5513+++ b/arch/microblaze/include/asm/cache.h
5514@@ -13,11 +13,12 @@
5515 #ifndef _ASM_MICROBLAZE_CACHE_H
5516 #define _ASM_MICROBLAZE_CACHE_H
5517
5518+#include <linux/const.h>
5519 #include <asm/registers.h>
5520
5521 #define L1_CACHE_SHIFT 5
5522 /* word-granular cache in microblaze */
5523-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5524+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5525
5526 #define SMP_CACHE_BYTES L1_CACHE_BYTES
5527
5528diff --git a/arch/mips/Kconfig b/arch/mips/Kconfig
5529index 95fa1f1..56a6fa2 100644
5530--- a/arch/mips/Kconfig
5531+++ b/arch/mips/Kconfig
5532@@ -2298,6 +2298,7 @@ source "kernel/Kconfig.preempt"
5533
5534 config KEXEC
5535 bool "Kexec system call"
5536+ depends on !GRKERNSEC_KMEM
5537 help
5538 kexec is a system call that implements the ability to shutdown your
5539 current kernel, and to start another kernel. It is like a reboot
5540diff --git a/arch/mips/cavium-octeon/dma-octeon.c b/arch/mips/cavium-octeon/dma-octeon.c
5541index 02f2444..506969c 100644
5542--- a/arch/mips/cavium-octeon/dma-octeon.c
5543+++ b/arch/mips/cavium-octeon/dma-octeon.c
5544@@ -199,7 +199,7 @@ static void octeon_dma_free_coherent(struct device *dev, size_t size,
5545 if (dma_release_from_coherent(dev, order, vaddr))
5546 return;
5547
5548- swiotlb_free_coherent(dev, size, vaddr, dma_handle);
5549+ swiotlb_free_coherent(dev, size, vaddr, dma_handle, attrs);
5550 }
5551
5552 static dma_addr_t octeon_unity_phys_to_dma(struct device *dev, phys_addr_t paddr)
5553diff --git a/arch/mips/include/asm/atomic.h b/arch/mips/include/asm/atomic.h
5554index 7eed2f2..c4e385d 100644
5555--- a/arch/mips/include/asm/atomic.h
5556+++ b/arch/mips/include/asm/atomic.h
5557@@ -21,15 +21,39 @@
5558 #include <asm/cmpxchg.h>
5559 #include <asm/war.h>
5560
5561+#ifdef CONFIG_GENERIC_ATOMIC64
5562+#include <asm-generic/atomic64.h>
5563+#endif
5564+
5565 #define ATOMIC_INIT(i) { (i) }
5566
5567+#ifdef CONFIG_64BIT
5568+#define _ASM_EXTABLE(from, to) \
5569+" .section __ex_table,\"a\"\n" \
5570+" .dword " #from ", " #to"\n" \
5571+" .previous\n"
5572+#else
5573+#define _ASM_EXTABLE(from, to) \
5574+" .section __ex_table,\"a\"\n" \
5575+" .word " #from ", " #to"\n" \
5576+" .previous\n"
5577+#endif
5578+
5579 /*
5580 * atomic_read - read atomic variable
5581 * @v: pointer of type atomic_t
5582 *
5583 * Atomically reads the value of @v.
5584 */
5585-#define atomic_read(v) (*(volatile int *)&(v)->counter)
5586+static inline int atomic_read(const atomic_t *v)
5587+{
5588+ return (*(volatile const int *) &v->counter);
5589+}
5590+
5591+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
5592+{
5593+ return (*(volatile const int *) &v->counter);
5594+}
5595
5596 /*
5597 * atomic_set - set atomic variable
5598@@ -38,7 +62,15 @@
5599 *
5600 * Atomically sets the value of @v to @i.
5601 */
5602-#define atomic_set(v, i) ((v)->counter = (i))
5603+static inline void atomic_set(atomic_t *v, int i)
5604+{
5605+ v->counter = i;
5606+}
5607+
5608+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
5609+{
5610+ v->counter = i;
5611+}
5612
5613 /*
5614 * atomic_add - add integer to atomic variable
5615@@ -47,7 +79,67 @@
5616 *
5617 * Atomically adds @i to @v.
5618 */
5619-static __inline__ void atomic_add(int i, atomic_t * v)
5620+static __inline__ void atomic_add(int i, atomic_t *v)
5621+{
5622+ int temp;
5623+
5624+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
5625+ __asm__ __volatile__(
5626+ " .set mips3 \n"
5627+ "1: ll %0, %1 # atomic_add \n"
5628+#ifdef CONFIG_PAX_REFCOUNT
5629+ /* Exception on overflow. */
5630+ "2: add %0, %2 \n"
5631+#else
5632+ " addu %0, %2 \n"
5633+#endif
5634+ " sc %0, %1 \n"
5635+ " beqzl %0, 1b \n"
5636+#ifdef CONFIG_PAX_REFCOUNT
5637+ "3: \n"
5638+ _ASM_EXTABLE(2b, 3b)
5639+#endif
5640+ " .set mips0 \n"
5641+ : "=&r" (temp), "+m" (v->counter)
5642+ : "Ir" (i));
5643+ } else if (kernel_uses_llsc) {
5644+ __asm__ __volatile__(
5645+ " .set mips3 \n"
5646+ "1: ll %0, %1 # atomic_add \n"
5647+#ifdef CONFIG_PAX_REFCOUNT
5648+ /* Exception on overflow. */
5649+ "2: add %0, %2 \n"
5650+#else
5651+ " addu %0, %2 \n"
5652+#endif
5653+ " sc %0, %1 \n"
5654+ " beqz %0, 1b \n"
5655+#ifdef CONFIG_PAX_REFCOUNT
5656+ "3: \n"
5657+ _ASM_EXTABLE(2b, 3b)
5658+#endif
5659+ " .set mips0 \n"
5660+ : "=&r" (temp), "+m" (v->counter)
5661+ : "Ir" (i));
5662+ } else {
5663+ unsigned long flags;
5664+
5665+ raw_local_irq_save(flags);
5666+ __asm__ __volatile__(
5667+#ifdef CONFIG_PAX_REFCOUNT
5668+ /* Exception on overflow. */
5669+ "1: add %0, %1 \n"
5670+ "2: \n"
5671+ _ASM_EXTABLE(1b, 2b)
5672+#else
5673+ " addu %0, %1 \n"
5674+#endif
5675+ : "+r" (v->counter) : "Ir" (i));
5676+ raw_local_irq_restore(flags);
5677+ }
5678+}
5679+
5680+static __inline__ void atomic_add_unchecked(int i, atomic_unchecked_t *v)
5681 {
5682 if (kernel_uses_llsc && R10000_LLSC_WAR) {
5683 int temp;
5684@@ -90,7 +182,67 @@ static __inline__ void atomic_add(int i, atomic_t * v)
5685 *
5686 * Atomically subtracts @i from @v.
5687 */
5688-static __inline__ void atomic_sub(int i, atomic_t * v)
5689+static __inline__ void atomic_sub(int i, atomic_t *v)
5690+{
5691+ int temp;
5692+
5693+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
5694+ __asm__ __volatile__(
5695+ " .set mips3 \n"
5696+ "1: ll %0, %1 # atomic64_sub \n"
5697+#ifdef CONFIG_PAX_REFCOUNT
5698+ /* Exception on overflow. */
5699+ "2: sub %0, %2 \n"
5700+#else
5701+ " subu %0, %2 \n"
5702+#endif
5703+ " sc %0, %1 \n"
5704+ " beqzl %0, 1b \n"
5705+#ifdef CONFIG_PAX_REFCOUNT
5706+ "3: \n"
5707+ _ASM_EXTABLE(2b, 3b)
5708+#endif
5709+ " .set mips0 \n"
5710+ : "=&r" (temp), "+m" (v->counter)
5711+ : "Ir" (i));
5712+ } else if (kernel_uses_llsc) {
5713+ __asm__ __volatile__(
5714+ " .set mips3 \n"
5715+ "1: ll %0, %1 # atomic64_sub \n"
5716+#ifdef CONFIG_PAX_REFCOUNT
5717+ /* Exception on overflow. */
5718+ "2: sub %0, %2 \n"
5719+#else
5720+ " subu %0, %2 \n"
5721+#endif
5722+ " sc %0, %1 \n"
5723+ " beqz %0, 1b \n"
5724+#ifdef CONFIG_PAX_REFCOUNT
5725+ "3: \n"
5726+ _ASM_EXTABLE(2b, 3b)
5727+#endif
5728+ " .set mips0 \n"
5729+ : "=&r" (temp), "+m" (v->counter)
5730+ : "Ir" (i));
5731+ } else {
5732+ unsigned long flags;
5733+
5734+ raw_local_irq_save(flags);
5735+ __asm__ __volatile__(
5736+#ifdef CONFIG_PAX_REFCOUNT
5737+ /* Exception on overflow. */
5738+ "1: sub %0, %1 \n"
5739+ "2: \n"
5740+ _ASM_EXTABLE(1b, 2b)
5741+#else
5742+ " subu %0, %1 \n"
5743+#endif
5744+ : "+r" (v->counter) : "Ir" (i));
5745+ raw_local_irq_restore(flags);
5746+ }
5747+}
5748+
5749+static __inline__ void atomic_sub_unchecked(long i, atomic_unchecked_t *v)
5750 {
5751 if (kernel_uses_llsc && R10000_LLSC_WAR) {
5752 int temp;
5753@@ -129,7 +281,93 @@ static __inline__ void atomic_sub(int i, atomic_t * v)
5754 /*
5755 * Same as above, but return the result value
5756 */
5757-static __inline__ int atomic_add_return(int i, atomic_t * v)
5758+static __inline__ int atomic_add_return(int i, atomic_t *v)
5759+{
5760+ int result;
5761+ int temp;
5762+
5763+ smp_mb__before_llsc();
5764+
5765+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
5766+ __asm__ __volatile__(
5767+ " .set mips3 \n"
5768+ "1: ll %1, %2 # atomic_add_return \n"
5769+#ifdef CONFIG_PAX_REFCOUNT
5770+ "2: add %0, %1, %3 \n"
5771+#else
5772+ " addu %0, %1, %3 \n"
5773+#endif
5774+ " sc %0, %2 \n"
5775+ " beqzl %0, 1b \n"
5776+#ifdef CONFIG_PAX_REFCOUNT
5777+ " b 4f \n"
5778+ " .set noreorder \n"
5779+ "3: b 5f \n"
5780+ " move %0, %1 \n"
5781+ " .set reorder \n"
5782+ _ASM_EXTABLE(2b, 3b)
5783+#endif
5784+ "4: addu %0, %1, %3 \n"
5785+#ifdef CONFIG_PAX_REFCOUNT
5786+ "5: \n"
5787+#endif
5788+ " .set mips0 \n"
5789+ : "=&r" (result), "=&r" (temp), "+m" (v->counter)
5790+ : "Ir" (i));
5791+ } else if (kernel_uses_llsc) {
5792+ __asm__ __volatile__(
5793+ " .set mips3 \n"
5794+ "1: ll %1, %2 # atomic_add_return \n"
5795+#ifdef CONFIG_PAX_REFCOUNT
5796+ "2: add %0, %1, %3 \n"
5797+#else
5798+ " addu %0, %1, %3 \n"
5799+#endif
5800+ " sc %0, %2 \n"
5801+ " bnez %0, 4f \n"
5802+ " b 1b \n"
5803+#ifdef CONFIG_PAX_REFCOUNT
5804+ " .set noreorder \n"
5805+ "3: b 5f \n"
5806+ " move %0, %1 \n"
5807+ " .set reorder \n"
5808+ _ASM_EXTABLE(2b, 3b)
5809+#endif
5810+ "4: addu %0, %1, %3 \n"
5811+#ifdef CONFIG_PAX_REFCOUNT
5812+ "5: \n"
5813+#endif
5814+ " .set mips0 \n"
5815+ : "=&r" (result), "=&r" (temp), "+m" (v->counter)
5816+ : "Ir" (i));
5817+ } else {
5818+ unsigned long flags;
5819+
5820+ raw_local_irq_save(flags);
5821+ __asm__ __volatile__(
5822+ " lw %0, %1 \n"
5823+#ifdef CONFIG_PAX_REFCOUNT
5824+ /* Exception on overflow. */
5825+ "1: add %0, %2 \n"
5826+#else
5827+ " addu %0, %2 \n"
5828+#endif
5829+ " sw %0, %1 \n"
5830+#ifdef CONFIG_PAX_REFCOUNT
5831+ /* Note: Dest reg is not modified on overflow */
5832+ "2: \n"
5833+ _ASM_EXTABLE(1b, 2b)
5834+#endif
5835+ : "=&r" (result), "+m" (v->counter) : "Ir" (i));
5836+ raw_local_irq_restore(flags);
5837+ }
5838+
5839+ smp_llsc_mb();
5840+
5841+ return result;
5842+}
5843+
5844+static __inline__ int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
5845 {
5846 int result;
5847
5848@@ -178,7 +416,93 @@ static __inline__ int atomic_add_return(int i, atomic_t * v)
5849 return result;
5850 }
5851
5852-static __inline__ int atomic_sub_return(int i, atomic_t * v)
5853+static __inline__ int atomic_sub_return(int i, atomic_t *v)
5854+{
5855+ int result;
5856+ int temp;
5857+
5858+ smp_mb__before_llsc();
5859+
5860+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
5861+ __asm__ __volatile__(
5862+ " .set mips3 \n"
5863+ "1: ll %1, %2 # atomic_sub_return \n"
5864+#ifdef CONFIG_PAX_REFCOUNT
5865+ "2: sub %0, %1, %3 \n"
5866+#else
5867+ " subu %0, %1, %3 \n"
5868+#endif
5869+ " sc %0, %2 \n"
5870+ " beqzl %0, 1b \n"
5871+#ifdef CONFIG_PAX_REFCOUNT
5872+ " b 4f \n"
5873+ " .set noreorder \n"
5874+ "3: b 5f \n"
5875+ " move %0, %1 \n"
5876+ " .set reorder \n"
5877+ _ASM_EXTABLE(2b, 3b)
5878+#endif
5879+ "4: subu %0, %1, %3 \n"
5880+#ifdef CONFIG_PAX_REFCOUNT
5881+ "5: \n"
5882+#endif
5883+ " .set mips0 \n"
5884+ : "=&r" (result), "=&r" (temp), "=m" (v->counter)
5885+ : "Ir" (i), "m" (v->counter)
5886+ : "memory");
5887+ } else if (kernel_uses_llsc) {
5888+ __asm__ __volatile__(
5889+ " .set mips3 \n"
5890+ "1: ll %1, %2 # atomic_sub_return \n"
5891+#ifdef CONFIG_PAX_REFCOUNT
5892+ "2: sub %0, %1, %3 \n"
5893+#else
5894+ " subu %0, %1, %3 \n"
5895+#endif
5896+ " sc %0, %2 \n"
5897+ " bnez %0, 4f \n"
5898+ " b 1b \n"
5899+#ifdef CONFIG_PAX_REFCOUNT
5900+ " .set noreorder \n"
5901+ "3: b 5f \n"
5902+ " move %0, %1 \n"
5903+ " .set reorder \n"
5904+ _ASM_EXTABLE(2b, 3b)
5905+#endif
5906+ "4: subu %0, %1, %3 \n"
5907+#ifdef CONFIG_PAX_REFCOUNT
5908+ "5: \n"
5909+#endif
5910+ " .set mips0 \n"
5911+ : "=&r" (result), "=&r" (temp), "+m" (v->counter)
5912+ : "Ir" (i));
5913+ } else {
5914+ unsigned long flags;
5915+
5916+ raw_local_irq_save(flags);
5917+ __asm__ __volatile__(
5918+ " lw %0, %1 \n"
5919+#ifdef CONFIG_PAX_REFCOUNT
5920+ /* Exception on overflow. */
5921+ "1: sub %0, %2 \n"
5922+#else
5923+ " subu %0, %2 \n"
5924+#endif
5925+ " sw %0, %1 \n"
5926+#ifdef CONFIG_PAX_REFCOUNT
5927+ /* Note: Dest reg is not modified on overflow */
5928+ "2: \n"
5929+ _ASM_EXTABLE(1b, 2b)
5930+#endif
5931+ : "=&r" (result), "+m" (v->counter) : "Ir" (i));
5932+ raw_local_irq_restore(flags);
5933+ }
5934+
5935+ smp_llsc_mb();
5936+
5937+ return result;
5938+}
5939+static __inline__ int atomic_sub_return_unchecked(int i, atomic_unchecked_t *v)
5940 {
5941 int result;
5942
5943@@ -238,7 +562,7 @@ static __inline__ int atomic_sub_return(int i, atomic_t * v)
5944 * Atomically test @v and subtract @i if @v is greater or equal than @i.
5945 * The function returns the old value of @v minus @i.
5946 */
5947-static __inline__ int atomic_sub_if_positive(int i, atomic_t * v)
5948+static __inline__ int atomic_sub_if_positive(int i, atomic_t *v)
5949 {
5950 int result;
5951
5952@@ -295,8 +619,26 @@ static __inline__ int atomic_sub_if_positive(int i, atomic_t * v)
5953 return result;
5954 }
5955
5956-#define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
5957-#define atomic_xchg(v, new) (xchg(&((v)->counter), (new)))
5958+static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
5959+{
5960+ return cmpxchg(&v->counter, old, new);
5961+}
5962+
5963+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old,
5964+ int new)
5965+{
5966+ return cmpxchg(&(v->counter), old, new);
5967+}
5968+
5969+static inline int atomic_xchg(atomic_t *v, int new)
5970+{
5971+ return xchg(&v->counter, new);
5972+}
5973+
5974+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
5975+{
5976+ return xchg(&(v->counter), new);
5977+}
5978
5979 /**
5980 * __atomic_add_unless - add unless the number is a given value
5981@@ -324,6 +666,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
5982
5983 #define atomic_dec_return(v) atomic_sub_return(1, (v))
5984 #define atomic_inc_return(v) atomic_add_return(1, (v))
5985+static __inline__ int atomic_inc_return_unchecked(atomic_unchecked_t *v)
5986+{
5987+ return atomic_add_return_unchecked(1, v);
5988+}
5989
5990 /*
5991 * atomic_sub_and_test - subtract value from variable and test result
5992@@ -345,6 +691,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
5993 * other cases.
5994 */
5995 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
5996+static __inline__ int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
5997+{
5998+ return atomic_add_return_unchecked(1, v) == 0;
5999+}
6000
6001 /*
6002 * atomic_dec_and_test - decrement by 1 and test
6003@@ -369,6 +719,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
6004 * Atomically increments @v by 1.
6005 */
6006 #define atomic_inc(v) atomic_add(1, (v))
6007+static __inline__ void atomic_inc_unchecked(atomic_unchecked_t *v)
6008+{
6009+ atomic_add_unchecked(1, v);
6010+}
6011
6012 /*
6013 * atomic_dec - decrement and test
6014@@ -377,6 +731,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
6015 * Atomically decrements @v by 1.
6016 */
6017 #define atomic_dec(v) atomic_sub(1, (v))
6018+static __inline__ void atomic_dec_unchecked(atomic_unchecked_t *v)
6019+{
6020+ atomic_sub_unchecked(1, v);
6021+}
6022
6023 /*
6024 * atomic_add_negative - add and test if negative
6025@@ -398,14 +756,30 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
6026 * @v: pointer of type atomic64_t
6027 *
6028 */
6029-#define atomic64_read(v) (*(volatile long *)&(v)->counter)
6030+static inline long atomic64_read(const atomic64_t *v)
6031+{
6032+ return (*(volatile const long *) &v->counter);
6033+}
6034+
6035+static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
6036+{
6037+ return (*(volatile const long *) &v->counter);
6038+}
6039
6040 /*
6041 * atomic64_set - set atomic variable
6042 * @v: pointer of type atomic64_t
6043 * @i: required value
6044 */
6045-#define atomic64_set(v, i) ((v)->counter = (i))
6046+static inline void atomic64_set(atomic64_t *v, long i)
6047+{
6048+ v->counter = i;
6049+}
6050+
6051+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
6052+{
6053+ v->counter = i;
6054+}
6055
6056 /*
6057 * atomic64_add - add integer to atomic variable
6058@@ -414,7 +788,66 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
6059 *
6060 * Atomically adds @i to @v.
6061 */
6062-static __inline__ void atomic64_add(long i, atomic64_t * v)
6063+static __inline__ void atomic64_add(long i, atomic64_t *v)
6064+{
6065+ long temp;
6066+
6067+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
6068+ __asm__ __volatile__(
6069+ " .set mips3 \n"
6070+ "1: lld %0, %1 # atomic64_add \n"
6071+#ifdef CONFIG_PAX_REFCOUNT
6072+ /* Exception on overflow. */
6073+ "2: dadd %0, %2 \n"
6074+#else
6075+ " daddu %0, %2 \n"
6076+#endif
6077+ " scd %0, %1 \n"
6078+ " beqzl %0, 1b \n"
6079+#ifdef CONFIG_PAX_REFCOUNT
6080+ "3: \n"
6081+ _ASM_EXTABLE(2b, 3b)
6082+#endif
6083+ " .set mips0 \n"
6084+ : "=&r" (temp), "+m" (v->counter)
6085+ : "Ir" (i));
6086+ } else if (kernel_uses_llsc) {
6087+ __asm__ __volatile__(
6088+ " .set mips3 \n"
6089+ "1: lld %0, %1 # atomic64_add \n"
6090+#ifdef CONFIG_PAX_REFCOUNT
6091+ /* Exception on overflow. */
6092+ "2: dadd %0, %2 \n"
6093+#else
6094+ " daddu %0, %2 \n"
6095+#endif
6096+ " scd %0, %1 \n"
6097+ " beqz %0, 1b \n"
6098+#ifdef CONFIG_PAX_REFCOUNT
6099+ "3: \n"
6100+ _ASM_EXTABLE(2b, 3b)
6101+#endif
6102+ " .set mips0 \n"
6103+ : "=&r" (temp), "+m" (v->counter)
6104+ : "Ir" (i));
6105+ } else {
6106+ unsigned long flags;
6107+
6108+ raw_local_irq_save(flags);
6109+ __asm__ __volatile__(
6110+#ifdef CONFIG_PAX_REFCOUNT
6111+ /* Exception on overflow. */
6112+ "1: dadd %0, %1 \n"
6113+ "2: \n"
6114+ _ASM_EXTABLE(1b, 2b)
6115+#else
6116+ " daddu %0, %1 \n"
6117+#endif
6118+ : "+r" (v->counter) : "Ir" (i));
6119+ raw_local_irq_restore(flags);
6120+ }
6121+}
6122+static __inline__ void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
6123 {
6124 if (kernel_uses_llsc && R10000_LLSC_WAR) {
6125 long temp;
6126@@ -457,7 +890,67 @@ static __inline__ void atomic64_add(long i, atomic64_t * v)
6127 *
6128 * Atomically subtracts @i from @v.
6129 */
6130-static __inline__ void atomic64_sub(long i, atomic64_t * v)
6131+static __inline__ void atomic64_sub(long i, atomic64_t *v)
6132+{
6133+ long temp;
6134+
6135+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
6136+ __asm__ __volatile__(
6137+ " .set mips3 \n"
6138+ "1: lld %0, %1 # atomic64_sub \n"
6139+#ifdef CONFIG_PAX_REFCOUNT
6140+ /* Exception on overflow. */
6141+ "2: dsub %0, %2 \n"
6142+#else
6143+ " dsubu %0, %2 \n"
6144+#endif
6145+ " scd %0, %1 \n"
6146+ " beqzl %0, 1b \n"
6147+#ifdef CONFIG_PAX_REFCOUNT
6148+ "3: \n"
6149+ _ASM_EXTABLE(2b, 3b)
6150+#endif
6151+ " .set mips0 \n"
6152+ : "=&r" (temp), "+m" (v->counter)
6153+ : "Ir" (i));
6154+ } else if (kernel_uses_llsc) {
6155+ __asm__ __volatile__(
6156+ " .set mips3 \n"
6157+ "1: lld %0, %1 # atomic64_sub \n"
6158+#ifdef CONFIG_PAX_REFCOUNT
6159+ /* Exception on overflow. */
6160+ "2: dsub %0, %2 \n"
6161+#else
6162+ " dsubu %0, %2 \n"
6163+#endif
6164+ " scd %0, %1 \n"
6165+ " beqz %0, 1b \n"
6166+#ifdef CONFIG_PAX_REFCOUNT
6167+ "3: \n"
6168+ _ASM_EXTABLE(2b, 3b)
6169+#endif
6170+ " .set mips0 \n"
6171+ : "=&r" (temp), "+m" (v->counter)
6172+ : "Ir" (i));
6173+ } else {
6174+ unsigned long flags;
6175+
6176+ raw_local_irq_save(flags);
6177+ __asm__ __volatile__(
6178+#ifdef CONFIG_PAX_REFCOUNT
6179+ /* Exception on overflow. */
6180+ "1: dsub %0, %1 \n"
6181+ "2: \n"
6182+ _ASM_EXTABLE(1b, 2b)
6183+#else
6184+ " dsubu %0, %1 \n"
6185+#endif
6186+ : "+r" (v->counter) : "Ir" (i));
6187+ raw_local_irq_restore(flags);
6188+ }
6189+}
6190+
6191+static __inline__ void atomic64_sub_unchecked(long i, atomic64_unchecked_t *v)
6192 {
6193 if (kernel_uses_llsc && R10000_LLSC_WAR) {
6194 long temp;
6195@@ -496,7 +989,93 @@ static __inline__ void atomic64_sub(long i, atomic64_t * v)
6196 /*
6197 * Same as above, but return the result value
6198 */
6199-static __inline__ long atomic64_add_return(long i, atomic64_t * v)
6200+static __inline__ long atomic64_add_return(long i, atomic64_t *v)
6201+{
6202+ long result;
6203+ long temp;
6204+
6205+ smp_mb__before_llsc();
6206+
6207+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
6208+ __asm__ __volatile__(
6209+ " .set mips3 \n"
6210+ "1: lld %1, %2 # atomic64_add_return \n"
6211+#ifdef CONFIG_PAX_REFCOUNT
6212+ "2: dadd %0, %1, %3 \n"
6213+#else
6214+ " daddu %0, %1, %3 \n"
6215+#endif
6216+ " scd %0, %2 \n"
6217+ " beqzl %0, 1b \n"
6218+#ifdef CONFIG_PAX_REFCOUNT
6219+ " b 4f \n"
6220+ " .set noreorder \n"
6221+ "3: b 5f \n"
6222+ " move %0, %1 \n"
6223+ " .set reorder \n"
6224+ _ASM_EXTABLE(2b, 3b)
6225+#endif
6226+ "4: daddu %0, %1, %3 \n"
6227+#ifdef CONFIG_PAX_REFCOUNT
6228+ "5: \n"
6229+#endif
6230+ " .set mips0 \n"
6231+ : "=&r" (result), "=&r" (temp), "+m" (v->counter)
6232+ : "Ir" (i));
6233+ } else if (kernel_uses_llsc) {
6234+ __asm__ __volatile__(
6235+ " .set mips3 \n"
6236+ "1: lld %1, %2 # atomic64_add_return \n"
6237+#ifdef CONFIG_PAX_REFCOUNT
6238+ "2: dadd %0, %1, %3 \n"
6239+#else
6240+ " daddu %0, %1, %3 \n"
6241+#endif
6242+ " scd %0, %2 \n"
6243+ " bnez %0, 4f \n"
6244+ " b 1b \n"
6245+#ifdef CONFIG_PAX_REFCOUNT
6246+ " .set noreorder \n"
6247+ "3: b 5f \n"
6248+ " move %0, %1 \n"
6249+ " .set reorder \n"
6250+ _ASM_EXTABLE(2b, 3b)
6251+#endif
6252+ "4: daddu %0, %1, %3 \n"
6253+#ifdef CONFIG_PAX_REFCOUNT
6254+ "5: \n"
6255+#endif
6256+ " .set mips0 \n"
6257+ : "=&r" (result), "=&r" (temp), "=m" (v->counter)
6258+ : "Ir" (i), "m" (v->counter)
6259+ : "memory");
6260+ } else {
6261+ unsigned long flags;
6262+
6263+ raw_local_irq_save(flags);
6264+ __asm__ __volatile__(
6265+ " ld %0, %1 \n"
6266+#ifdef CONFIG_PAX_REFCOUNT
6267+ /* Exception on overflow. */
6268+ "1: dadd %0, %2 \n"
6269+#else
6270+ " daddu %0, %2 \n"
6271+#endif
6272+ " sd %0, %1 \n"
6273+#ifdef CONFIG_PAX_REFCOUNT
6274+ /* Note: Dest reg is not modified on overflow */
6275+ "2: \n"
6276+ _ASM_EXTABLE(1b, 2b)
6277+#endif
6278+ : "=&r" (result), "+m" (v->counter) : "Ir" (i));
6279+ raw_local_irq_restore(flags);
6280+ }
6281+
6282+ smp_llsc_mb();
6283+
6284+ return result;
6285+}
6286+static __inline__ long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
6287 {
6288 long result;
6289
6290@@ -546,7 +1125,97 @@ static __inline__ long atomic64_add_return(long i, atomic64_t * v)
6291 return result;
6292 }
6293
6294-static __inline__ long atomic64_sub_return(long i, atomic64_t * v)
6295+static __inline__ long atomic64_sub_return(long i, atomic64_t *v)
6296+{
6297+ long result;
6298+ long temp;
6299+
6300+ smp_mb__before_llsc();
6301+
6302+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
6303+ long temp;
6304+
6305+ __asm__ __volatile__(
6306+ " .set mips3 \n"
6307+ "1: lld %1, %2 # atomic64_sub_return \n"
6308+#ifdef CONFIG_PAX_REFCOUNT
6309+ "2: dsub %0, %1, %3 \n"
6310+#else
6311+ " dsubu %0, %1, %3 \n"
6312+#endif
6313+ " scd %0, %2 \n"
6314+ " beqzl %0, 1b \n"
6315+#ifdef CONFIG_PAX_REFCOUNT
6316+ " b 4f \n"
6317+ " .set noreorder \n"
6318+ "3: b 5f \n"
6319+ " move %0, %1 \n"
6320+ " .set reorder \n"
6321+ _ASM_EXTABLE(2b, 3b)
6322+#endif
6323+ "4: dsubu %0, %1, %3 \n"
6324+#ifdef CONFIG_PAX_REFCOUNT
6325+ "5: \n"
6326+#endif
6327+ " .set mips0 \n"
6328+ : "=&r" (result), "=&r" (temp), "=m" (v->counter)
6329+ : "Ir" (i), "m" (v->counter)
6330+ : "memory");
6331+ } else if (kernel_uses_llsc) {
6332+ __asm__ __volatile__(
6333+ " .set mips3 \n"
6334+ "1: lld %1, %2 # atomic64_sub_return \n"
6335+#ifdef CONFIG_PAX_REFCOUNT
6336+ "2: dsub %0, %1, %3 \n"
6337+#else
6338+ " dsubu %0, %1, %3 \n"
6339+#endif
6340+ " scd %0, %2 \n"
6341+ " bnez %0, 4f \n"
6342+ " b 1b \n"
6343+#ifdef CONFIG_PAX_REFCOUNT
6344+ " .set noreorder \n"
6345+ "3: b 5f \n"
6346+ " move %0, %1 \n"
6347+ " .set reorder \n"
6348+ _ASM_EXTABLE(2b, 3b)
6349+#endif
6350+ "4: dsubu %0, %1, %3 \n"
6351+#ifdef CONFIG_PAX_REFCOUNT
6352+ "5: \n"
6353+#endif
6354+ " .set mips0 \n"
6355+ : "=&r" (result), "=&r" (temp), "=m" (v->counter)
6356+ : "Ir" (i), "m" (v->counter)
6357+ : "memory");
6358+ } else {
6359+ unsigned long flags;
6360+
6361+ raw_local_irq_save(flags);
6362+ __asm__ __volatile__(
6363+ " ld %0, %1 \n"
6364+#ifdef CONFIG_PAX_REFCOUNT
6365+ /* Exception on overflow. */
6366+ "1: dsub %0, %2 \n"
6367+#else
6368+ " dsubu %0, %2 \n"
6369+#endif
6370+ " sd %0, %1 \n"
6371+#ifdef CONFIG_PAX_REFCOUNT
6372+ /* Note: Dest reg is not modified on overflow */
6373+ "2: \n"
6374+ _ASM_EXTABLE(1b, 2b)
6375+#endif
6376+ : "=&r" (result), "+m" (v->counter) : "Ir" (i));
6377+ raw_local_irq_restore(flags);
6378+ }
6379+
6380+ smp_llsc_mb();
6381+
6382+ return result;
6383+}
6384+
6385+static __inline__ long atomic64_sub_return_unchecked(long i, atomic64_unchecked_t *v)
6386 {
6387 long result;
6388
6389@@ -605,7 +1274,7 @@ static __inline__ long atomic64_sub_return(long i, atomic64_t * v)
6390 * Atomically test @v and subtract @i if @v is greater or equal than @i.
6391 * The function returns the old value of @v minus @i.
6392 */
6393-static __inline__ long atomic64_sub_if_positive(long i, atomic64_t * v)
6394+static __inline__ long atomic64_sub_if_positive(long i, atomic64_t *v)
6395 {
6396 long result;
6397
6398@@ -662,9 +1331,26 @@ static __inline__ long atomic64_sub_if_positive(long i, atomic64_t * v)
6399 return result;
6400 }
6401
6402-#define atomic64_cmpxchg(v, o, n) \
6403- ((__typeof__((v)->counter))cmpxchg(&((v)->counter), (o), (n)))
6404-#define atomic64_xchg(v, new) (xchg(&((v)->counter), (new)))
6405+static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
6406+{
6407+ return cmpxchg(&v->counter, old, new);
6408+}
6409+
6410+static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old,
6411+ long new)
6412+{
6413+ return cmpxchg(&(v->counter), old, new);
6414+}
6415+
6416+static inline long atomic64_xchg(atomic64_t *v, long new)
6417+{
6418+ return xchg(&v->counter, new);
6419+}
6420+
6421+static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
6422+{
6423+ return xchg(&(v->counter), new);
6424+}
6425
6426 /**
6427 * atomic64_add_unless - add unless the number is a given value
6428@@ -694,6 +1380,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
6429
6430 #define atomic64_dec_return(v) atomic64_sub_return(1, (v))
6431 #define atomic64_inc_return(v) atomic64_add_return(1, (v))
6432+#define atomic64_inc_return_unchecked(v) atomic64_add_return_unchecked(1, (v))
6433
6434 /*
6435 * atomic64_sub_and_test - subtract value from variable and test result
6436@@ -715,6 +1402,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
6437 * other cases.
6438 */
6439 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
6440+#define atomic64_inc_and_test_unchecked(v) atomic64_add_return_unchecked(1, (v)) == 0)
6441
6442 /*
6443 * atomic64_dec_and_test - decrement by 1 and test
6444@@ -739,6 +1427,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
6445 * Atomically increments @v by 1.
6446 */
6447 #define atomic64_inc(v) atomic64_add(1, (v))
6448+#define atomic64_inc_unchecked(v) atomic64_add_unchecked(1, (v))
6449
6450 /*
6451 * atomic64_dec - decrement and test
6452@@ -747,6 +1436,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
6453 * Atomically decrements @v by 1.
6454 */
6455 #define atomic64_dec(v) atomic64_sub(1, (v))
6456+#define atomic64_dec_unchecked(v) atomic64_sub_unchecked(1, (v))
6457
6458 /*
6459 * atomic64_add_negative - add and test if negative
6460diff --git a/arch/mips/include/asm/cache.h b/arch/mips/include/asm/cache.h
6461index b4db69f..8f3b093 100644
6462--- a/arch/mips/include/asm/cache.h
6463+++ b/arch/mips/include/asm/cache.h
6464@@ -9,10 +9,11 @@
6465 #ifndef _ASM_CACHE_H
6466 #define _ASM_CACHE_H
6467
6468+#include <linux/const.h>
6469 #include <kmalloc.h>
6470
6471 #define L1_CACHE_SHIFT CONFIG_MIPS_L1_CACHE_SHIFT
6472-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
6473+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
6474
6475 #define SMP_CACHE_SHIFT L1_CACHE_SHIFT
6476 #define SMP_CACHE_BYTES L1_CACHE_BYTES
6477diff --git a/arch/mips/include/asm/elf.h b/arch/mips/include/asm/elf.h
6478index d414405..6bb4ba2 100644
6479--- a/arch/mips/include/asm/elf.h
6480+++ b/arch/mips/include/asm/elf.h
6481@@ -398,13 +398,16 @@ extern const char *__elf_platform;
6482 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
6483 #endif
6484
6485+#ifdef CONFIG_PAX_ASLR
6486+#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
6487+
6488+#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6489+#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6490+#endif
6491+
6492 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
6493 struct linux_binprm;
6494 extern int arch_setup_additional_pages(struct linux_binprm *bprm,
6495 int uses_interp);
6496
6497-struct mm_struct;
6498-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
6499-#define arch_randomize_brk arch_randomize_brk
6500-
6501 #endif /* _ASM_ELF_H */
6502diff --git a/arch/mips/include/asm/exec.h b/arch/mips/include/asm/exec.h
6503index c1f6afa..38cc6e9 100644
6504--- a/arch/mips/include/asm/exec.h
6505+++ b/arch/mips/include/asm/exec.h
6506@@ -12,6 +12,6 @@
6507 #ifndef _ASM_EXEC_H
6508 #define _ASM_EXEC_H
6509
6510-extern unsigned long arch_align_stack(unsigned long sp);
6511+#define arch_align_stack(x) ((x) & ~0xfUL)
6512
6513 #endif /* _ASM_EXEC_H */
6514diff --git a/arch/mips/include/asm/hw_irq.h b/arch/mips/include/asm/hw_irq.h
6515index 9e8ef59..1139d6b 100644
6516--- a/arch/mips/include/asm/hw_irq.h
6517+++ b/arch/mips/include/asm/hw_irq.h
6518@@ -10,7 +10,7 @@
6519
6520 #include <linux/atomic.h>
6521
6522-extern atomic_t irq_err_count;
6523+extern atomic_unchecked_t irq_err_count;
6524
6525 /*
6526 * interrupt-retrigger: NOP for now. This may not be appropriate for all
6527diff --git a/arch/mips/include/asm/local.h b/arch/mips/include/asm/local.h
6528index d44622c..64990d2 100644
6529--- a/arch/mips/include/asm/local.h
6530+++ b/arch/mips/include/asm/local.h
6531@@ -12,15 +12,25 @@ typedef struct
6532 atomic_long_t a;
6533 } local_t;
6534
6535+typedef struct {
6536+ atomic_long_unchecked_t a;
6537+} local_unchecked_t;
6538+
6539 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
6540
6541 #define local_read(l) atomic_long_read(&(l)->a)
6542+#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
6543 #define local_set(l, i) atomic_long_set(&(l)->a, (i))
6544+#define local_set_unchecked(l, i) atomic_long_set_unchecked(&(l)->a, (i))
6545
6546 #define local_add(i, l) atomic_long_add((i), (&(l)->a))
6547+#define local_add_unchecked(i, l) atomic_long_add_unchecked((i), (&(l)->a))
6548 #define local_sub(i, l) atomic_long_sub((i), (&(l)->a))
6549+#define local_sub_unchecked(i, l) atomic_long_sub_unchecked((i), (&(l)->a))
6550 #define local_inc(l) atomic_long_inc(&(l)->a)
6551+#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
6552 #define local_dec(l) atomic_long_dec(&(l)->a)
6553+#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
6554
6555 /*
6556 * Same as above, but return the result value
6557@@ -70,6 +80,51 @@ static __inline__ long local_add_return(long i, local_t * l)
6558 return result;
6559 }
6560
6561+static __inline__ long local_add_return_unchecked(long i, local_unchecked_t * l)
6562+{
6563+ unsigned long result;
6564+
6565+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
6566+ unsigned long temp;
6567+
6568+ __asm__ __volatile__(
6569+ " .set mips3 \n"
6570+ "1:" __LL "%1, %2 # local_add_return \n"
6571+ " addu %0, %1, %3 \n"
6572+ __SC "%0, %2 \n"
6573+ " beqzl %0, 1b \n"
6574+ " addu %0, %1, %3 \n"
6575+ " .set mips0 \n"
6576+ : "=&r" (result), "=&r" (temp), "=m" (l->a.counter)
6577+ : "Ir" (i), "m" (l->a.counter)
6578+ : "memory");
6579+ } else if (kernel_uses_llsc) {
6580+ unsigned long temp;
6581+
6582+ __asm__ __volatile__(
6583+ " .set mips3 \n"
6584+ "1:" __LL "%1, %2 # local_add_return \n"
6585+ " addu %0, %1, %3 \n"
6586+ __SC "%0, %2 \n"
6587+ " beqz %0, 1b \n"
6588+ " addu %0, %1, %3 \n"
6589+ " .set mips0 \n"
6590+ : "=&r" (result), "=&r" (temp), "=m" (l->a.counter)
6591+ : "Ir" (i), "m" (l->a.counter)
6592+ : "memory");
6593+ } else {
6594+ unsigned long flags;
6595+
6596+ local_irq_save(flags);
6597+ result = l->a.counter;
6598+ result += i;
6599+ l->a.counter = result;
6600+ local_irq_restore(flags);
6601+ }
6602+
6603+ return result;
6604+}
6605+
6606 static __inline__ long local_sub_return(long i, local_t * l)
6607 {
6608 unsigned long result;
6609@@ -117,6 +172,8 @@ static __inline__ long local_sub_return(long i, local_t * l)
6610
6611 #define local_cmpxchg(l, o, n) \
6612 ((long)cmpxchg_local(&((l)->a.counter), (o), (n)))
6613+#define local_cmpxchg_unchecked(l, o, n) \
6614+ ((long)cmpxchg_local(&((l)->a.counter), (o), (n)))
6615 #define local_xchg(l, n) (atomic_long_xchg((&(l)->a), (n)))
6616
6617 /**
6618diff --git a/arch/mips/include/asm/page.h b/arch/mips/include/asm/page.h
6619index 5e08bcc..cfedefc 100644
6620--- a/arch/mips/include/asm/page.h
6621+++ b/arch/mips/include/asm/page.h
6622@@ -120,7 +120,7 @@ extern void copy_user_highpage(struct page *to, struct page *from,
6623 #ifdef CONFIG_CPU_MIPS32
6624 typedef struct { unsigned long pte_low, pte_high; } pte_t;
6625 #define pte_val(x) ((x).pte_low | ((unsigned long long)(x).pte_high << 32))
6626- #define __pte(x) ({ pte_t __pte = {(x), ((unsigned long long)(x)) >> 32}; __pte; })
6627+ #define __pte(x) ({ pte_t __pte = {(x), (x) >> 32}; __pte; })
6628 #else
6629 typedef struct { unsigned long long pte; } pte_t;
6630 #define pte_val(x) ((x).pte)
6631diff --git a/arch/mips/include/asm/pgalloc.h b/arch/mips/include/asm/pgalloc.h
6632index b336037..5b874cc 100644
6633--- a/arch/mips/include/asm/pgalloc.h
6634+++ b/arch/mips/include/asm/pgalloc.h
6635@@ -37,6 +37,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
6636 {
6637 set_pud(pud, __pud((unsigned long)pmd));
6638 }
6639+
6640+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
6641+{
6642+ pud_populate(mm, pud, pmd);
6643+}
6644 #endif
6645
6646 /*
6647diff --git a/arch/mips/include/asm/pgtable.h b/arch/mips/include/asm/pgtable.h
6648index 008324d..f67c239 100644
6649--- a/arch/mips/include/asm/pgtable.h
6650+++ b/arch/mips/include/asm/pgtable.h
6651@@ -20,6 +20,9 @@
6652 #include <asm/io.h>
6653 #include <asm/pgtable-bits.h>
6654
6655+#define ktla_ktva(addr) (addr)
6656+#define ktva_ktla(addr) (addr)
6657+
6658 struct mm_struct;
6659 struct vm_area_struct;
6660
6661diff --git a/arch/mips/include/asm/smtc_proc.h b/arch/mips/include/asm/smtc_proc.h
6662index 25da651..ae2a259 100644
6663--- a/arch/mips/include/asm/smtc_proc.h
6664+++ b/arch/mips/include/asm/smtc_proc.h
6665@@ -18,6 +18,6 @@ extern struct smtc_cpu_proc smtc_cpu_stats[NR_CPUS];
6666
6667 /* Count of number of recoveries of "stolen" FPU access rights on 34K */
6668
6669-extern atomic_t smtc_fpu_recoveries;
6670+extern atomic_unchecked_t smtc_fpu_recoveries;
6671
6672 #endif /* __ASM_SMTC_PROC_H */
6673diff --git a/arch/mips/include/asm/thread_info.h b/arch/mips/include/asm/thread_info.h
6674index 24846f9..61c49f0 100644
6675--- a/arch/mips/include/asm/thread_info.h
6676+++ b/arch/mips/include/asm/thread_info.h
6677@@ -116,6 +116,8 @@ static inline struct thread_info *current_thread_info(void)
6678 #define TIF_LOAD_WATCH 25 /* If set, load watch registers */
6679 #define TIF_SYSCALL_TRACEPOINT 26 /* syscall tracepoint instrumentation */
6680 #define TIF_32BIT_FPREGS 27 /* 32-bit floating point registers */
6681+/* li takes a 32bit immediate */
6682+#define TIF_GRSEC_SETXID 29 /* update credentials on syscall entry/exit */
6683 #define TIF_SYSCALL_TRACE 31 /* syscall trace active */
6684
6685 #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
6686@@ -134,13 +136,14 @@ static inline struct thread_info *current_thread_info(void)
6687 #define _TIF_LOAD_WATCH (1<<TIF_LOAD_WATCH)
6688 #define _TIF_32BIT_FPREGS (1<<TIF_32BIT_FPREGS)
6689 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
6690+#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
6691
6692 #define _TIF_WORK_SYSCALL_ENTRY (_TIF_NOHZ | _TIF_SYSCALL_TRACE | \
6693- _TIF_SYSCALL_AUDIT | _TIF_SYSCALL_TRACEPOINT)
6694+ _TIF_SYSCALL_AUDIT | _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
6695
6696 /* work to do in syscall_trace_leave() */
6697 #define _TIF_WORK_SYSCALL_EXIT (_TIF_NOHZ | _TIF_SYSCALL_TRACE | \
6698- _TIF_SYSCALL_AUDIT | _TIF_SYSCALL_TRACEPOINT)
6699+ _TIF_SYSCALL_AUDIT | _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
6700
6701 /* work to do on interrupt/exception return */
6702 #define _TIF_WORK_MASK \
6703@@ -148,7 +151,7 @@ static inline struct thread_info *current_thread_info(void)
6704 /* work to do on any return to u-space */
6705 #define _TIF_ALLWORK_MASK (_TIF_NOHZ | _TIF_WORK_MASK | \
6706 _TIF_WORK_SYSCALL_EXIT | \
6707- _TIF_SYSCALL_TRACEPOINT)
6708+ _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
6709
6710 /*
6711 * We stash processor id into a COP0 register to retrieve it fast
6712diff --git a/arch/mips/include/asm/uaccess.h b/arch/mips/include/asm/uaccess.h
6713index f3fa375..3af6637 100644
6714--- a/arch/mips/include/asm/uaccess.h
6715+++ b/arch/mips/include/asm/uaccess.h
6716@@ -128,6 +128,7 @@ extern u64 __ua_limit;
6717 __ok == 0; \
6718 })
6719
6720+#define access_ok_noprefault(type, addr, size) access_ok((type), (addr), (size))
6721 #define access_ok(type, addr, size) \
6722 likely(__access_ok((addr), (size), __access_mask))
6723
6724diff --git a/arch/mips/kernel/binfmt_elfn32.c b/arch/mips/kernel/binfmt_elfn32.c
6725index 1188e00..41cf144 100644
6726--- a/arch/mips/kernel/binfmt_elfn32.c
6727+++ b/arch/mips/kernel/binfmt_elfn32.c
6728@@ -50,6 +50,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
6729 #undef ELF_ET_DYN_BASE
6730 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
6731
6732+#ifdef CONFIG_PAX_ASLR
6733+#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
6734+
6735+#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6736+#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6737+#endif
6738+
6739 #include <asm/processor.h>
6740 #include <linux/module.h>
6741 #include <linux/elfcore.h>
6742diff --git a/arch/mips/kernel/binfmt_elfo32.c b/arch/mips/kernel/binfmt_elfo32.c
6743index 7faf5f2..f3d3cf4 100644
6744--- a/arch/mips/kernel/binfmt_elfo32.c
6745+++ b/arch/mips/kernel/binfmt_elfo32.c
6746@@ -70,6 +70,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
6747 #undef ELF_ET_DYN_BASE
6748 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
6749
6750+#ifdef CONFIG_PAX_ASLR
6751+#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
6752+
6753+#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6754+#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6755+#endif
6756+
6757 #include <asm/processor.h>
6758
6759 /*
6760diff --git a/arch/mips/kernel/i8259.c b/arch/mips/kernel/i8259.c
6761index 2b91fe8..fe4f6b4 100644
6762--- a/arch/mips/kernel/i8259.c
6763+++ b/arch/mips/kernel/i8259.c
6764@@ -205,7 +205,7 @@ spurious_8259A_irq:
6765 printk(KERN_DEBUG "spurious 8259A interrupt: IRQ%d.\n", irq);
6766 spurious_irq_mask |= irqmask;
6767 }
6768- atomic_inc(&irq_err_count);
6769+ atomic_inc_unchecked(&irq_err_count);
6770 /*
6771 * Theoretically we do not have to handle this IRQ,
6772 * but in Linux this does not cause problems and is
6773diff --git a/arch/mips/kernel/irq-gt641xx.c b/arch/mips/kernel/irq-gt641xx.c
6774index 44a1f79..2bd6aa3 100644
6775--- a/arch/mips/kernel/irq-gt641xx.c
6776+++ b/arch/mips/kernel/irq-gt641xx.c
6777@@ -110,7 +110,7 @@ void gt641xx_irq_dispatch(void)
6778 }
6779 }
6780
6781- atomic_inc(&irq_err_count);
6782+ atomic_inc_unchecked(&irq_err_count);
6783 }
6784
6785 void __init gt641xx_irq_init(void)
6786diff --git a/arch/mips/kernel/irq.c b/arch/mips/kernel/irq.c
6787index d1fea7a..2e591b0 100644
6788--- a/arch/mips/kernel/irq.c
6789+++ b/arch/mips/kernel/irq.c
6790@@ -77,17 +77,17 @@ void ack_bad_irq(unsigned int irq)
6791 printk("unexpected IRQ # %d\n", irq);
6792 }
6793
6794-atomic_t irq_err_count;
6795+atomic_unchecked_t irq_err_count;
6796
6797 int arch_show_interrupts(struct seq_file *p, int prec)
6798 {
6799- seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
6800+ seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
6801 return 0;
6802 }
6803
6804 asmlinkage void spurious_interrupt(void)
6805 {
6806- atomic_inc(&irq_err_count);
6807+ atomic_inc_unchecked(&irq_err_count);
6808 }
6809
6810 void __init init_IRQ(void)
6811@@ -110,7 +110,10 @@ void __init init_IRQ(void)
6812 #endif
6813 }
6814
6815+
6816 #ifdef DEBUG_STACKOVERFLOW
6817+extern void gr_handle_kernel_exploit(void);
6818+
6819 static inline void check_stack_overflow(void)
6820 {
6821 unsigned long sp;
6822@@ -126,6 +129,7 @@ static inline void check_stack_overflow(void)
6823 printk("do_IRQ: stack overflow: %ld\n",
6824 sp - sizeof(struct thread_info));
6825 dump_stack();
6826+ gr_handle_kernel_exploit();
6827 }
6828 }
6829 #else
6830diff --git a/arch/mips/kernel/process.c b/arch/mips/kernel/process.c
6831index 6ae540e..b7396dc 100644
6832--- a/arch/mips/kernel/process.c
6833+++ b/arch/mips/kernel/process.c
6834@@ -562,15 +562,3 @@ unsigned long get_wchan(struct task_struct *task)
6835 out:
6836 return pc;
6837 }
6838-
6839-/*
6840- * Don't forget that the stack pointer must be aligned on a 8 bytes
6841- * boundary for 32-bits ABI and 16 bytes for 64-bits ABI.
6842- */
6843-unsigned long arch_align_stack(unsigned long sp)
6844-{
6845- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
6846- sp -= get_random_int() & ~PAGE_MASK;
6847-
6848- return sp & ALMASK;
6849-}
6850diff --git a/arch/mips/kernel/ptrace.c b/arch/mips/kernel/ptrace.c
6851index 7da9b76..21578be 100644
6852--- a/arch/mips/kernel/ptrace.c
6853+++ b/arch/mips/kernel/ptrace.c
6854@@ -658,6 +658,10 @@ long arch_ptrace(struct task_struct *child, long request,
6855 return ret;
6856 }
6857
6858+#ifdef CONFIG_GRKERNSEC_SETXID
6859+extern void gr_delayed_cred_worker(void);
6860+#endif
6861+
6862 /*
6863 * Notification of system call entry/exit
6864 * - triggered by current->work.syscall_trace
6865@@ -674,6 +678,11 @@ asmlinkage void syscall_trace_enter(struct pt_regs *regs)
6866 tracehook_report_syscall_entry(regs))
6867 ret = -1;
6868
6869+#ifdef CONFIG_GRKERNSEC_SETXID
6870+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
6871+ gr_delayed_cred_worker();
6872+#endif
6873+
6874 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
6875 trace_sys_enter(regs, regs->regs[2]);
6876
6877diff --git a/arch/mips/kernel/reset.c b/arch/mips/kernel/reset.c
6878index 07fc524..b9d7f28 100644
6879--- a/arch/mips/kernel/reset.c
6880+++ b/arch/mips/kernel/reset.c
6881@@ -13,6 +13,7 @@
6882 #include <linux/reboot.h>
6883
6884 #include <asm/reboot.h>
6885+#include <asm/bug.h>
6886
6887 /*
6888 * Urgs ... Too many MIPS machines to handle this in a generic way.
6889@@ -29,16 +30,19 @@ void machine_restart(char *command)
6890 {
6891 if (_machine_restart)
6892 _machine_restart(command);
6893+ BUG();
6894 }
6895
6896 void machine_halt(void)
6897 {
6898 if (_machine_halt)
6899 _machine_halt();
6900+ BUG();
6901 }
6902
6903 void machine_power_off(void)
6904 {
6905 if (pm_power_off)
6906 pm_power_off();
6907+ BUG();
6908 }
6909diff --git a/arch/mips/kernel/smtc-proc.c b/arch/mips/kernel/smtc-proc.c
6910index c10aa84..9ec2e60 100644
6911--- a/arch/mips/kernel/smtc-proc.c
6912+++ b/arch/mips/kernel/smtc-proc.c
6913@@ -31,7 +31,7 @@ unsigned long selfipis[NR_CPUS];
6914
6915 struct smtc_cpu_proc smtc_cpu_stats[NR_CPUS];
6916
6917-atomic_t smtc_fpu_recoveries;
6918+atomic_unchecked_t smtc_fpu_recoveries;
6919
6920 static int smtc_proc_show(struct seq_file *m, void *v)
6921 {
6922@@ -48,7 +48,7 @@ static int smtc_proc_show(struct seq_file *m, void *v)
6923 for(i = 0; i < NR_CPUS; i++)
6924 seq_printf(m, "%d: %ld\n", i, smtc_cpu_stats[i].selfipis);
6925 seq_printf(m, "%d Recoveries of \"stolen\" FPU\n",
6926- atomic_read(&smtc_fpu_recoveries));
6927+ atomic_read_unchecked(&smtc_fpu_recoveries));
6928 return 0;
6929 }
6930
6931@@ -73,7 +73,7 @@ void init_smtc_stats(void)
6932 smtc_cpu_stats[i].selfipis = 0;
6933 }
6934
6935- atomic_set(&smtc_fpu_recoveries, 0);
6936+ atomic_set_unchecked(&smtc_fpu_recoveries, 0);
6937
6938 proc_create("smtc", 0444, NULL, &smtc_proc_fops);
6939 }
6940diff --git a/arch/mips/kernel/smtc.c b/arch/mips/kernel/smtc.c
6941index dfc1b91..11a2c07 100644
6942--- a/arch/mips/kernel/smtc.c
6943+++ b/arch/mips/kernel/smtc.c
6944@@ -1359,7 +1359,7 @@ void smtc_soft_dump(void)
6945 }
6946 smtc_ipi_qdump();
6947 printk("%d Recoveries of \"stolen\" FPU\n",
6948- atomic_read(&smtc_fpu_recoveries));
6949+ atomic_read_unchecked(&smtc_fpu_recoveries));
6950 }
6951
6952
6953diff --git a/arch/mips/kernel/sync-r4k.c b/arch/mips/kernel/sync-r4k.c
6954index c24ad5f..9983ab2 100644
6955--- a/arch/mips/kernel/sync-r4k.c
6956+++ b/arch/mips/kernel/sync-r4k.c
6957@@ -20,8 +20,8 @@
6958 #include <asm/mipsregs.h>
6959
6960 static atomic_t count_start_flag = ATOMIC_INIT(0);
6961-static atomic_t count_count_start = ATOMIC_INIT(0);
6962-static atomic_t count_count_stop = ATOMIC_INIT(0);
6963+static atomic_unchecked_t count_count_start = ATOMIC_INIT(0);
6964+static atomic_unchecked_t count_count_stop = ATOMIC_INIT(0);
6965 static atomic_t count_reference = ATOMIC_INIT(0);
6966
6967 #define COUNTON 100
6968@@ -68,13 +68,13 @@ void synchronise_count_master(int cpu)
6969
6970 for (i = 0; i < NR_LOOPS; i++) {
6971 /* slaves loop on '!= 2' */
6972- while (atomic_read(&count_count_start) != 1)
6973+ while (atomic_read_unchecked(&count_count_start) != 1)
6974 mb();
6975- atomic_set(&count_count_stop, 0);
6976+ atomic_set_unchecked(&count_count_stop, 0);
6977 smp_wmb();
6978
6979 /* this lets the slaves write their count register */
6980- atomic_inc(&count_count_start);
6981+ atomic_inc_unchecked(&count_count_start);
6982
6983 /*
6984 * Everyone initialises count in the last loop:
6985@@ -85,11 +85,11 @@ void synchronise_count_master(int cpu)
6986 /*
6987 * Wait for all slaves to leave the synchronization point:
6988 */
6989- while (atomic_read(&count_count_stop) != 1)
6990+ while (atomic_read_unchecked(&count_count_stop) != 1)
6991 mb();
6992- atomic_set(&count_count_start, 0);
6993+ atomic_set_unchecked(&count_count_start, 0);
6994 smp_wmb();
6995- atomic_inc(&count_count_stop);
6996+ atomic_inc_unchecked(&count_count_stop);
6997 }
6998 /* Arrange for an interrupt in a short while */
6999 write_c0_compare(read_c0_count() + COUNTON);
7000@@ -130,8 +130,8 @@ void synchronise_count_slave(int cpu)
7001 initcount = atomic_read(&count_reference);
7002
7003 for (i = 0; i < NR_LOOPS; i++) {
7004- atomic_inc(&count_count_start);
7005- while (atomic_read(&count_count_start) != 2)
7006+ atomic_inc_unchecked(&count_count_start);
7007+ while (atomic_read_unchecked(&count_count_start) != 2)
7008 mb();
7009
7010 /*
7011@@ -140,8 +140,8 @@ void synchronise_count_slave(int cpu)
7012 if (i == NR_LOOPS-1)
7013 write_c0_count(initcount);
7014
7015- atomic_inc(&count_count_stop);
7016- while (atomic_read(&count_count_stop) != 2)
7017+ atomic_inc_unchecked(&count_count_stop);
7018+ while (atomic_read_unchecked(&count_count_stop) != 2)
7019 mb();
7020 }
7021 /* Arrange for an interrupt in a short while */
7022diff --git a/arch/mips/kernel/traps.c b/arch/mips/kernel/traps.c
7023index e0b4996..6b43ce7 100644
7024--- a/arch/mips/kernel/traps.c
7025+++ b/arch/mips/kernel/traps.c
7026@@ -691,7 +691,18 @@ asmlinkage void do_ov(struct pt_regs *regs)
7027 siginfo_t info;
7028
7029 prev_state = exception_enter();
7030- die_if_kernel("Integer overflow", regs);
7031+ if (unlikely(!user_mode(regs))) {
7032+
7033+#ifdef CONFIG_PAX_REFCOUNT
7034+ if (fixup_exception(regs)) {
7035+ pax_report_refcount_overflow(regs);
7036+ exception_exit(prev_state);
7037+ return;
7038+ }
7039+#endif
7040+
7041+ die("Integer overflow", regs);
7042+ }
7043
7044 info.si_code = FPE_INTOVF;
7045 info.si_signo = SIGFPE;
7046diff --git a/arch/mips/mm/fault.c b/arch/mips/mm/fault.c
7047index becc42b..9e43d4b 100644
7048--- a/arch/mips/mm/fault.c
7049+++ b/arch/mips/mm/fault.c
7050@@ -28,6 +28,23 @@
7051 #include <asm/highmem.h> /* For VMALLOC_END */
7052 #include <linux/kdebug.h>
7053
7054+#ifdef CONFIG_PAX_PAGEEXEC
7055+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
7056+{
7057+ unsigned long i;
7058+
7059+ printk(KERN_ERR "PAX: bytes at PC: ");
7060+ for (i = 0; i < 5; i++) {
7061+ unsigned int c;
7062+ if (get_user(c, (unsigned int *)pc+i))
7063+ printk(KERN_CONT "???????? ");
7064+ else
7065+ printk(KERN_CONT "%08x ", c);
7066+ }
7067+ printk("\n");
7068+}
7069+#endif
7070+
7071 /*
7072 * This routine handles page faults. It determines the address,
7073 * and the problem, and then passes it off to one of the appropriate
7074@@ -199,6 +216,14 @@ bad_area:
7075 bad_area_nosemaphore:
7076 /* User mode accesses just cause a SIGSEGV */
7077 if (user_mode(regs)) {
7078+
7079+#ifdef CONFIG_PAX_PAGEEXEC
7080+ if (cpu_has_rixi && (mm->pax_flags & MF_PAX_PAGEEXEC) && !write && address == instruction_pointer(regs)) {
7081+ pax_report_fault(regs, (void *)address, (void *)user_stack_pointer(regs));
7082+ do_group_exit(SIGKILL);
7083+ }
7084+#endif
7085+
7086 tsk->thread.cp0_badvaddr = address;
7087 tsk->thread.error_code = write;
7088 #if 0
7089diff --git a/arch/mips/mm/mmap.c b/arch/mips/mm/mmap.c
7090index f1baadd..5472dca 100644
7091--- a/arch/mips/mm/mmap.c
7092+++ b/arch/mips/mm/mmap.c
7093@@ -59,6 +59,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
7094 struct vm_area_struct *vma;
7095 unsigned long addr = addr0;
7096 int do_color_align;
7097+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
7098 struct vm_unmapped_area_info info;
7099
7100 if (unlikely(len > TASK_SIZE))
7101@@ -84,6 +85,11 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
7102 do_color_align = 1;
7103
7104 /* requesting a specific address */
7105+
7106+#ifdef CONFIG_PAX_RANDMMAP
7107+ if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
7108+#endif
7109+
7110 if (addr) {
7111 if (do_color_align)
7112 addr = COLOUR_ALIGN(addr, pgoff);
7113@@ -91,14 +97,14 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
7114 addr = PAGE_ALIGN(addr);
7115
7116 vma = find_vma(mm, addr);
7117- if (TASK_SIZE - len >= addr &&
7118- (!vma || addr + len <= vma->vm_start))
7119+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
7120 return addr;
7121 }
7122
7123 info.length = len;
7124 info.align_mask = do_color_align ? (PAGE_MASK & shm_align_mask) : 0;
7125 info.align_offset = pgoff << PAGE_SHIFT;
7126+ info.threadstack_offset = offset;
7127
7128 if (dir == DOWN) {
7129 info.flags = VM_UNMAPPED_AREA_TOPDOWN;
7130@@ -146,6 +152,10 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
7131 {
7132 unsigned long random_factor = 0UL;
7133
7134+#ifdef CONFIG_PAX_RANDMMAP
7135+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
7136+#endif
7137+
7138 if (current->flags & PF_RANDOMIZE) {
7139 random_factor = get_random_int();
7140 random_factor = random_factor << PAGE_SHIFT;
7141@@ -157,40 +167,25 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
7142
7143 if (mmap_is_legacy()) {
7144 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
7145+
7146+#ifdef CONFIG_PAX_RANDMMAP
7147+ if (mm->pax_flags & MF_PAX_RANDMMAP)
7148+ mm->mmap_base += mm->delta_mmap;
7149+#endif
7150+
7151 mm->get_unmapped_area = arch_get_unmapped_area;
7152 } else {
7153 mm->mmap_base = mmap_base(random_factor);
7154+
7155+#ifdef CONFIG_PAX_RANDMMAP
7156+ if (mm->pax_flags & MF_PAX_RANDMMAP)
7157+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
7158+#endif
7159+
7160 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
7161 }
7162 }
7163
7164-static inline unsigned long brk_rnd(void)
7165-{
7166- unsigned long rnd = get_random_int();
7167-
7168- rnd = rnd << PAGE_SHIFT;
7169- /* 8MB for 32bit, 256MB for 64bit */
7170- if (TASK_IS_32BIT_ADDR)
7171- rnd = rnd & 0x7ffffful;
7172- else
7173- rnd = rnd & 0xffffffful;
7174-
7175- return rnd;
7176-}
7177-
7178-unsigned long arch_randomize_brk(struct mm_struct *mm)
7179-{
7180- unsigned long base = mm->brk;
7181- unsigned long ret;
7182-
7183- ret = PAGE_ALIGN(base + brk_rnd());
7184-
7185- if (ret < mm->brk)
7186- return mm->brk;
7187-
7188- return ret;
7189-}
7190-
7191 int __virt_addr_valid(const volatile void *kaddr)
7192 {
7193 return pfn_valid(PFN_DOWN(virt_to_phys(kaddr)));
7194diff --git a/arch/mips/pci/pci-octeon.c b/arch/mips/pci/pci-octeon.c
7195index 59cccd9..f39ac2f 100644
7196--- a/arch/mips/pci/pci-octeon.c
7197+++ b/arch/mips/pci/pci-octeon.c
7198@@ -327,8 +327,8 @@ static int octeon_write_config(struct pci_bus *bus, unsigned int devfn,
7199
7200
7201 static struct pci_ops octeon_pci_ops = {
7202- octeon_read_config,
7203- octeon_write_config,
7204+ .read = octeon_read_config,
7205+ .write = octeon_write_config,
7206 };
7207
7208 static struct resource octeon_pci_mem_resource = {
7209diff --git a/arch/mips/pci/pcie-octeon.c b/arch/mips/pci/pcie-octeon.c
7210index 5e36c33..eb4a17b 100644
7211--- a/arch/mips/pci/pcie-octeon.c
7212+++ b/arch/mips/pci/pcie-octeon.c
7213@@ -1792,8 +1792,8 @@ static int octeon_dummy_write_config(struct pci_bus *bus, unsigned int devfn,
7214 }
7215
7216 static struct pci_ops octeon_pcie0_ops = {
7217- octeon_pcie0_read_config,
7218- octeon_pcie0_write_config,
7219+ .read = octeon_pcie0_read_config,
7220+ .write = octeon_pcie0_write_config,
7221 };
7222
7223 static struct resource octeon_pcie0_mem_resource = {
7224@@ -1813,8 +1813,8 @@ static struct pci_controller octeon_pcie0_controller = {
7225 };
7226
7227 static struct pci_ops octeon_pcie1_ops = {
7228- octeon_pcie1_read_config,
7229- octeon_pcie1_write_config,
7230+ .read = octeon_pcie1_read_config,
7231+ .write = octeon_pcie1_write_config,
7232 };
7233
7234 static struct resource octeon_pcie1_mem_resource = {
7235@@ -1834,8 +1834,8 @@ static struct pci_controller octeon_pcie1_controller = {
7236 };
7237
7238 static struct pci_ops octeon_dummy_ops = {
7239- octeon_dummy_read_config,
7240- octeon_dummy_write_config,
7241+ .read = octeon_dummy_read_config,
7242+ .write = octeon_dummy_write_config,
7243 };
7244
7245 static struct resource octeon_dummy_mem_resource = {
7246diff --git a/arch/mips/sgi-ip27/ip27-nmi.c b/arch/mips/sgi-ip27/ip27-nmi.c
7247index a2358b4..7cead4f 100644
7248--- a/arch/mips/sgi-ip27/ip27-nmi.c
7249+++ b/arch/mips/sgi-ip27/ip27-nmi.c
7250@@ -187,9 +187,9 @@ void
7251 cont_nmi_dump(void)
7252 {
7253 #ifndef REAL_NMI_SIGNAL
7254- static atomic_t nmied_cpus = ATOMIC_INIT(0);
7255+ static atomic_unchecked_t nmied_cpus = ATOMIC_INIT(0);
7256
7257- atomic_inc(&nmied_cpus);
7258+ atomic_inc_unchecked(&nmied_cpus);
7259 #endif
7260 /*
7261 * Only allow 1 cpu to proceed
7262@@ -233,7 +233,7 @@ cont_nmi_dump(void)
7263 udelay(10000);
7264 }
7265 #else
7266- while (atomic_read(&nmied_cpus) != num_online_cpus());
7267+ while (atomic_read_unchecked(&nmied_cpus) != num_online_cpus());
7268 #endif
7269
7270 /*
7271diff --git a/arch/mips/sni/rm200.c b/arch/mips/sni/rm200.c
7272index a046b30..6799527 100644
7273--- a/arch/mips/sni/rm200.c
7274+++ b/arch/mips/sni/rm200.c
7275@@ -270,7 +270,7 @@ spurious_8259A_irq:
7276 "spurious RM200 8259A interrupt: IRQ%d.\n", irq);
7277 spurious_irq_mask |= irqmask;
7278 }
7279- atomic_inc(&irq_err_count);
7280+ atomic_inc_unchecked(&irq_err_count);
7281 /*
7282 * Theoretically we do not have to handle this IRQ,
7283 * but in Linux this does not cause problems and is
7284diff --git a/arch/mips/vr41xx/common/icu.c b/arch/mips/vr41xx/common/icu.c
7285index 41e873b..34d33a7 100644
7286--- a/arch/mips/vr41xx/common/icu.c
7287+++ b/arch/mips/vr41xx/common/icu.c
7288@@ -653,7 +653,7 @@ static int icu_get_irq(unsigned int irq)
7289
7290 printk(KERN_ERR "spurious ICU interrupt: %04x,%04x\n", pend1, pend2);
7291
7292- atomic_inc(&irq_err_count);
7293+ atomic_inc_unchecked(&irq_err_count);
7294
7295 return -1;
7296 }
7297diff --git a/arch/mips/vr41xx/common/irq.c b/arch/mips/vr41xx/common/irq.c
7298index ae0e4ee..e8f0692 100644
7299--- a/arch/mips/vr41xx/common/irq.c
7300+++ b/arch/mips/vr41xx/common/irq.c
7301@@ -64,7 +64,7 @@ static void irq_dispatch(unsigned int irq)
7302 irq_cascade_t *cascade;
7303
7304 if (irq >= NR_IRQS) {
7305- atomic_inc(&irq_err_count);
7306+ atomic_inc_unchecked(&irq_err_count);
7307 return;
7308 }
7309
7310@@ -84,7 +84,7 @@ static void irq_dispatch(unsigned int irq)
7311 ret = cascade->get_irq(irq);
7312 irq = ret;
7313 if (ret < 0)
7314- atomic_inc(&irq_err_count);
7315+ atomic_inc_unchecked(&irq_err_count);
7316 else
7317 irq_dispatch(irq);
7318 if (!irqd_irq_disabled(idata) && chip->irq_unmask)
7319diff --git a/arch/mn10300/proc-mn103e010/include/proc/cache.h b/arch/mn10300/proc-mn103e010/include/proc/cache.h
7320index 967d144..db12197 100644
7321--- a/arch/mn10300/proc-mn103e010/include/proc/cache.h
7322+++ b/arch/mn10300/proc-mn103e010/include/proc/cache.h
7323@@ -11,12 +11,14 @@
7324 #ifndef _ASM_PROC_CACHE_H
7325 #define _ASM_PROC_CACHE_H
7326
7327+#include <linux/const.h>
7328+
7329 /* L1 cache */
7330
7331 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
7332 #define L1_CACHE_NENTRIES 256 /* number of entries in each way */
7333-#define L1_CACHE_BYTES 16 /* bytes per entry */
7334 #define L1_CACHE_SHIFT 4 /* shift for bytes per entry */
7335+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
7336 #define L1_CACHE_WAYDISP 0x1000 /* displacement of one way from the next */
7337
7338 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
7339diff --git a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
7340index bcb5df2..84fabd2 100644
7341--- a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
7342+++ b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
7343@@ -16,13 +16,15 @@
7344 #ifndef _ASM_PROC_CACHE_H
7345 #define _ASM_PROC_CACHE_H
7346
7347+#include <linux/const.h>
7348+
7349 /*
7350 * L1 cache
7351 */
7352 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
7353 #define L1_CACHE_NENTRIES 128 /* number of entries in each way */
7354-#define L1_CACHE_BYTES 32 /* bytes per entry */
7355 #define L1_CACHE_SHIFT 5 /* shift for bytes per entry */
7356+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
7357 #define L1_CACHE_WAYDISP 0x1000 /* distance from one way to the next */
7358
7359 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
7360diff --git a/arch/openrisc/include/asm/cache.h b/arch/openrisc/include/asm/cache.h
7361index 4ce7a01..449202a 100644
7362--- a/arch/openrisc/include/asm/cache.h
7363+++ b/arch/openrisc/include/asm/cache.h
7364@@ -19,11 +19,13 @@
7365 #ifndef __ASM_OPENRISC_CACHE_H
7366 #define __ASM_OPENRISC_CACHE_H
7367
7368+#include <linux/const.h>
7369+
7370 /* FIXME: How can we replace these with values from the CPU...
7371 * they shouldn't be hard-coded!
7372 */
7373
7374-#define L1_CACHE_BYTES 16
7375 #define L1_CACHE_SHIFT 4
7376+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7377
7378 #endif /* __ASM_OPENRISC_CACHE_H */
7379diff --git a/arch/parisc/include/asm/atomic.h b/arch/parisc/include/asm/atomic.h
7380index 472886c..00e7df9 100644
7381--- a/arch/parisc/include/asm/atomic.h
7382+++ b/arch/parisc/include/asm/atomic.h
7383@@ -252,6 +252,16 @@ static inline long atomic64_dec_if_positive(atomic64_t *v)
7384 return dec;
7385 }
7386
7387+#define atomic64_read_unchecked(v) atomic64_read(v)
7388+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
7389+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
7390+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
7391+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
7392+#define atomic64_inc_unchecked(v) atomic64_inc(v)
7393+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
7394+#define atomic64_dec_unchecked(v) atomic64_dec(v)
7395+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
7396+
7397 #endif /* !CONFIG_64BIT */
7398
7399
7400diff --git a/arch/parisc/include/asm/cache.h b/arch/parisc/include/asm/cache.h
7401index 47f11c7..3420df2 100644
7402--- a/arch/parisc/include/asm/cache.h
7403+++ b/arch/parisc/include/asm/cache.h
7404@@ -5,6 +5,7 @@
7405 #ifndef __ARCH_PARISC_CACHE_H
7406 #define __ARCH_PARISC_CACHE_H
7407
7408+#include <linux/const.h>
7409
7410 /*
7411 * PA 2.0 processors have 64-byte cachelines; PA 1.1 processors have
7412@@ -15,13 +16,13 @@
7413 * just ruin performance.
7414 */
7415 #ifdef CONFIG_PA20
7416-#define L1_CACHE_BYTES 64
7417 #define L1_CACHE_SHIFT 6
7418 #else
7419-#define L1_CACHE_BYTES 32
7420 #define L1_CACHE_SHIFT 5
7421 #endif
7422
7423+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7424+
7425 #ifndef __ASSEMBLY__
7426
7427 #define SMP_CACHE_BYTES L1_CACHE_BYTES
7428diff --git a/arch/parisc/include/asm/elf.h b/arch/parisc/include/asm/elf.h
7429index 3391d06..c23a2cc 100644
7430--- a/arch/parisc/include/asm/elf.h
7431+++ b/arch/parisc/include/asm/elf.h
7432@@ -342,6 +342,13 @@ struct pt_regs; /* forward declaration... */
7433
7434 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x01000000)
7435
7436+#ifdef CONFIG_PAX_ASLR
7437+#define PAX_ELF_ET_DYN_BASE 0x10000UL
7438+
7439+#define PAX_DELTA_MMAP_LEN 16
7440+#define PAX_DELTA_STACK_LEN 16
7441+#endif
7442+
7443 /* This yields a mask that user programs can use to figure out what
7444 instruction set this CPU supports. This could be done in user space,
7445 but it's not easy, and we've already done it here. */
7446diff --git a/arch/parisc/include/asm/pgalloc.h b/arch/parisc/include/asm/pgalloc.h
7447index f213f5b..0af3e8e 100644
7448--- a/arch/parisc/include/asm/pgalloc.h
7449+++ b/arch/parisc/include/asm/pgalloc.h
7450@@ -61,6 +61,11 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
7451 (__u32)(__pa((unsigned long)pmd) >> PxD_VALUE_SHIFT));
7452 }
7453
7454+static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
7455+{
7456+ pgd_populate(mm, pgd, pmd);
7457+}
7458+
7459 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long address)
7460 {
7461 pmd_t *pmd = (pmd_t *)__get_free_pages(GFP_KERNEL|__GFP_REPEAT,
7462@@ -93,6 +98,7 @@ static inline void pmd_free(struct mm_struct *mm, pmd_t *pmd)
7463 #define pmd_alloc_one(mm, addr) ({ BUG(); ((pmd_t *)2); })
7464 #define pmd_free(mm, x) do { } while (0)
7465 #define pgd_populate(mm, pmd, pte) BUG()
7466+#define pgd_populate_kernel(mm, pmd, pte) BUG()
7467
7468 #endif
7469
7470diff --git a/arch/parisc/include/asm/pgtable.h b/arch/parisc/include/asm/pgtable.h
7471index 22b89d1..ce34230 100644
7472--- a/arch/parisc/include/asm/pgtable.h
7473+++ b/arch/parisc/include/asm/pgtable.h
7474@@ -223,6 +223,17 @@ extern void purge_tlb_entries(struct mm_struct *, unsigned long);
7475 #define PAGE_EXECREAD __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_EXEC |_PAGE_ACCESSED)
7476 #define PAGE_COPY PAGE_EXECREAD
7477 #define PAGE_RWX __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_EXEC |_PAGE_ACCESSED)
7478+
7479+#ifdef CONFIG_PAX_PAGEEXEC
7480+# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_ACCESSED)
7481+# define PAGE_COPY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
7482+# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
7483+#else
7484+# define PAGE_SHARED_NOEXEC PAGE_SHARED
7485+# define PAGE_COPY_NOEXEC PAGE_COPY
7486+# define PAGE_READONLY_NOEXEC PAGE_READONLY
7487+#endif
7488+
7489 #define PAGE_KERNEL __pgprot(_PAGE_KERNEL)
7490 #define PAGE_KERNEL_EXEC __pgprot(_PAGE_KERNEL_EXEC)
7491 #define PAGE_KERNEL_RWX __pgprot(_PAGE_KERNEL_RWX)
7492diff --git a/arch/parisc/include/asm/uaccess.h b/arch/parisc/include/asm/uaccess.h
7493index 4006964..fcb3cc2 100644
7494--- a/arch/parisc/include/asm/uaccess.h
7495+++ b/arch/parisc/include/asm/uaccess.h
7496@@ -246,10 +246,10 @@ static inline unsigned long __must_check copy_from_user(void *to,
7497 const void __user *from,
7498 unsigned long n)
7499 {
7500- int sz = __compiletime_object_size(to);
7501+ size_t sz = __compiletime_object_size(to);
7502 int ret = -EFAULT;
7503
7504- if (likely(sz == -1 || !__builtin_constant_p(n) || sz >= n))
7505+ if (likely(sz == (size_t)-1 || !__builtin_constant_p(n) || sz >= n))
7506 ret = __copy_from_user(to, from, n);
7507 else
7508 copy_from_user_overflow();
7509diff --git a/arch/parisc/include/uapi/asm/resource.h b/arch/parisc/include/uapi/asm/resource.h
7510index 8b06343..090483c 100644
7511--- a/arch/parisc/include/uapi/asm/resource.h
7512+++ b/arch/parisc/include/uapi/asm/resource.h
7513@@ -1,7 +1,6 @@
7514 #ifndef _ASM_PARISC_RESOURCE_H
7515 #define _ASM_PARISC_RESOURCE_H
7516
7517-#define _STK_LIM_MAX 10 * _STK_LIM
7518 #include <asm-generic/resource.h>
7519
7520 #endif
7521diff --git a/arch/parisc/kernel/module.c b/arch/parisc/kernel/module.c
7522index 50dfafc..b9fc230 100644
7523--- a/arch/parisc/kernel/module.c
7524+++ b/arch/parisc/kernel/module.c
7525@@ -98,16 +98,38 @@
7526
7527 /* three functions to determine where in the module core
7528 * or init pieces the location is */
7529+static inline int in_init_rx(struct module *me, void *loc)
7530+{
7531+ return (loc >= me->module_init_rx &&
7532+ loc < (me->module_init_rx + me->init_size_rx));
7533+}
7534+
7535+static inline int in_init_rw(struct module *me, void *loc)
7536+{
7537+ return (loc >= me->module_init_rw &&
7538+ loc < (me->module_init_rw + me->init_size_rw));
7539+}
7540+
7541 static inline int in_init(struct module *me, void *loc)
7542 {
7543- return (loc >= me->module_init &&
7544- loc <= (me->module_init + me->init_size));
7545+ return in_init_rx(me, loc) || in_init_rw(me, loc);
7546+}
7547+
7548+static inline int in_core_rx(struct module *me, void *loc)
7549+{
7550+ return (loc >= me->module_core_rx &&
7551+ loc < (me->module_core_rx + me->core_size_rx));
7552+}
7553+
7554+static inline int in_core_rw(struct module *me, void *loc)
7555+{
7556+ return (loc >= me->module_core_rw &&
7557+ loc < (me->module_core_rw + me->core_size_rw));
7558 }
7559
7560 static inline int in_core(struct module *me, void *loc)
7561 {
7562- return (loc >= me->module_core &&
7563- loc <= (me->module_core + me->core_size));
7564+ return in_core_rx(me, loc) || in_core_rw(me, loc);
7565 }
7566
7567 static inline int in_local(struct module *me, void *loc)
7568@@ -371,13 +393,13 @@ int module_frob_arch_sections(CONST Elf_Ehdr *hdr,
7569 }
7570
7571 /* align things a bit */
7572- me->core_size = ALIGN(me->core_size, 16);
7573- me->arch.got_offset = me->core_size;
7574- me->core_size += gots * sizeof(struct got_entry);
7575+ me->core_size_rw = ALIGN(me->core_size_rw, 16);
7576+ me->arch.got_offset = me->core_size_rw;
7577+ me->core_size_rw += gots * sizeof(struct got_entry);
7578
7579- me->core_size = ALIGN(me->core_size, 16);
7580- me->arch.fdesc_offset = me->core_size;
7581- me->core_size += fdescs * sizeof(Elf_Fdesc);
7582+ me->core_size_rw = ALIGN(me->core_size_rw, 16);
7583+ me->arch.fdesc_offset = me->core_size_rw;
7584+ me->core_size_rw += fdescs * sizeof(Elf_Fdesc);
7585
7586 me->arch.got_max = gots;
7587 me->arch.fdesc_max = fdescs;
7588@@ -395,7 +417,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
7589
7590 BUG_ON(value == 0);
7591
7592- got = me->module_core + me->arch.got_offset;
7593+ got = me->module_core_rw + me->arch.got_offset;
7594 for (i = 0; got[i].addr; i++)
7595 if (got[i].addr == value)
7596 goto out;
7597@@ -413,7 +435,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
7598 #ifdef CONFIG_64BIT
7599 static Elf_Addr get_fdesc(struct module *me, unsigned long value)
7600 {
7601- Elf_Fdesc *fdesc = me->module_core + me->arch.fdesc_offset;
7602+ Elf_Fdesc *fdesc = me->module_core_rw + me->arch.fdesc_offset;
7603
7604 if (!value) {
7605 printk(KERN_ERR "%s: zero OPD requested!\n", me->name);
7606@@ -431,7 +453,7 @@ static Elf_Addr get_fdesc(struct module *me, unsigned long value)
7607
7608 /* Create new one */
7609 fdesc->addr = value;
7610- fdesc->gp = (Elf_Addr)me->module_core + me->arch.got_offset;
7611+ fdesc->gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
7612 return (Elf_Addr)fdesc;
7613 }
7614 #endif /* CONFIG_64BIT */
7615@@ -843,7 +865,7 @@ register_unwind_table(struct module *me,
7616
7617 table = (unsigned char *)sechdrs[me->arch.unwind_section].sh_addr;
7618 end = table + sechdrs[me->arch.unwind_section].sh_size;
7619- gp = (Elf_Addr)me->module_core + me->arch.got_offset;
7620+ gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
7621
7622 DEBUGP("register_unwind_table(), sect = %d at 0x%p - 0x%p (gp=0x%lx)\n",
7623 me->arch.unwind_section, table, end, gp);
7624diff --git a/arch/parisc/kernel/sys_parisc.c b/arch/parisc/kernel/sys_parisc.c
7625index b7cadc4..bf4a32d 100644
7626--- a/arch/parisc/kernel/sys_parisc.c
7627+++ b/arch/parisc/kernel/sys_parisc.c
7628@@ -89,6 +89,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
7629 unsigned long task_size = TASK_SIZE;
7630 int do_color_align, last_mmap;
7631 struct vm_unmapped_area_info info;
7632+ unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
7633
7634 if (len > task_size)
7635 return -ENOMEM;
7636@@ -106,6 +107,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
7637 goto found_addr;
7638 }
7639
7640+#ifdef CONFIG_PAX_RANDMMAP
7641+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
7642+#endif
7643+
7644 if (addr) {
7645 if (do_color_align && last_mmap)
7646 addr = COLOR_ALIGN(addr, last_mmap, pgoff);
7647@@ -124,6 +129,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
7648 info.high_limit = mmap_upper_limit();
7649 info.align_mask = last_mmap ? (PAGE_MASK & (SHMLBA - 1)) : 0;
7650 info.align_offset = shared_align_offset(last_mmap, pgoff);
7651+ info.threadstack_offset = offset;
7652 addr = vm_unmapped_area(&info);
7653
7654 found_addr:
7655@@ -143,6 +149,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7656 unsigned long addr = addr0;
7657 int do_color_align, last_mmap;
7658 struct vm_unmapped_area_info info;
7659+ unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
7660
7661 #ifdef CONFIG_64BIT
7662 /* This should only ever run for 32-bit processes. */
7663@@ -167,6 +174,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7664 }
7665
7666 /* requesting a specific address */
7667+#ifdef CONFIG_PAX_RANDMMAP
7668+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
7669+#endif
7670+
7671 if (addr) {
7672 if (do_color_align && last_mmap)
7673 addr = COLOR_ALIGN(addr, last_mmap, pgoff);
7674@@ -184,6 +195,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7675 info.high_limit = mm->mmap_base;
7676 info.align_mask = last_mmap ? (PAGE_MASK & (SHMLBA - 1)) : 0;
7677 info.align_offset = shared_align_offset(last_mmap, pgoff);
7678+ info.threadstack_offset = offset;
7679 addr = vm_unmapped_area(&info);
7680 if (!(addr & ~PAGE_MASK))
7681 goto found_addr;
7682@@ -249,6 +261,13 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
7683 mm->mmap_legacy_base = mmap_legacy_base();
7684 mm->mmap_base = mmap_upper_limit();
7685
7686+#ifdef CONFIG_PAX_RANDMMAP
7687+ if (mm->pax_flags & MF_PAX_RANDMMAP) {
7688+ mm->mmap_legacy_base += mm->delta_mmap;
7689+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
7690+ }
7691+#endif
7692+
7693 if (mmap_is_legacy()) {
7694 mm->mmap_base = mm->mmap_legacy_base;
7695 mm->get_unmapped_area = arch_get_unmapped_area;
7696diff --git a/arch/parisc/kernel/traps.c b/arch/parisc/kernel/traps.c
7697index 1cd1d0c..44ec918 100644
7698--- a/arch/parisc/kernel/traps.c
7699+++ b/arch/parisc/kernel/traps.c
7700@@ -722,9 +722,7 @@ void notrace handle_interruption(int code, struct pt_regs *regs)
7701
7702 down_read(&current->mm->mmap_sem);
7703 vma = find_vma(current->mm,regs->iaoq[0]);
7704- if (vma && (regs->iaoq[0] >= vma->vm_start)
7705- && (vma->vm_flags & VM_EXEC)) {
7706-
7707+ if (vma && (regs->iaoq[0] >= vma->vm_start)) {
7708 fault_address = regs->iaoq[0];
7709 fault_space = regs->iasq[0];
7710
7711diff --git a/arch/parisc/mm/fault.c b/arch/parisc/mm/fault.c
7712index 9d08c71..e2b4d20 100644
7713--- a/arch/parisc/mm/fault.c
7714+++ b/arch/parisc/mm/fault.c
7715@@ -15,6 +15,7 @@
7716 #include <linux/sched.h>
7717 #include <linux/interrupt.h>
7718 #include <linux/module.h>
7719+#include <linux/unistd.h>
7720
7721 #include <asm/uaccess.h>
7722 #include <asm/traps.h>
7723@@ -52,7 +53,7 @@ DEFINE_PER_CPU(struct exception_data, exception_data);
7724 static unsigned long
7725 parisc_acctyp(unsigned long code, unsigned int inst)
7726 {
7727- if (code == 6 || code == 16)
7728+ if (code == 6 || code == 7 || code == 16)
7729 return VM_EXEC;
7730
7731 switch (inst & 0xf0000000) {
7732@@ -138,6 +139,116 @@ parisc_acctyp(unsigned long code, unsigned int inst)
7733 }
7734 #endif
7735
7736+#ifdef CONFIG_PAX_PAGEEXEC
7737+/*
7738+ * PaX: decide what to do with offenders (instruction_pointer(regs) = fault address)
7739+ *
7740+ * returns 1 when task should be killed
7741+ * 2 when rt_sigreturn trampoline was detected
7742+ * 3 when unpatched PLT trampoline was detected
7743+ */
7744+static int pax_handle_fetch_fault(struct pt_regs *regs)
7745+{
7746+
7747+#ifdef CONFIG_PAX_EMUPLT
7748+ int err;
7749+
7750+ do { /* PaX: unpatched PLT emulation */
7751+ unsigned int bl, depwi;
7752+
7753+ err = get_user(bl, (unsigned int *)instruction_pointer(regs));
7754+ err |= get_user(depwi, (unsigned int *)(instruction_pointer(regs)+4));
7755+
7756+ if (err)
7757+ break;
7758+
7759+ if (bl == 0xEA9F1FDDU && depwi == 0xD6801C1EU) {
7760+ unsigned int ldw, bv, ldw2, addr = instruction_pointer(regs)-12;
7761+
7762+ err = get_user(ldw, (unsigned int *)addr);
7763+ err |= get_user(bv, (unsigned int *)(addr+4));
7764+ err |= get_user(ldw2, (unsigned int *)(addr+8));
7765+
7766+ if (err)
7767+ break;
7768+
7769+ if (ldw == 0x0E801096U &&
7770+ bv == 0xEAC0C000U &&
7771+ ldw2 == 0x0E881095U)
7772+ {
7773+ unsigned int resolver, map;
7774+
7775+ err = get_user(resolver, (unsigned int *)(instruction_pointer(regs)+8));
7776+ err |= get_user(map, (unsigned int *)(instruction_pointer(regs)+12));
7777+ if (err)
7778+ break;
7779+
7780+ regs->gr[20] = instruction_pointer(regs)+8;
7781+ regs->gr[21] = map;
7782+ regs->gr[22] = resolver;
7783+ regs->iaoq[0] = resolver | 3UL;
7784+ regs->iaoq[1] = regs->iaoq[0] + 4;
7785+ return 3;
7786+ }
7787+ }
7788+ } while (0);
7789+#endif
7790+
7791+#ifdef CONFIG_PAX_EMUTRAMP
7792+
7793+#ifndef CONFIG_PAX_EMUSIGRT
7794+ if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
7795+ return 1;
7796+#endif
7797+
7798+ do { /* PaX: rt_sigreturn emulation */
7799+ unsigned int ldi1, ldi2, bel, nop;
7800+
7801+ err = get_user(ldi1, (unsigned int *)instruction_pointer(regs));
7802+ err |= get_user(ldi2, (unsigned int *)(instruction_pointer(regs)+4));
7803+ err |= get_user(bel, (unsigned int *)(instruction_pointer(regs)+8));
7804+ err |= get_user(nop, (unsigned int *)(instruction_pointer(regs)+12));
7805+
7806+ if (err)
7807+ break;
7808+
7809+ if ((ldi1 == 0x34190000U || ldi1 == 0x34190002U) &&
7810+ ldi2 == 0x3414015AU &&
7811+ bel == 0xE4008200U &&
7812+ nop == 0x08000240U)
7813+ {
7814+ regs->gr[25] = (ldi1 & 2) >> 1;
7815+ regs->gr[20] = __NR_rt_sigreturn;
7816+ regs->gr[31] = regs->iaoq[1] + 16;
7817+ regs->sr[0] = regs->iasq[1];
7818+ regs->iaoq[0] = 0x100UL;
7819+ regs->iaoq[1] = regs->iaoq[0] + 4;
7820+ regs->iasq[0] = regs->sr[2];
7821+ regs->iasq[1] = regs->sr[2];
7822+ return 2;
7823+ }
7824+ } while (0);
7825+#endif
7826+
7827+ return 1;
7828+}
7829+
7830+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
7831+{
7832+ unsigned long i;
7833+
7834+ printk(KERN_ERR "PAX: bytes at PC: ");
7835+ for (i = 0; i < 5; i++) {
7836+ unsigned int c;
7837+ if (get_user(c, (unsigned int *)pc+i))
7838+ printk(KERN_CONT "???????? ");
7839+ else
7840+ printk(KERN_CONT "%08x ", c);
7841+ }
7842+ printk("\n");
7843+}
7844+#endif
7845+
7846 int fixup_exception(struct pt_regs *regs)
7847 {
7848 const struct exception_table_entry *fix;
7849@@ -210,8 +321,33 @@ retry:
7850
7851 good_area:
7852
7853- if ((vma->vm_flags & acc_type) != acc_type)
7854+ if ((vma->vm_flags & acc_type) != acc_type) {
7855+
7856+#ifdef CONFIG_PAX_PAGEEXEC
7857+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && (acc_type & VM_EXEC) &&
7858+ (address & ~3UL) == instruction_pointer(regs))
7859+ {
7860+ up_read(&mm->mmap_sem);
7861+ switch (pax_handle_fetch_fault(regs)) {
7862+
7863+#ifdef CONFIG_PAX_EMUPLT
7864+ case 3:
7865+ return;
7866+#endif
7867+
7868+#ifdef CONFIG_PAX_EMUTRAMP
7869+ case 2:
7870+ return;
7871+#endif
7872+
7873+ }
7874+ pax_report_fault(regs, (void *)instruction_pointer(regs), (void *)regs->gr[30]);
7875+ do_group_exit(SIGKILL);
7876+ }
7877+#endif
7878+
7879 goto bad_area;
7880+ }
7881
7882 /*
7883 * If for any reason at all we couldn't handle the fault, make
7884diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
7885index 957bf34..3430cc8 100644
7886--- a/arch/powerpc/Kconfig
7887+++ b/arch/powerpc/Kconfig
7888@@ -393,6 +393,7 @@ config PPC64_SUPPORTS_MEMORY_FAILURE
7889 config KEXEC
7890 bool "kexec system call"
7891 depends on (PPC_BOOK3S || FSL_BOOKE || (44x && !SMP))
7892+ depends on !GRKERNSEC_KMEM
7893 help
7894 kexec is a system call that implements the ability to shutdown your
7895 current kernel, and to start another kernel. It is like a reboot
7896diff --git a/arch/powerpc/include/asm/atomic.h b/arch/powerpc/include/asm/atomic.h
7897index e3b1d41..8e81edf 100644
7898--- a/arch/powerpc/include/asm/atomic.h
7899+++ b/arch/powerpc/include/asm/atomic.h
7900@@ -523,6 +523,16 @@ static __inline__ long atomic64_inc_not_zero(atomic64_t *v)
7901 return t1;
7902 }
7903
7904+#define atomic64_read_unchecked(v) atomic64_read(v)
7905+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
7906+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
7907+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
7908+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
7909+#define atomic64_inc_unchecked(v) atomic64_inc(v)
7910+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
7911+#define atomic64_dec_unchecked(v) atomic64_dec(v)
7912+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
7913+
7914 #endif /* __powerpc64__ */
7915
7916 #endif /* __KERNEL__ */
7917diff --git a/arch/powerpc/include/asm/cache.h b/arch/powerpc/include/asm/cache.h
7918index ed0afc1..0332825 100644
7919--- a/arch/powerpc/include/asm/cache.h
7920+++ b/arch/powerpc/include/asm/cache.h
7921@@ -3,6 +3,7 @@
7922
7923 #ifdef __KERNEL__
7924
7925+#include <linux/const.h>
7926
7927 /* bytes per L1 cache line */
7928 #if defined(CONFIG_8xx) || defined(CONFIG_403GCX)
7929@@ -22,7 +23,7 @@
7930 #define L1_CACHE_SHIFT 7
7931 #endif
7932
7933-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
7934+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7935
7936 #define SMP_CACHE_BYTES L1_CACHE_BYTES
7937
7938diff --git a/arch/powerpc/include/asm/elf.h b/arch/powerpc/include/asm/elf.h
7939index 935b5e7..7001d2d 100644
7940--- a/arch/powerpc/include/asm/elf.h
7941+++ b/arch/powerpc/include/asm/elf.h
7942@@ -28,8 +28,19 @@
7943 the loader. We need to make sure that it is out of the way of the program
7944 that it will "exec", and that there is sufficient room for the brk. */
7945
7946-extern unsigned long randomize_et_dyn(unsigned long base);
7947-#define ELF_ET_DYN_BASE (randomize_et_dyn(0x20000000))
7948+#define ELF_ET_DYN_BASE (0x20000000)
7949+
7950+#ifdef CONFIG_PAX_ASLR
7951+#define PAX_ELF_ET_DYN_BASE (0x10000000UL)
7952+
7953+#ifdef __powerpc64__
7954+#define PAX_DELTA_MMAP_LEN (is_32bit_task() ? 16 : 28)
7955+#define PAX_DELTA_STACK_LEN (is_32bit_task() ? 16 : 28)
7956+#else
7957+#define PAX_DELTA_MMAP_LEN 15
7958+#define PAX_DELTA_STACK_LEN 15
7959+#endif
7960+#endif
7961
7962 #define ELF_CORE_EFLAGS (is_elf2_task() ? 2 : 0)
7963
7964@@ -127,10 +138,6 @@ extern int arch_setup_additional_pages(struct linux_binprm *bprm,
7965 (0x7ff >> (PAGE_SHIFT - 12)) : \
7966 (0x3ffff >> (PAGE_SHIFT - 12)))
7967
7968-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
7969-#define arch_randomize_brk arch_randomize_brk
7970-
7971-
7972 #ifdef CONFIG_SPU_BASE
7973 /* Notes used in ET_CORE. Note name is "SPU/<fd>/<filename>". */
7974 #define NT_SPU 1
7975diff --git a/arch/powerpc/include/asm/exec.h b/arch/powerpc/include/asm/exec.h
7976index 8196e9c..d83a9f3 100644
7977--- a/arch/powerpc/include/asm/exec.h
7978+++ b/arch/powerpc/include/asm/exec.h
7979@@ -4,6 +4,6 @@
7980 #ifndef _ASM_POWERPC_EXEC_H
7981 #define _ASM_POWERPC_EXEC_H
7982
7983-extern unsigned long arch_align_stack(unsigned long sp);
7984+#define arch_align_stack(x) ((x) & ~0xfUL)
7985
7986 #endif /* _ASM_POWERPC_EXEC_H */
7987diff --git a/arch/powerpc/include/asm/kmap_types.h b/arch/powerpc/include/asm/kmap_types.h
7988index 5acabbd..7ea14fa 100644
7989--- a/arch/powerpc/include/asm/kmap_types.h
7990+++ b/arch/powerpc/include/asm/kmap_types.h
7991@@ -10,7 +10,7 @@
7992 * 2 of the License, or (at your option) any later version.
7993 */
7994
7995-#define KM_TYPE_NR 16
7996+#define KM_TYPE_NR 17
7997
7998 #endif /* __KERNEL__ */
7999 #endif /* _ASM_POWERPC_KMAP_TYPES_H */
8000diff --git a/arch/powerpc/include/asm/local.h b/arch/powerpc/include/asm/local.h
8001index b8da913..60b608a 100644
8002--- a/arch/powerpc/include/asm/local.h
8003+++ b/arch/powerpc/include/asm/local.h
8004@@ -9,15 +9,26 @@ typedef struct
8005 atomic_long_t a;
8006 } local_t;
8007
8008+typedef struct
8009+{
8010+ atomic_long_unchecked_t a;
8011+} local_unchecked_t;
8012+
8013 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
8014
8015 #define local_read(l) atomic_long_read(&(l)->a)
8016+#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
8017 #define local_set(l,i) atomic_long_set(&(l)->a, (i))
8018+#define local_set_unchecked(l,i) atomic_long_set_unchecked(&(l)->a, (i))
8019
8020 #define local_add(i,l) atomic_long_add((i),(&(l)->a))
8021+#define local_add_unchecked(i,l) atomic_long_add_unchecked((i),(&(l)->a))
8022 #define local_sub(i,l) atomic_long_sub((i),(&(l)->a))
8023+#define local_sub_unchecked(i,l) atomic_long_sub_unchecked((i),(&(l)->a))
8024 #define local_inc(l) atomic_long_inc(&(l)->a)
8025+#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
8026 #define local_dec(l) atomic_long_dec(&(l)->a)
8027+#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
8028
8029 static __inline__ long local_add_return(long a, local_t *l)
8030 {
8031@@ -35,6 +46,7 @@ static __inline__ long local_add_return(long a, local_t *l)
8032
8033 return t;
8034 }
8035+#define local_add_return_unchecked(i, l) atomic_long_add_return_unchecked((i), (&(l)->a))
8036
8037 #define local_add_negative(a, l) (local_add_return((a), (l)) < 0)
8038
8039@@ -54,6 +66,7 @@ static __inline__ long local_sub_return(long a, local_t *l)
8040
8041 return t;
8042 }
8043+#define local_sub_return_unchecked(i, l) atomic_long_sub_return_unchecked((i), (&(l)->a))
8044
8045 static __inline__ long local_inc_return(local_t *l)
8046 {
8047@@ -101,6 +114,8 @@ static __inline__ long local_dec_return(local_t *l)
8048
8049 #define local_cmpxchg(l, o, n) \
8050 (cmpxchg_local(&((l)->a.counter), (o), (n)))
8051+#define local_cmpxchg_unchecked(l, o, n) \
8052+ (cmpxchg_local(&((l)->a.counter), (o), (n)))
8053 #define local_xchg(l, n) (xchg_local(&((l)->a.counter), (n)))
8054
8055 /**
8056diff --git a/arch/powerpc/include/asm/mman.h b/arch/powerpc/include/asm/mman.h
8057index 8565c25..2865190 100644
8058--- a/arch/powerpc/include/asm/mman.h
8059+++ b/arch/powerpc/include/asm/mman.h
8060@@ -24,7 +24,7 @@ static inline unsigned long arch_calc_vm_prot_bits(unsigned long prot)
8061 }
8062 #define arch_calc_vm_prot_bits(prot) arch_calc_vm_prot_bits(prot)
8063
8064-static inline pgprot_t arch_vm_get_page_prot(unsigned long vm_flags)
8065+static inline pgprot_t arch_vm_get_page_prot(vm_flags_t vm_flags)
8066 {
8067 return (vm_flags & VM_SAO) ? __pgprot(_PAGE_SAO) : __pgprot(0);
8068 }
8069diff --git a/arch/powerpc/include/asm/page.h b/arch/powerpc/include/asm/page.h
8070index 32e4e21..62afb12 100644
8071--- a/arch/powerpc/include/asm/page.h
8072+++ b/arch/powerpc/include/asm/page.h
8073@@ -230,8 +230,9 @@ extern long long virt_phys_offset;
8074 * and needs to be executable. This means the whole heap ends
8075 * up being executable.
8076 */
8077-#define VM_DATA_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
8078- VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
8079+#define VM_DATA_DEFAULT_FLAGS32 \
8080+ (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
8081+ VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
8082
8083 #define VM_DATA_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
8084 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
8085@@ -259,6 +260,9 @@ extern long long virt_phys_offset;
8086 #define is_kernel_addr(x) ((x) >= PAGE_OFFSET)
8087 #endif
8088
8089+#define ktla_ktva(addr) (addr)
8090+#define ktva_ktla(addr) (addr)
8091+
8092 #ifndef CONFIG_PPC_BOOK3S_64
8093 /*
8094 * Use the top bit of the higher-level page table entries to indicate whether
8095diff --git a/arch/powerpc/include/asm/page_64.h b/arch/powerpc/include/asm/page_64.h
8096index 88693ce..ac6f9ab 100644
8097--- a/arch/powerpc/include/asm/page_64.h
8098+++ b/arch/powerpc/include/asm/page_64.h
8099@@ -153,15 +153,18 @@ do { \
8100 * stack by default, so in the absence of a PT_GNU_STACK program header
8101 * we turn execute permission off.
8102 */
8103-#define VM_STACK_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
8104- VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
8105+#define VM_STACK_DEFAULT_FLAGS32 \
8106+ (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
8107+ VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
8108
8109 #define VM_STACK_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
8110 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
8111
8112+#ifndef CONFIG_PAX_PAGEEXEC
8113 #define VM_STACK_DEFAULT_FLAGS \
8114 (is_32bit_task() ? \
8115 VM_STACK_DEFAULT_FLAGS32 : VM_STACK_DEFAULT_FLAGS64)
8116+#endif
8117
8118 #include <asm-generic/getorder.h>
8119
8120diff --git a/arch/powerpc/include/asm/pgalloc-64.h b/arch/powerpc/include/asm/pgalloc-64.h
8121index 4b0be20..c15a27d 100644
8122--- a/arch/powerpc/include/asm/pgalloc-64.h
8123+++ b/arch/powerpc/include/asm/pgalloc-64.h
8124@@ -54,6 +54,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
8125 #ifndef CONFIG_PPC_64K_PAGES
8126
8127 #define pgd_populate(MM, PGD, PUD) pgd_set(PGD, PUD)
8128+#define pgd_populate_kernel(MM, PGD, PUD) pgd_populate((MM), (PGD), (PUD))
8129
8130 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
8131 {
8132@@ -71,6 +72,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
8133 pud_set(pud, (unsigned long)pmd);
8134 }
8135
8136+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
8137+{
8138+ pud_populate(mm, pud, pmd);
8139+}
8140+
8141 #define pmd_populate(mm, pmd, pte_page) \
8142 pmd_populate_kernel(mm, pmd, page_address(pte_page))
8143 #define pmd_populate_kernel(mm, pmd, pte) pmd_set(pmd, (unsigned long)(pte))
8144@@ -173,6 +179,7 @@ extern void __tlb_remove_table(void *_table);
8145 #endif
8146
8147 #define pud_populate(mm, pud, pmd) pud_set(pud, (unsigned long)pmd)
8148+#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
8149
8150 static inline void pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmd,
8151 pte_t *pte)
8152diff --git a/arch/powerpc/include/asm/pgtable.h b/arch/powerpc/include/asm/pgtable.h
8153index 3ebb188..e17dddf 100644
8154--- a/arch/powerpc/include/asm/pgtable.h
8155+++ b/arch/powerpc/include/asm/pgtable.h
8156@@ -2,6 +2,7 @@
8157 #define _ASM_POWERPC_PGTABLE_H
8158 #ifdef __KERNEL__
8159
8160+#include <linux/const.h>
8161 #ifndef __ASSEMBLY__
8162 #include <linux/mmdebug.h>
8163 #include <asm/processor.h> /* For TASK_SIZE */
8164diff --git a/arch/powerpc/include/asm/pte-hash32.h b/arch/powerpc/include/asm/pte-hash32.h
8165index 4aad413..85d86bf 100644
8166--- a/arch/powerpc/include/asm/pte-hash32.h
8167+++ b/arch/powerpc/include/asm/pte-hash32.h
8168@@ -21,6 +21,7 @@
8169 #define _PAGE_FILE 0x004 /* when !present: nonlinear file mapping */
8170 #define _PAGE_USER 0x004 /* usermode access allowed */
8171 #define _PAGE_GUARDED 0x008 /* G: prohibit speculative access */
8172+#define _PAGE_EXEC _PAGE_GUARDED
8173 #define _PAGE_COHERENT 0x010 /* M: enforce memory coherence (SMP systems) */
8174 #define _PAGE_NO_CACHE 0x020 /* I: cache inhibit */
8175 #define _PAGE_WRITETHRU 0x040 /* W: cache write-through */
8176diff --git a/arch/powerpc/include/asm/reg.h b/arch/powerpc/include/asm/reg.h
8177index ce17815..c5574cc 100644
8178--- a/arch/powerpc/include/asm/reg.h
8179+++ b/arch/powerpc/include/asm/reg.h
8180@@ -249,6 +249,7 @@
8181 #define SPRN_DBCR 0x136 /* e300 Data Breakpoint Control Reg */
8182 #define SPRN_DSISR 0x012 /* Data Storage Interrupt Status Register */
8183 #define DSISR_NOHPTE 0x40000000 /* no translation found */
8184+#define DSISR_GUARDED 0x10000000 /* fetch from guarded storage */
8185 #define DSISR_PROTFAULT 0x08000000 /* protection fault */
8186 #define DSISR_ISSTORE 0x02000000 /* access was a store */
8187 #define DSISR_DABRMATCH 0x00400000 /* hit data breakpoint */
8188diff --git a/arch/powerpc/include/asm/smp.h b/arch/powerpc/include/asm/smp.h
8189index 084e080..9415a3d 100644
8190--- a/arch/powerpc/include/asm/smp.h
8191+++ b/arch/powerpc/include/asm/smp.h
8192@@ -51,7 +51,7 @@ struct smp_ops_t {
8193 int (*cpu_disable)(void);
8194 void (*cpu_die)(unsigned int nr);
8195 int (*cpu_bootable)(unsigned int nr);
8196-};
8197+} __no_const;
8198
8199 extern void smp_send_debugger_break(void);
8200 extern void start_secondary_resume(void);
8201diff --git a/arch/powerpc/include/asm/thread_info.h b/arch/powerpc/include/asm/thread_info.h
8202index b034ecd..af7e31f 100644
8203--- a/arch/powerpc/include/asm/thread_info.h
8204+++ b/arch/powerpc/include/asm/thread_info.h
8205@@ -107,6 +107,8 @@ static inline struct thread_info *current_thread_info(void)
8206 #if defined(CONFIG_PPC64)
8207 #define TIF_ELF2ABI 18 /* function descriptors must die! */
8208 #endif
8209+/* mask must be expressable within 16 bits to satisfy 'andi' instruction reqs */
8210+#define TIF_GRSEC_SETXID 6 /* update credentials on syscall entry/exit */
8211
8212 /* as above, but as bit values */
8213 #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
8214@@ -125,9 +127,10 @@ static inline struct thread_info *current_thread_info(void)
8215 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
8216 #define _TIF_EMULATE_STACK_STORE (1<<TIF_EMULATE_STACK_STORE)
8217 #define _TIF_NOHZ (1<<TIF_NOHZ)
8218+#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
8219 #define _TIF_SYSCALL_T_OR_A (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
8220 _TIF_SECCOMP | _TIF_SYSCALL_TRACEPOINT | \
8221- _TIF_NOHZ)
8222+ _TIF_NOHZ | _TIF_GRSEC_SETXID)
8223
8224 #define _TIF_USER_WORK_MASK (_TIF_SIGPENDING | _TIF_NEED_RESCHED | \
8225 _TIF_NOTIFY_RESUME | _TIF_UPROBE | \
8226diff --git a/arch/powerpc/include/asm/uaccess.h b/arch/powerpc/include/asm/uaccess.h
8227index 9485b43..3bd3c16 100644
8228--- a/arch/powerpc/include/asm/uaccess.h
8229+++ b/arch/powerpc/include/asm/uaccess.h
8230@@ -58,6 +58,7 @@
8231
8232 #endif
8233
8234+#define access_ok_noprefault(type, addr, size) access_ok((type), (addr), (size))
8235 #define access_ok(type, addr, size) \
8236 (__chk_user_ptr(addr), \
8237 __access_ok((__force unsigned long)(addr), (size), get_fs()))
8238@@ -318,52 +319,6 @@ do { \
8239 extern unsigned long __copy_tofrom_user(void __user *to,
8240 const void __user *from, unsigned long size);
8241
8242-#ifndef __powerpc64__
8243-
8244-static inline unsigned long copy_from_user(void *to,
8245- const void __user *from, unsigned long n)
8246-{
8247- unsigned long over;
8248-
8249- if (access_ok(VERIFY_READ, from, n))
8250- return __copy_tofrom_user((__force void __user *)to, from, n);
8251- if ((unsigned long)from < TASK_SIZE) {
8252- over = (unsigned long)from + n - TASK_SIZE;
8253- return __copy_tofrom_user((__force void __user *)to, from,
8254- n - over) + over;
8255- }
8256- return n;
8257-}
8258-
8259-static inline unsigned long copy_to_user(void __user *to,
8260- const void *from, unsigned long n)
8261-{
8262- unsigned long over;
8263-
8264- if (access_ok(VERIFY_WRITE, to, n))
8265- return __copy_tofrom_user(to, (__force void __user *)from, n);
8266- if ((unsigned long)to < TASK_SIZE) {
8267- over = (unsigned long)to + n - TASK_SIZE;
8268- return __copy_tofrom_user(to, (__force void __user *)from,
8269- n - over) + over;
8270- }
8271- return n;
8272-}
8273-
8274-#else /* __powerpc64__ */
8275-
8276-#define __copy_in_user(to, from, size) \
8277- __copy_tofrom_user((to), (from), (size))
8278-
8279-extern unsigned long copy_from_user(void *to, const void __user *from,
8280- unsigned long n);
8281-extern unsigned long copy_to_user(void __user *to, const void *from,
8282- unsigned long n);
8283-extern unsigned long copy_in_user(void __user *to, const void __user *from,
8284- unsigned long n);
8285-
8286-#endif /* __powerpc64__ */
8287-
8288 static inline unsigned long __copy_from_user_inatomic(void *to,
8289 const void __user *from, unsigned long n)
8290 {
8291@@ -387,6 +342,10 @@ static inline unsigned long __copy_from_user_inatomic(void *to,
8292 if (ret == 0)
8293 return 0;
8294 }
8295+
8296+ if (!__builtin_constant_p(n))
8297+ check_object_size(to, n, false);
8298+
8299 return __copy_tofrom_user((__force void __user *)to, from, n);
8300 }
8301
8302@@ -413,6 +372,10 @@ static inline unsigned long __copy_to_user_inatomic(void __user *to,
8303 if (ret == 0)
8304 return 0;
8305 }
8306+
8307+ if (!__builtin_constant_p(n))
8308+ check_object_size(from, n, true);
8309+
8310 return __copy_tofrom_user(to, (__force const void __user *)from, n);
8311 }
8312
8313@@ -430,6 +393,92 @@ static inline unsigned long __copy_to_user(void __user *to,
8314 return __copy_to_user_inatomic(to, from, size);
8315 }
8316
8317+#ifndef __powerpc64__
8318+
8319+static inline unsigned long __must_check copy_from_user(void *to,
8320+ const void __user *from, unsigned long n)
8321+{
8322+ unsigned long over;
8323+
8324+ if ((long)n < 0)
8325+ return n;
8326+
8327+ if (access_ok(VERIFY_READ, from, n)) {
8328+ if (!__builtin_constant_p(n))
8329+ check_object_size(to, n, false);
8330+ return __copy_tofrom_user((__force void __user *)to, from, n);
8331+ }
8332+ if ((unsigned long)from < TASK_SIZE) {
8333+ over = (unsigned long)from + n - TASK_SIZE;
8334+ if (!__builtin_constant_p(n - over))
8335+ check_object_size(to, n - over, false);
8336+ return __copy_tofrom_user((__force void __user *)to, from,
8337+ n - over) + over;
8338+ }
8339+ return n;
8340+}
8341+
8342+static inline unsigned long __must_check copy_to_user(void __user *to,
8343+ const void *from, unsigned long n)
8344+{
8345+ unsigned long over;
8346+
8347+ if ((long)n < 0)
8348+ return n;
8349+
8350+ if (access_ok(VERIFY_WRITE, to, n)) {
8351+ if (!__builtin_constant_p(n))
8352+ check_object_size(from, n, true);
8353+ return __copy_tofrom_user(to, (__force void __user *)from, n);
8354+ }
8355+ if ((unsigned long)to < TASK_SIZE) {
8356+ over = (unsigned long)to + n - TASK_SIZE;
8357+ if (!__builtin_constant_p(n))
8358+ check_object_size(from, n - over, true);
8359+ return __copy_tofrom_user(to, (__force void __user *)from,
8360+ n - over) + over;
8361+ }
8362+ return n;
8363+}
8364+
8365+#else /* __powerpc64__ */
8366+
8367+#define __copy_in_user(to, from, size) \
8368+ __copy_tofrom_user((to), (from), (size))
8369+
8370+static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
8371+{
8372+ if ((long)n < 0 || n > INT_MAX)
8373+ return n;
8374+
8375+ if (!__builtin_constant_p(n))
8376+ check_object_size(to, n, false);
8377+
8378+ if (likely(access_ok(VERIFY_READ, from, n)))
8379+ n = __copy_from_user(to, from, n);
8380+ else
8381+ memset(to, 0, n);
8382+ return n;
8383+}
8384+
8385+static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
8386+{
8387+ if ((long)n < 0 || n > INT_MAX)
8388+ return n;
8389+
8390+ if (likely(access_ok(VERIFY_WRITE, to, n))) {
8391+ if (!__builtin_constant_p(n))
8392+ check_object_size(from, n, true);
8393+ n = __copy_to_user(to, from, n);
8394+ }
8395+ return n;
8396+}
8397+
8398+extern unsigned long copy_in_user(void __user *to, const void __user *from,
8399+ unsigned long n);
8400+
8401+#endif /* __powerpc64__ */
8402+
8403 extern unsigned long __clear_user(void __user *addr, unsigned long size);
8404
8405 static inline unsigned long clear_user(void __user *addr, unsigned long size)
8406diff --git a/arch/powerpc/kernel/Makefile b/arch/powerpc/kernel/Makefile
8407index fcc9a89..07be2bb 100644
8408--- a/arch/powerpc/kernel/Makefile
8409+++ b/arch/powerpc/kernel/Makefile
8410@@ -26,6 +26,8 @@ CFLAGS_REMOVE_ftrace.o = -pg -mno-sched-epilog
8411 CFLAGS_REMOVE_time.o = -pg -mno-sched-epilog
8412 endif
8413
8414+CFLAGS_REMOVE_prom_init.o += $(LATENT_ENTROPY_PLUGIN_CFLAGS)
8415+
8416 obj-y := cputable.o ptrace.o syscalls.o \
8417 irq.o align.o signal_32.o pmc.o vdso.o \
8418 process.o systbl.o idle.o \
8419diff --git a/arch/powerpc/kernel/exceptions-64e.S b/arch/powerpc/kernel/exceptions-64e.S
8420index 063b65d..7a26e9d 100644
8421--- a/arch/powerpc/kernel/exceptions-64e.S
8422+++ b/arch/powerpc/kernel/exceptions-64e.S
8423@@ -771,6 +771,7 @@ storage_fault_common:
8424 std r14,_DAR(r1)
8425 std r15,_DSISR(r1)
8426 addi r3,r1,STACK_FRAME_OVERHEAD
8427+ bl .save_nvgprs
8428 mr r4,r14
8429 mr r5,r15
8430 ld r14,PACA_EXGEN+EX_R14(r13)
8431@@ -779,8 +780,7 @@ storage_fault_common:
8432 cmpdi r3,0
8433 bne- 1f
8434 b .ret_from_except_lite
8435-1: bl .save_nvgprs
8436- mr r5,r3
8437+1: mr r5,r3
8438 addi r3,r1,STACK_FRAME_OVERHEAD
8439 ld r4,_DAR(r1)
8440 bl .bad_page_fault
8441diff --git a/arch/powerpc/kernel/exceptions-64s.S b/arch/powerpc/kernel/exceptions-64s.S
8442index 38d5073..f00af8d 100644
8443--- a/arch/powerpc/kernel/exceptions-64s.S
8444+++ b/arch/powerpc/kernel/exceptions-64s.S
8445@@ -1584,10 +1584,10 @@ handle_page_fault:
8446 11: ld r4,_DAR(r1)
8447 ld r5,_DSISR(r1)
8448 addi r3,r1,STACK_FRAME_OVERHEAD
8449+ bl .save_nvgprs
8450 bl .do_page_fault
8451 cmpdi r3,0
8452 beq+ 12f
8453- bl .save_nvgprs
8454 mr r5,r3
8455 addi r3,r1,STACK_FRAME_OVERHEAD
8456 lwz r4,_DAR(r1)
8457diff --git a/arch/powerpc/kernel/irq.c b/arch/powerpc/kernel/irq.c
8458index 1d0848b..d74685f 100644
8459--- a/arch/powerpc/kernel/irq.c
8460+++ b/arch/powerpc/kernel/irq.c
8461@@ -447,6 +447,8 @@ void migrate_irqs(void)
8462 }
8463 #endif
8464
8465+extern void gr_handle_kernel_exploit(void);
8466+
8467 static inline void check_stack_overflow(void)
8468 {
8469 #ifdef CONFIG_DEBUG_STACKOVERFLOW
8470@@ -459,6 +461,7 @@ static inline void check_stack_overflow(void)
8471 printk("do_IRQ: stack overflow: %ld\n",
8472 sp - sizeof(struct thread_info));
8473 dump_stack();
8474+ gr_handle_kernel_exploit();
8475 }
8476 #endif
8477 }
8478diff --git a/arch/powerpc/kernel/module_32.c b/arch/powerpc/kernel/module_32.c
8479index 6cff040..74ac5d1 100644
8480--- a/arch/powerpc/kernel/module_32.c
8481+++ b/arch/powerpc/kernel/module_32.c
8482@@ -161,7 +161,7 @@ int module_frob_arch_sections(Elf32_Ehdr *hdr,
8483 me->arch.core_plt_section = i;
8484 }
8485 if (!me->arch.core_plt_section || !me->arch.init_plt_section) {
8486- printk("Module doesn't contain .plt or .init.plt sections.\n");
8487+ printk("Module %s doesn't contain .plt or .init.plt sections.\n", me->name);
8488 return -ENOEXEC;
8489 }
8490
8491@@ -191,11 +191,16 @@ static uint32_t do_plt_call(void *location,
8492
8493 DEBUGP("Doing plt for call to 0x%x at 0x%x\n", val, (unsigned int)location);
8494 /* Init, or core PLT? */
8495- if (location >= mod->module_core
8496- && location < mod->module_core + mod->core_size)
8497+ if ((location >= mod->module_core_rx && location < mod->module_core_rx + mod->core_size_rx) ||
8498+ (location >= mod->module_core_rw && location < mod->module_core_rw + mod->core_size_rw))
8499 entry = (void *)sechdrs[mod->arch.core_plt_section].sh_addr;
8500- else
8501+ else if ((location >= mod->module_init_rx && location < mod->module_init_rx + mod->init_size_rx) ||
8502+ (location >= mod->module_init_rw && location < mod->module_init_rw + mod->init_size_rw))
8503 entry = (void *)sechdrs[mod->arch.init_plt_section].sh_addr;
8504+ else {
8505+ printk(KERN_ERR "%s: invalid R_PPC_REL24 entry found\n", mod->name);
8506+ return ~0UL;
8507+ }
8508
8509 /* Find this entry, or if that fails, the next avail. entry */
8510 while (entry->jump[0]) {
8511@@ -299,7 +304,7 @@ int apply_relocate_add(Elf32_Shdr *sechdrs,
8512 }
8513 #ifdef CONFIG_DYNAMIC_FTRACE
8514 module->arch.tramp =
8515- do_plt_call(module->module_core,
8516+ do_plt_call(module->module_core_rx,
8517 (unsigned long)ftrace_caller,
8518 sechdrs, module);
8519 #endif
8520diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
8521index 31d0215..206af70 100644
8522--- a/arch/powerpc/kernel/process.c
8523+++ b/arch/powerpc/kernel/process.c
8524@@ -1031,8 +1031,8 @@ void show_regs(struct pt_regs * regs)
8525 * Lookup NIP late so we have the best change of getting the
8526 * above info out without failing
8527 */
8528- printk("NIP ["REG"] %pS\n", regs->nip, (void *)regs->nip);
8529- printk("LR ["REG"] %pS\n", regs->link, (void *)regs->link);
8530+ printk("NIP ["REG"] %pA\n", regs->nip, (void *)regs->nip);
8531+ printk("LR ["REG"] %pA\n", regs->link, (void *)regs->link);
8532 #endif
8533 show_stack(current, (unsigned long *) regs->gpr[1]);
8534 if (!user_mode(regs))
8535@@ -1554,10 +1554,10 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
8536 newsp = stack[0];
8537 ip = stack[STACK_FRAME_LR_SAVE];
8538 if (!firstframe || ip != lr) {
8539- printk("["REG"] ["REG"] %pS", sp, ip, (void *)ip);
8540+ printk("["REG"] ["REG"] %pA", sp, ip, (void *)ip);
8541 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
8542 if ((ip == rth || ip == mrth) && curr_frame >= 0) {
8543- printk(" (%pS)",
8544+ printk(" (%pA)",
8545 (void *)current->ret_stack[curr_frame].ret);
8546 curr_frame--;
8547 }
8548@@ -1577,7 +1577,7 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
8549 struct pt_regs *regs = (struct pt_regs *)
8550 (sp + STACK_FRAME_OVERHEAD);
8551 lr = regs->link;
8552- printk("--- Exception: %lx at %pS\n LR = %pS\n",
8553+ printk("--- Exception: %lx at %pA\n LR = %pA\n",
8554 regs->trap, (void *)regs->nip, (void *)lr);
8555 firstframe = 1;
8556 }
8557@@ -1613,58 +1613,3 @@ void notrace __ppc64_runlatch_off(void)
8558 mtspr(SPRN_CTRLT, ctrl);
8559 }
8560 #endif /* CONFIG_PPC64 */
8561-
8562-unsigned long arch_align_stack(unsigned long sp)
8563-{
8564- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
8565- sp -= get_random_int() & ~PAGE_MASK;
8566- return sp & ~0xf;
8567-}
8568-
8569-static inline unsigned long brk_rnd(void)
8570-{
8571- unsigned long rnd = 0;
8572-
8573- /* 8MB for 32bit, 1GB for 64bit */
8574- if (is_32bit_task())
8575- rnd = (long)(get_random_int() % (1<<(23-PAGE_SHIFT)));
8576- else
8577- rnd = (long)(get_random_int() % (1<<(30-PAGE_SHIFT)));
8578-
8579- return rnd << PAGE_SHIFT;
8580-}
8581-
8582-unsigned long arch_randomize_brk(struct mm_struct *mm)
8583-{
8584- unsigned long base = mm->brk;
8585- unsigned long ret;
8586-
8587-#ifdef CONFIG_PPC_STD_MMU_64
8588- /*
8589- * If we are using 1TB segments and we are allowed to randomise
8590- * the heap, we can put it above 1TB so it is backed by a 1TB
8591- * segment. Otherwise the heap will be in the bottom 1TB
8592- * which always uses 256MB segments and this may result in a
8593- * performance penalty.
8594- */
8595- if (!is_32bit_task() && (mmu_highuser_ssize == MMU_SEGSIZE_1T))
8596- base = max_t(unsigned long, mm->brk, 1UL << SID_SHIFT_1T);
8597-#endif
8598-
8599- ret = PAGE_ALIGN(base + brk_rnd());
8600-
8601- if (ret < mm->brk)
8602- return mm->brk;
8603-
8604- return ret;
8605-}
8606-
8607-unsigned long randomize_et_dyn(unsigned long base)
8608-{
8609- unsigned long ret = PAGE_ALIGN(base + brk_rnd());
8610-
8611- if (ret < base)
8612- return base;
8613-
8614- return ret;
8615-}
8616diff --git a/arch/powerpc/kernel/ptrace.c b/arch/powerpc/kernel/ptrace.c
8617index 2e3d2bf..35df241 100644
8618--- a/arch/powerpc/kernel/ptrace.c
8619+++ b/arch/powerpc/kernel/ptrace.c
8620@@ -1762,6 +1762,10 @@ long arch_ptrace(struct task_struct *child, long request,
8621 return ret;
8622 }
8623
8624+#ifdef CONFIG_GRKERNSEC_SETXID
8625+extern void gr_delayed_cred_worker(void);
8626+#endif
8627+
8628 /*
8629 * We must return the syscall number to actually look up in the table.
8630 * This can be -1L to skip running any syscall at all.
8631@@ -1774,6 +1778,11 @@ long do_syscall_trace_enter(struct pt_regs *regs)
8632
8633 secure_computing_strict(regs->gpr[0]);
8634
8635+#ifdef CONFIG_GRKERNSEC_SETXID
8636+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
8637+ gr_delayed_cred_worker();
8638+#endif
8639+
8640 if (test_thread_flag(TIF_SYSCALL_TRACE) &&
8641 tracehook_report_syscall_entry(regs))
8642 /*
8643@@ -1808,6 +1817,11 @@ void do_syscall_trace_leave(struct pt_regs *regs)
8644 {
8645 int step;
8646
8647+#ifdef CONFIG_GRKERNSEC_SETXID
8648+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
8649+ gr_delayed_cred_worker();
8650+#endif
8651+
8652 audit_syscall_exit(regs);
8653
8654 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
8655diff --git a/arch/powerpc/kernel/signal_32.c b/arch/powerpc/kernel/signal_32.c
8656index 4e47db6..6dcc96e 100644
8657--- a/arch/powerpc/kernel/signal_32.c
8658+++ b/arch/powerpc/kernel/signal_32.c
8659@@ -1013,7 +1013,7 @@ int handle_rt_signal32(unsigned long sig, struct k_sigaction *ka,
8660 /* Save user registers on the stack */
8661 frame = &rt_sf->uc.uc_mcontext;
8662 addr = frame;
8663- if (vdso32_rt_sigtramp && current->mm->context.vdso_base) {
8664+ if (vdso32_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
8665 sigret = 0;
8666 tramp = current->mm->context.vdso_base + vdso32_rt_sigtramp;
8667 } else {
8668diff --git a/arch/powerpc/kernel/signal_64.c b/arch/powerpc/kernel/signal_64.c
8669index d501dc4..e5a0de0 100644
8670--- a/arch/powerpc/kernel/signal_64.c
8671+++ b/arch/powerpc/kernel/signal_64.c
8672@@ -760,7 +760,7 @@ int handle_rt_signal64(int signr, struct k_sigaction *ka, siginfo_t *info,
8673 current->thread.fp_state.fpscr = 0;
8674
8675 /* Set up to return from userspace. */
8676- if (vdso64_rt_sigtramp && current->mm->context.vdso_base) {
8677+ if (vdso64_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
8678 regs->link = current->mm->context.vdso_base + vdso64_rt_sigtramp;
8679 } else {
8680 err |= setup_trampoline(__NR_rt_sigreturn, &frame->tramp[0]);
8681diff --git a/arch/powerpc/kernel/traps.c b/arch/powerpc/kernel/traps.c
8682index 33cd7a0..d615344 100644
8683--- a/arch/powerpc/kernel/traps.c
8684+++ b/arch/powerpc/kernel/traps.c
8685@@ -142,6 +142,8 @@ static unsigned __kprobes long oops_begin(struct pt_regs *regs)
8686 return flags;
8687 }
8688
8689+extern void gr_handle_kernel_exploit(void);
8690+
8691 static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
8692 int signr)
8693 {
8694@@ -191,6 +193,9 @@ static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
8695 panic("Fatal exception in interrupt");
8696 if (panic_on_oops)
8697 panic("Fatal exception");
8698+
8699+ gr_handle_kernel_exploit();
8700+
8701 do_exit(signr);
8702 }
8703
8704diff --git a/arch/powerpc/kernel/vdso.c b/arch/powerpc/kernel/vdso.c
8705index 094e45c..d82b848 100644
8706--- a/arch/powerpc/kernel/vdso.c
8707+++ b/arch/powerpc/kernel/vdso.c
8708@@ -35,6 +35,7 @@
8709 #include <asm/vdso.h>
8710 #include <asm/vdso_datapage.h>
8711 #include <asm/setup.h>
8712+#include <asm/mman.h>
8713
8714 #undef DEBUG
8715
8716@@ -221,7 +222,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
8717 vdso_base = VDSO32_MBASE;
8718 #endif
8719
8720- current->mm->context.vdso_base = 0;
8721+ current->mm->context.vdso_base = ~0UL;
8722
8723 /* vDSO has a problem and was disabled, just don't "enable" it for the
8724 * process
8725@@ -241,7 +242,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
8726 vdso_base = get_unmapped_area(NULL, vdso_base,
8727 (vdso_pages << PAGE_SHIFT) +
8728 ((VDSO_ALIGNMENT - 1) & PAGE_MASK),
8729- 0, 0);
8730+ 0, MAP_PRIVATE | MAP_EXECUTABLE);
8731 if (IS_ERR_VALUE(vdso_base)) {
8732 rc = vdso_base;
8733 goto fail_mmapsem;
8734diff --git a/arch/powerpc/kvm/powerpc.c b/arch/powerpc/kvm/powerpc.c
8735index 3cf541a..ab2d825 100644
8736--- a/arch/powerpc/kvm/powerpc.c
8737+++ b/arch/powerpc/kvm/powerpc.c
8738@@ -1153,7 +1153,7 @@ void kvmppc_init_lpid(unsigned long nr_lpids_param)
8739 }
8740 EXPORT_SYMBOL_GPL(kvmppc_init_lpid);
8741
8742-int kvm_arch_init(void *opaque)
8743+int kvm_arch_init(const void *opaque)
8744 {
8745 return 0;
8746 }
8747diff --git a/arch/powerpc/lib/usercopy_64.c b/arch/powerpc/lib/usercopy_64.c
8748index 5eea6f3..5d10396 100644
8749--- a/arch/powerpc/lib/usercopy_64.c
8750+++ b/arch/powerpc/lib/usercopy_64.c
8751@@ -9,22 +9,6 @@
8752 #include <linux/module.h>
8753 #include <asm/uaccess.h>
8754
8755-unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
8756-{
8757- if (likely(access_ok(VERIFY_READ, from, n)))
8758- n = __copy_from_user(to, from, n);
8759- else
8760- memset(to, 0, n);
8761- return n;
8762-}
8763-
8764-unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
8765-{
8766- if (likely(access_ok(VERIFY_WRITE, to, n)))
8767- n = __copy_to_user(to, from, n);
8768- return n;
8769-}
8770-
8771 unsigned long copy_in_user(void __user *to, const void __user *from,
8772 unsigned long n)
8773 {
8774@@ -35,7 +19,5 @@ unsigned long copy_in_user(void __user *to, const void __user *from,
8775 return n;
8776 }
8777
8778-EXPORT_SYMBOL(copy_from_user);
8779-EXPORT_SYMBOL(copy_to_user);
8780 EXPORT_SYMBOL(copy_in_user);
8781
8782diff --git a/arch/powerpc/mm/fault.c b/arch/powerpc/mm/fault.c
8783index 51ab9e7..7d3c78b 100644
8784--- a/arch/powerpc/mm/fault.c
8785+++ b/arch/powerpc/mm/fault.c
8786@@ -33,6 +33,10 @@
8787 #include <linux/magic.h>
8788 #include <linux/ratelimit.h>
8789 #include <linux/context_tracking.h>
8790+#include <linux/slab.h>
8791+#include <linux/pagemap.h>
8792+#include <linux/compiler.h>
8793+#include <linux/unistd.h>
8794
8795 #include <asm/firmware.h>
8796 #include <asm/page.h>
8797@@ -69,6 +73,33 @@ static inline int notify_page_fault(struct pt_regs *regs)
8798 }
8799 #endif
8800
8801+#ifdef CONFIG_PAX_PAGEEXEC
8802+/*
8803+ * PaX: decide what to do with offenders (regs->nip = fault address)
8804+ *
8805+ * returns 1 when task should be killed
8806+ */
8807+static int pax_handle_fetch_fault(struct pt_regs *regs)
8808+{
8809+ return 1;
8810+}
8811+
8812+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
8813+{
8814+ unsigned long i;
8815+
8816+ printk(KERN_ERR "PAX: bytes at PC: ");
8817+ for (i = 0; i < 5; i++) {
8818+ unsigned int c;
8819+ if (get_user(c, (unsigned int __user *)pc+i))
8820+ printk(KERN_CONT "???????? ");
8821+ else
8822+ printk(KERN_CONT "%08x ", c);
8823+ }
8824+ printk("\n");
8825+}
8826+#endif
8827+
8828 /*
8829 * Check whether the instruction at regs->nip is a store using
8830 * an update addressing form which will update r1.
8831@@ -216,7 +247,7 @@ int __kprobes do_page_fault(struct pt_regs *regs, unsigned long address,
8832 * indicate errors in DSISR but can validly be set in SRR1.
8833 */
8834 if (trap == 0x400)
8835- error_code &= 0x48200000;
8836+ error_code &= 0x58200000;
8837 else
8838 is_write = error_code & DSISR_ISSTORE;
8839 #else
8840@@ -378,7 +409,7 @@ good_area:
8841 * "undefined". Of those that can be set, this is the only
8842 * one which seems bad.
8843 */
8844- if (error_code & 0x10000000)
8845+ if (error_code & DSISR_GUARDED)
8846 /* Guarded storage error. */
8847 goto bad_area;
8848 #endif /* CONFIG_8xx */
8849@@ -393,7 +424,7 @@ good_area:
8850 * processors use the same I/D cache coherency mechanism
8851 * as embedded.
8852 */
8853- if (error_code & DSISR_PROTFAULT)
8854+ if (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))
8855 goto bad_area;
8856 #endif /* CONFIG_PPC_STD_MMU */
8857
8858@@ -483,6 +514,23 @@ bad_area:
8859 bad_area_nosemaphore:
8860 /* User mode accesses cause a SIGSEGV */
8861 if (user_mode(regs)) {
8862+
8863+#ifdef CONFIG_PAX_PAGEEXEC
8864+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
8865+#ifdef CONFIG_PPC_STD_MMU
8866+ if (is_exec && (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))) {
8867+#else
8868+ if (is_exec && regs->nip == address) {
8869+#endif
8870+ switch (pax_handle_fetch_fault(regs)) {
8871+ }
8872+
8873+ pax_report_fault(regs, (void *)regs->nip, (void *)regs->gpr[PT_R1]);
8874+ do_group_exit(SIGKILL);
8875+ }
8876+ }
8877+#endif
8878+
8879 _exception(SIGSEGV, regs, code, address);
8880 goto bail;
8881 }
8882diff --git a/arch/powerpc/mm/mmap.c b/arch/powerpc/mm/mmap.c
8883index cb8bdbe..cde4bc7 100644
8884--- a/arch/powerpc/mm/mmap.c
8885+++ b/arch/powerpc/mm/mmap.c
8886@@ -53,10 +53,14 @@ static inline int mmap_is_legacy(void)
8887 return sysctl_legacy_va_layout;
8888 }
8889
8890-static unsigned long mmap_rnd(void)
8891+static unsigned long mmap_rnd(struct mm_struct *mm)
8892 {
8893 unsigned long rnd = 0;
8894
8895+#ifdef CONFIG_PAX_RANDMMAP
8896+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
8897+#endif
8898+
8899 if (current->flags & PF_RANDOMIZE) {
8900 /* 8MB for 32bit, 1GB for 64bit */
8901 if (is_32bit_task())
8902@@ -67,7 +71,7 @@ static unsigned long mmap_rnd(void)
8903 return rnd << PAGE_SHIFT;
8904 }
8905
8906-static inline unsigned long mmap_base(void)
8907+static inline unsigned long mmap_base(struct mm_struct *mm)
8908 {
8909 unsigned long gap = rlimit(RLIMIT_STACK);
8910
8911@@ -76,7 +80,7 @@ static inline unsigned long mmap_base(void)
8912 else if (gap > MAX_GAP)
8913 gap = MAX_GAP;
8914
8915- return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
8916+ return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd(mm));
8917 }
8918
8919 /*
8920@@ -91,9 +95,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
8921 */
8922 if (mmap_is_legacy()) {
8923 mm->mmap_base = TASK_UNMAPPED_BASE;
8924+
8925+#ifdef CONFIG_PAX_RANDMMAP
8926+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8927+ mm->mmap_base += mm->delta_mmap;
8928+#endif
8929+
8930 mm->get_unmapped_area = arch_get_unmapped_area;
8931 } else {
8932- mm->mmap_base = mmap_base();
8933+ mm->mmap_base = mmap_base(mm);
8934+
8935+#ifdef CONFIG_PAX_RANDMMAP
8936+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8937+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
8938+#endif
8939+
8940 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
8941 }
8942 }
8943diff --git a/arch/powerpc/mm/slice.c b/arch/powerpc/mm/slice.c
8944index b0c75cc..ef7fb93 100644
8945--- a/arch/powerpc/mm/slice.c
8946+++ b/arch/powerpc/mm/slice.c
8947@@ -103,7 +103,7 @@ static int slice_area_is_free(struct mm_struct *mm, unsigned long addr,
8948 if ((mm->task_size - len) < addr)
8949 return 0;
8950 vma = find_vma(mm, addr);
8951- return (!vma || (addr + len) <= vma->vm_start);
8952+ return check_heap_stack_gap(vma, addr, len, 0);
8953 }
8954
8955 static int slice_low_has_vma(struct mm_struct *mm, unsigned long slice)
8956@@ -277,6 +277,12 @@ static unsigned long slice_find_area_bottomup(struct mm_struct *mm,
8957 info.align_offset = 0;
8958
8959 addr = TASK_UNMAPPED_BASE;
8960+
8961+#ifdef CONFIG_PAX_RANDMMAP
8962+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8963+ addr += mm->delta_mmap;
8964+#endif
8965+
8966 while (addr < TASK_SIZE) {
8967 info.low_limit = addr;
8968 if (!slice_scan_available(addr, available, 1, &addr))
8969@@ -410,6 +416,11 @@ unsigned long slice_get_unmapped_area(unsigned long addr, unsigned long len,
8970 if (fixed && addr > (mm->task_size - len))
8971 return -ENOMEM;
8972
8973+#ifdef CONFIG_PAX_RANDMMAP
8974+ if (!fixed && (mm->pax_flags & MF_PAX_RANDMMAP))
8975+ addr = 0;
8976+#endif
8977+
8978 /* If hint, make sure it matches our alignment restrictions */
8979 if (!fixed && addr) {
8980 addr = _ALIGN_UP(addr, 1ul << pshift);
8981diff --git a/arch/powerpc/platforms/cell/celleb_scc_pciex.c b/arch/powerpc/platforms/cell/celleb_scc_pciex.c
8982index 4278acf..67fd0e6 100644
8983--- a/arch/powerpc/platforms/cell/celleb_scc_pciex.c
8984+++ b/arch/powerpc/platforms/cell/celleb_scc_pciex.c
8985@@ -400,8 +400,8 @@ static int scc_pciex_write_config(struct pci_bus *bus, unsigned int devfn,
8986 }
8987
8988 static struct pci_ops scc_pciex_pci_ops = {
8989- scc_pciex_read_config,
8990- scc_pciex_write_config,
8991+ .read = scc_pciex_read_config,
8992+ .write = scc_pciex_write_config,
8993 };
8994
8995 static void pciex_clear_intr_all(unsigned int __iomem *base)
8996diff --git a/arch/powerpc/platforms/cell/spufs/file.c b/arch/powerpc/platforms/cell/spufs/file.c
8997index 9098692..3d54cd1 100644
8998--- a/arch/powerpc/platforms/cell/spufs/file.c
8999+++ b/arch/powerpc/platforms/cell/spufs/file.c
9000@@ -280,9 +280,9 @@ spufs_mem_mmap_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
9001 return VM_FAULT_NOPAGE;
9002 }
9003
9004-static int spufs_mem_mmap_access(struct vm_area_struct *vma,
9005+static ssize_t spufs_mem_mmap_access(struct vm_area_struct *vma,
9006 unsigned long address,
9007- void *buf, int len, int write)
9008+ void *buf, size_t len, int write)
9009 {
9010 struct spu_context *ctx = vma->vm_file->private_data;
9011 unsigned long offset = address - vma->vm_start;
9012diff --git a/arch/s390/include/asm/atomic.h b/arch/s390/include/asm/atomic.h
9013index 1d47061..0714963 100644
9014--- a/arch/s390/include/asm/atomic.h
9015+++ b/arch/s390/include/asm/atomic.h
9016@@ -412,6 +412,16 @@ static inline long long atomic64_dec_if_positive(atomic64_t *v)
9017 #define atomic64_dec_and_test(_v) (atomic64_sub_return(1, _v) == 0)
9018 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
9019
9020+#define atomic64_read_unchecked(v) atomic64_read(v)
9021+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
9022+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
9023+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
9024+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
9025+#define atomic64_inc_unchecked(v) atomic64_inc(v)
9026+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
9027+#define atomic64_dec_unchecked(v) atomic64_dec(v)
9028+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
9029+
9030 #define smp_mb__before_atomic_dec() smp_mb()
9031 #define smp_mb__after_atomic_dec() smp_mb()
9032 #define smp_mb__before_atomic_inc() smp_mb()
9033diff --git a/arch/s390/include/asm/cache.h b/arch/s390/include/asm/cache.h
9034index 4d7ccac..d03d0ad 100644
9035--- a/arch/s390/include/asm/cache.h
9036+++ b/arch/s390/include/asm/cache.h
9037@@ -9,8 +9,10 @@
9038 #ifndef __ARCH_S390_CACHE_H
9039 #define __ARCH_S390_CACHE_H
9040
9041-#define L1_CACHE_BYTES 256
9042+#include <linux/const.h>
9043+
9044 #define L1_CACHE_SHIFT 8
9045+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
9046 #define NET_SKB_PAD 32
9047
9048 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
9049diff --git a/arch/s390/include/asm/elf.h b/arch/s390/include/asm/elf.h
9050index 78f4f87..598ce39 100644
9051--- a/arch/s390/include/asm/elf.h
9052+++ b/arch/s390/include/asm/elf.h
9053@@ -162,8 +162,14 @@ extern unsigned int vdso_enabled;
9054 the loader. We need to make sure that it is out of the way of the program
9055 that it will "exec", and that there is sufficient room for the brk. */
9056
9057-extern unsigned long randomize_et_dyn(unsigned long base);
9058-#define ELF_ET_DYN_BASE (randomize_et_dyn(STACK_TOP / 3 * 2))
9059+#define ELF_ET_DYN_BASE (STACK_TOP / 3 * 2)
9060+
9061+#ifdef CONFIG_PAX_ASLR
9062+#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_31BIT) ? 0x10000UL : 0x80000000UL)
9063+
9064+#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
9065+#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
9066+#endif
9067
9068 /* This yields a mask that user programs can use to figure out what
9069 instruction set this CPU supports. */
9070@@ -222,9 +228,6 @@ struct linux_binprm;
9071 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
9072 int arch_setup_additional_pages(struct linux_binprm *, int);
9073
9074-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
9075-#define arch_randomize_brk arch_randomize_brk
9076-
9077 void *fill_cpu_elf_notes(void *ptr, struct save_area *sa);
9078
9079 #endif
9080diff --git a/arch/s390/include/asm/exec.h b/arch/s390/include/asm/exec.h
9081index c4a93d6..4d2a9b4 100644
9082--- a/arch/s390/include/asm/exec.h
9083+++ b/arch/s390/include/asm/exec.h
9084@@ -7,6 +7,6 @@
9085 #ifndef __ASM_EXEC_H
9086 #define __ASM_EXEC_H
9087
9088-extern unsigned long arch_align_stack(unsigned long sp);
9089+#define arch_align_stack(x) ((x) & ~0xfUL)
9090
9091 #endif /* __ASM_EXEC_H */
9092diff --git a/arch/s390/include/asm/uaccess.h b/arch/s390/include/asm/uaccess.h
9093index 79330af..254cf37 100644
9094--- a/arch/s390/include/asm/uaccess.h
9095+++ b/arch/s390/include/asm/uaccess.h
9096@@ -59,6 +59,7 @@ static inline int __range_ok(unsigned long addr, unsigned long size)
9097 __range_ok((unsigned long)(addr), (size)); \
9098 })
9099
9100+#define access_ok_noprefault(type, addr, size) access_ok((type), (addr), (size))
9101 #define access_ok(type, addr, size) __access_ok(addr, size)
9102
9103 /*
9104@@ -245,6 +246,10 @@ static inline unsigned long __must_check
9105 copy_to_user(void __user *to, const void *from, unsigned long n)
9106 {
9107 might_fault();
9108+
9109+ if ((long)n < 0)
9110+ return n;
9111+
9112 return __copy_to_user(to, from, n);
9113 }
9114
9115@@ -268,6 +273,9 @@ copy_to_user(void __user *to, const void *from, unsigned long n)
9116 static inline unsigned long __must_check
9117 __copy_from_user(void *to, const void __user *from, unsigned long n)
9118 {
9119+ if ((long)n < 0)
9120+ return n;
9121+
9122 return uaccess.copy_from_user(n, from, to);
9123 }
9124
9125@@ -296,10 +304,14 @@ __compiletime_warning("copy_from_user() buffer size is not provably correct")
9126 static inline unsigned long __must_check
9127 copy_from_user(void *to, const void __user *from, unsigned long n)
9128 {
9129- unsigned int sz = __compiletime_object_size(to);
9130+ size_t sz = __compiletime_object_size(to);
9131
9132 might_fault();
9133- if (unlikely(sz != -1 && sz < n)) {
9134+
9135+ if ((long)n < 0)
9136+ return n;
9137+
9138+ if (unlikely(sz != (size_t)-1 && sz < n)) {
9139 copy_from_user_overflow();
9140 return n;
9141 }
9142diff --git a/arch/s390/kernel/module.c b/arch/s390/kernel/module.c
9143index b89b591..fd9609d 100644
9144--- a/arch/s390/kernel/module.c
9145+++ b/arch/s390/kernel/module.c
9146@@ -169,11 +169,11 @@ int module_frob_arch_sections(Elf_Ehdr *hdr, Elf_Shdr *sechdrs,
9147
9148 /* Increase core size by size of got & plt and set start
9149 offsets for got and plt. */
9150- me->core_size = ALIGN(me->core_size, 4);
9151- me->arch.got_offset = me->core_size;
9152- me->core_size += me->arch.got_size;
9153- me->arch.plt_offset = me->core_size;
9154- me->core_size += me->arch.plt_size;
9155+ me->core_size_rw = ALIGN(me->core_size_rw, 4);
9156+ me->arch.got_offset = me->core_size_rw;
9157+ me->core_size_rw += me->arch.got_size;
9158+ me->arch.plt_offset = me->core_size_rx;
9159+ me->core_size_rx += me->arch.plt_size;
9160 return 0;
9161 }
9162
9163@@ -289,7 +289,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9164 if (info->got_initialized == 0) {
9165 Elf_Addr *gotent;
9166
9167- gotent = me->module_core + me->arch.got_offset +
9168+ gotent = me->module_core_rw + me->arch.got_offset +
9169 info->got_offset;
9170 *gotent = val;
9171 info->got_initialized = 1;
9172@@ -312,7 +312,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9173 rc = apply_rela_bits(loc, val, 0, 64, 0);
9174 else if (r_type == R_390_GOTENT ||
9175 r_type == R_390_GOTPLTENT) {
9176- val += (Elf_Addr) me->module_core - loc;
9177+ val += (Elf_Addr) me->module_core_rw - loc;
9178 rc = apply_rela_bits(loc, val, 1, 32, 1);
9179 }
9180 break;
9181@@ -325,7 +325,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9182 case R_390_PLTOFF64: /* 16 bit offset from GOT to PLT. */
9183 if (info->plt_initialized == 0) {
9184 unsigned int *ip;
9185- ip = me->module_core + me->arch.plt_offset +
9186+ ip = me->module_core_rx + me->arch.plt_offset +
9187 info->plt_offset;
9188 #ifndef CONFIG_64BIT
9189 ip[0] = 0x0d105810; /* basr 1,0; l 1,6(1); br 1 */
9190@@ -350,7 +350,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9191 val - loc + 0xffffUL < 0x1ffffeUL) ||
9192 (r_type == R_390_PLT32DBL &&
9193 val - loc + 0xffffffffULL < 0x1fffffffeULL)))
9194- val = (Elf_Addr) me->module_core +
9195+ val = (Elf_Addr) me->module_core_rx +
9196 me->arch.plt_offset +
9197 info->plt_offset;
9198 val += rela->r_addend - loc;
9199@@ -372,7 +372,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9200 case R_390_GOTOFF32: /* 32 bit offset to GOT. */
9201 case R_390_GOTOFF64: /* 64 bit offset to GOT. */
9202 val = val + rela->r_addend -
9203- ((Elf_Addr) me->module_core + me->arch.got_offset);
9204+ ((Elf_Addr) me->module_core_rw + me->arch.got_offset);
9205 if (r_type == R_390_GOTOFF16)
9206 rc = apply_rela_bits(loc, val, 0, 16, 0);
9207 else if (r_type == R_390_GOTOFF32)
9208@@ -382,7 +382,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9209 break;
9210 case R_390_GOTPC: /* 32 bit PC relative offset to GOT. */
9211 case R_390_GOTPCDBL: /* 32 bit PC rel. off. to GOT shifted by 1. */
9212- val = (Elf_Addr) me->module_core + me->arch.got_offset +
9213+ val = (Elf_Addr) me->module_core_rw + me->arch.got_offset +
9214 rela->r_addend - loc;
9215 if (r_type == R_390_GOTPC)
9216 rc = apply_rela_bits(loc, val, 1, 32, 0);
9217diff --git a/arch/s390/kernel/process.c b/arch/s390/kernel/process.c
9218index dd14532..1dfc145 100644
9219--- a/arch/s390/kernel/process.c
9220+++ b/arch/s390/kernel/process.c
9221@@ -242,37 +242,3 @@ unsigned long get_wchan(struct task_struct *p)
9222 }
9223 return 0;
9224 }
9225-
9226-unsigned long arch_align_stack(unsigned long sp)
9227-{
9228- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
9229- sp -= get_random_int() & ~PAGE_MASK;
9230- return sp & ~0xf;
9231-}
9232-
9233-static inline unsigned long brk_rnd(void)
9234-{
9235- /* 8MB for 32bit, 1GB for 64bit */
9236- if (is_32bit_task())
9237- return (get_random_int() & 0x7ffUL) << PAGE_SHIFT;
9238- else
9239- return (get_random_int() & 0x3ffffUL) << PAGE_SHIFT;
9240-}
9241-
9242-unsigned long arch_randomize_brk(struct mm_struct *mm)
9243-{
9244- unsigned long ret;
9245-
9246- ret = PAGE_ALIGN(mm->brk + brk_rnd());
9247- return (ret > mm->brk) ? ret : mm->brk;
9248-}
9249-
9250-unsigned long randomize_et_dyn(unsigned long base)
9251-{
9252- unsigned long ret;
9253-
9254- if (!(current->flags & PF_RANDOMIZE))
9255- return base;
9256- ret = PAGE_ALIGN(base + brk_rnd());
9257- return (ret > base) ? ret : base;
9258-}
9259diff --git a/arch/s390/mm/mmap.c b/arch/s390/mm/mmap.c
9260index 9b436c2..54fbf0a 100644
9261--- a/arch/s390/mm/mmap.c
9262+++ b/arch/s390/mm/mmap.c
9263@@ -95,9 +95,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
9264 */
9265 if (mmap_is_legacy()) {
9266 mm->mmap_base = mmap_base_legacy();
9267+
9268+#ifdef CONFIG_PAX_RANDMMAP
9269+ if (mm->pax_flags & MF_PAX_RANDMMAP)
9270+ mm->mmap_base += mm->delta_mmap;
9271+#endif
9272+
9273 mm->get_unmapped_area = arch_get_unmapped_area;
9274 } else {
9275 mm->mmap_base = mmap_base();
9276+
9277+#ifdef CONFIG_PAX_RANDMMAP
9278+ if (mm->pax_flags & MF_PAX_RANDMMAP)
9279+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
9280+#endif
9281+
9282 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
9283 }
9284 }
9285@@ -170,9 +182,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
9286 */
9287 if (mmap_is_legacy()) {
9288 mm->mmap_base = mmap_base_legacy();
9289+
9290+#ifdef CONFIG_PAX_RANDMMAP
9291+ if (mm->pax_flags & MF_PAX_RANDMMAP)
9292+ mm->mmap_base += mm->delta_mmap;
9293+#endif
9294+
9295 mm->get_unmapped_area = s390_get_unmapped_area;
9296 } else {
9297 mm->mmap_base = mmap_base();
9298+
9299+#ifdef CONFIG_PAX_RANDMMAP
9300+ if (mm->pax_flags & MF_PAX_RANDMMAP)
9301+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
9302+#endif
9303+
9304 mm->get_unmapped_area = s390_get_unmapped_area_topdown;
9305 }
9306 }
9307diff --git a/arch/score/include/asm/cache.h b/arch/score/include/asm/cache.h
9308index ae3d59f..f65f075 100644
9309--- a/arch/score/include/asm/cache.h
9310+++ b/arch/score/include/asm/cache.h
9311@@ -1,7 +1,9 @@
9312 #ifndef _ASM_SCORE_CACHE_H
9313 #define _ASM_SCORE_CACHE_H
9314
9315+#include <linux/const.h>
9316+
9317 #define L1_CACHE_SHIFT 4
9318-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
9319+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
9320
9321 #endif /* _ASM_SCORE_CACHE_H */
9322diff --git a/arch/score/include/asm/exec.h b/arch/score/include/asm/exec.h
9323index f9f3cd5..58ff438 100644
9324--- a/arch/score/include/asm/exec.h
9325+++ b/arch/score/include/asm/exec.h
9326@@ -1,6 +1,6 @@
9327 #ifndef _ASM_SCORE_EXEC_H
9328 #define _ASM_SCORE_EXEC_H
9329
9330-extern unsigned long arch_align_stack(unsigned long sp);
9331+#define arch_align_stack(x) (x)
9332
9333 #endif /* _ASM_SCORE_EXEC_H */
9334diff --git a/arch/score/kernel/process.c b/arch/score/kernel/process.c
9335index a1519ad3..e8ac1ff 100644
9336--- a/arch/score/kernel/process.c
9337+++ b/arch/score/kernel/process.c
9338@@ -116,8 +116,3 @@ unsigned long get_wchan(struct task_struct *task)
9339
9340 return task_pt_regs(task)->cp0_epc;
9341 }
9342-
9343-unsigned long arch_align_stack(unsigned long sp)
9344-{
9345- return sp;
9346-}
9347diff --git a/arch/sh/include/asm/cache.h b/arch/sh/include/asm/cache.h
9348index ef9e555..331bd29 100644
9349--- a/arch/sh/include/asm/cache.h
9350+++ b/arch/sh/include/asm/cache.h
9351@@ -9,10 +9,11 @@
9352 #define __ASM_SH_CACHE_H
9353 #ifdef __KERNEL__
9354
9355+#include <linux/const.h>
9356 #include <linux/init.h>
9357 #include <cpu/cache.h>
9358
9359-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
9360+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
9361
9362 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
9363
9364diff --git a/arch/sh/mm/mmap.c b/arch/sh/mm/mmap.c
9365index 6777177..cb5e44f 100644
9366--- a/arch/sh/mm/mmap.c
9367+++ b/arch/sh/mm/mmap.c
9368@@ -36,6 +36,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
9369 struct mm_struct *mm = current->mm;
9370 struct vm_area_struct *vma;
9371 int do_colour_align;
9372+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
9373 struct vm_unmapped_area_info info;
9374
9375 if (flags & MAP_FIXED) {
9376@@ -55,6 +56,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
9377 if (filp || (flags & MAP_SHARED))
9378 do_colour_align = 1;
9379
9380+#ifdef CONFIG_PAX_RANDMMAP
9381+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
9382+#endif
9383+
9384 if (addr) {
9385 if (do_colour_align)
9386 addr = COLOUR_ALIGN(addr, pgoff);
9387@@ -62,14 +67,13 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
9388 addr = PAGE_ALIGN(addr);
9389
9390 vma = find_vma(mm, addr);
9391- if (TASK_SIZE - len >= addr &&
9392- (!vma || addr + len <= vma->vm_start))
9393+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
9394 return addr;
9395 }
9396
9397 info.flags = 0;
9398 info.length = len;
9399- info.low_limit = TASK_UNMAPPED_BASE;
9400+ info.low_limit = mm->mmap_base;
9401 info.high_limit = TASK_SIZE;
9402 info.align_mask = do_colour_align ? (PAGE_MASK & shm_align_mask) : 0;
9403 info.align_offset = pgoff << PAGE_SHIFT;
9404@@ -85,6 +89,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9405 struct mm_struct *mm = current->mm;
9406 unsigned long addr = addr0;
9407 int do_colour_align;
9408+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
9409 struct vm_unmapped_area_info info;
9410
9411 if (flags & MAP_FIXED) {
9412@@ -104,6 +109,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9413 if (filp || (flags & MAP_SHARED))
9414 do_colour_align = 1;
9415
9416+#ifdef CONFIG_PAX_RANDMMAP
9417+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
9418+#endif
9419+
9420 /* requesting a specific address */
9421 if (addr) {
9422 if (do_colour_align)
9423@@ -112,8 +121,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9424 addr = PAGE_ALIGN(addr);
9425
9426 vma = find_vma(mm, addr);
9427- if (TASK_SIZE - len >= addr &&
9428- (!vma || addr + len <= vma->vm_start))
9429+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
9430 return addr;
9431 }
9432
9433@@ -135,6 +143,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9434 VM_BUG_ON(addr != -ENOMEM);
9435 info.flags = 0;
9436 info.low_limit = TASK_UNMAPPED_BASE;
9437+
9438+#ifdef CONFIG_PAX_RANDMMAP
9439+ if (mm->pax_flags & MF_PAX_RANDMMAP)
9440+ info.low_limit += mm->delta_mmap;
9441+#endif
9442+
9443 info.high_limit = TASK_SIZE;
9444 addr = vm_unmapped_area(&info);
9445 }
9446diff --git a/arch/sparc/include/asm/atomic_64.h b/arch/sparc/include/asm/atomic_64.h
9447index be56a24..443328f 100644
9448--- a/arch/sparc/include/asm/atomic_64.h
9449+++ b/arch/sparc/include/asm/atomic_64.h
9450@@ -14,18 +14,40 @@
9451 #define ATOMIC64_INIT(i) { (i) }
9452
9453 #define atomic_read(v) (*(volatile int *)&(v)->counter)
9454+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
9455+{
9456+ return v->counter;
9457+}
9458 #define atomic64_read(v) (*(volatile long *)&(v)->counter)
9459+static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
9460+{
9461+ return v->counter;
9462+}
9463
9464 #define atomic_set(v, i) (((v)->counter) = i)
9465+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
9466+{
9467+ v->counter = i;
9468+}
9469 #define atomic64_set(v, i) (((v)->counter) = i)
9470+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
9471+{
9472+ v->counter = i;
9473+}
9474
9475 extern void atomic_add(int, atomic_t *);
9476+extern void atomic_add_unchecked(int, atomic_unchecked_t *);
9477 extern void atomic64_add(long, atomic64_t *);
9478+extern void atomic64_add_unchecked(long, atomic64_unchecked_t *);
9479 extern void atomic_sub(int, atomic_t *);
9480+extern void atomic_sub_unchecked(int, atomic_unchecked_t *);
9481 extern void atomic64_sub(long, atomic64_t *);
9482+extern void atomic64_sub_unchecked(long, atomic64_unchecked_t *);
9483
9484 extern int atomic_add_ret(int, atomic_t *);
9485+extern int atomic_add_ret_unchecked(int, atomic_unchecked_t *);
9486 extern long atomic64_add_ret(long, atomic64_t *);
9487+extern long atomic64_add_ret_unchecked(long, atomic64_unchecked_t *);
9488 extern int atomic_sub_ret(int, atomic_t *);
9489 extern long atomic64_sub_ret(long, atomic64_t *);
9490
9491@@ -33,13 +55,29 @@ extern long atomic64_sub_ret(long, atomic64_t *);
9492 #define atomic64_dec_return(v) atomic64_sub_ret(1, v)
9493
9494 #define atomic_inc_return(v) atomic_add_ret(1, v)
9495+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
9496+{
9497+ return atomic_add_ret_unchecked(1, v);
9498+}
9499 #define atomic64_inc_return(v) atomic64_add_ret(1, v)
9500+static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
9501+{
9502+ return atomic64_add_ret_unchecked(1, v);
9503+}
9504
9505 #define atomic_sub_return(i, v) atomic_sub_ret(i, v)
9506 #define atomic64_sub_return(i, v) atomic64_sub_ret(i, v)
9507
9508 #define atomic_add_return(i, v) atomic_add_ret(i, v)
9509+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
9510+{
9511+ return atomic_add_ret_unchecked(i, v);
9512+}
9513 #define atomic64_add_return(i, v) atomic64_add_ret(i, v)
9514+static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
9515+{
9516+ return atomic64_add_ret_unchecked(i, v);
9517+}
9518
9519 /*
9520 * atomic_inc_and_test - increment and test
9521@@ -50,6 +88,10 @@ extern long atomic64_sub_ret(long, atomic64_t *);
9522 * other cases.
9523 */
9524 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
9525+static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
9526+{
9527+ return atomic_inc_return_unchecked(v) == 0;
9528+}
9529 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
9530
9531 #define atomic_sub_and_test(i, v) (atomic_sub_ret(i, v) == 0)
9532@@ -59,25 +101,60 @@ extern long atomic64_sub_ret(long, atomic64_t *);
9533 #define atomic64_dec_and_test(v) (atomic64_sub_ret(1, v) == 0)
9534
9535 #define atomic_inc(v) atomic_add(1, v)
9536+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
9537+{
9538+ atomic_add_unchecked(1, v);
9539+}
9540 #define atomic64_inc(v) atomic64_add(1, v)
9541+static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
9542+{
9543+ atomic64_add_unchecked(1, v);
9544+}
9545
9546 #define atomic_dec(v) atomic_sub(1, v)
9547+static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
9548+{
9549+ atomic_sub_unchecked(1, v);
9550+}
9551 #define atomic64_dec(v) atomic64_sub(1, v)
9552+static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
9553+{
9554+ atomic64_sub_unchecked(1, v);
9555+}
9556
9557 #define atomic_add_negative(i, v) (atomic_add_ret(i, v) < 0)
9558 #define atomic64_add_negative(i, v) (atomic64_add_ret(i, v) < 0)
9559
9560 #define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
9561+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
9562+{
9563+ return cmpxchg(&v->counter, old, new);
9564+}
9565 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
9566+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
9567+{
9568+ return xchg(&v->counter, new);
9569+}
9570
9571 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
9572 {
9573- int c, old;
9574+ int c, old, new;
9575 c = atomic_read(v);
9576 for (;;) {
9577- if (unlikely(c == (u)))
9578+ if (unlikely(c == u))
9579 break;
9580- old = atomic_cmpxchg((v), c, c + (a));
9581+
9582+ asm volatile("addcc %2, %0, %0\n"
9583+
9584+#ifdef CONFIG_PAX_REFCOUNT
9585+ "tvs %%icc, 6\n"
9586+#endif
9587+
9588+ : "=r" (new)
9589+ : "0" (c), "ir" (a)
9590+ : "cc");
9591+
9592+ old = atomic_cmpxchg(v, c, new);
9593 if (likely(old == c))
9594 break;
9595 c = old;
9596@@ -88,20 +165,35 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
9597 #define atomic64_cmpxchg(v, o, n) \
9598 ((__typeof__((v)->counter))cmpxchg(&((v)->counter), (o), (n)))
9599 #define atomic64_xchg(v, new) (xchg(&((v)->counter), new))
9600+static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
9601+{
9602+ return xchg(&v->counter, new);
9603+}
9604
9605 static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
9606 {
9607- long c, old;
9608+ long c, old, new;
9609 c = atomic64_read(v);
9610 for (;;) {
9611- if (unlikely(c == (u)))
9612+ if (unlikely(c == u))
9613 break;
9614- old = atomic64_cmpxchg((v), c, c + (a));
9615+
9616+ asm volatile("addcc %2, %0, %0\n"
9617+
9618+#ifdef CONFIG_PAX_REFCOUNT
9619+ "tvs %%xcc, 6\n"
9620+#endif
9621+
9622+ : "=r" (new)
9623+ : "0" (c), "ir" (a)
9624+ : "cc");
9625+
9626+ old = atomic64_cmpxchg(v, c, new);
9627 if (likely(old == c))
9628 break;
9629 c = old;
9630 }
9631- return c != (u);
9632+ return c != u;
9633 }
9634
9635 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
9636diff --git a/arch/sparc/include/asm/cache.h b/arch/sparc/include/asm/cache.h
9637index 5bb6991..5c2132e 100644
9638--- a/arch/sparc/include/asm/cache.h
9639+++ b/arch/sparc/include/asm/cache.h
9640@@ -7,10 +7,12 @@
9641 #ifndef _SPARC_CACHE_H
9642 #define _SPARC_CACHE_H
9643
9644+#include <linux/const.h>
9645+
9646 #define ARCH_SLAB_MINALIGN __alignof__(unsigned long long)
9647
9648 #define L1_CACHE_SHIFT 5
9649-#define L1_CACHE_BYTES 32
9650+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
9651
9652 #ifdef CONFIG_SPARC32
9653 #define SMP_CACHE_BYTES_SHIFT 5
9654diff --git a/arch/sparc/include/asm/elf_32.h b/arch/sparc/include/asm/elf_32.h
9655index a24e41f..47677ff 100644
9656--- a/arch/sparc/include/asm/elf_32.h
9657+++ b/arch/sparc/include/asm/elf_32.h
9658@@ -114,6 +114,13 @@ typedef struct {
9659
9660 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE)
9661
9662+#ifdef CONFIG_PAX_ASLR
9663+#define PAX_ELF_ET_DYN_BASE 0x10000UL
9664+
9665+#define PAX_DELTA_MMAP_LEN 16
9666+#define PAX_DELTA_STACK_LEN 16
9667+#endif
9668+
9669 /* This yields a mask that user programs can use to figure out what
9670 instruction set this cpu supports. This can NOT be done in userspace
9671 on Sparc. */
9672diff --git a/arch/sparc/include/asm/elf_64.h b/arch/sparc/include/asm/elf_64.h
9673index 370ca1e..d4f4a98 100644
9674--- a/arch/sparc/include/asm/elf_64.h
9675+++ b/arch/sparc/include/asm/elf_64.h
9676@@ -189,6 +189,13 @@ typedef struct {
9677 #define ELF_ET_DYN_BASE 0x0000010000000000UL
9678 #define COMPAT_ELF_ET_DYN_BASE 0x0000000070000000UL
9679
9680+#ifdef CONFIG_PAX_ASLR
9681+#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_32BIT) ? 0x10000UL : 0x100000UL)
9682+
9683+#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_32BIT) ? 14 : 28)
9684+#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_32BIT) ? 15 : 29)
9685+#endif
9686+
9687 extern unsigned long sparc64_elf_hwcap;
9688 #define ELF_HWCAP sparc64_elf_hwcap
9689
9690diff --git a/arch/sparc/include/asm/pgalloc_32.h b/arch/sparc/include/asm/pgalloc_32.h
9691index 9b1c36d..209298b 100644
9692--- a/arch/sparc/include/asm/pgalloc_32.h
9693+++ b/arch/sparc/include/asm/pgalloc_32.h
9694@@ -33,6 +33,7 @@ static inline void pgd_set(pgd_t * pgdp, pmd_t * pmdp)
9695 }
9696
9697 #define pgd_populate(MM, PGD, PMD) pgd_set(PGD, PMD)
9698+#define pgd_populate_kernel(MM, PGD, PMD) pgd_populate((MM), (PGD), (PMD))
9699
9700 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm,
9701 unsigned long address)
9702diff --git a/arch/sparc/include/asm/pgalloc_64.h b/arch/sparc/include/asm/pgalloc_64.h
9703index bcfe063..b333142 100644
9704--- a/arch/sparc/include/asm/pgalloc_64.h
9705+++ b/arch/sparc/include/asm/pgalloc_64.h
9706@@ -26,6 +26,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
9707 }
9708
9709 #define pud_populate(MM, PUD, PMD) pud_set(PUD, PMD)
9710+#define pud_populate_kernel(MM, PUD, PMD) pud_populate((MM), (PUD), (PMD))
9711
9712 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
9713 {
9714diff --git a/arch/sparc/include/asm/pgtable.h b/arch/sparc/include/asm/pgtable.h
9715index 59ba6f6..4518128 100644
9716--- a/arch/sparc/include/asm/pgtable.h
9717+++ b/arch/sparc/include/asm/pgtable.h
9718@@ -5,4 +5,8 @@
9719 #else
9720 #include <asm/pgtable_32.h>
9721 #endif
9722+
9723+#define ktla_ktva(addr) (addr)
9724+#define ktva_ktla(addr) (addr)
9725+
9726 #endif
9727diff --git a/arch/sparc/include/asm/pgtable_32.h b/arch/sparc/include/asm/pgtable_32.h
9728index 502f632..da1917f 100644
9729--- a/arch/sparc/include/asm/pgtable_32.h
9730+++ b/arch/sparc/include/asm/pgtable_32.h
9731@@ -50,6 +50,9 @@ extern unsigned long calc_highpages(void);
9732 #define PAGE_SHARED SRMMU_PAGE_SHARED
9733 #define PAGE_COPY SRMMU_PAGE_COPY
9734 #define PAGE_READONLY SRMMU_PAGE_RDONLY
9735+#define PAGE_SHARED_NOEXEC SRMMU_PAGE_SHARED_NOEXEC
9736+#define PAGE_COPY_NOEXEC SRMMU_PAGE_COPY_NOEXEC
9737+#define PAGE_READONLY_NOEXEC SRMMU_PAGE_RDONLY_NOEXEC
9738 #define PAGE_KERNEL SRMMU_PAGE_KERNEL
9739
9740 /* Top-level page directory - dummy used by init-mm.
9741@@ -62,18 +65,18 @@ extern unsigned long ptr_in_current_pgd;
9742
9743 /* xwr */
9744 #define __P000 PAGE_NONE
9745-#define __P001 PAGE_READONLY
9746-#define __P010 PAGE_COPY
9747-#define __P011 PAGE_COPY
9748+#define __P001 PAGE_READONLY_NOEXEC
9749+#define __P010 PAGE_COPY_NOEXEC
9750+#define __P011 PAGE_COPY_NOEXEC
9751 #define __P100 PAGE_READONLY
9752 #define __P101 PAGE_READONLY
9753 #define __P110 PAGE_COPY
9754 #define __P111 PAGE_COPY
9755
9756 #define __S000 PAGE_NONE
9757-#define __S001 PAGE_READONLY
9758-#define __S010 PAGE_SHARED
9759-#define __S011 PAGE_SHARED
9760+#define __S001 PAGE_READONLY_NOEXEC
9761+#define __S010 PAGE_SHARED_NOEXEC
9762+#define __S011 PAGE_SHARED_NOEXEC
9763 #define __S100 PAGE_READONLY
9764 #define __S101 PAGE_READONLY
9765 #define __S110 PAGE_SHARED
9766diff --git a/arch/sparc/include/asm/pgtable_64.h b/arch/sparc/include/asm/pgtable_64.h
9767index 0f9e945..a949e55 100644
9768--- a/arch/sparc/include/asm/pgtable_64.h
9769+++ b/arch/sparc/include/asm/pgtable_64.h
9770@@ -71,6 +71,23 @@
9771
9772 #include <linux/sched.h>
9773
9774+extern unsigned long sparc64_valid_addr_bitmap[];
9775+
9776+/* Needs to be defined here and not in linux/mm.h, as it is arch dependent */
9777+static inline bool __kern_addr_valid(unsigned long paddr)
9778+{
9779+ if ((paddr >> MAX_PHYS_ADDRESS_BITS) != 0UL)
9780+ return false;
9781+ return test_bit(paddr >> ILOG2_4MB, sparc64_valid_addr_bitmap);
9782+}
9783+
9784+static inline bool kern_addr_valid(unsigned long addr)
9785+{
9786+ unsigned long paddr = __pa(addr);
9787+
9788+ return __kern_addr_valid(paddr);
9789+}
9790+
9791 /* Entries per page directory level. */
9792 #define PTRS_PER_PTE (1UL << (PAGE_SHIFT-3))
9793 #define PTRS_PER_PMD (1UL << PMD_BITS)
9794@@ -79,9 +96,12 @@
9795 /* Kernel has a separate 44bit address space. */
9796 #define FIRST_USER_ADDRESS 0
9797
9798-#define pte_ERROR(e) __builtin_trap()
9799-#define pmd_ERROR(e) __builtin_trap()
9800-#define pgd_ERROR(e) __builtin_trap()
9801+#define pmd_ERROR(e) \
9802+ pr_err("%s:%d: bad pmd %p(%016lx) seen at (%pS)\n", \
9803+ __FILE__, __LINE__, &(e), pmd_val(e), __builtin_return_address(0))
9804+#define pgd_ERROR(e) \
9805+ pr_err("%s:%d: bad pgd %p(%016lx) seen at (%pS)\n", \
9806+ __FILE__, __LINE__, &(e), pgd_val(e), __builtin_return_address(0))
9807
9808 #endif /* !(__ASSEMBLY__) */
9809
9810@@ -633,7 +653,7 @@ static inline unsigned long pmd_large(pmd_t pmd)
9811 {
9812 pte_t pte = __pte(pmd_val(pmd));
9813
9814- return (pte_val(pte) & _PAGE_PMD_HUGE) && pte_present(pte);
9815+ return pte_val(pte) & _PAGE_PMD_HUGE;
9816 }
9817
9818 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
9819@@ -719,20 +739,6 @@ static inline pmd_t pmd_mkwrite(pmd_t pmd)
9820 return __pmd(pte_val(pte));
9821 }
9822
9823-static inline pmd_t pmd_mknotpresent(pmd_t pmd)
9824-{
9825- unsigned long mask;
9826-
9827- if (tlb_type == hypervisor)
9828- mask = _PAGE_PRESENT_4V;
9829- else
9830- mask = _PAGE_PRESENT_4U;
9831-
9832- pmd_val(pmd) &= ~mask;
9833-
9834- return pmd;
9835-}
9836-
9837 static inline pmd_t pmd_mksplitting(pmd_t pmd)
9838 {
9839 pte_t pte = __pte(pmd_val(pmd));
9840@@ -757,6 +763,20 @@ static inline int pmd_present(pmd_t pmd)
9841
9842 #define pmd_none(pmd) (!pmd_val(pmd))
9843
9844+/* pmd_bad() is only called on non-trans-huge PMDs. Our encoding is
9845+ * very simple, it's just the physical address. PTE tables are of
9846+ * size PAGE_SIZE so make sure the sub-PAGE_SIZE bits are clear and
9847+ * the top bits outside of the range of any physical address size we
9848+ * support are clear as well. We also validate the physical itself.
9849+ */
9850+#define pmd_bad(pmd) ((pmd_val(pmd) & ~PAGE_MASK) || \
9851+ !__kern_addr_valid(pmd_val(pmd)))
9852+
9853+#define pud_none(pud) (!pud_val(pud))
9854+
9855+#define pud_bad(pud) ((pud_val(pud) & ~PAGE_MASK) || \
9856+ !__kern_addr_valid(pud_val(pud)))
9857+
9858 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
9859 extern void set_pmd_at(struct mm_struct *mm, unsigned long addr,
9860 pmd_t *pmdp, pmd_t pmd);
9861@@ -790,10 +810,7 @@ static inline unsigned long __pmd_page(pmd_t pmd)
9862 #define pud_page_vaddr(pud) \
9863 ((unsigned long) __va(pud_val(pud)))
9864 #define pud_page(pud) virt_to_page((void *)pud_page_vaddr(pud))
9865-#define pmd_bad(pmd) (0)
9866 #define pmd_clear(pmdp) (pmd_val(*(pmdp)) = 0UL)
9867-#define pud_none(pud) (!pud_val(pud))
9868-#define pud_bad(pud) (0)
9869 #define pud_present(pud) (pud_val(pud) != 0U)
9870 #define pud_clear(pudp) (pud_val(*(pudp)) = 0UL)
9871
9872@@ -893,6 +910,10 @@ extern void update_mmu_cache(struct vm_area_struct *, unsigned long, pte_t *);
9873 extern void update_mmu_cache_pmd(struct vm_area_struct *vma, unsigned long addr,
9874 pmd_t *pmd);
9875
9876+#define __HAVE_ARCH_PMDP_INVALIDATE
9877+extern void pmdp_invalidate(struct vm_area_struct *vma, unsigned long address,
9878+ pmd_t *pmdp);
9879+
9880 #define __HAVE_ARCH_PGTABLE_DEPOSIT
9881 extern void pgtable_trans_huge_deposit(struct mm_struct *mm, pmd_t *pmdp,
9882 pgtable_t pgtable);
9883@@ -919,18 +940,6 @@ extern unsigned long pte_file(pte_t);
9884 extern pte_t pgoff_to_pte(unsigned long);
9885 #define PTE_FILE_MAX_BITS (64UL - PAGE_SHIFT - 1UL)
9886
9887-extern unsigned long sparc64_valid_addr_bitmap[];
9888-
9889-/* Needs to be defined here and not in linux/mm.h, as it is arch dependent */
9890-static inline bool kern_addr_valid(unsigned long addr)
9891-{
9892- unsigned long paddr = __pa(addr);
9893-
9894- if ((paddr >> 41UL) != 0UL)
9895- return false;
9896- return test_bit(paddr >> 22, sparc64_valid_addr_bitmap);
9897-}
9898-
9899 extern int page_in_phys_avail(unsigned long paddr);
9900
9901 /*
9902diff --git a/arch/sparc/include/asm/pgtsrmmu.h b/arch/sparc/include/asm/pgtsrmmu.h
9903index 79da178..c2eede8 100644
9904--- a/arch/sparc/include/asm/pgtsrmmu.h
9905+++ b/arch/sparc/include/asm/pgtsrmmu.h
9906@@ -115,6 +115,11 @@
9907 SRMMU_EXEC | SRMMU_REF)
9908 #define SRMMU_PAGE_RDONLY __pgprot(SRMMU_VALID | SRMMU_CACHE | \
9909 SRMMU_EXEC | SRMMU_REF)
9910+
9911+#define SRMMU_PAGE_SHARED_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_WRITE | SRMMU_REF)
9912+#define SRMMU_PAGE_COPY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
9913+#define SRMMU_PAGE_RDONLY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
9914+
9915 #define SRMMU_PAGE_KERNEL __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_PRIV | \
9916 SRMMU_DIRTY | SRMMU_REF)
9917
9918diff --git a/arch/sparc/include/asm/spinlock_64.h b/arch/sparc/include/asm/spinlock_64.h
9919index 9689176..63c18ea 100644
9920--- a/arch/sparc/include/asm/spinlock_64.h
9921+++ b/arch/sparc/include/asm/spinlock_64.h
9922@@ -92,14 +92,19 @@ static inline void arch_spin_lock_flags(arch_spinlock_t *lock, unsigned long fla
9923
9924 /* Multi-reader locks, these are much saner than the 32-bit Sparc ones... */
9925
9926-static void inline arch_read_lock(arch_rwlock_t *lock)
9927+static inline void arch_read_lock(arch_rwlock_t *lock)
9928 {
9929 unsigned long tmp1, tmp2;
9930
9931 __asm__ __volatile__ (
9932 "1: ldsw [%2], %0\n"
9933 " brlz,pn %0, 2f\n"
9934-"4: add %0, 1, %1\n"
9935+"4: addcc %0, 1, %1\n"
9936+
9937+#ifdef CONFIG_PAX_REFCOUNT
9938+" tvs %%icc, 6\n"
9939+#endif
9940+
9941 " cas [%2], %0, %1\n"
9942 " cmp %0, %1\n"
9943 " bne,pn %%icc, 1b\n"
9944@@ -112,10 +117,10 @@ static void inline arch_read_lock(arch_rwlock_t *lock)
9945 " .previous"
9946 : "=&r" (tmp1), "=&r" (tmp2)
9947 : "r" (lock)
9948- : "memory");
9949+ : "memory", "cc");
9950 }
9951
9952-static int inline arch_read_trylock(arch_rwlock_t *lock)
9953+static inline int arch_read_trylock(arch_rwlock_t *lock)
9954 {
9955 int tmp1, tmp2;
9956
9957@@ -123,7 +128,12 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
9958 "1: ldsw [%2], %0\n"
9959 " brlz,a,pn %0, 2f\n"
9960 " mov 0, %0\n"
9961-" add %0, 1, %1\n"
9962+" addcc %0, 1, %1\n"
9963+
9964+#ifdef CONFIG_PAX_REFCOUNT
9965+" tvs %%icc, 6\n"
9966+#endif
9967+
9968 " cas [%2], %0, %1\n"
9969 " cmp %0, %1\n"
9970 " bne,pn %%icc, 1b\n"
9971@@ -136,13 +146,18 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
9972 return tmp1;
9973 }
9974
9975-static void inline arch_read_unlock(arch_rwlock_t *lock)
9976+static inline void arch_read_unlock(arch_rwlock_t *lock)
9977 {
9978 unsigned long tmp1, tmp2;
9979
9980 __asm__ __volatile__(
9981 "1: lduw [%2], %0\n"
9982-" sub %0, 1, %1\n"
9983+" subcc %0, 1, %1\n"
9984+
9985+#ifdef CONFIG_PAX_REFCOUNT
9986+" tvs %%icc, 6\n"
9987+#endif
9988+
9989 " cas [%2], %0, %1\n"
9990 " cmp %0, %1\n"
9991 " bne,pn %%xcc, 1b\n"
9992@@ -152,7 +167,7 @@ static void inline arch_read_unlock(arch_rwlock_t *lock)
9993 : "memory");
9994 }
9995
9996-static void inline arch_write_lock(arch_rwlock_t *lock)
9997+static inline void arch_write_lock(arch_rwlock_t *lock)
9998 {
9999 unsigned long mask, tmp1, tmp2;
10000
10001@@ -177,7 +192,7 @@ static void inline arch_write_lock(arch_rwlock_t *lock)
10002 : "memory");
10003 }
10004
10005-static void inline arch_write_unlock(arch_rwlock_t *lock)
10006+static inline void arch_write_unlock(arch_rwlock_t *lock)
10007 {
10008 __asm__ __volatile__(
10009 " stw %%g0, [%0]"
10010@@ -186,7 +201,7 @@ static void inline arch_write_unlock(arch_rwlock_t *lock)
10011 : "memory");
10012 }
10013
10014-static int inline arch_write_trylock(arch_rwlock_t *lock)
10015+static inline int arch_write_trylock(arch_rwlock_t *lock)
10016 {
10017 unsigned long mask, tmp1, tmp2, result;
10018
10019diff --git a/arch/sparc/include/asm/thread_info_32.h b/arch/sparc/include/asm/thread_info_32.h
10020index 96efa7a..16858bf 100644
10021--- a/arch/sparc/include/asm/thread_info_32.h
10022+++ b/arch/sparc/include/asm/thread_info_32.h
10023@@ -49,6 +49,8 @@ struct thread_info {
10024 unsigned long w_saved;
10025
10026 struct restart_block restart_block;
10027+
10028+ unsigned long lowest_stack;
10029 };
10030
10031 /*
10032diff --git a/arch/sparc/include/asm/thread_info_64.h b/arch/sparc/include/asm/thread_info_64.h
10033index a5f01ac..703b554 100644
10034--- a/arch/sparc/include/asm/thread_info_64.h
10035+++ b/arch/sparc/include/asm/thread_info_64.h
10036@@ -63,6 +63,8 @@ struct thread_info {
10037 struct pt_regs *kern_una_regs;
10038 unsigned int kern_una_insn;
10039
10040+ unsigned long lowest_stack;
10041+
10042 unsigned long fpregs[0] __attribute__ ((aligned(64)));
10043 };
10044
10045@@ -188,12 +190,13 @@ register struct thread_info *current_thread_info_reg asm("g6");
10046 #define TIF_NEED_RESCHED 3 /* rescheduling necessary */
10047 /* flag bit 4 is available */
10048 #define TIF_UNALIGNED 5 /* allowed to do unaligned accesses */
10049-/* flag bit 6 is available */
10050+#define TIF_GRSEC_SETXID 6 /* update credentials on syscall entry/exit */
10051 #define TIF_32BIT 7 /* 32-bit binary */
10052 #define TIF_NOHZ 8 /* in adaptive nohz mode */
10053 #define TIF_SECCOMP 9 /* secure computing */
10054 #define TIF_SYSCALL_AUDIT 10 /* syscall auditing active */
10055 #define TIF_SYSCALL_TRACEPOINT 11 /* syscall tracepoint instrumentation */
10056+
10057 /* NOTE: Thread flags >= 12 should be ones we have no interest
10058 * in using in assembly, else we can't use the mask as
10059 * an immediate value in instructions such as andcc.
10060@@ -213,12 +216,18 @@ register struct thread_info *current_thread_info_reg asm("g6");
10061 #define _TIF_SYSCALL_AUDIT (1<<TIF_SYSCALL_AUDIT)
10062 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
10063 #define _TIF_POLLING_NRFLAG (1<<TIF_POLLING_NRFLAG)
10064+#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
10065
10066 #define _TIF_USER_WORK_MASK ((0xff << TI_FLAG_WSAVED_SHIFT) | \
10067 _TIF_DO_NOTIFY_RESUME_MASK | \
10068 _TIF_NEED_RESCHED)
10069 #define _TIF_DO_NOTIFY_RESUME_MASK (_TIF_NOTIFY_RESUME | _TIF_SIGPENDING)
10070
10071+#define _TIF_WORK_SYSCALL \
10072+ (_TIF_SYSCALL_TRACE | _TIF_SECCOMP | _TIF_SYSCALL_AUDIT | \
10073+ _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ | _TIF_GRSEC_SETXID)
10074+
10075+
10076 /*
10077 * Thread-synchronous status.
10078 *
10079diff --git a/arch/sparc/include/asm/tsb.h b/arch/sparc/include/asm/tsb.h
10080index 2230f80..90916f9 100644
10081--- a/arch/sparc/include/asm/tsb.h
10082+++ b/arch/sparc/include/asm/tsb.h
10083@@ -171,7 +171,8 @@ extern struct tsb_phys_patch_entry __tsb_phys_patch, __tsb_phys_patch_end;
10084 andcc REG1, REG2, %g0; \
10085 be,pt %xcc, 700f; \
10086 sethi %hi(4 * 1024 * 1024), REG2; \
10087- andn REG1, REG2, REG1; \
10088+ brgez,pn REG1, FAIL_LABEL; \
10089+ andn REG1, REG2, REG1; \
10090 and VADDR, REG2, REG2; \
10091 brlz,pt REG1, PTE_LABEL; \
10092 or REG1, REG2, REG1; \
10093diff --git a/arch/sparc/include/asm/uaccess.h b/arch/sparc/include/asm/uaccess.h
10094index 0167d26..767bb0c 100644
10095--- a/arch/sparc/include/asm/uaccess.h
10096+++ b/arch/sparc/include/asm/uaccess.h
10097@@ -1,5 +1,6 @@
10098 #ifndef ___ASM_SPARC_UACCESS_H
10099 #define ___ASM_SPARC_UACCESS_H
10100+
10101 #if defined(__sparc__) && defined(__arch64__)
10102 #include <asm/uaccess_64.h>
10103 #else
10104diff --git a/arch/sparc/include/asm/uaccess_32.h b/arch/sparc/include/asm/uaccess_32.h
10105index 53a28dd..50c38c3 100644
10106--- a/arch/sparc/include/asm/uaccess_32.h
10107+++ b/arch/sparc/include/asm/uaccess_32.h
10108@@ -250,27 +250,46 @@ extern unsigned long __copy_user(void __user *to, const void __user *from, unsig
10109
10110 static inline unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
10111 {
10112- if (n && __access_ok((unsigned long) to, n))
10113+ if ((long)n < 0)
10114+ return n;
10115+
10116+ if (n && __access_ok((unsigned long) to, n)) {
10117+ if (!__builtin_constant_p(n))
10118+ check_object_size(from, n, true);
10119 return __copy_user(to, (__force void __user *) from, n);
10120- else
10121+ } else
10122 return n;
10123 }
10124
10125 static inline unsigned long __copy_to_user(void __user *to, const void *from, unsigned long n)
10126 {
10127+ if ((long)n < 0)
10128+ return n;
10129+
10130+ if (!__builtin_constant_p(n))
10131+ check_object_size(from, n, true);
10132+
10133 return __copy_user(to, (__force void __user *) from, n);
10134 }
10135
10136 static inline unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
10137 {
10138- if (n && __access_ok((unsigned long) from, n))
10139+ if ((long)n < 0)
10140+ return n;
10141+
10142+ if (n && __access_ok((unsigned long) from, n)) {
10143+ if (!__builtin_constant_p(n))
10144+ check_object_size(to, n, false);
10145 return __copy_user((__force void __user *) to, from, n);
10146- else
10147+ } else
10148 return n;
10149 }
10150
10151 static inline unsigned long __copy_from_user(void *to, const void __user *from, unsigned long n)
10152 {
10153+ if ((long)n < 0)
10154+ return n;
10155+
10156 return __copy_user((__force void __user *) to, from, n);
10157 }
10158
10159diff --git a/arch/sparc/include/asm/uaccess_64.h b/arch/sparc/include/asm/uaccess_64.h
10160index ad7e178..c9e7423 100644
10161--- a/arch/sparc/include/asm/uaccess_64.h
10162+++ b/arch/sparc/include/asm/uaccess_64.h
10163@@ -10,6 +10,7 @@
10164 #include <linux/compiler.h>
10165 #include <linux/string.h>
10166 #include <linux/thread_info.h>
10167+#include <linux/kernel.h>
10168 #include <asm/asi.h>
10169 #include <asm/spitfire.h>
10170 #include <asm-generic/uaccess-unaligned.h>
10171@@ -214,8 +215,15 @@ extern unsigned long copy_from_user_fixup(void *to, const void __user *from,
10172 static inline unsigned long __must_check
10173 copy_from_user(void *to, const void __user *from, unsigned long size)
10174 {
10175- unsigned long ret = ___copy_from_user(to, from, size);
10176+ unsigned long ret;
10177
10178+ if ((long)size < 0 || size > INT_MAX)
10179+ return size;
10180+
10181+ if (!__builtin_constant_p(size))
10182+ check_object_size(to, size, false);
10183+
10184+ ret = ___copy_from_user(to, from, size);
10185 if (unlikely(ret))
10186 ret = copy_from_user_fixup(to, from, size);
10187
10188@@ -231,8 +239,15 @@ extern unsigned long copy_to_user_fixup(void __user *to, const void *from,
10189 static inline unsigned long __must_check
10190 copy_to_user(void __user *to, const void *from, unsigned long size)
10191 {
10192- unsigned long ret = ___copy_to_user(to, from, size);
10193+ unsigned long ret;
10194
10195+ if ((long)size < 0 || size > INT_MAX)
10196+ return size;
10197+
10198+ if (!__builtin_constant_p(size))
10199+ check_object_size(from, size, true);
10200+
10201+ ret = ___copy_to_user(to, from, size);
10202 if (unlikely(ret))
10203 ret = copy_to_user_fixup(to, from, size);
10204 return ret;
10205diff --git a/arch/sparc/kernel/Makefile b/arch/sparc/kernel/Makefile
10206index d15cc17..d0ae796 100644
10207--- a/arch/sparc/kernel/Makefile
10208+++ b/arch/sparc/kernel/Makefile
10209@@ -4,7 +4,7 @@
10210 #
10211
10212 asflags-y := -ansi
10213-ccflags-y := -Werror
10214+#ccflags-y := -Werror
10215
10216 extra-y := head_$(BITS).o
10217
10218diff --git a/arch/sparc/kernel/process_32.c b/arch/sparc/kernel/process_32.c
10219index 510baec..9ff2607 100644
10220--- a/arch/sparc/kernel/process_32.c
10221+++ b/arch/sparc/kernel/process_32.c
10222@@ -115,14 +115,14 @@ void show_regs(struct pt_regs *r)
10223
10224 printk("PSR: %08lx PC: %08lx NPC: %08lx Y: %08lx %s\n",
10225 r->psr, r->pc, r->npc, r->y, print_tainted());
10226- printk("PC: <%pS>\n", (void *) r->pc);
10227+ printk("PC: <%pA>\n", (void *) r->pc);
10228 printk("%%G: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
10229 r->u_regs[0], r->u_regs[1], r->u_regs[2], r->u_regs[3],
10230 r->u_regs[4], r->u_regs[5], r->u_regs[6], r->u_regs[7]);
10231 printk("%%O: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
10232 r->u_regs[8], r->u_regs[9], r->u_regs[10], r->u_regs[11],
10233 r->u_regs[12], r->u_regs[13], r->u_regs[14], r->u_regs[15]);
10234- printk("RPC: <%pS>\n", (void *) r->u_regs[15]);
10235+ printk("RPC: <%pA>\n", (void *) r->u_regs[15]);
10236
10237 printk("%%L: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
10238 rw->locals[0], rw->locals[1], rw->locals[2], rw->locals[3],
10239@@ -159,7 +159,7 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
10240 rw = (struct reg_window32 *) fp;
10241 pc = rw->ins[7];
10242 printk("[%08lx : ", pc);
10243- printk("%pS ] ", (void *) pc);
10244+ printk("%pA ] ", (void *) pc);
10245 fp = rw->ins[6];
10246 } while (++count < 16);
10247 printk("\n");
10248diff --git a/arch/sparc/kernel/process_64.c b/arch/sparc/kernel/process_64.c
10249index d7b4967..2edf827 100644
10250--- a/arch/sparc/kernel/process_64.c
10251+++ b/arch/sparc/kernel/process_64.c
10252@@ -161,7 +161,7 @@ static void show_regwindow(struct pt_regs *regs)
10253 printk("i4: %016lx i5: %016lx i6: %016lx i7: %016lx\n",
10254 rwk->ins[4], rwk->ins[5], rwk->ins[6], rwk->ins[7]);
10255 if (regs->tstate & TSTATE_PRIV)
10256- printk("I7: <%pS>\n", (void *) rwk->ins[7]);
10257+ printk("I7: <%pA>\n", (void *) rwk->ins[7]);
10258 }
10259
10260 void show_regs(struct pt_regs *regs)
10261@@ -170,7 +170,7 @@ void show_regs(struct pt_regs *regs)
10262
10263 printk("TSTATE: %016lx TPC: %016lx TNPC: %016lx Y: %08x %s\n", regs->tstate,
10264 regs->tpc, regs->tnpc, regs->y, print_tainted());
10265- printk("TPC: <%pS>\n", (void *) regs->tpc);
10266+ printk("TPC: <%pA>\n", (void *) regs->tpc);
10267 printk("g0: %016lx g1: %016lx g2: %016lx g3: %016lx\n",
10268 regs->u_regs[0], regs->u_regs[1], regs->u_regs[2],
10269 regs->u_regs[3]);
10270@@ -183,7 +183,7 @@ void show_regs(struct pt_regs *regs)
10271 printk("o4: %016lx o5: %016lx sp: %016lx ret_pc: %016lx\n",
10272 regs->u_regs[12], regs->u_regs[13], regs->u_regs[14],
10273 regs->u_regs[15]);
10274- printk("RPC: <%pS>\n", (void *) regs->u_regs[15]);
10275+ printk("RPC: <%pA>\n", (void *) regs->u_regs[15]);
10276 show_regwindow(regs);
10277 show_stack(current, (unsigned long *) regs->u_regs[UREG_FP]);
10278 }
10279@@ -272,7 +272,7 @@ void arch_trigger_all_cpu_backtrace(void)
10280 ((tp && tp->task) ? tp->task->pid : -1));
10281
10282 if (gp->tstate & TSTATE_PRIV) {
10283- printk(" TPC[%pS] O7[%pS] I7[%pS] RPC[%pS]\n",
10284+ printk(" TPC[%pA] O7[%pA] I7[%pA] RPC[%pA]\n",
10285 (void *) gp->tpc,
10286 (void *) gp->o7,
10287 (void *) gp->i7,
10288diff --git a/arch/sparc/kernel/prom_common.c b/arch/sparc/kernel/prom_common.c
10289index 79cc0d1..ec62734 100644
10290--- a/arch/sparc/kernel/prom_common.c
10291+++ b/arch/sparc/kernel/prom_common.c
10292@@ -144,7 +144,7 @@ static int __init prom_common_nextprop(phandle node, char *prev, char *buf)
10293
10294 unsigned int prom_early_allocated __initdata;
10295
10296-static struct of_pdt_ops prom_sparc_ops __initdata = {
10297+static struct of_pdt_ops prom_sparc_ops __initconst = {
10298 .nextprop = prom_common_nextprop,
10299 .getproplen = prom_getproplen,
10300 .getproperty = prom_getproperty,
10301diff --git a/arch/sparc/kernel/ptrace_64.c b/arch/sparc/kernel/ptrace_64.c
10302index c13c9f2..d572c34 100644
10303--- a/arch/sparc/kernel/ptrace_64.c
10304+++ b/arch/sparc/kernel/ptrace_64.c
10305@@ -1060,6 +1060,10 @@ long arch_ptrace(struct task_struct *child, long request,
10306 return ret;
10307 }
10308
10309+#ifdef CONFIG_GRKERNSEC_SETXID
10310+extern void gr_delayed_cred_worker(void);
10311+#endif
10312+
10313 asmlinkage int syscall_trace_enter(struct pt_regs *regs)
10314 {
10315 int ret = 0;
10316@@ -1070,6 +1074,11 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)
10317 if (test_thread_flag(TIF_NOHZ))
10318 user_exit();
10319
10320+#ifdef CONFIG_GRKERNSEC_SETXID
10321+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
10322+ gr_delayed_cred_worker();
10323+#endif
10324+
10325 if (test_thread_flag(TIF_SYSCALL_TRACE))
10326 ret = tracehook_report_syscall_entry(regs);
10327
10328@@ -1093,6 +1102,11 @@ asmlinkage void syscall_trace_leave(struct pt_regs *regs)
10329 if (test_thread_flag(TIF_NOHZ))
10330 user_exit();
10331
10332+#ifdef CONFIG_GRKERNSEC_SETXID
10333+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
10334+ gr_delayed_cred_worker();
10335+#endif
10336+
10337 audit_syscall_exit(regs);
10338
10339 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
10340diff --git a/arch/sparc/kernel/smp_64.c b/arch/sparc/kernel/smp_64.c
10341index b085311..6f885f7 100644
10342--- a/arch/sparc/kernel/smp_64.c
10343+++ b/arch/sparc/kernel/smp_64.c
10344@@ -870,8 +870,8 @@ extern unsigned long xcall_flush_dcache_page_cheetah;
10345 extern unsigned long xcall_flush_dcache_page_spitfire;
10346
10347 #ifdef CONFIG_DEBUG_DCFLUSH
10348-extern atomic_t dcpage_flushes;
10349-extern atomic_t dcpage_flushes_xcall;
10350+extern atomic_unchecked_t dcpage_flushes;
10351+extern atomic_unchecked_t dcpage_flushes_xcall;
10352 #endif
10353
10354 static inline void __local_flush_dcache_page(struct page *page)
10355@@ -895,7 +895,7 @@ void smp_flush_dcache_page_impl(struct page *page, int cpu)
10356 return;
10357
10358 #ifdef CONFIG_DEBUG_DCFLUSH
10359- atomic_inc(&dcpage_flushes);
10360+ atomic_inc_unchecked(&dcpage_flushes);
10361 #endif
10362
10363 this_cpu = get_cpu();
10364@@ -919,7 +919,7 @@ void smp_flush_dcache_page_impl(struct page *page, int cpu)
10365 xcall_deliver(data0, __pa(pg_addr),
10366 (u64) pg_addr, cpumask_of(cpu));
10367 #ifdef CONFIG_DEBUG_DCFLUSH
10368- atomic_inc(&dcpage_flushes_xcall);
10369+ atomic_inc_unchecked(&dcpage_flushes_xcall);
10370 #endif
10371 }
10372 }
10373@@ -938,7 +938,7 @@ void flush_dcache_page_all(struct mm_struct *mm, struct page *page)
10374 preempt_disable();
10375
10376 #ifdef CONFIG_DEBUG_DCFLUSH
10377- atomic_inc(&dcpage_flushes);
10378+ atomic_inc_unchecked(&dcpage_flushes);
10379 #endif
10380 data0 = 0;
10381 pg_addr = page_address(page);
10382@@ -955,7 +955,7 @@ void flush_dcache_page_all(struct mm_struct *mm, struct page *page)
10383 xcall_deliver(data0, __pa(pg_addr),
10384 (u64) pg_addr, cpu_online_mask);
10385 #ifdef CONFIG_DEBUG_DCFLUSH
10386- atomic_inc(&dcpage_flushes_xcall);
10387+ atomic_inc_unchecked(&dcpage_flushes_xcall);
10388 #endif
10389 }
10390 __local_flush_dcache_page(page);
10391diff --git a/arch/sparc/kernel/sys_sparc_32.c b/arch/sparc/kernel/sys_sparc_32.c
10392index 3a8d184..49498a8 100644
10393--- a/arch/sparc/kernel/sys_sparc_32.c
10394+++ b/arch/sparc/kernel/sys_sparc_32.c
10395@@ -52,7 +52,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
10396 if (len > TASK_SIZE - PAGE_SIZE)
10397 return -ENOMEM;
10398 if (!addr)
10399- addr = TASK_UNMAPPED_BASE;
10400+ addr = current->mm->mmap_base;
10401
10402 info.flags = 0;
10403 info.length = len;
10404diff --git a/arch/sparc/kernel/sys_sparc_64.c b/arch/sparc/kernel/sys_sparc_64.c
10405index beb0b5a..5a153f7 100644
10406--- a/arch/sparc/kernel/sys_sparc_64.c
10407+++ b/arch/sparc/kernel/sys_sparc_64.c
10408@@ -88,13 +88,14 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
10409 struct vm_area_struct * vma;
10410 unsigned long task_size = TASK_SIZE;
10411 int do_color_align;
10412+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
10413 struct vm_unmapped_area_info info;
10414
10415 if (flags & MAP_FIXED) {
10416 /* We do not accept a shared mapping if it would violate
10417 * cache aliasing constraints.
10418 */
10419- if ((flags & MAP_SHARED) &&
10420+ if ((filp || (flags & MAP_SHARED)) &&
10421 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
10422 return -EINVAL;
10423 return addr;
10424@@ -109,6 +110,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
10425 if (filp || (flags & MAP_SHARED))
10426 do_color_align = 1;
10427
10428+#ifdef CONFIG_PAX_RANDMMAP
10429+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
10430+#endif
10431+
10432 if (addr) {
10433 if (do_color_align)
10434 addr = COLOR_ALIGN(addr, pgoff);
10435@@ -116,22 +121,28 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
10436 addr = PAGE_ALIGN(addr);
10437
10438 vma = find_vma(mm, addr);
10439- if (task_size - len >= addr &&
10440- (!vma || addr + len <= vma->vm_start))
10441+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
10442 return addr;
10443 }
10444
10445 info.flags = 0;
10446 info.length = len;
10447- info.low_limit = TASK_UNMAPPED_BASE;
10448+ info.low_limit = mm->mmap_base;
10449 info.high_limit = min(task_size, VA_EXCLUDE_START);
10450 info.align_mask = do_color_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
10451 info.align_offset = pgoff << PAGE_SHIFT;
10452+ info.threadstack_offset = offset;
10453 addr = vm_unmapped_area(&info);
10454
10455 if ((addr & ~PAGE_MASK) && task_size > VA_EXCLUDE_END) {
10456 VM_BUG_ON(addr != -ENOMEM);
10457 info.low_limit = VA_EXCLUDE_END;
10458+
10459+#ifdef CONFIG_PAX_RANDMMAP
10460+ if (mm->pax_flags & MF_PAX_RANDMMAP)
10461+ info.low_limit += mm->delta_mmap;
10462+#endif
10463+
10464 info.high_limit = task_size;
10465 addr = vm_unmapped_area(&info);
10466 }
10467@@ -149,6 +160,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10468 unsigned long task_size = STACK_TOP32;
10469 unsigned long addr = addr0;
10470 int do_color_align;
10471+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
10472 struct vm_unmapped_area_info info;
10473
10474 /* This should only ever run for 32-bit processes. */
10475@@ -158,7 +170,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10476 /* We do not accept a shared mapping if it would violate
10477 * cache aliasing constraints.
10478 */
10479- if ((flags & MAP_SHARED) &&
10480+ if ((filp || (flags & MAP_SHARED)) &&
10481 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
10482 return -EINVAL;
10483 return addr;
10484@@ -171,6 +183,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10485 if (filp || (flags & MAP_SHARED))
10486 do_color_align = 1;
10487
10488+#ifdef CONFIG_PAX_RANDMMAP
10489+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
10490+#endif
10491+
10492 /* requesting a specific address */
10493 if (addr) {
10494 if (do_color_align)
10495@@ -179,8 +195,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10496 addr = PAGE_ALIGN(addr);
10497
10498 vma = find_vma(mm, addr);
10499- if (task_size - len >= addr &&
10500- (!vma || addr + len <= vma->vm_start))
10501+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
10502 return addr;
10503 }
10504
10505@@ -190,6 +205,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10506 info.high_limit = mm->mmap_base;
10507 info.align_mask = do_color_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
10508 info.align_offset = pgoff << PAGE_SHIFT;
10509+ info.threadstack_offset = offset;
10510 addr = vm_unmapped_area(&info);
10511
10512 /*
10513@@ -202,6 +218,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10514 VM_BUG_ON(addr != -ENOMEM);
10515 info.flags = 0;
10516 info.low_limit = TASK_UNMAPPED_BASE;
10517+
10518+#ifdef CONFIG_PAX_RANDMMAP
10519+ if (mm->pax_flags & MF_PAX_RANDMMAP)
10520+ info.low_limit += mm->delta_mmap;
10521+#endif
10522+
10523 info.high_limit = STACK_TOP32;
10524 addr = vm_unmapped_area(&info);
10525 }
10526@@ -258,10 +280,14 @@ unsigned long get_fb_unmapped_area(struct file *filp, unsigned long orig_addr, u
10527 EXPORT_SYMBOL(get_fb_unmapped_area);
10528
10529 /* Essentially the same as PowerPC. */
10530-static unsigned long mmap_rnd(void)
10531+static unsigned long mmap_rnd(struct mm_struct *mm)
10532 {
10533 unsigned long rnd = 0UL;
10534
10535+#ifdef CONFIG_PAX_RANDMMAP
10536+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
10537+#endif
10538+
10539 if (current->flags & PF_RANDOMIZE) {
10540 unsigned long val = get_random_int();
10541 if (test_thread_flag(TIF_32BIT))
10542@@ -274,7 +300,7 @@ static unsigned long mmap_rnd(void)
10543
10544 void arch_pick_mmap_layout(struct mm_struct *mm)
10545 {
10546- unsigned long random_factor = mmap_rnd();
10547+ unsigned long random_factor = mmap_rnd(mm);
10548 unsigned long gap;
10549
10550 /*
10551@@ -287,6 +313,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
10552 gap == RLIM_INFINITY ||
10553 sysctl_legacy_va_layout) {
10554 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
10555+
10556+#ifdef CONFIG_PAX_RANDMMAP
10557+ if (mm->pax_flags & MF_PAX_RANDMMAP)
10558+ mm->mmap_base += mm->delta_mmap;
10559+#endif
10560+
10561 mm->get_unmapped_area = arch_get_unmapped_area;
10562 } else {
10563 /* We know it's 32-bit */
10564@@ -298,6 +330,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
10565 gap = (task_size / 6 * 5);
10566
10567 mm->mmap_base = PAGE_ALIGN(task_size - gap - random_factor);
10568+
10569+#ifdef CONFIG_PAX_RANDMMAP
10570+ if (mm->pax_flags & MF_PAX_RANDMMAP)
10571+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
10572+#endif
10573+
10574 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
10575 }
10576 }
10577diff --git a/arch/sparc/kernel/syscalls.S b/arch/sparc/kernel/syscalls.S
10578index 33a17e7..d87fb1f 100644
10579--- a/arch/sparc/kernel/syscalls.S
10580+++ b/arch/sparc/kernel/syscalls.S
10581@@ -52,7 +52,7 @@ sys32_rt_sigreturn:
10582 #endif
10583 .align 32
10584 1: ldx [%g6 + TI_FLAGS], %l5
10585- andcc %l5, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT|_TIF_NOHZ), %g0
10586+ andcc %l5, _TIF_WORK_SYSCALL, %g0
10587 be,pt %icc, rtrap
10588 nop
10589 call syscall_trace_leave
10590@@ -184,7 +184,7 @@ linux_sparc_syscall32:
10591
10592 srl %i3, 0, %o3 ! IEU0
10593 srl %i2, 0, %o2 ! IEU0 Group
10594- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT|_TIF_NOHZ), %g0
10595+ andcc %l0, _TIF_WORK_SYSCALL, %g0
10596 bne,pn %icc, linux_syscall_trace32 ! CTI
10597 mov %i0, %l5 ! IEU1
10598 5: call %l7 ! CTI Group brk forced
10599@@ -208,7 +208,7 @@ linux_sparc_syscall:
10600
10601 mov %i3, %o3 ! IEU1
10602 mov %i4, %o4 ! IEU0 Group
10603- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT|_TIF_NOHZ), %g0
10604+ andcc %l0, _TIF_WORK_SYSCALL, %g0
10605 bne,pn %icc, linux_syscall_trace ! CTI Group
10606 mov %i0, %l5 ! IEU0
10607 2: call %l7 ! CTI Group brk forced
10608@@ -223,7 +223,7 @@ ret_sys_call:
10609
10610 cmp %o0, -ERESTART_RESTARTBLOCK
10611 bgeu,pn %xcc, 1f
10612- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT|_TIF_NOHZ), %g0
10613+ andcc %l0, _TIF_WORK_SYSCALL, %g0
10614 ldx [%sp + PTREGS_OFF + PT_V9_TNPC], %l1 ! pc = npc
10615
10616 2:
10617diff --git a/arch/sparc/kernel/traps_32.c b/arch/sparc/kernel/traps_32.c
10618index 6629829..036032d 100644
10619--- a/arch/sparc/kernel/traps_32.c
10620+++ b/arch/sparc/kernel/traps_32.c
10621@@ -44,6 +44,8 @@ static void instruction_dump(unsigned long *pc)
10622 #define __SAVE __asm__ __volatile__("save %sp, -0x40, %sp\n\t")
10623 #define __RESTORE __asm__ __volatile__("restore %g0, %g0, %g0\n\t")
10624
10625+extern void gr_handle_kernel_exploit(void);
10626+
10627 void die_if_kernel(char *str, struct pt_regs *regs)
10628 {
10629 static int die_counter;
10630@@ -76,15 +78,17 @@ void die_if_kernel(char *str, struct pt_regs *regs)
10631 count++ < 30 &&
10632 (((unsigned long) rw) >= PAGE_OFFSET) &&
10633 !(((unsigned long) rw) & 0x7)) {
10634- printk("Caller[%08lx]: %pS\n", rw->ins[7],
10635+ printk("Caller[%08lx]: %pA\n", rw->ins[7],
10636 (void *) rw->ins[7]);
10637 rw = (struct reg_window32 *)rw->ins[6];
10638 }
10639 }
10640 printk("Instruction DUMP:");
10641 instruction_dump ((unsigned long *) regs->pc);
10642- if(regs->psr & PSR_PS)
10643+ if(regs->psr & PSR_PS) {
10644+ gr_handle_kernel_exploit();
10645 do_exit(SIGKILL);
10646+ }
10647 do_exit(SIGSEGV);
10648 }
10649
10650diff --git a/arch/sparc/kernel/traps_64.c b/arch/sparc/kernel/traps_64.c
10651index 4ced92f..965eeed 100644
10652--- a/arch/sparc/kernel/traps_64.c
10653+++ b/arch/sparc/kernel/traps_64.c
10654@@ -77,7 +77,7 @@ static void dump_tl1_traplog(struct tl1_traplog *p)
10655 i + 1,
10656 p->trapstack[i].tstate, p->trapstack[i].tpc,
10657 p->trapstack[i].tnpc, p->trapstack[i].tt);
10658- printk("TRAPLOG: TPC<%pS>\n", (void *) p->trapstack[i].tpc);
10659+ printk("TRAPLOG: TPC<%pA>\n", (void *) p->trapstack[i].tpc);
10660 }
10661 }
10662
10663@@ -97,6 +97,12 @@ void bad_trap(struct pt_regs *regs, long lvl)
10664
10665 lvl -= 0x100;
10666 if (regs->tstate & TSTATE_PRIV) {
10667+
10668+#ifdef CONFIG_PAX_REFCOUNT
10669+ if (lvl == 6)
10670+ pax_report_refcount_overflow(regs);
10671+#endif
10672+
10673 sprintf(buffer, "Kernel bad sw trap %lx", lvl);
10674 die_if_kernel(buffer, regs);
10675 }
10676@@ -115,11 +121,16 @@ void bad_trap(struct pt_regs *regs, long lvl)
10677 void bad_trap_tl1(struct pt_regs *regs, long lvl)
10678 {
10679 char buffer[32];
10680-
10681+
10682 if (notify_die(DIE_TRAP_TL1, "bad trap tl1", regs,
10683 0, lvl, SIGTRAP) == NOTIFY_STOP)
10684 return;
10685
10686+#ifdef CONFIG_PAX_REFCOUNT
10687+ if (lvl == 6)
10688+ pax_report_refcount_overflow(regs);
10689+#endif
10690+
10691 dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
10692
10693 sprintf (buffer, "Bad trap %lx at tl>0", lvl);
10694@@ -1149,7 +1160,7 @@ static void cheetah_log_errors(struct pt_regs *regs, struct cheetah_err_info *in
10695 regs->tpc, regs->tnpc, regs->u_regs[UREG_I7], regs->tstate);
10696 printk("%s" "ERROR(%d): ",
10697 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id());
10698- printk("TPC<%pS>\n", (void *) regs->tpc);
10699+ printk("TPC<%pA>\n", (void *) regs->tpc);
10700 printk("%s" "ERROR(%d): M_SYND(%lx), E_SYND(%lx)%s%s\n",
10701 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id(),
10702 (afsr & CHAFSR_M_SYNDROME) >> CHAFSR_M_SYNDROME_SHIFT,
10703@@ -1756,7 +1767,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
10704 smp_processor_id(),
10705 (type & 0x1) ? 'I' : 'D',
10706 regs->tpc);
10707- printk(KERN_EMERG "TPC<%pS>\n", (void *) regs->tpc);
10708+ printk(KERN_EMERG "TPC<%pA>\n", (void *) regs->tpc);
10709 panic("Irrecoverable Cheetah+ parity error.");
10710 }
10711
10712@@ -1764,7 +1775,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
10713 smp_processor_id(),
10714 (type & 0x1) ? 'I' : 'D',
10715 regs->tpc);
10716- printk(KERN_WARNING "TPC<%pS>\n", (void *) regs->tpc);
10717+ printk(KERN_WARNING "TPC<%pA>\n", (void *) regs->tpc);
10718 }
10719
10720 struct sun4v_error_entry {
10721@@ -1837,8 +1848,8 @@ struct sun4v_error_entry {
10722 /*0x38*/u64 reserved_5;
10723 };
10724
10725-static atomic_t sun4v_resum_oflow_cnt = ATOMIC_INIT(0);
10726-static atomic_t sun4v_nonresum_oflow_cnt = ATOMIC_INIT(0);
10727+static atomic_unchecked_t sun4v_resum_oflow_cnt = ATOMIC_INIT(0);
10728+static atomic_unchecked_t sun4v_nonresum_oflow_cnt = ATOMIC_INIT(0);
10729
10730 static const char *sun4v_err_type_to_str(u8 type)
10731 {
10732@@ -1930,7 +1941,7 @@ static void sun4v_report_real_raddr(const char *pfx, struct pt_regs *regs)
10733 }
10734
10735 static void sun4v_log_error(struct pt_regs *regs, struct sun4v_error_entry *ent,
10736- int cpu, const char *pfx, atomic_t *ocnt)
10737+ int cpu, const char *pfx, atomic_unchecked_t *ocnt)
10738 {
10739 u64 *raw_ptr = (u64 *) ent;
10740 u32 attrs;
10741@@ -1988,8 +1999,8 @@ static void sun4v_log_error(struct pt_regs *regs, struct sun4v_error_entry *ent,
10742
10743 show_regs(regs);
10744
10745- if ((cnt = atomic_read(ocnt)) != 0) {
10746- atomic_set(ocnt, 0);
10747+ if ((cnt = atomic_read_unchecked(ocnt)) != 0) {
10748+ atomic_set_unchecked(ocnt, 0);
10749 wmb();
10750 printk("%s: Queue overflowed %d times.\n",
10751 pfx, cnt);
10752@@ -2046,7 +2057,7 @@ out:
10753 */
10754 void sun4v_resum_overflow(struct pt_regs *regs)
10755 {
10756- atomic_inc(&sun4v_resum_oflow_cnt);
10757+ atomic_inc_unchecked(&sun4v_resum_oflow_cnt);
10758 }
10759
10760 /* We run with %pil set to PIL_NORMAL_MAX and PSTATE_IE enabled in %pstate.
10761@@ -2099,7 +2110,7 @@ void sun4v_nonresum_overflow(struct pt_regs *regs)
10762 /* XXX Actually even this can make not that much sense. Perhaps
10763 * XXX we should just pull the plug and panic directly from here?
10764 */
10765- atomic_inc(&sun4v_nonresum_oflow_cnt);
10766+ atomic_inc_unchecked(&sun4v_nonresum_oflow_cnt);
10767 }
10768
10769 unsigned long sun4v_err_itlb_vaddr;
10770@@ -2114,9 +2125,9 @@ void sun4v_itlb_error_report(struct pt_regs *regs, int tl)
10771
10772 printk(KERN_EMERG "SUN4V-ITLB: Error at TPC[%lx], tl %d\n",
10773 regs->tpc, tl);
10774- printk(KERN_EMERG "SUN4V-ITLB: TPC<%pS>\n", (void *) regs->tpc);
10775+ printk(KERN_EMERG "SUN4V-ITLB: TPC<%pA>\n", (void *) regs->tpc);
10776 printk(KERN_EMERG "SUN4V-ITLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
10777- printk(KERN_EMERG "SUN4V-ITLB: O7<%pS>\n",
10778+ printk(KERN_EMERG "SUN4V-ITLB: O7<%pA>\n",
10779 (void *) regs->u_regs[UREG_I7]);
10780 printk(KERN_EMERG "SUN4V-ITLB: vaddr[%lx] ctx[%lx] "
10781 "pte[%lx] error[%lx]\n",
10782@@ -2138,9 +2149,9 @@ void sun4v_dtlb_error_report(struct pt_regs *regs, int tl)
10783
10784 printk(KERN_EMERG "SUN4V-DTLB: Error at TPC[%lx], tl %d\n",
10785 regs->tpc, tl);
10786- printk(KERN_EMERG "SUN4V-DTLB: TPC<%pS>\n", (void *) regs->tpc);
10787+ printk(KERN_EMERG "SUN4V-DTLB: TPC<%pA>\n", (void *) regs->tpc);
10788 printk(KERN_EMERG "SUN4V-DTLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
10789- printk(KERN_EMERG "SUN4V-DTLB: O7<%pS>\n",
10790+ printk(KERN_EMERG "SUN4V-DTLB: O7<%pA>\n",
10791 (void *) regs->u_regs[UREG_I7]);
10792 printk(KERN_EMERG "SUN4V-DTLB: vaddr[%lx] ctx[%lx] "
10793 "pte[%lx] error[%lx]\n",
10794@@ -2359,13 +2370,13 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
10795 fp = (unsigned long)sf->fp + STACK_BIAS;
10796 }
10797
10798- printk(" [%016lx] %pS\n", pc, (void *) pc);
10799+ printk(" [%016lx] %pA\n", pc, (void *) pc);
10800 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
10801 if ((pc + 8UL) == (unsigned long) &return_to_handler) {
10802 int index = tsk->curr_ret_stack;
10803 if (tsk->ret_stack && index >= graph) {
10804 pc = tsk->ret_stack[index - graph].ret;
10805- printk(" [%016lx] %pS\n", pc, (void *) pc);
10806+ printk(" [%016lx] %pA\n", pc, (void *) pc);
10807 graph++;
10808 }
10809 }
10810@@ -2383,6 +2394,8 @@ static inline struct reg_window *kernel_stack_up(struct reg_window *rw)
10811 return (struct reg_window *) (fp + STACK_BIAS);
10812 }
10813
10814+extern void gr_handle_kernel_exploit(void);
10815+
10816 void die_if_kernel(char *str, struct pt_regs *regs)
10817 {
10818 static int die_counter;
10819@@ -2411,7 +2424,7 @@ void die_if_kernel(char *str, struct pt_regs *regs)
10820 while (rw &&
10821 count++ < 30 &&
10822 kstack_valid(tp, (unsigned long) rw)) {
10823- printk("Caller[%016lx]: %pS\n", rw->ins[7],
10824+ printk("Caller[%016lx]: %pA\n", rw->ins[7],
10825 (void *) rw->ins[7]);
10826
10827 rw = kernel_stack_up(rw);
10828@@ -2424,8 +2437,10 @@ void die_if_kernel(char *str, struct pt_regs *regs)
10829 }
10830 user_instruction_dump ((unsigned int __user *) regs->tpc);
10831 }
10832- if (regs->tstate & TSTATE_PRIV)
10833+ if (regs->tstate & TSTATE_PRIV) {
10834+ gr_handle_kernel_exploit();
10835 do_exit(SIGKILL);
10836+ }
10837 do_exit(SIGSEGV);
10838 }
10839 EXPORT_SYMBOL(die_if_kernel);
10840diff --git a/arch/sparc/kernel/unaligned_64.c b/arch/sparc/kernel/unaligned_64.c
10841index 3c1a7cb..9046547 100644
10842--- a/arch/sparc/kernel/unaligned_64.c
10843+++ b/arch/sparc/kernel/unaligned_64.c
10844@@ -166,17 +166,23 @@ static unsigned long *fetch_reg_addr(unsigned int reg, struct pt_regs *regs)
10845 unsigned long compute_effective_address(struct pt_regs *regs,
10846 unsigned int insn, unsigned int rd)
10847 {
10848+ int from_kernel = (regs->tstate & TSTATE_PRIV) != 0;
10849 unsigned int rs1 = (insn >> 14) & 0x1f;
10850 unsigned int rs2 = insn & 0x1f;
10851- int from_kernel = (regs->tstate & TSTATE_PRIV) != 0;
10852+ unsigned long addr;
10853
10854 if (insn & 0x2000) {
10855 maybe_flush_windows(rs1, 0, rd, from_kernel);
10856- return (fetch_reg(rs1, regs) + sign_extend_imm13(insn));
10857+ addr = (fetch_reg(rs1, regs) + sign_extend_imm13(insn));
10858 } else {
10859 maybe_flush_windows(rs1, rs2, rd, from_kernel);
10860- return (fetch_reg(rs1, regs) + fetch_reg(rs2, regs));
10861+ addr = (fetch_reg(rs1, regs) + fetch_reg(rs2, regs));
10862 }
10863+
10864+ if (!from_kernel && test_thread_flag(TIF_32BIT))
10865+ addr &= 0xffffffff;
10866+
10867+ return addr;
10868 }
10869
10870 /* This is just to make gcc think die_if_kernel does return... */
10871@@ -289,7 +295,7 @@ static void log_unaligned(struct pt_regs *regs)
10872 static DEFINE_RATELIMIT_STATE(ratelimit, 5 * HZ, 5);
10873
10874 if (__ratelimit(&ratelimit)) {
10875- printk("Kernel unaligned access at TPC[%lx] %pS\n",
10876+ printk("Kernel unaligned access at TPC[%lx] %pA\n",
10877 regs->tpc, (void *) regs->tpc);
10878 }
10879 }
10880diff --git a/arch/sparc/lib/Makefile b/arch/sparc/lib/Makefile
10881index dbe119b..089c7c1 100644
10882--- a/arch/sparc/lib/Makefile
10883+++ b/arch/sparc/lib/Makefile
10884@@ -2,7 +2,7 @@
10885 #
10886
10887 asflags-y := -ansi -DST_DIV0=0x02
10888-ccflags-y := -Werror
10889+#ccflags-y := -Werror
10890
10891 lib-$(CONFIG_SPARC32) += ashrdi3.o
10892 lib-$(CONFIG_SPARC32) += memcpy.o memset.o
10893diff --git a/arch/sparc/lib/atomic_64.S b/arch/sparc/lib/atomic_64.S
10894index 85c233d..68500e0 100644
10895--- a/arch/sparc/lib/atomic_64.S
10896+++ b/arch/sparc/lib/atomic_64.S
10897@@ -17,7 +17,12 @@
10898 ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
10899 BACKOFF_SETUP(%o2)
10900 1: lduw [%o1], %g1
10901- add %g1, %o0, %g7
10902+ addcc %g1, %o0, %g7
10903+
10904+#ifdef CONFIG_PAX_REFCOUNT
10905+ tvs %icc, 6
10906+#endif
10907+
10908 cas [%o1], %g1, %g7
10909 cmp %g1, %g7
10910 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
10911@@ -27,10 +32,28 @@ ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
10912 2: BACKOFF_SPIN(%o2, %o3, 1b)
10913 ENDPROC(atomic_add)
10914
10915+ENTRY(atomic_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
10916+ BACKOFF_SETUP(%o2)
10917+1: lduw [%o1], %g1
10918+ add %g1, %o0, %g7
10919+ cas [%o1], %g1, %g7
10920+ cmp %g1, %g7
10921+ bne,pn %icc, 2f
10922+ nop
10923+ retl
10924+ nop
10925+2: BACKOFF_SPIN(%o2, %o3, 1b)
10926+ENDPROC(atomic_add_unchecked)
10927+
10928 ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
10929 BACKOFF_SETUP(%o2)
10930 1: lduw [%o1], %g1
10931- sub %g1, %o0, %g7
10932+ subcc %g1, %o0, %g7
10933+
10934+#ifdef CONFIG_PAX_REFCOUNT
10935+ tvs %icc, 6
10936+#endif
10937+
10938 cas [%o1], %g1, %g7
10939 cmp %g1, %g7
10940 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
10941@@ -40,10 +63,28 @@ ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
10942 2: BACKOFF_SPIN(%o2, %o3, 1b)
10943 ENDPROC(atomic_sub)
10944
10945+ENTRY(atomic_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
10946+ BACKOFF_SETUP(%o2)
10947+1: lduw [%o1], %g1
10948+ sub %g1, %o0, %g7
10949+ cas [%o1], %g1, %g7
10950+ cmp %g1, %g7
10951+ bne,pn %icc, 2f
10952+ nop
10953+ retl
10954+ nop
10955+2: BACKOFF_SPIN(%o2, %o3, 1b)
10956+ENDPROC(atomic_sub_unchecked)
10957+
10958 ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
10959 BACKOFF_SETUP(%o2)
10960 1: lduw [%o1], %g1
10961- add %g1, %o0, %g7
10962+ addcc %g1, %o0, %g7
10963+
10964+#ifdef CONFIG_PAX_REFCOUNT
10965+ tvs %icc, 6
10966+#endif
10967+
10968 cas [%o1], %g1, %g7
10969 cmp %g1, %g7
10970 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
10971@@ -53,10 +94,29 @@ ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
10972 2: BACKOFF_SPIN(%o2, %o3, 1b)
10973 ENDPROC(atomic_add_ret)
10974
10975+ENTRY(atomic_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
10976+ BACKOFF_SETUP(%o2)
10977+1: lduw [%o1], %g1
10978+ addcc %g1, %o0, %g7
10979+ cas [%o1], %g1, %g7
10980+ cmp %g1, %g7
10981+ bne,pn %icc, 2f
10982+ add %g7, %o0, %g7
10983+ sra %g7, 0, %o0
10984+ retl
10985+ nop
10986+2: BACKOFF_SPIN(%o2, %o3, 1b)
10987+ENDPROC(atomic_add_ret_unchecked)
10988+
10989 ENTRY(atomic_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
10990 BACKOFF_SETUP(%o2)
10991 1: lduw [%o1], %g1
10992- sub %g1, %o0, %g7
10993+ subcc %g1, %o0, %g7
10994+
10995+#ifdef CONFIG_PAX_REFCOUNT
10996+ tvs %icc, 6
10997+#endif
10998+
10999 cas [%o1], %g1, %g7
11000 cmp %g1, %g7
11001 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
11002@@ -69,7 +129,12 @@ ENDPROC(atomic_sub_ret)
11003 ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
11004 BACKOFF_SETUP(%o2)
11005 1: ldx [%o1], %g1
11006- add %g1, %o0, %g7
11007+ addcc %g1, %o0, %g7
11008+
11009+#ifdef CONFIG_PAX_REFCOUNT
11010+ tvs %xcc, 6
11011+#endif
11012+
11013 casx [%o1], %g1, %g7
11014 cmp %g1, %g7
11015 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
11016@@ -79,10 +144,28 @@ ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
11017 2: BACKOFF_SPIN(%o2, %o3, 1b)
11018 ENDPROC(atomic64_add)
11019
11020+ENTRY(atomic64_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
11021+ BACKOFF_SETUP(%o2)
11022+1: ldx [%o1], %g1
11023+ addcc %g1, %o0, %g7
11024+ casx [%o1], %g1, %g7
11025+ cmp %g1, %g7
11026+ bne,pn %xcc, 2f
11027+ nop
11028+ retl
11029+ nop
11030+2: BACKOFF_SPIN(%o2, %o3, 1b)
11031+ENDPROC(atomic64_add_unchecked)
11032+
11033 ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
11034 BACKOFF_SETUP(%o2)
11035 1: ldx [%o1], %g1
11036- sub %g1, %o0, %g7
11037+ subcc %g1, %o0, %g7
11038+
11039+#ifdef CONFIG_PAX_REFCOUNT
11040+ tvs %xcc, 6
11041+#endif
11042+
11043 casx [%o1], %g1, %g7
11044 cmp %g1, %g7
11045 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
11046@@ -92,10 +175,28 @@ ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
11047 2: BACKOFF_SPIN(%o2, %o3, 1b)
11048 ENDPROC(atomic64_sub)
11049
11050+ENTRY(atomic64_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
11051+ BACKOFF_SETUP(%o2)
11052+1: ldx [%o1], %g1
11053+ subcc %g1, %o0, %g7
11054+ casx [%o1], %g1, %g7
11055+ cmp %g1, %g7
11056+ bne,pn %xcc, 2f
11057+ nop
11058+ retl
11059+ nop
11060+2: BACKOFF_SPIN(%o2, %o3, 1b)
11061+ENDPROC(atomic64_sub_unchecked)
11062+
11063 ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
11064 BACKOFF_SETUP(%o2)
11065 1: ldx [%o1], %g1
11066- add %g1, %o0, %g7
11067+ addcc %g1, %o0, %g7
11068+
11069+#ifdef CONFIG_PAX_REFCOUNT
11070+ tvs %xcc, 6
11071+#endif
11072+
11073 casx [%o1], %g1, %g7
11074 cmp %g1, %g7
11075 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
11076@@ -105,10 +206,29 @@ ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
11077 2: BACKOFF_SPIN(%o2, %o3, 1b)
11078 ENDPROC(atomic64_add_ret)
11079
11080+ENTRY(atomic64_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
11081+ BACKOFF_SETUP(%o2)
11082+1: ldx [%o1], %g1
11083+ addcc %g1, %o0, %g7
11084+ casx [%o1], %g1, %g7
11085+ cmp %g1, %g7
11086+ bne,pn %xcc, 2f
11087+ add %g7, %o0, %g7
11088+ mov %g7, %o0
11089+ retl
11090+ nop
11091+2: BACKOFF_SPIN(%o2, %o3, 1b)
11092+ENDPROC(atomic64_add_ret_unchecked)
11093+
11094 ENTRY(atomic64_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
11095 BACKOFF_SETUP(%o2)
11096 1: ldx [%o1], %g1
11097- sub %g1, %o0, %g7
11098+ subcc %g1, %o0, %g7
11099+
11100+#ifdef CONFIG_PAX_REFCOUNT
11101+ tvs %xcc, 6
11102+#endif
11103+
11104 casx [%o1], %g1, %g7
11105 cmp %g1, %g7
11106 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
11107diff --git a/arch/sparc/lib/ksyms.c b/arch/sparc/lib/ksyms.c
11108index 323335b..ed85ea2 100644
11109--- a/arch/sparc/lib/ksyms.c
11110+++ b/arch/sparc/lib/ksyms.c
11111@@ -100,12 +100,18 @@ EXPORT_SYMBOL(__clear_user);
11112
11113 /* Atomic counter implementation. */
11114 EXPORT_SYMBOL(atomic_add);
11115+EXPORT_SYMBOL(atomic_add_unchecked);
11116 EXPORT_SYMBOL(atomic_add_ret);
11117+EXPORT_SYMBOL(atomic_add_ret_unchecked);
11118 EXPORT_SYMBOL(atomic_sub);
11119+EXPORT_SYMBOL(atomic_sub_unchecked);
11120 EXPORT_SYMBOL(atomic_sub_ret);
11121 EXPORT_SYMBOL(atomic64_add);
11122+EXPORT_SYMBOL(atomic64_add_unchecked);
11123 EXPORT_SYMBOL(atomic64_add_ret);
11124+EXPORT_SYMBOL(atomic64_add_ret_unchecked);
11125 EXPORT_SYMBOL(atomic64_sub);
11126+EXPORT_SYMBOL(atomic64_sub_unchecked);
11127 EXPORT_SYMBOL(atomic64_sub_ret);
11128 EXPORT_SYMBOL(atomic64_dec_if_positive);
11129
11130diff --git a/arch/sparc/mm/Makefile b/arch/sparc/mm/Makefile
11131index 30c3ecc..736f015 100644
11132--- a/arch/sparc/mm/Makefile
11133+++ b/arch/sparc/mm/Makefile
11134@@ -2,7 +2,7 @@
11135 #
11136
11137 asflags-y := -ansi
11138-ccflags-y := -Werror
11139+#ccflags-y := -Werror
11140
11141 obj-$(CONFIG_SPARC64) += ultra.o tlb.o tsb.o gup.o
11142 obj-y += fault_$(BITS).o
11143diff --git a/arch/sparc/mm/fault_32.c b/arch/sparc/mm/fault_32.c
11144index 59dbd46..1dd7f5e 100644
11145--- a/arch/sparc/mm/fault_32.c
11146+++ b/arch/sparc/mm/fault_32.c
11147@@ -21,6 +21,9 @@
11148 #include <linux/perf_event.h>
11149 #include <linux/interrupt.h>
11150 #include <linux/kdebug.h>
11151+#include <linux/slab.h>
11152+#include <linux/pagemap.h>
11153+#include <linux/compiler.h>
11154
11155 #include <asm/page.h>
11156 #include <asm/pgtable.h>
11157@@ -159,6 +162,277 @@ static unsigned long compute_si_addr(struct pt_regs *regs, int text_fault)
11158 return safe_compute_effective_address(regs, insn);
11159 }
11160
11161+#ifdef CONFIG_PAX_PAGEEXEC
11162+#ifdef CONFIG_PAX_DLRESOLVE
11163+static void pax_emuplt_close(struct vm_area_struct *vma)
11164+{
11165+ vma->vm_mm->call_dl_resolve = 0UL;
11166+}
11167+
11168+static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
11169+{
11170+ unsigned int *kaddr;
11171+
11172+ vmf->page = alloc_page(GFP_HIGHUSER);
11173+ if (!vmf->page)
11174+ return VM_FAULT_OOM;
11175+
11176+ kaddr = kmap(vmf->page);
11177+ memset(kaddr, 0, PAGE_SIZE);
11178+ kaddr[0] = 0x9DE3BFA8U; /* save */
11179+ flush_dcache_page(vmf->page);
11180+ kunmap(vmf->page);
11181+ return VM_FAULT_MAJOR;
11182+}
11183+
11184+static const struct vm_operations_struct pax_vm_ops = {
11185+ .close = pax_emuplt_close,
11186+ .fault = pax_emuplt_fault
11187+};
11188+
11189+static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
11190+{
11191+ int ret;
11192+
11193+ INIT_LIST_HEAD(&vma->anon_vma_chain);
11194+ vma->vm_mm = current->mm;
11195+ vma->vm_start = addr;
11196+ vma->vm_end = addr + PAGE_SIZE;
11197+ vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
11198+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
11199+ vma->vm_ops = &pax_vm_ops;
11200+
11201+ ret = insert_vm_struct(current->mm, vma);
11202+ if (ret)
11203+ return ret;
11204+
11205+ ++current->mm->total_vm;
11206+ return 0;
11207+}
11208+#endif
11209+
11210+/*
11211+ * PaX: decide what to do with offenders (regs->pc = fault address)
11212+ *
11213+ * returns 1 when task should be killed
11214+ * 2 when patched PLT trampoline was detected
11215+ * 3 when unpatched PLT trampoline was detected
11216+ */
11217+static int pax_handle_fetch_fault(struct pt_regs *regs)
11218+{
11219+
11220+#ifdef CONFIG_PAX_EMUPLT
11221+ int err;
11222+
11223+ do { /* PaX: patched PLT emulation #1 */
11224+ unsigned int sethi1, sethi2, jmpl;
11225+
11226+ err = get_user(sethi1, (unsigned int *)regs->pc);
11227+ err |= get_user(sethi2, (unsigned int *)(regs->pc+4));
11228+ err |= get_user(jmpl, (unsigned int *)(regs->pc+8));
11229+
11230+ if (err)
11231+ break;
11232+
11233+ if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
11234+ (sethi2 & 0xFFC00000U) == 0x03000000U &&
11235+ (jmpl & 0xFFFFE000U) == 0x81C06000U)
11236+ {
11237+ unsigned int addr;
11238+
11239+ regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
11240+ addr = regs->u_regs[UREG_G1];
11241+ addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
11242+ regs->pc = addr;
11243+ regs->npc = addr+4;
11244+ return 2;
11245+ }
11246+ } while (0);
11247+
11248+ do { /* PaX: patched PLT emulation #2 */
11249+ unsigned int ba;
11250+
11251+ err = get_user(ba, (unsigned int *)regs->pc);
11252+
11253+ if (err)
11254+ break;
11255+
11256+ if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
11257+ unsigned int addr;
11258+
11259+ if ((ba & 0xFFC00000U) == 0x30800000U)
11260+ addr = regs->pc + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
11261+ else
11262+ addr = regs->pc + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
11263+ regs->pc = addr;
11264+ regs->npc = addr+4;
11265+ return 2;
11266+ }
11267+ } while (0);
11268+
11269+ do { /* PaX: patched PLT emulation #3 */
11270+ unsigned int sethi, bajmpl, nop;
11271+
11272+ err = get_user(sethi, (unsigned int *)regs->pc);
11273+ err |= get_user(bajmpl, (unsigned int *)(regs->pc+4));
11274+ err |= get_user(nop, (unsigned int *)(regs->pc+8));
11275+
11276+ if (err)
11277+ break;
11278+
11279+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
11280+ ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
11281+ nop == 0x01000000U)
11282+ {
11283+ unsigned int addr;
11284+
11285+ addr = (sethi & 0x003FFFFFU) << 10;
11286+ regs->u_regs[UREG_G1] = addr;
11287+ if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
11288+ addr += (((bajmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
11289+ else
11290+ addr = regs->pc + ((((bajmpl | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
11291+ regs->pc = addr;
11292+ regs->npc = addr+4;
11293+ return 2;
11294+ }
11295+ } while (0);
11296+
11297+ do { /* PaX: unpatched PLT emulation step 1 */
11298+ unsigned int sethi, ba, nop;
11299+
11300+ err = get_user(sethi, (unsigned int *)regs->pc);
11301+ err |= get_user(ba, (unsigned int *)(regs->pc+4));
11302+ err |= get_user(nop, (unsigned int *)(regs->pc+8));
11303+
11304+ if (err)
11305+ break;
11306+
11307+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
11308+ ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
11309+ nop == 0x01000000U)
11310+ {
11311+ unsigned int addr, save, call;
11312+
11313+ if ((ba & 0xFFC00000U) == 0x30800000U)
11314+ addr = regs->pc + 4 + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
11315+ else
11316+ addr = regs->pc + 4 + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
11317+
11318+ err = get_user(save, (unsigned int *)addr);
11319+ err |= get_user(call, (unsigned int *)(addr+4));
11320+ err |= get_user(nop, (unsigned int *)(addr+8));
11321+ if (err)
11322+ break;
11323+
11324+#ifdef CONFIG_PAX_DLRESOLVE
11325+ if (save == 0x9DE3BFA8U &&
11326+ (call & 0xC0000000U) == 0x40000000U &&
11327+ nop == 0x01000000U)
11328+ {
11329+ struct vm_area_struct *vma;
11330+ unsigned long call_dl_resolve;
11331+
11332+ down_read(&current->mm->mmap_sem);
11333+ call_dl_resolve = current->mm->call_dl_resolve;
11334+ up_read(&current->mm->mmap_sem);
11335+ if (likely(call_dl_resolve))
11336+ goto emulate;
11337+
11338+ vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
11339+
11340+ down_write(&current->mm->mmap_sem);
11341+ if (current->mm->call_dl_resolve) {
11342+ call_dl_resolve = current->mm->call_dl_resolve;
11343+ up_write(&current->mm->mmap_sem);
11344+ if (vma)
11345+ kmem_cache_free(vm_area_cachep, vma);
11346+ goto emulate;
11347+ }
11348+
11349+ call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
11350+ if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
11351+ up_write(&current->mm->mmap_sem);
11352+ if (vma)
11353+ kmem_cache_free(vm_area_cachep, vma);
11354+ return 1;
11355+ }
11356+
11357+ if (pax_insert_vma(vma, call_dl_resolve)) {
11358+ up_write(&current->mm->mmap_sem);
11359+ kmem_cache_free(vm_area_cachep, vma);
11360+ return 1;
11361+ }
11362+
11363+ current->mm->call_dl_resolve = call_dl_resolve;
11364+ up_write(&current->mm->mmap_sem);
11365+
11366+emulate:
11367+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
11368+ regs->pc = call_dl_resolve;
11369+ regs->npc = addr+4;
11370+ return 3;
11371+ }
11372+#endif
11373+
11374+ /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
11375+ if ((save & 0xFFC00000U) == 0x05000000U &&
11376+ (call & 0xFFFFE000U) == 0x85C0A000U &&
11377+ nop == 0x01000000U)
11378+ {
11379+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
11380+ regs->u_regs[UREG_G2] = addr + 4;
11381+ addr = (save & 0x003FFFFFU) << 10;
11382+ addr += (((call | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
11383+ regs->pc = addr;
11384+ regs->npc = addr+4;
11385+ return 3;
11386+ }
11387+ }
11388+ } while (0);
11389+
11390+ do { /* PaX: unpatched PLT emulation step 2 */
11391+ unsigned int save, call, nop;
11392+
11393+ err = get_user(save, (unsigned int *)(regs->pc-4));
11394+ err |= get_user(call, (unsigned int *)regs->pc);
11395+ err |= get_user(nop, (unsigned int *)(regs->pc+4));
11396+ if (err)
11397+ break;
11398+
11399+ if (save == 0x9DE3BFA8U &&
11400+ (call & 0xC0000000U) == 0x40000000U &&
11401+ nop == 0x01000000U)
11402+ {
11403+ unsigned int dl_resolve = regs->pc + ((((call | 0xC0000000U) ^ 0x20000000U) + 0x20000000U) << 2);
11404+
11405+ regs->u_regs[UREG_RETPC] = regs->pc;
11406+ regs->pc = dl_resolve;
11407+ regs->npc = dl_resolve+4;
11408+ return 3;
11409+ }
11410+ } while (0);
11411+#endif
11412+
11413+ return 1;
11414+}
11415+
11416+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
11417+{
11418+ unsigned long i;
11419+
11420+ printk(KERN_ERR "PAX: bytes at PC: ");
11421+ for (i = 0; i < 8; i++) {
11422+ unsigned int c;
11423+ if (get_user(c, (unsigned int *)pc+i))
11424+ printk(KERN_CONT "???????? ");
11425+ else
11426+ printk(KERN_CONT "%08x ", c);
11427+ }
11428+ printk("\n");
11429+}
11430+#endif
11431+
11432 static noinline void do_fault_siginfo(int code, int sig, struct pt_regs *regs,
11433 int text_fault)
11434 {
11435@@ -229,6 +503,24 @@ good_area:
11436 if (!(vma->vm_flags & VM_WRITE))
11437 goto bad_area;
11438 } else {
11439+
11440+#ifdef CONFIG_PAX_PAGEEXEC
11441+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && text_fault && !(vma->vm_flags & VM_EXEC)) {
11442+ up_read(&mm->mmap_sem);
11443+ switch (pax_handle_fetch_fault(regs)) {
11444+
11445+#ifdef CONFIG_PAX_EMUPLT
11446+ case 2:
11447+ case 3:
11448+ return;
11449+#endif
11450+
11451+ }
11452+ pax_report_fault(regs, (void *)regs->pc, (void *)regs->u_regs[UREG_FP]);
11453+ do_group_exit(SIGKILL);
11454+ }
11455+#endif
11456+
11457 /* Allow reads even for write-only mappings */
11458 if (!(vma->vm_flags & (VM_READ | VM_EXEC)))
11459 goto bad_area;
11460diff --git a/arch/sparc/mm/fault_64.c b/arch/sparc/mm/fault_64.c
11461index 69bb818..3542236 100644
11462--- a/arch/sparc/mm/fault_64.c
11463+++ b/arch/sparc/mm/fault_64.c
11464@@ -22,6 +22,9 @@
11465 #include <linux/kdebug.h>
11466 #include <linux/percpu.h>
11467 #include <linux/context_tracking.h>
11468+#include <linux/slab.h>
11469+#include <linux/pagemap.h>
11470+#include <linux/compiler.h>
11471
11472 #include <asm/page.h>
11473 #include <asm/pgtable.h>
11474@@ -75,7 +78,7 @@ static void __kprobes bad_kernel_pc(struct pt_regs *regs, unsigned long vaddr)
11475 printk(KERN_CRIT "OOPS: Bogus kernel PC [%016lx] in fault handler\n",
11476 regs->tpc);
11477 printk(KERN_CRIT "OOPS: RPC [%016lx]\n", regs->u_regs[15]);
11478- printk("OOPS: RPC <%pS>\n", (void *) regs->u_regs[15]);
11479+ printk("OOPS: RPC <%pA>\n", (void *) regs->u_regs[15]);
11480 printk(KERN_CRIT "OOPS: Fault was to vaddr[%lx]\n", vaddr);
11481 dump_stack();
11482 unhandled_fault(regs->tpc, current, regs);
11483@@ -96,38 +99,51 @@ static unsigned int get_user_insn(unsigned long tpc)
11484 pte_t *ptep, pte;
11485 unsigned long pa;
11486 u32 insn = 0;
11487- unsigned long pstate;
11488
11489- if (pgd_none(*pgdp))
11490- goto outret;
11491+ if (pgd_none(*pgdp) || unlikely(pgd_bad(*pgdp)))
11492+ goto out;
11493 pudp = pud_offset(pgdp, tpc);
11494- if (pud_none(*pudp))
11495- goto outret;
11496- pmdp = pmd_offset(pudp, tpc);
11497- if (pmd_none(*pmdp))
11498- goto outret;
11499+ if (pud_none(*pudp) || unlikely(pud_bad(*pudp)))
11500+ goto out;
11501
11502 /* This disables preemption for us as well. */
11503- __asm__ __volatile__("rdpr %%pstate, %0" : "=r" (pstate));
11504- __asm__ __volatile__("wrpr %0, %1, %%pstate"
11505- : : "r" (pstate), "i" (PSTATE_IE));
11506- ptep = pte_offset_map(pmdp, tpc);
11507- pte = *ptep;
11508- if (!pte_present(pte))
11509- goto out;
11510+ local_irq_disable();
11511
11512- pa = (pte_pfn(pte) << PAGE_SHIFT);
11513- pa += (tpc & ~PAGE_MASK);
11514+ pmdp = pmd_offset(pudp, tpc);
11515+ if (pmd_none(*pmdp) || unlikely(pmd_bad(*pmdp)))
11516+ goto out_irq_enable;
11517
11518- /* Use phys bypass so we don't pollute dtlb/dcache. */
11519- __asm__ __volatile__("lduwa [%1] %2, %0"
11520- : "=r" (insn)
11521- : "r" (pa), "i" (ASI_PHYS_USE_EC));
11522+#ifdef CONFIG_TRANSPARENT_HUGEPAGE
11523+ if (pmd_trans_huge(*pmdp)) {
11524+ if (pmd_trans_splitting(*pmdp))
11525+ goto out_irq_enable;
11526
11527+ pa = pmd_pfn(*pmdp) << PAGE_SHIFT;
11528+ pa += tpc & ~HPAGE_MASK;
11529+
11530+ /* Use phys bypass so we don't pollute dtlb/dcache. */
11531+ __asm__ __volatile__("lduwa [%1] %2, %0"
11532+ : "=r" (insn)
11533+ : "r" (pa), "i" (ASI_PHYS_USE_EC));
11534+ } else
11535+#endif
11536+ {
11537+ ptep = pte_offset_map(pmdp, tpc);
11538+ pte = *ptep;
11539+ if (pte_present(pte)) {
11540+ pa = (pte_pfn(pte) << PAGE_SHIFT);
11541+ pa += (tpc & ~PAGE_MASK);
11542+
11543+ /* Use phys bypass so we don't pollute dtlb/dcache. */
11544+ __asm__ __volatile__("lduwa [%1] %2, %0"
11545+ : "=r" (insn)
11546+ : "r" (pa), "i" (ASI_PHYS_USE_EC));
11547+ }
11548+ pte_unmap(ptep);
11549+ }
11550+out_irq_enable:
11551+ local_irq_enable();
11552 out:
11553- pte_unmap(ptep);
11554- __asm__ __volatile__("wrpr %0, 0x0, %%pstate" : : "r" (pstate));
11555-outret:
11556 return insn;
11557 }
11558
11559@@ -153,7 +169,8 @@ show_signal_msg(struct pt_regs *regs, int sig, int code,
11560 }
11561
11562 static void do_fault_siginfo(int code, int sig, struct pt_regs *regs,
11563- unsigned int insn, int fault_code)
11564+ unsigned long fault_addr, unsigned int insn,
11565+ int fault_code)
11566 {
11567 unsigned long addr;
11568 siginfo_t info;
11569@@ -161,10 +178,18 @@ static void do_fault_siginfo(int code, int sig, struct pt_regs *regs,
11570 info.si_code = code;
11571 info.si_signo = sig;
11572 info.si_errno = 0;
11573- if (fault_code & FAULT_CODE_ITLB)
11574+ if (fault_code & FAULT_CODE_ITLB) {
11575 addr = regs->tpc;
11576- else
11577- addr = compute_effective_address(regs, insn, 0);
11578+ } else {
11579+ /* If we were able to probe the faulting instruction, use it
11580+ * to compute a precise fault address. Otherwise use the fault
11581+ * time provided address which may only have page granularity.
11582+ */
11583+ if (insn)
11584+ addr = compute_effective_address(regs, insn, 0);
11585+ else
11586+ addr = fault_addr;
11587+ }
11588 info.si_addr = (void __user *) addr;
11589 info.si_trapno = 0;
11590
11591@@ -239,7 +264,7 @@ static void __kprobes do_kernel_fault(struct pt_regs *regs, int si_code,
11592 /* The si_code was set to make clear whether
11593 * this was a SEGV_MAPERR or SEGV_ACCERR fault.
11594 */
11595- do_fault_siginfo(si_code, SIGSEGV, regs, insn, fault_code);
11596+ do_fault_siginfo(si_code, SIGSEGV, regs, address, insn, fault_code);
11597 return;
11598 }
11599
11600@@ -271,6 +296,466 @@ static void noinline __kprobes bogus_32bit_fault_address(struct pt_regs *regs,
11601 show_regs(regs);
11602 }
11603
11604+#ifdef CONFIG_PAX_PAGEEXEC
11605+#ifdef CONFIG_PAX_DLRESOLVE
11606+static void pax_emuplt_close(struct vm_area_struct *vma)
11607+{
11608+ vma->vm_mm->call_dl_resolve = 0UL;
11609+}
11610+
11611+static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
11612+{
11613+ unsigned int *kaddr;
11614+
11615+ vmf->page = alloc_page(GFP_HIGHUSER);
11616+ if (!vmf->page)
11617+ return VM_FAULT_OOM;
11618+
11619+ kaddr = kmap(vmf->page);
11620+ memset(kaddr, 0, PAGE_SIZE);
11621+ kaddr[0] = 0x9DE3BFA8U; /* save */
11622+ flush_dcache_page(vmf->page);
11623+ kunmap(vmf->page);
11624+ return VM_FAULT_MAJOR;
11625+}
11626+
11627+static const struct vm_operations_struct pax_vm_ops = {
11628+ .close = pax_emuplt_close,
11629+ .fault = pax_emuplt_fault
11630+};
11631+
11632+static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
11633+{
11634+ int ret;
11635+
11636+ INIT_LIST_HEAD(&vma->anon_vma_chain);
11637+ vma->vm_mm = current->mm;
11638+ vma->vm_start = addr;
11639+ vma->vm_end = addr + PAGE_SIZE;
11640+ vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
11641+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
11642+ vma->vm_ops = &pax_vm_ops;
11643+
11644+ ret = insert_vm_struct(current->mm, vma);
11645+ if (ret)
11646+ return ret;
11647+
11648+ ++current->mm->total_vm;
11649+ return 0;
11650+}
11651+#endif
11652+
11653+/*
11654+ * PaX: decide what to do with offenders (regs->tpc = fault address)
11655+ *
11656+ * returns 1 when task should be killed
11657+ * 2 when patched PLT trampoline was detected
11658+ * 3 when unpatched PLT trampoline was detected
11659+ */
11660+static int pax_handle_fetch_fault(struct pt_regs *regs)
11661+{
11662+
11663+#ifdef CONFIG_PAX_EMUPLT
11664+ int err;
11665+
11666+ do { /* PaX: patched PLT emulation #1 */
11667+ unsigned int sethi1, sethi2, jmpl;
11668+
11669+ err = get_user(sethi1, (unsigned int *)regs->tpc);
11670+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+4));
11671+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+8));
11672+
11673+ if (err)
11674+ break;
11675+
11676+ if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
11677+ (sethi2 & 0xFFC00000U) == 0x03000000U &&
11678+ (jmpl & 0xFFFFE000U) == 0x81C06000U)
11679+ {
11680+ unsigned long addr;
11681+
11682+ regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
11683+ addr = regs->u_regs[UREG_G1];
11684+ addr += (((jmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
11685+
11686+ if (test_thread_flag(TIF_32BIT))
11687+ addr &= 0xFFFFFFFFUL;
11688+
11689+ regs->tpc = addr;
11690+ regs->tnpc = addr+4;
11691+ return 2;
11692+ }
11693+ } while (0);
11694+
11695+ do { /* PaX: patched PLT emulation #2 */
11696+ unsigned int ba;
11697+
11698+ err = get_user(ba, (unsigned int *)regs->tpc);
11699+
11700+ if (err)
11701+ break;
11702+
11703+ if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
11704+ unsigned long addr;
11705+
11706+ if ((ba & 0xFFC00000U) == 0x30800000U)
11707+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
11708+ else
11709+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
11710+
11711+ if (test_thread_flag(TIF_32BIT))
11712+ addr &= 0xFFFFFFFFUL;
11713+
11714+ regs->tpc = addr;
11715+ regs->tnpc = addr+4;
11716+ return 2;
11717+ }
11718+ } while (0);
11719+
11720+ do { /* PaX: patched PLT emulation #3 */
11721+ unsigned int sethi, bajmpl, nop;
11722+
11723+ err = get_user(sethi, (unsigned int *)regs->tpc);
11724+ err |= get_user(bajmpl, (unsigned int *)(regs->tpc+4));
11725+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
11726+
11727+ if (err)
11728+ break;
11729+
11730+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
11731+ ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
11732+ nop == 0x01000000U)
11733+ {
11734+ unsigned long addr;
11735+
11736+ addr = (sethi & 0x003FFFFFU) << 10;
11737+ regs->u_regs[UREG_G1] = addr;
11738+ if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
11739+ addr += (((bajmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
11740+ else
11741+ addr = regs->tpc + ((((bajmpl | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
11742+
11743+ if (test_thread_flag(TIF_32BIT))
11744+ addr &= 0xFFFFFFFFUL;
11745+
11746+ regs->tpc = addr;
11747+ regs->tnpc = addr+4;
11748+ return 2;
11749+ }
11750+ } while (0);
11751+
11752+ do { /* PaX: patched PLT emulation #4 */
11753+ unsigned int sethi, mov1, call, mov2;
11754+
11755+ err = get_user(sethi, (unsigned int *)regs->tpc);
11756+ err |= get_user(mov1, (unsigned int *)(regs->tpc+4));
11757+ err |= get_user(call, (unsigned int *)(regs->tpc+8));
11758+ err |= get_user(mov2, (unsigned int *)(regs->tpc+12));
11759+
11760+ if (err)
11761+ break;
11762+
11763+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
11764+ mov1 == 0x8210000FU &&
11765+ (call & 0xC0000000U) == 0x40000000U &&
11766+ mov2 == 0x9E100001U)
11767+ {
11768+ unsigned long addr;
11769+
11770+ regs->u_regs[UREG_G1] = regs->u_regs[UREG_RETPC];
11771+ addr = regs->tpc + 4 + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
11772+
11773+ if (test_thread_flag(TIF_32BIT))
11774+ addr &= 0xFFFFFFFFUL;
11775+
11776+ regs->tpc = addr;
11777+ regs->tnpc = addr+4;
11778+ return 2;
11779+ }
11780+ } while (0);
11781+
11782+ do { /* PaX: patched PLT emulation #5 */
11783+ unsigned int sethi, sethi1, sethi2, or1, or2, sllx, jmpl, nop;
11784+
11785+ err = get_user(sethi, (unsigned int *)regs->tpc);
11786+ err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
11787+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
11788+ err |= get_user(or1, (unsigned int *)(regs->tpc+12));
11789+ err |= get_user(or2, (unsigned int *)(regs->tpc+16));
11790+ err |= get_user(sllx, (unsigned int *)(regs->tpc+20));
11791+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+24));
11792+ err |= get_user(nop, (unsigned int *)(regs->tpc+28));
11793+
11794+ if (err)
11795+ break;
11796+
11797+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
11798+ (sethi1 & 0xFFC00000U) == 0x03000000U &&
11799+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
11800+ (or1 & 0xFFFFE000U) == 0x82106000U &&
11801+ (or2 & 0xFFFFE000U) == 0x8A116000U &&
11802+ sllx == 0x83287020U &&
11803+ jmpl == 0x81C04005U &&
11804+ nop == 0x01000000U)
11805+ {
11806+ unsigned long addr;
11807+
11808+ regs->u_regs[UREG_G1] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
11809+ regs->u_regs[UREG_G1] <<= 32;
11810+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
11811+ addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
11812+ regs->tpc = addr;
11813+ regs->tnpc = addr+4;
11814+ return 2;
11815+ }
11816+ } while (0);
11817+
11818+ do { /* PaX: patched PLT emulation #6 */
11819+ unsigned int sethi, sethi1, sethi2, sllx, or, jmpl, nop;
11820+
11821+ err = get_user(sethi, (unsigned int *)regs->tpc);
11822+ err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
11823+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
11824+ err |= get_user(sllx, (unsigned int *)(regs->tpc+12));
11825+ err |= get_user(or, (unsigned int *)(regs->tpc+16));
11826+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+20));
11827+ err |= get_user(nop, (unsigned int *)(regs->tpc+24));
11828+
11829+ if (err)
11830+ break;
11831+
11832+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
11833+ (sethi1 & 0xFFC00000U) == 0x03000000U &&
11834+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
11835+ sllx == 0x83287020U &&
11836+ (or & 0xFFFFE000U) == 0x8A116000U &&
11837+ jmpl == 0x81C04005U &&
11838+ nop == 0x01000000U)
11839+ {
11840+ unsigned long addr;
11841+
11842+ regs->u_regs[UREG_G1] = (sethi1 & 0x003FFFFFU) << 10;
11843+ regs->u_regs[UREG_G1] <<= 32;
11844+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or & 0x3FFU);
11845+ addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
11846+ regs->tpc = addr;
11847+ regs->tnpc = addr+4;
11848+ return 2;
11849+ }
11850+ } while (0);
11851+
11852+ do { /* PaX: unpatched PLT emulation step 1 */
11853+ unsigned int sethi, ba, nop;
11854+
11855+ err = get_user(sethi, (unsigned int *)regs->tpc);
11856+ err |= get_user(ba, (unsigned int *)(regs->tpc+4));
11857+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
11858+
11859+ if (err)
11860+ break;
11861+
11862+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
11863+ ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
11864+ nop == 0x01000000U)
11865+ {
11866+ unsigned long addr;
11867+ unsigned int save, call;
11868+ unsigned int sethi1, sethi2, or1, or2, sllx, add, jmpl;
11869+
11870+ if ((ba & 0xFFC00000U) == 0x30800000U)
11871+ addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
11872+ else
11873+ addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
11874+
11875+ if (test_thread_flag(TIF_32BIT))
11876+ addr &= 0xFFFFFFFFUL;
11877+
11878+ err = get_user(save, (unsigned int *)addr);
11879+ err |= get_user(call, (unsigned int *)(addr+4));
11880+ err |= get_user(nop, (unsigned int *)(addr+8));
11881+ if (err)
11882+ break;
11883+
11884+#ifdef CONFIG_PAX_DLRESOLVE
11885+ if (save == 0x9DE3BFA8U &&
11886+ (call & 0xC0000000U) == 0x40000000U &&
11887+ nop == 0x01000000U)
11888+ {
11889+ struct vm_area_struct *vma;
11890+ unsigned long call_dl_resolve;
11891+
11892+ down_read(&current->mm->mmap_sem);
11893+ call_dl_resolve = current->mm->call_dl_resolve;
11894+ up_read(&current->mm->mmap_sem);
11895+ if (likely(call_dl_resolve))
11896+ goto emulate;
11897+
11898+ vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
11899+
11900+ down_write(&current->mm->mmap_sem);
11901+ if (current->mm->call_dl_resolve) {
11902+ call_dl_resolve = current->mm->call_dl_resolve;
11903+ up_write(&current->mm->mmap_sem);
11904+ if (vma)
11905+ kmem_cache_free(vm_area_cachep, vma);
11906+ goto emulate;
11907+ }
11908+
11909+ call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
11910+ if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
11911+ up_write(&current->mm->mmap_sem);
11912+ if (vma)
11913+ kmem_cache_free(vm_area_cachep, vma);
11914+ return 1;
11915+ }
11916+
11917+ if (pax_insert_vma(vma, call_dl_resolve)) {
11918+ up_write(&current->mm->mmap_sem);
11919+ kmem_cache_free(vm_area_cachep, vma);
11920+ return 1;
11921+ }
11922+
11923+ current->mm->call_dl_resolve = call_dl_resolve;
11924+ up_write(&current->mm->mmap_sem);
11925+
11926+emulate:
11927+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
11928+ regs->tpc = call_dl_resolve;
11929+ regs->tnpc = addr+4;
11930+ return 3;
11931+ }
11932+#endif
11933+
11934+ /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
11935+ if ((save & 0xFFC00000U) == 0x05000000U &&
11936+ (call & 0xFFFFE000U) == 0x85C0A000U &&
11937+ nop == 0x01000000U)
11938+ {
11939+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
11940+ regs->u_regs[UREG_G2] = addr + 4;
11941+ addr = (save & 0x003FFFFFU) << 10;
11942+ addr += (((call | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
11943+
11944+ if (test_thread_flag(TIF_32BIT))
11945+ addr &= 0xFFFFFFFFUL;
11946+
11947+ regs->tpc = addr;
11948+ regs->tnpc = addr+4;
11949+ return 3;
11950+ }
11951+
11952+ /* PaX: 64-bit PLT stub */
11953+ err = get_user(sethi1, (unsigned int *)addr);
11954+ err |= get_user(sethi2, (unsigned int *)(addr+4));
11955+ err |= get_user(or1, (unsigned int *)(addr+8));
11956+ err |= get_user(or2, (unsigned int *)(addr+12));
11957+ err |= get_user(sllx, (unsigned int *)(addr+16));
11958+ err |= get_user(add, (unsigned int *)(addr+20));
11959+ err |= get_user(jmpl, (unsigned int *)(addr+24));
11960+ err |= get_user(nop, (unsigned int *)(addr+28));
11961+ if (err)
11962+ break;
11963+
11964+ if ((sethi1 & 0xFFC00000U) == 0x09000000U &&
11965+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
11966+ (or1 & 0xFFFFE000U) == 0x88112000U &&
11967+ (or2 & 0xFFFFE000U) == 0x8A116000U &&
11968+ sllx == 0x89293020U &&
11969+ add == 0x8A010005U &&
11970+ jmpl == 0x89C14000U &&
11971+ nop == 0x01000000U)
11972+ {
11973+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
11974+ regs->u_regs[UREG_G4] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
11975+ regs->u_regs[UREG_G4] <<= 32;
11976+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
11977+ regs->u_regs[UREG_G5] += regs->u_regs[UREG_G4];
11978+ regs->u_regs[UREG_G4] = addr + 24;
11979+ addr = regs->u_regs[UREG_G5];
11980+ regs->tpc = addr;
11981+ regs->tnpc = addr+4;
11982+ return 3;
11983+ }
11984+ }
11985+ } while (0);
11986+
11987+#ifdef CONFIG_PAX_DLRESOLVE
11988+ do { /* PaX: unpatched PLT emulation step 2 */
11989+ unsigned int save, call, nop;
11990+
11991+ err = get_user(save, (unsigned int *)(regs->tpc-4));
11992+ err |= get_user(call, (unsigned int *)regs->tpc);
11993+ err |= get_user(nop, (unsigned int *)(regs->tpc+4));
11994+ if (err)
11995+ break;
11996+
11997+ if (save == 0x9DE3BFA8U &&
11998+ (call & 0xC0000000U) == 0x40000000U &&
11999+ nop == 0x01000000U)
12000+ {
12001+ unsigned long dl_resolve = regs->tpc + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
12002+
12003+ if (test_thread_flag(TIF_32BIT))
12004+ dl_resolve &= 0xFFFFFFFFUL;
12005+
12006+ regs->u_regs[UREG_RETPC] = regs->tpc;
12007+ regs->tpc = dl_resolve;
12008+ regs->tnpc = dl_resolve+4;
12009+ return 3;
12010+ }
12011+ } while (0);
12012+#endif
12013+
12014+ do { /* PaX: patched PLT emulation #7, must be AFTER the unpatched PLT emulation */
12015+ unsigned int sethi, ba, nop;
12016+
12017+ err = get_user(sethi, (unsigned int *)regs->tpc);
12018+ err |= get_user(ba, (unsigned int *)(regs->tpc+4));
12019+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
12020+
12021+ if (err)
12022+ break;
12023+
12024+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
12025+ (ba & 0xFFF00000U) == 0x30600000U &&
12026+ nop == 0x01000000U)
12027+ {
12028+ unsigned long addr;
12029+
12030+ addr = (sethi & 0x003FFFFFU) << 10;
12031+ regs->u_regs[UREG_G1] = addr;
12032+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
12033+
12034+ if (test_thread_flag(TIF_32BIT))
12035+ addr &= 0xFFFFFFFFUL;
12036+
12037+ regs->tpc = addr;
12038+ regs->tnpc = addr+4;
12039+ return 2;
12040+ }
12041+ } while (0);
12042+
12043+#endif
12044+
12045+ return 1;
12046+}
12047+
12048+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
12049+{
12050+ unsigned long i;
12051+
12052+ printk(KERN_ERR "PAX: bytes at PC: ");
12053+ for (i = 0; i < 8; i++) {
12054+ unsigned int c;
12055+ if (get_user(c, (unsigned int *)pc+i))
12056+ printk(KERN_CONT "???????? ");
12057+ else
12058+ printk(KERN_CONT "%08x ", c);
12059+ }
12060+ printk("\n");
12061+}
12062+#endif
12063+
12064 asmlinkage void __kprobes do_sparc64_fault(struct pt_regs *regs)
12065 {
12066 enum ctx_state prev_state = exception_enter();
12067@@ -344,6 +829,29 @@ retry:
12068 if (!vma)
12069 goto bad_area;
12070
12071+#ifdef CONFIG_PAX_PAGEEXEC
12072+ /* PaX: detect ITLB misses on non-exec pages */
12073+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && vma->vm_start <= address &&
12074+ !(vma->vm_flags & VM_EXEC) && (fault_code & FAULT_CODE_ITLB))
12075+ {
12076+ if (address != regs->tpc)
12077+ goto good_area;
12078+
12079+ up_read(&mm->mmap_sem);
12080+ switch (pax_handle_fetch_fault(regs)) {
12081+
12082+#ifdef CONFIG_PAX_EMUPLT
12083+ case 2:
12084+ case 3:
12085+ return;
12086+#endif
12087+
12088+ }
12089+ pax_report_fault(regs, (void *)regs->tpc, (void *)(regs->u_regs[UREG_FP] + STACK_BIAS));
12090+ do_group_exit(SIGKILL);
12091+ }
12092+#endif
12093+
12094 /* Pure DTLB misses do not tell us whether the fault causing
12095 * load/store/atomic was a write or not, it only says that there
12096 * was no match. So in such a case we (carefully) read the
12097@@ -525,7 +1033,7 @@ do_sigbus:
12098 * Send a sigbus, regardless of whether we were in kernel
12099 * or user mode.
12100 */
12101- do_fault_siginfo(BUS_ADRERR, SIGBUS, regs, insn, fault_code);
12102+ do_fault_siginfo(BUS_ADRERR, SIGBUS, regs, address, insn, fault_code);
12103
12104 /* Kernel mode? Handle exceptions or die */
12105 if (regs->tstate & TSTATE_PRIV)
12106diff --git a/arch/sparc/mm/gup.c b/arch/sparc/mm/gup.c
12107index c4d3da6..1aed043 100644
12108--- a/arch/sparc/mm/gup.c
12109+++ b/arch/sparc/mm/gup.c
12110@@ -73,7 +73,7 @@ static int gup_huge_pmd(pmd_t *pmdp, pmd_t pmd, unsigned long addr,
12111 struct page *head, *page, *tail;
12112 int refs;
12113
12114- if (!pmd_large(pmd))
12115+ if (!(pmd_val(pmd) & _PAGE_VALID))
12116 return 0;
12117
12118 if (write && !pmd_write(pmd))
12119diff --git a/arch/sparc/mm/hugetlbpage.c b/arch/sparc/mm/hugetlbpage.c
12120index 9bd9ce8..dc84852 100644
12121--- a/arch/sparc/mm/hugetlbpage.c
12122+++ b/arch/sparc/mm/hugetlbpage.c
12123@@ -25,8 +25,10 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *filp,
12124 unsigned long addr,
12125 unsigned long len,
12126 unsigned long pgoff,
12127- unsigned long flags)
12128+ unsigned long flags,
12129+ unsigned long offset)
12130 {
12131+ struct mm_struct *mm = current->mm;
12132 unsigned long task_size = TASK_SIZE;
12133 struct vm_unmapped_area_info info;
12134
12135@@ -35,15 +37,22 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *filp,
12136
12137 info.flags = 0;
12138 info.length = len;
12139- info.low_limit = TASK_UNMAPPED_BASE;
12140+ info.low_limit = mm->mmap_base;
12141 info.high_limit = min(task_size, VA_EXCLUDE_START);
12142 info.align_mask = PAGE_MASK & ~HPAGE_MASK;
12143 info.align_offset = 0;
12144+ info.threadstack_offset = offset;
12145 addr = vm_unmapped_area(&info);
12146
12147 if ((addr & ~PAGE_MASK) && task_size > VA_EXCLUDE_END) {
12148 VM_BUG_ON(addr != -ENOMEM);
12149 info.low_limit = VA_EXCLUDE_END;
12150+
12151+#ifdef CONFIG_PAX_RANDMMAP
12152+ if (mm->pax_flags & MF_PAX_RANDMMAP)
12153+ info.low_limit += mm->delta_mmap;
12154+#endif
12155+
12156 info.high_limit = task_size;
12157 addr = vm_unmapped_area(&info);
12158 }
12159@@ -55,7 +64,8 @@ static unsigned long
12160 hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
12161 const unsigned long len,
12162 const unsigned long pgoff,
12163- const unsigned long flags)
12164+ const unsigned long flags,
12165+ const unsigned long offset)
12166 {
12167 struct mm_struct *mm = current->mm;
12168 unsigned long addr = addr0;
12169@@ -70,6 +80,7 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
12170 info.high_limit = mm->mmap_base;
12171 info.align_mask = PAGE_MASK & ~HPAGE_MASK;
12172 info.align_offset = 0;
12173+ info.threadstack_offset = offset;
12174 addr = vm_unmapped_area(&info);
12175
12176 /*
12177@@ -82,6 +93,12 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
12178 VM_BUG_ON(addr != -ENOMEM);
12179 info.flags = 0;
12180 info.low_limit = TASK_UNMAPPED_BASE;
12181+
12182+#ifdef CONFIG_PAX_RANDMMAP
12183+ if (mm->pax_flags & MF_PAX_RANDMMAP)
12184+ info.low_limit += mm->delta_mmap;
12185+#endif
12186+
12187 info.high_limit = STACK_TOP32;
12188 addr = vm_unmapped_area(&info);
12189 }
12190@@ -96,6 +113,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
12191 struct mm_struct *mm = current->mm;
12192 struct vm_area_struct *vma;
12193 unsigned long task_size = TASK_SIZE;
12194+ unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
12195
12196 if (test_thread_flag(TIF_32BIT))
12197 task_size = STACK_TOP32;
12198@@ -111,19 +129,22 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
12199 return addr;
12200 }
12201
12202+#ifdef CONFIG_PAX_RANDMMAP
12203+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
12204+#endif
12205+
12206 if (addr) {
12207 addr = ALIGN(addr, HPAGE_SIZE);
12208 vma = find_vma(mm, addr);
12209- if (task_size - len >= addr &&
12210- (!vma || addr + len <= vma->vm_start))
12211+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
12212 return addr;
12213 }
12214 if (mm->get_unmapped_area == arch_get_unmapped_area)
12215 return hugetlb_get_unmapped_area_bottomup(file, addr, len,
12216- pgoff, flags);
12217+ pgoff, flags, offset);
12218 else
12219 return hugetlb_get_unmapped_area_topdown(file, addr, len,
12220- pgoff, flags);
12221+ pgoff, flags, offset);
12222 }
12223
12224 pte_t *huge_pte_alloc(struct mm_struct *mm,
12225diff --git a/arch/sparc/mm/init_64.c b/arch/sparc/mm/init_64.c
12226index eafbc65..5a8070d 100644
12227--- a/arch/sparc/mm/init_64.c
12228+++ b/arch/sparc/mm/init_64.c
12229@@ -188,9 +188,9 @@ unsigned long sparc64_kern_sec_context __read_mostly;
12230 int num_kernel_image_mappings;
12231
12232 #ifdef CONFIG_DEBUG_DCFLUSH
12233-atomic_t dcpage_flushes = ATOMIC_INIT(0);
12234+atomic_unchecked_t dcpage_flushes = ATOMIC_INIT(0);
12235 #ifdef CONFIG_SMP
12236-atomic_t dcpage_flushes_xcall = ATOMIC_INIT(0);
12237+atomic_unchecked_t dcpage_flushes_xcall = ATOMIC_INIT(0);
12238 #endif
12239 #endif
12240
12241@@ -198,7 +198,7 @@ inline void flush_dcache_page_impl(struct page *page)
12242 {
12243 BUG_ON(tlb_type == hypervisor);
12244 #ifdef CONFIG_DEBUG_DCFLUSH
12245- atomic_inc(&dcpage_flushes);
12246+ atomic_inc_unchecked(&dcpage_flushes);
12247 #endif
12248
12249 #ifdef DCACHE_ALIASING_POSSIBLE
12250@@ -466,10 +466,10 @@ void mmu_info(struct seq_file *m)
12251
12252 #ifdef CONFIG_DEBUG_DCFLUSH
12253 seq_printf(m, "DCPageFlushes\t: %d\n",
12254- atomic_read(&dcpage_flushes));
12255+ atomic_read_unchecked(&dcpage_flushes));
12256 #ifdef CONFIG_SMP
12257 seq_printf(m, "DCPageFlushesXC\t: %d\n",
12258- atomic_read(&dcpage_flushes_xcall));
12259+ atomic_read_unchecked(&dcpage_flushes_xcall));
12260 #endif /* CONFIG_SMP */
12261 #endif /* CONFIG_DEBUG_DCFLUSH */
12262 }
12263diff --git a/arch/sparc/mm/tlb.c b/arch/sparc/mm/tlb.c
12264index b12cb5e..b89aba2 100644
12265--- a/arch/sparc/mm/tlb.c
12266+++ b/arch/sparc/mm/tlb.c
12267@@ -134,7 +134,7 @@ no_cache_flush:
12268
12269 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
12270 static void tlb_batch_pmd_scan(struct mm_struct *mm, unsigned long vaddr,
12271- pmd_t pmd, bool exec)
12272+ pmd_t pmd)
12273 {
12274 unsigned long end;
12275 pte_t *pte;
12276@@ -142,8 +142,11 @@ static void tlb_batch_pmd_scan(struct mm_struct *mm, unsigned long vaddr,
12277 pte = pte_offset_map(&pmd, vaddr);
12278 end = vaddr + HPAGE_SIZE;
12279 while (vaddr < end) {
12280- if (pte_val(*pte) & _PAGE_VALID)
12281+ if (pte_val(*pte) & _PAGE_VALID) {
12282+ bool exec = pte_exec(*pte);
12283+
12284 tlb_batch_add_one(mm, vaddr, exec);
12285+ }
12286 pte++;
12287 vaddr += PAGE_SIZE;
12288 }
12289@@ -177,19 +180,30 @@ void set_pmd_at(struct mm_struct *mm, unsigned long addr,
12290 }
12291
12292 if (!pmd_none(orig)) {
12293- pte_t orig_pte = __pte(pmd_val(orig));
12294- bool exec = pte_exec(orig_pte);
12295-
12296 addr &= HPAGE_MASK;
12297 if (pmd_trans_huge(orig)) {
12298+ pte_t orig_pte = __pte(pmd_val(orig));
12299+ bool exec = pte_exec(orig_pte);
12300+
12301 tlb_batch_add_one(mm, addr, exec);
12302 tlb_batch_add_one(mm, addr + REAL_HPAGE_SIZE, exec);
12303 } else {
12304- tlb_batch_pmd_scan(mm, addr, orig, exec);
12305+ tlb_batch_pmd_scan(mm, addr, orig);
12306 }
12307 }
12308 }
12309
12310+void pmdp_invalidate(struct vm_area_struct *vma, unsigned long address,
12311+ pmd_t *pmdp)
12312+{
12313+ pmd_t entry = *pmdp;
12314+
12315+ pmd_val(entry) &= ~_PAGE_VALID;
12316+
12317+ set_pmd_at(vma->vm_mm, address, pmdp, entry);
12318+ flush_tlb_range(vma, address, address + HPAGE_PMD_SIZE);
12319+}
12320+
12321 void pgtable_trans_huge_deposit(struct mm_struct *mm, pmd_t *pmdp,
12322 pgtable_t pgtable)
12323 {
12324diff --git a/arch/tile/Kconfig b/arch/tile/Kconfig
12325index b3692ce..e4517c9 100644
12326--- a/arch/tile/Kconfig
12327+++ b/arch/tile/Kconfig
12328@@ -184,6 +184,7 @@ source "kernel/Kconfig.hz"
12329
12330 config KEXEC
12331 bool "kexec system call"
12332+ depends on !GRKERNSEC_KMEM
12333 ---help---
12334 kexec is a system call that implements the ability to shutdown your
12335 current kernel, and to start another kernel. It is like a reboot
12336diff --git a/arch/tile/include/asm/atomic_64.h b/arch/tile/include/asm/atomic_64.h
12337index ad220ee..2f537b3 100644
12338--- a/arch/tile/include/asm/atomic_64.h
12339+++ b/arch/tile/include/asm/atomic_64.h
12340@@ -105,6 +105,16 @@ static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
12341
12342 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
12343
12344+#define atomic64_read_unchecked(v) atomic64_read(v)
12345+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
12346+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
12347+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
12348+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
12349+#define atomic64_inc_unchecked(v) atomic64_inc(v)
12350+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
12351+#define atomic64_dec_unchecked(v) atomic64_dec(v)
12352+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
12353+
12354 /* Atomic dec and inc don't implement barrier, so provide them if needed. */
12355 #define smp_mb__before_atomic_dec() smp_mb()
12356 #define smp_mb__after_atomic_dec() smp_mb()
12357diff --git a/arch/tile/include/asm/cache.h b/arch/tile/include/asm/cache.h
12358index 6160761..00cac88 100644
12359--- a/arch/tile/include/asm/cache.h
12360+++ b/arch/tile/include/asm/cache.h
12361@@ -15,11 +15,12 @@
12362 #ifndef _ASM_TILE_CACHE_H
12363 #define _ASM_TILE_CACHE_H
12364
12365+#include <linux/const.h>
12366 #include <arch/chip.h>
12367
12368 /* bytes per L1 data cache line */
12369 #define L1_CACHE_SHIFT CHIP_L1D_LOG_LINE_SIZE()
12370-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
12371+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
12372
12373 /* bytes per L2 cache line */
12374 #define L2_CACHE_SHIFT CHIP_L2_LOG_LINE_SIZE()
12375diff --git a/arch/tile/include/asm/uaccess.h b/arch/tile/include/asm/uaccess.h
12376index b6cde32..c0cb736 100644
12377--- a/arch/tile/include/asm/uaccess.h
12378+++ b/arch/tile/include/asm/uaccess.h
12379@@ -414,9 +414,9 @@ static inline unsigned long __must_check copy_from_user(void *to,
12380 const void __user *from,
12381 unsigned long n)
12382 {
12383- int sz = __compiletime_object_size(to);
12384+ size_t sz = __compiletime_object_size(to);
12385
12386- if (likely(sz == -1 || sz >= n))
12387+ if (likely(sz == (size_t)-1 || sz >= n))
12388 n = _copy_from_user(to, from, n);
12389 else
12390 copy_from_user_overflow();
12391diff --git a/arch/tile/mm/hugetlbpage.c b/arch/tile/mm/hugetlbpage.c
12392index 0cb3bba..7338b2d 100644
12393--- a/arch/tile/mm/hugetlbpage.c
12394+++ b/arch/tile/mm/hugetlbpage.c
12395@@ -212,6 +212,7 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
12396 info.high_limit = TASK_SIZE;
12397 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
12398 info.align_offset = 0;
12399+ info.threadstack_offset = 0;
12400 return vm_unmapped_area(&info);
12401 }
12402
12403@@ -229,6 +230,7 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
12404 info.high_limit = current->mm->mmap_base;
12405 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
12406 info.align_offset = 0;
12407+ info.threadstack_offset = 0;
12408 addr = vm_unmapped_area(&info);
12409
12410 /*
12411diff --git a/arch/um/Makefile b/arch/um/Makefile
12412index 36e658a..71a5c5a 100644
12413--- a/arch/um/Makefile
12414+++ b/arch/um/Makefile
12415@@ -72,6 +72,10 @@ USER_CFLAGS = $(patsubst $(KERNEL_DEFINES),,$(patsubst -D__KERNEL__,,\
12416 $(patsubst -I%,,$(KBUILD_CFLAGS)))) $(ARCH_INCLUDE) $(MODE_INCLUDE) \
12417 $(filter -I%,$(CFLAGS)) -D_FILE_OFFSET_BITS=64 -idirafter include
12418
12419+ifdef CONSTIFY_PLUGIN
12420+USER_CFLAGS += -fplugin-arg-constify_plugin-no-constify
12421+endif
12422+
12423 #This will adjust *FLAGS accordingly to the platform.
12424 include $(srctree)/$(ARCH_DIR)/Makefile-os-$(OS)
12425
12426diff --git a/arch/um/include/asm/cache.h b/arch/um/include/asm/cache.h
12427index 19e1bdd..3665b77 100644
12428--- a/arch/um/include/asm/cache.h
12429+++ b/arch/um/include/asm/cache.h
12430@@ -1,6 +1,7 @@
12431 #ifndef __UM_CACHE_H
12432 #define __UM_CACHE_H
12433
12434+#include <linux/const.h>
12435
12436 #if defined(CONFIG_UML_X86) && !defined(CONFIG_64BIT)
12437 # define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
12438@@ -12,6 +13,6 @@
12439 # define L1_CACHE_SHIFT 5
12440 #endif
12441
12442-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
12443+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
12444
12445 #endif
12446diff --git a/arch/um/include/asm/kmap_types.h b/arch/um/include/asm/kmap_types.h
12447index 2e0a6b1..a64d0f5 100644
12448--- a/arch/um/include/asm/kmap_types.h
12449+++ b/arch/um/include/asm/kmap_types.h
12450@@ -8,6 +8,6 @@
12451
12452 /* No more #include "asm/arch/kmap_types.h" ! */
12453
12454-#define KM_TYPE_NR 14
12455+#define KM_TYPE_NR 15
12456
12457 #endif
12458diff --git a/arch/um/include/asm/page.h b/arch/um/include/asm/page.h
12459index 5ff53d9..5850cdf 100644
12460--- a/arch/um/include/asm/page.h
12461+++ b/arch/um/include/asm/page.h
12462@@ -14,6 +14,9 @@
12463 #define PAGE_SIZE (_AC(1, UL) << PAGE_SHIFT)
12464 #define PAGE_MASK (~(PAGE_SIZE-1))
12465
12466+#define ktla_ktva(addr) (addr)
12467+#define ktva_ktla(addr) (addr)
12468+
12469 #ifndef __ASSEMBLY__
12470
12471 struct page;
12472diff --git a/arch/um/include/asm/pgtable-3level.h b/arch/um/include/asm/pgtable-3level.h
12473index 0032f92..cd151e0 100644
12474--- a/arch/um/include/asm/pgtable-3level.h
12475+++ b/arch/um/include/asm/pgtable-3level.h
12476@@ -58,6 +58,7 @@
12477 #define pud_present(x) (pud_val(x) & _PAGE_PRESENT)
12478 #define pud_populate(mm, pud, pmd) \
12479 set_pud(pud, __pud(_PAGE_TABLE + __pa(pmd)))
12480+#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
12481
12482 #ifdef CONFIG_64BIT
12483 #define set_pud(pudptr, pudval) set_64bit((u64 *) (pudptr), pud_val(pudval))
12484diff --git a/arch/um/kernel/process.c b/arch/um/kernel/process.c
12485index eecc414..48adb87 100644
12486--- a/arch/um/kernel/process.c
12487+++ b/arch/um/kernel/process.c
12488@@ -356,22 +356,6 @@ int singlestepping(void * t)
12489 return 2;
12490 }
12491
12492-/*
12493- * Only x86 and x86_64 have an arch_align_stack().
12494- * All other arches have "#define arch_align_stack(x) (x)"
12495- * in their asm/system.h
12496- * As this is included in UML from asm-um/system-generic.h,
12497- * we can use it to behave as the subarch does.
12498- */
12499-#ifndef arch_align_stack
12500-unsigned long arch_align_stack(unsigned long sp)
12501-{
12502- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
12503- sp -= get_random_int() % 8192;
12504- return sp & ~0xf;
12505-}
12506-#endif
12507-
12508 unsigned long get_wchan(struct task_struct *p)
12509 {
12510 unsigned long stack_page, sp, ip;
12511diff --git a/arch/unicore32/include/asm/cache.h b/arch/unicore32/include/asm/cache.h
12512index ad8f795..2c7eec6 100644
12513--- a/arch/unicore32/include/asm/cache.h
12514+++ b/arch/unicore32/include/asm/cache.h
12515@@ -12,8 +12,10 @@
12516 #ifndef __UNICORE_CACHE_H__
12517 #define __UNICORE_CACHE_H__
12518
12519-#define L1_CACHE_SHIFT (5)
12520-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
12521+#include <linux/const.h>
12522+
12523+#define L1_CACHE_SHIFT 5
12524+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
12525
12526 /*
12527 * Memory returned by kmalloc() may be used for DMA, so we must make
12528diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
12529index 0af5250..59f9597 100644
12530--- a/arch/x86/Kconfig
12531+++ b/arch/x86/Kconfig
12532@@ -126,7 +126,7 @@ config X86
12533 select RTC_LIB
12534 select HAVE_DEBUG_STACKOVERFLOW
12535 select HAVE_IRQ_EXIT_ON_IRQ_STACK if X86_64
12536- select HAVE_CC_STACKPROTECTOR
12537+ select HAVE_CC_STACKPROTECTOR if X86_64 || !PAX_MEMORY_UDEREF
12538
12539 config INSTRUCTION_DECODER
12540 def_bool y
12541@@ -251,7 +251,7 @@ config X86_HT
12542
12543 config X86_32_LAZY_GS
12544 def_bool y
12545- depends on X86_32 && !CC_STACKPROTECTOR
12546+ depends on X86_32 && !CC_STACKPROTECTOR && !PAX_MEMORY_UDEREF
12547
12548 config ARCH_HWEIGHT_CFLAGS
12549 string
12550@@ -589,6 +589,7 @@ config SCHED_OMIT_FRAME_POINTER
12551
12552 menuconfig HYPERVISOR_GUEST
12553 bool "Linux guest support"
12554+ depends on !GRKERNSEC_CONFIG_AUTO || GRKERNSEC_CONFIG_VIRT_GUEST || (GRKERNSEC_CONFIG_VIRT_HOST && GRKERNSEC_CONFIG_VIRT_XEN)
12555 ---help---
12556 Say Y here to enable options for running Linux under various hyper-
12557 visors. This option enables basic hypervisor detection and platform
12558@@ -1111,7 +1112,7 @@ choice
12559
12560 config NOHIGHMEM
12561 bool "off"
12562- depends on !X86_NUMAQ
12563+ depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
12564 ---help---
12565 Linux can use up to 64 Gigabytes of physical memory on x86 systems.
12566 However, the address space of 32-bit x86 processors is only 4
12567@@ -1148,7 +1149,7 @@ config NOHIGHMEM
12568
12569 config HIGHMEM4G
12570 bool "4GB"
12571- depends on !X86_NUMAQ
12572+ depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
12573 ---help---
12574 Select this if you have a 32-bit processor and between 1 and 4
12575 gigabytes of physical RAM.
12576@@ -1201,7 +1202,7 @@ config PAGE_OFFSET
12577 hex
12578 default 0xB0000000 if VMSPLIT_3G_OPT
12579 default 0x80000000 if VMSPLIT_2G
12580- default 0x78000000 if VMSPLIT_2G_OPT
12581+ default 0x70000000 if VMSPLIT_2G_OPT
12582 default 0x40000000 if VMSPLIT_1G
12583 default 0xC0000000
12584 depends on X86_32
12585@@ -1605,6 +1606,7 @@ source kernel/Kconfig.hz
12586
12587 config KEXEC
12588 bool "kexec system call"
12589+ depends on !GRKERNSEC_KMEM
12590 ---help---
12591 kexec is a system call that implements the ability to shutdown your
12592 current kernel, and to start another kernel. It is like a reboot
12593@@ -1756,7 +1758,9 @@ config X86_NEED_RELOCS
12594
12595 config PHYSICAL_ALIGN
12596 hex "Alignment value to which kernel should be aligned"
12597- default "0x200000"
12598+ default "0x1000000"
12599+ range 0x200000 0x1000000 if PAX_KERNEXEC && X86_PAE
12600+ range 0x400000 0x1000000 if PAX_KERNEXEC && !X86_PAE
12601 range 0x2000 0x1000000 if X86_32
12602 range 0x200000 0x1000000 if X86_64
12603 ---help---
12604@@ -1836,9 +1840,10 @@ config DEBUG_HOTPLUG_CPU0
12605 If unsure, say N.
12606
12607 config COMPAT_VDSO
12608- def_bool y
12609+ def_bool n
12610 prompt "Compat VDSO support"
12611 depends on X86_32 || IA32_EMULATION
12612+ depends on !PAX_PAGEEXEC && !PAX_SEGMEXEC && !PAX_KERNEXEC && !PAX_MEMORY_UDEREF
12613 ---help---
12614 Map the 32-bit VDSO to the predictable old-style address too.
12615
12616diff --git a/arch/x86/Kconfig.cpu b/arch/x86/Kconfig.cpu
12617index f3aaf23..a1d3c49 100644
12618--- a/arch/x86/Kconfig.cpu
12619+++ b/arch/x86/Kconfig.cpu
12620@@ -319,7 +319,7 @@ config X86_PPRO_FENCE
12621
12622 config X86_F00F_BUG
12623 def_bool y
12624- depends on M586MMX || M586TSC || M586 || M486
12625+ depends on (M586MMX || M586TSC || M586 || M486) && !PAX_KERNEXEC
12626
12627 config X86_INVD_BUG
12628 def_bool y
12629@@ -327,7 +327,7 @@ config X86_INVD_BUG
12630
12631 config X86_ALIGNMENT_16
12632 def_bool y
12633- depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || MELAN || MK6 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
12634+ depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || X86_ELAN || MK8 || MK7 || MK6 || MCORE2 || MPENTIUM4 || MPENTIUMIII || MPENTIUMII || M686 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
12635
12636 config X86_INTEL_USERCOPY
12637 def_bool y
12638@@ -369,7 +369,7 @@ config X86_CMPXCHG64
12639 # generates cmov.
12640 config X86_CMOV
12641 def_bool y
12642- depends on (MK8 || MK7 || MCORE2 || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
12643+ depends on (MK8 || MK7 || MCORE2 || MPSC || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
12644
12645 config X86_MINIMUM_CPU_FAMILY
12646 int
12647diff --git a/arch/x86/Kconfig.debug b/arch/x86/Kconfig.debug
12648index 321a52c..3d51a5e 100644
12649--- a/arch/x86/Kconfig.debug
12650+++ b/arch/x86/Kconfig.debug
12651@@ -84,7 +84,7 @@ config X86_PTDUMP
12652 config DEBUG_RODATA
12653 bool "Write protect kernel read-only data structures"
12654 default y
12655- depends on DEBUG_KERNEL
12656+ depends on DEBUG_KERNEL && BROKEN
12657 ---help---
12658 Mark the kernel read-only data as write-protected in the pagetables,
12659 in order to catch accidental (and incorrect) writes to such const
12660@@ -102,7 +102,7 @@ config DEBUG_RODATA_TEST
12661
12662 config DEBUG_SET_MODULE_RONX
12663 bool "Set loadable kernel module data as NX and text as RO"
12664- depends on MODULES
12665+ depends on MODULES && BROKEN
12666 ---help---
12667 This option helps catch unintended modifications to loadable
12668 kernel module's text and read-only data. It also prevents execution
12669diff --git a/arch/x86/Makefile b/arch/x86/Makefile
12670index 0dd99ea..4a63d82 100644
12671--- a/arch/x86/Makefile
12672+++ b/arch/x86/Makefile
12673@@ -71,9 +71,6 @@ 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@@ -112,6 +109,9 @@ else
12684 KBUILD_CFLAGS += -maccumulate-outgoing-args
12685 endif
12686
12687+# temporary until string.h is fixed
12688+KBUILD_CFLAGS += -ffreestanding
12689+
12690 # Make sure compiler does not have buggy stack-protector support.
12691 ifdef CONFIG_CC_STACKPROTECTOR
12692 cc_has_sp := $(srctree)/scripts/gcc-x86_$(BITS)-has-stack-protector.sh
12693@@ -269,3 +269,12 @@ define archhelp
12694 echo ' FDINITRD=file initrd for the booted kernel'
12695 echo ' kvmconfig - Enable additional options for guest kernel support'
12696 endef
12697+
12698+define OLD_LD
12699+
12700+*** ${VERSION}.${PATCHLEVEL} PaX kernels no longer build correctly with old versions of binutils.
12701+*** Please upgrade your binutils to 2.18 or newer
12702+endef
12703+
12704+archprepare:
12705+ $(if $(LDFLAGS_BUILD_ID),,$(error $(OLD_LD)))
12706diff --git a/arch/x86/boot/Makefile b/arch/x86/boot/Makefile
12707index 878df7e..a803913 100644
12708--- a/arch/x86/boot/Makefile
12709+++ b/arch/x86/boot/Makefile
12710@@ -52,6 +52,9 @@ $(obj)/cpustr.h: $(obj)/mkcpustr FORCE
12711 # ---------------------------------------------------------------------------
12712
12713 KBUILD_CFLAGS := $(USERINCLUDE) $(REALMODE_CFLAGS) -D_SETUP
12714+ifdef CONSTIFY_PLUGIN
12715+KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
12716+endif
12717 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
12718 GCOV_PROFILE := n
12719
12720diff --git a/arch/x86/boot/bitops.h b/arch/x86/boot/bitops.h
12721index 878e4b9..20537ab 100644
12722--- a/arch/x86/boot/bitops.h
12723+++ b/arch/x86/boot/bitops.h
12724@@ -26,7 +26,7 @@ static inline int variable_test_bit(int nr, const void *addr)
12725 u8 v;
12726 const u32 *p = (const u32 *)addr;
12727
12728- asm("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
12729+ asm volatile("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
12730 return v;
12731 }
12732
12733@@ -37,7 +37,7 @@ static inline int variable_test_bit(int nr, const void *addr)
12734
12735 static inline void set_bit(int nr, void *addr)
12736 {
12737- asm("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
12738+ asm volatile("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
12739 }
12740
12741 #endif /* BOOT_BITOPS_H */
12742diff --git a/arch/x86/boot/boot.h b/arch/x86/boot/boot.h
12743index 50f8c5e..4f84fff 100644
12744--- a/arch/x86/boot/boot.h
12745+++ b/arch/x86/boot/boot.h
12746@@ -84,7 +84,7 @@ static inline void io_delay(void)
12747 static inline u16 ds(void)
12748 {
12749 u16 seg;
12750- asm("movw %%ds,%0" : "=rm" (seg));
12751+ asm volatile("movw %%ds,%0" : "=rm" (seg));
12752 return seg;
12753 }
12754
12755@@ -180,7 +180,7 @@ static inline void wrgs32(u32 v, addr_t addr)
12756 static inline int memcmp(const void *s1, const void *s2, size_t len)
12757 {
12758 u8 diff;
12759- asm("repe; cmpsb; setnz %0"
12760+ asm volatile("repe; cmpsb; setnz %0"
12761 : "=qm" (diff), "+D" (s1), "+S" (s2), "+c" (len));
12762 return diff;
12763 }
12764diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile
12765index 0fcd913..3bb5c42 100644
12766--- a/arch/x86/boot/compressed/Makefile
12767+++ b/arch/x86/boot/compressed/Makefile
12768@@ -16,6 +16,9 @@ KBUILD_CFLAGS += $(cflags-y)
12769 KBUILD_CFLAGS += -mno-mmx -mno-sse
12770 KBUILD_CFLAGS += $(call cc-option,-ffreestanding)
12771 KBUILD_CFLAGS += $(call cc-option,-fno-stack-protector)
12772+ifdef CONSTIFY_PLUGIN
12773+KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
12774+endif
12775
12776 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
12777 GCOV_PROFILE := n
12778diff --git a/arch/x86/boot/compressed/efi_stub_32.S b/arch/x86/boot/compressed/efi_stub_32.S
12779index a53440e..c3dbf1e 100644
12780--- a/arch/x86/boot/compressed/efi_stub_32.S
12781+++ b/arch/x86/boot/compressed/efi_stub_32.S
12782@@ -46,16 +46,13 @@ ENTRY(efi_call_phys)
12783 * parameter 2, ..., param n. To make things easy, we save the return
12784 * address of efi_call_phys in a global variable.
12785 */
12786- popl %ecx
12787- movl %ecx, saved_return_addr(%edx)
12788- /* get the function pointer into ECX*/
12789- popl %ecx
12790- movl %ecx, efi_rt_function_ptr(%edx)
12791+ popl saved_return_addr(%edx)
12792+ popl efi_rt_function_ptr(%edx)
12793
12794 /*
12795 * 3. Call the physical function.
12796 */
12797- call *%ecx
12798+ call *efi_rt_function_ptr(%edx)
12799
12800 /*
12801 * 4. Balance the stack. And because EAX contain the return value,
12802@@ -67,15 +64,12 @@ ENTRY(efi_call_phys)
12803 1: popl %edx
12804 subl $1b, %edx
12805
12806- movl efi_rt_function_ptr(%edx), %ecx
12807- pushl %ecx
12808+ pushl efi_rt_function_ptr(%edx)
12809
12810 /*
12811 * 10. Push the saved return address onto the stack and return.
12812 */
12813- movl saved_return_addr(%edx), %ecx
12814- pushl %ecx
12815- ret
12816+ jmpl *saved_return_addr(%edx)
12817 ENDPROC(efi_call_phys)
12818 .previous
12819
12820diff --git a/arch/x86/boot/compressed/head_32.S b/arch/x86/boot/compressed/head_32.S
12821index f45ab7a..ebc015f 100644
12822--- a/arch/x86/boot/compressed/head_32.S
12823+++ b/arch/x86/boot/compressed/head_32.S
12824@@ -119,10 +119,10 @@ preferred_addr:
12825 addl %eax, %ebx
12826 notl %eax
12827 andl %eax, %ebx
12828- cmpl $LOAD_PHYSICAL_ADDR, %ebx
12829+ cmpl $____LOAD_PHYSICAL_ADDR, %ebx
12830 jge 1f
12831 #endif
12832- movl $LOAD_PHYSICAL_ADDR, %ebx
12833+ movl $____LOAD_PHYSICAL_ADDR, %ebx
12834 1:
12835
12836 /* Target address to relocate to for decompression */
12837diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S
12838index b10fa66..5ee0472 100644
12839--- a/arch/x86/boot/compressed/head_64.S
12840+++ b/arch/x86/boot/compressed/head_64.S
12841@@ -94,10 +94,10 @@ ENTRY(startup_32)
12842 addl %eax, %ebx
12843 notl %eax
12844 andl %eax, %ebx
12845- cmpl $LOAD_PHYSICAL_ADDR, %ebx
12846+ cmpl $____LOAD_PHYSICAL_ADDR, %ebx
12847 jge 1f
12848 #endif
12849- movl $LOAD_PHYSICAL_ADDR, %ebx
12850+ movl $____LOAD_PHYSICAL_ADDR, %ebx
12851 1:
12852
12853 /* Target address to relocate to for decompression */
12854@@ -268,10 +268,10 @@ preferred_addr:
12855 addq %rax, %rbp
12856 notq %rax
12857 andq %rax, %rbp
12858- cmpq $LOAD_PHYSICAL_ADDR, %rbp
12859+ cmpq $____LOAD_PHYSICAL_ADDR, %rbp
12860 jge 1f
12861 #endif
12862- movq $LOAD_PHYSICAL_ADDR, %rbp
12863+ movq $____LOAD_PHYSICAL_ADDR, %rbp
12864 1:
12865
12866 /* Target address to relocate to for decompression */
12867@@ -363,8 +363,8 @@ gdt:
12868 .long gdt
12869 .word 0
12870 .quad 0x0000000000000000 /* NULL descriptor */
12871- .quad 0x00af9a000000ffff /* __KERNEL_CS */
12872- .quad 0x00cf92000000ffff /* __KERNEL_DS */
12873+ .quad 0x00af9b000000ffff /* __KERNEL_CS */
12874+ .quad 0x00cf93000000ffff /* __KERNEL_DS */
12875 .quad 0x0080890000000000 /* TS descriptor */
12876 .quad 0x0000000000000000 /* TS continued */
12877 gdt_end:
12878diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/misc.c
12879index 196eaf3..c96716d 100644
12880--- a/arch/x86/boot/compressed/misc.c
12881+++ b/arch/x86/boot/compressed/misc.c
12882@@ -218,7 +218,7 @@ void __putstr(const char *s)
12883
12884 void *memset(void *s, int c, size_t n)
12885 {
12886- int i;
12887+ size_t i;
12888 char *ss = s;
12889
12890 for (i = 0; i < n; i++)
12891@@ -277,7 +277,7 @@ static void handle_relocations(void *output, unsigned long output_len)
12892 * Calculate the delta between where vmlinux was linked to load
12893 * and where it was actually loaded.
12894 */
12895- delta = min_addr - LOAD_PHYSICAL_ADDR;
12896+ delta = min_addr - ____LOAD_PHYSICAL_ADDR;
12897 if (!delta) {
12898 debug_putstr("No relocation needed... ");
12899 return;
12900@@ -347,7 +347,7 @@ static void parse_elf(void *output)
12901 Elf32_Ehdr ehdr;
12902 Elf32_Phdr *phdrs, *phdr;
12903 #endif
12904- void *dest;
12905+ void *dest, *prev;
12906 int i;
12907
12908 memcpy(&ehdr, output, sizeof(ehdr));
12909@@ -374,13 +374,16 @@ static void parse_elf(void *output)
12910 case PT_LOAD:
12911 #ifdef CONFIG_RELOCATABLE
12912 dest = output;
12913- dest += (phdr->p_paddr - LOAD_PHYSICAL_ADDR);
12914+ dest += (phdr->p_paddr - ____LOAD_PHYSICAL_ADDR);
12915 #else
12916 dest = (void *)(phdr->p_paddr);
12917 #endif
12918 memcpy(dest,
12919 output + phdr->p_offset,
12920 phdr->p_filesz);
12921+ if (i)
12922+ memset(prev, 0xff, dest - prev);
12923+ prev = dest + phdr->p_filesz;
12924 break;
12925 default: /* Ignore other PT_* */ break;
12926 }
12927@@ -430,7 +433,7 @@ asmlinkage void *decompress_kernel(void *rmode, memptr heap,
12928 error("Destination address too large");
12929 #endif
12930 #ifndef CONFIG_RELOCATABLE
12931- if ((unsigned long)output != LOAD_PHYSICAL_ADDR)
12932+ if ((unsigned long)output != ____LOAD_PHYSICAL_ADDR)
12933 error("Wrong destination address");
12934 #endif
12935
12936diff --git a/arch/x86/boot/cpucheck.c b/arch/x86/boot/cpucheck.c
12937index 100a9a1..bb3bdb0 100644
12938--- a/arch/x86/boot/cpucheck.c
12939+++ b/arch/x86/boot/cpucheck.c
12940@@ -117,9 +117,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
12941 u32 ecx = MSR_K7_HWCR;
12942 u32 eax, edx;
12943
12944- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12945+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12946 eax &= ~(1 << 15);
12947- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12948+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12949
12950 get_cpuflags(); /* Make sure it really did something */
12951 err = check_cpuflags();
12952@@ -132,9 +132,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
12953 u32 ecx = MSR_VIA_FCR;
12954 u32 eax, edx;
12955
12956- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12957+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12958 eax |= (1<<1)|(1<<7);
12959- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12960+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12961
12962 set_bit(X86_FEATURE_CX8, cpu.flags);
12963 err = check_cpuflags();
12964@@ -145,12 +145,12 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
12965 u32 eax, edx;
12966 u32 level = 1;
12967
12968- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12969- asm("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
12970- asm("cpuid"
12971+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12972+ asm volatile("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
12973+ asm volatile("cpuid"
12974 : "+a" (level), "=d" (cpu.flags[0])
12975 : : "ecx", "ebx");
12976- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12977+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12978
12979 err = check_cpuflags();
12980 }
12981diff --git a/arch/x86/boot/header.S b/arch/x86/boot/header.S
12982index ec3b8ba..6a0db1f 100644
12983--- a/arch/x86/boot/header.S
12984+++ b/arch/x86/boot/header.S
12985@@ -416,10 +416,14 @@ setup_data: .quad 0 # 64-bit physical pointer to
12986 # single linked list of
12987 # struct setup_data
12988
12989-pref_address: .quad LOAD_PHYSICAL_ADDR # preferred load addr
12990+pref_address: .quad ____LOAD_PHYSICAL_ADDR # preferred load addr
12991
12992 #define ZO_INIT_SIZE (ZO__end - ZO_startup_32 + ZO_z_extract_offset)
12993+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
12994+#define VO_INIT_SIZE (VO__end - VO__text - __PAGE_OFFSET - ____LOAD_PHYSICAL_ADDR)
12995+#else
12996 #define VO_INIT_SIZE (VO__end - VO__text)
12997+#endif
12998 #if ZO_INIT_SIZE > VO_INIT_SIZE
12999 #define INIT_SIZE ZO_INIT_SIZE
13000 #else
13001diff --git a/arch/x86/boot/memory.c b/arch/x86/boot/memory.c
13002index db75d07..8e6d0af 100644
13003--- a/arch/x86/boot/memory.c
13004+++ b/arch/x86/boot/memory.c
13005@@ -19,7 +19,7 @@
13006
13007 static int detect_memory_e820(void)
13008 {
13009- int count = 0;
13010+ unsigned int count = 0;
13011 struct biosregs ireg, oreg;
13012 struct e820entry *desc = boot_params.e820_map;
13013 static struct e820entry buf; /* static so it is zeroed */
13014diff --git a/arch/x86/boot/video-vesa.c b/arch/x86/boot/video-vesa.c
13015index 11e8c6e..fdbb1ed 100644
13016--- a/arch/x86/boot/video-vesa.c
13017+++ b/arch/x86/boot/video-vesa.c
13018@@ -200,6 +200,7 @@ static void vesa_store_pm_info(void)
13019
13020 boot_params.screen_info.vesapm_seg = oreg.es;
13021 boot_params.screen_info.vesapm_off = oreg.di;
13022+ boot_params.screen_info.vesapm_size = oreg.cx;
13023 }
13024
13025 /*
13026diff --git a/arch/x86/boot/video.c b/arch/x86/boot/video.c
13027index 43eda28..5ab5fdb 100644
13028--- a/arch/x86/boot/video.c
13029+++ b/arch/x86/boot/video.c
13030@@ -96,7 +96,7 @@ static void store_mode_params(void)
13031 static unsigned int get_entry(void)
13032 {
13033 char entry_buf[4];
13034- int i, len = 0;
13035+ unsigned int i, len = 0;
13036 int key;
13037 unsigned int v;
13038
13039diff --git a/arch/x86/crypto/aes-x86_64-asm_64.S b/arch/x86/crypto/aes-x86_64-asm_64.S
13040index 9105655..41779c1 100644
13041--- a/arch/x86/crypto/aes-x86_64-asm_64.S
13042+++ b/arch/x86/crypto/aes-x86_64-asm_64.S
13043@@ -8,6 +8,8 @@
13044 * including this sentence is retained in full.
13045 */
13046
13047+#include <asm/alternative-asm.h>
13048+
13049 .extern crypto_ft_tab
13050 .extern crypto_it_tab
13051 .extern crypto_fl_tab
13052@@ -70,6 +72,8 @@
13053 je B192; \
13054 leaq 32(r9),r9;
13055
13056+#define ret pax_force_retaddr; ret
13057+
13058 #define epilogue(FUNC,r1,r2,r3,r4,r5,r6,r7,r8,r9) \
13059 movq r1,r2; \
13060 movq r3,r4; \
13061diff --git a/arch/x86/crypto/aesni-intel_asm.S b/arch/x86/crypto/aesni-intel_asm.S
13062index 477e9d7..c92c7d8 100644
13063--- a/arch/x86/crypto/aesni-intel_asm.S
13064+++ b/arch/x86/crypto/aesni-intel_asm.S
13065@@ -31,6 +31,7 @@
13066
13067 #include <linux/linkage.h>
13068 #include <asm/inst.h>
13069+#include <asm/alternative-asm.h>
13070
13071 #ifdef __x86_64__
13072 .data
13073@@ -205,7 +206,7 @@ enc: .octa 0x2
13074 * num_initial_blocks = b mod 4
13075 * encrypt the initial num_initial_blocks blocks and apply ghash on
13076 * the ciphertext
13077-* %r10, %r11, %r12, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
13078+* %r10, %r11, %r15, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
13079 * are clobbered
13080 * arg1, %arg2, %arg3, %r14 are used as a pointer only, not modified
13081 */
13082@@ -214,8 +215,8 @@ enc: .octa 0x2
13083 .macro INITIAL_BLOCKS_DEC num_initial_blocks TMP1 TMP2 TMP3 TMP4 TMP5 XMM0 XMM1 \
13084 XMM2 XMM3 XMM4 XMMDst TMP6 TMP7 i i_seq operation
13085 mov arg7, %r10 # %r10 = AAD
13086- mov arg8, %r12 # %r12 = aadLen
13087- mov %r12, %r11
13088+ mov arg8, %r15 # %r15 = aadLen
13089+ mov %r15, %r11
13090 pxor %xmm\i, %xmm\i
13091 _get_AAD_loop\num_initial_blocks\operation:
13092 movd (%r10), \TMP1
13093@@ -223,15 +224,15 @@ _get_AAD_loop\num_initial_blocks\operation:
13094 psrldq $4, %xmm\i
13095 pxor \TMP1, %xmm\i
13096 add $4, %r10
13097- sub $4, %r12
13098+ sub $4, %r15
13099 jne _get_AAD_loop\num_initial_blocks\operation
13100 cmp $16, %r11
13101 je _get_AAD_loop2_done\num_initial_blocks\operation
13102- mov $16, %r12
13103+ mov $16, %r15
13104 _get_AAD_loop2\num_initial_blocks\operation:
13105 psrldq $4, %xmm\i
13106- sub $4, %r12
13107- cmp %r11, %r12
13108+ sub $4, %r15
13109+ cmp %r11, %r15
13110 jne _get_AAD_loop2\num_initial_blocks\operation
13111 _get_AAD_loop2_done\num_initial_blocks\operation:
13112 movdqa SHUF_MASK(%rip), %xmm14
13113@@ -443,7 +444,7 @@ _initial_blocks_done\num_initial_blocks\operation:
13114 * num_initial_blocks = b mod 4
13115 * encrypt the initial num_initial_blocks blocks and apply ghash on
13116 * the ciphertext
13117-* %r10, %r11, %r12, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
13118+* %r10, %r11, %r15, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
13119 * are clobbered
13120 * arg1, %arg2, %arg3, %r14 are used as a pointer only, not modified
13121 */
13122@@ -452,8 +453,8 @@ _initial_blocks_done\num_initial_blocks\operation:
13123 .macro INITIAL_BLOCKS_ENC num_initial_blocks TMP1 TMP2 TMP3 TMP4 TMP5 XMM0 XMM1 \
13124 XMM2 XMM3 XMM4 XMMDst TMP6 TMP7 i i_seq operation
13125 mov arg7, %r10 # %r10 = AAD
13126- mov arg8, %r12 # %r12 = aadLen
13127- mov %r12, %r11
13128+ mov arg8, %r15 # %r15 = aadLen
13129+ mov %r15, %r11
13130 pxor %xmm\i, %xmm\i
13131 _get_AAD_loop\num_initial_blocks\operation:
13132 movd (%r10), \TMP1
13133@@ -461,15 +462,15 @@ _get_AAD_loop\num_initial_blocks\operation:
13134 psrldq $4, %xmm\i
13135 pxor \TMP1, %xmm\i
13136 add $4, %r10
13137- sub $4, %r12
13138+ sub $4, %r15
13139 jne _get_AAD_loop\num_initial_blocks\operation
13140 cmp $16, %r11
13141 je _get_AAD_loop2_done\num_initial_blocks\operation
13142- mov $16, %r12
13143+ mov $16, %r15
13144 _get_AAD_loop2\num_initial_blocks\operation:
13145 psrldq $4, %xmm\i
13146- sub $4, %r12
13147- cmp %r11, %r12
13148+ sub $4, %r15
13149+ cmp %r11, %r15
13150 jne _get_AAD_loop2\num_initial_blocks\operation
13151 _get_AAD_loop2_done\num_initial_blocks\operation:
13152 movdqa SHUF_MASK(%rip), %xmm14
13153@@ -1269,7 +1270,7 @@ TMP7 XMM1 XMM2 XMM3 XMM4 XMMDst
13154 *
13155 *****************************************************************************/
13156 ENTRY(aesni_gcm_dec)
13157- push %r12
13158+ push %r15
13159 push %r13
13160 push %r14
13161 mov %rsp, %r14
13162@@ -1279,8 +1280,8 @@ ENTRY(aesni_gcm_dec)
13163 */
13164 sub $VARIABLE_OFFSET, %rsp
13165 and $~63, %rsp # align rsp to 64 bytes
13166- mov %arg6, %r12
13167- movdqu (%r12), %xmm13 # %xmm13 = HashKey
13168+ mov %arg6, %r15
13169+ movdqu (%r15), %xmm13 # %xmm13 = HashKey
13170 movdqa SHUF_MASK(%rip), %xmm2
13171 PSHUFB_XMM %xmm2, %xmm13
13172
13173@@ -1308,10 +1309,10 @@ ENTRY(aesni_gcm_dec)
13174 movdqa %xmm13, HashKey(%rsp) # store HashKey<<1 (mod poly)
13175 mov %arg4, %r13 # save the number of bytes of plaintext/ciphertext
13176 and $-16, %r13 # %r13 = %r13 - (%r13 mod 16)
13177- mov %r13, %r12
13178- and $(3<<4), %r12
13179+ mov %r13, %r15
13180+ and $(3<<4), %r15
13181 jz _initial_num_blocks_is_0_decrypt
13182- cmp $(2<<4), %r12
13183+ cmp $(2<<4), %r15
13184 jb _initial_num_blocks_is_1_decrypt
13185 je _initial_num_blocks_is_2_decrypt
13186 _initial_num_blocks_is_3_decrypt:
13187@@ -1361,16 +1362,16 @@ _zero_cipher_left_decrypt:
13188 sub $16, %r11
13189 add %r13, %r11
13190 movdqu (%arg3,%r11,1), %xmm1 # receive the last <16 byte block
13191- lea SHIFT_MASK+16(%rip), %r12
13192- sub %r13, %r12
13193+ lea SHIFT_MASK+16(%rip), %r15
13194+ sub %r13, %r15
13195 # adjust the shuffle mask pointer to be able to shift 16-%r13 bytes
13196 # (%r13 is the number of bytes in plaintext mod 16)
13197- movdqu (%r12), %xmm2 # get the appropriate shuffle mask
13198+ movdqu (%r15), %xmm2 # get the appropriate shuffle mask
13199 PSHUFB_XMM %xmm2, %xmm1 # right shift 16-%r13 butes
13200
13201 movdqa %xmm1, %xmm2
13202 pxor %xmm1, %xmm0 # Ciphertext XOR E(K, Yn)
13203- movdqu ALL_F-SHIFT_MASK(%r12), %xmm1
13204+ movdqu ALL_F-SHIFT_MASK(%r15), %xmm1
13205 # get the appropriate mask to mask out top 16-%r13 bytes of %xmm0
13206 pand %xmm1, %xmm0 # mask out top 16-%r13 bytes of %xmm0
13207 pand %xmm1, %xmm2
13208@@ -1399,9 +1400,9 @@ _less_than_8_bytes_left_decrypt:
13209 sub $1, %r13
13210 jne _less_than_8_bytes_left_decrypt
13211 _multiple_of_16_bytes_decrypt:
13212- mov arg8, %r12 # %r13 = aadLen (number of bytes)
13213- shl $3, %r12 # convert into number of bits
13214- movd %r12d, %xmm15 # len(A) in %xmm15
13215+ mov arg8, %r15 # %r13 = aadLen (number of bytes)
13216+ shl $3, %r15 # convert into number of bits
13217+ movd %r15d, %xmm15 # len(A) in %xmm15
13218 shl $3, %arg4 # len(C) in bits (*128)
13219 MOVQ_R64_XMM %arg4, %xmm1
13220 pslldq $8, %xmm15 # %xmm15 = len(A)||0x0000000000000000
13221@@ -1440,7 +1441,8 @@ _return_T_done_decrypt:
13222 mov %r14, %rsp
13223 pop %r14
13224 pop %r13
13225- pop %r12
13226+ pop %r15
13227+ pax_force_retaddr
13228 ret
13229 ENDPROC(aesni_gcm_dec)
13230
13231@@ -1529,7 +1531,7 @@ ENDPROC(aesni_gcm_dec)
13232 * poly = x^128 + x^127 + x^126 + x^121 + 1
13233 ***************************************************************************/
13234 ENTRY(aesni_gcm_enc)
13235- push %r12
13236+ push %r15
13237 push %r13
13238 push %r14
13239 mov %rsp, %r14
13240@@ -1539,8 +1541,8 @@ ENTRY(aesni_gcm_enc)
13241 #
13242 sub $VARIABLE_OFFSET, %rsp
13243 and $~63, %rsp
13244- mov %arg6, %r12
13245- movdqu (%r12), %xmm13
13246+ mov %arg6, %r15
13247+ movdqu (%r15), %xmm13
13248 movdqa SHUF_MASK(%rip), %xmm2
13249 PSHUFB_XMM %xmm2, %xmm13
13250
13251@@ -1564,13 +1566,13 @@ ENTRY(aesni_gcm_enc)
13252 movdqa %xmm13, HashKey(%rsp)
13253 mov %arg4, %r13 # %xmm13 holds HashKey<<1 (mod poly)
13254 and $-16, %r13
13255- mov %r13, %r12
13256+ mov %r13, %r15
13257
13258 # Encrypt first few blocks
13259
13260- and $(3<<4), %r12
13261+ and $(3<<4), %r15
13262 jz _initial_num_blocks_is_0_encrypt
13263- cmp $(2<<4), %r12
13264+ cmp $(2<<4), %r15
13265 jb _initial_num_blocks_is_1_encrypt
13266 je _initial_num_blocks_is_2_encrypt
13267 _initial_num_blocks_is_3_encrypt:
13268@@ -1623,14 +1625,14 @@ _zero_cipher_left_encrypt:
13269 sub $16, %r11
13270 add %r13, %r11
13271 movdqu (%arg3,%r11,1), %xmm1 # receive the last <16 byte blocks
13272- lea SHIFT_MASK+16(%rip), %r12
13273- sub %r13, %r12
13274+ lea SHIFT_MASK+16(%rip), %r15
13275+ sub %r13, %r15
13276 # adjust the shuffle mask pointer to be able to shift 16-r13 bytes
13277 # (%r13 is the number of bytes in plaintext mod 16)
13278- movdqu (%r12), %xmm2 # get the appropriate shuffle mask
13279+ movdqu (%r15), %xmm2 # get the appropriate shuffle mask
13280 PSHUFB_XMM %xmm2, %xmm1 # shift right 16-r13 byte
13281 pxor %xmm1, %xmm0 # Plaintext XOR Encrypt(K, Yn)
13282- movdqu ALL_F-SHIFT_MASK(%r12), %xmm1
13283+ movdqu ALL_F-SHIFT_MASK(%r15), %xmm1
13284 # get the appropriate mask to mask out top 16-r13 bytes of xmm0
13285 pand %xmm1, %xmm0 # mask out top 16-r13 bytes of xmm0
13286 movdqa SHUF_MASK(%rip), %xmm10
13287@@ -1663,9 +1665,9 @@ _less_than_8_bytes_left_encrypt:
13288 sub $1, %r13
13289 jne _less_than_8_bytes_left_encrypt
13290 _multiple_of_16_bytes_encrypt:
13291- mov arg8, %r12 # %r12 = addLen (number of bytes)
13292- shl $3, %r12
13293- movd %r12d, %xmm15 # len(A) in %xmm15
13294+ mov arg8, %r15 # %r15 = addLen (number of bytes)
13295+ shl $3, %r15
13296+ movd %r15d, %xmm15 # len(A) in %xmm15
13297 shl $3, %arg4 # len(C) in bits (*128)
13298 MOVQ_R64_XMM %arg4, %xmm1
13299 pslldq $8, %xmm15 # %xmm15 = len(A)||0x0000000000000000
13300@@ -1704,7 +1706,8 @@ _return_T_done_encrypt:
13301 mov %r14, %rsp
13302 pop %r14
13303 pop %r13
13304- pop %r12
13305+ pop %r15
13306+ pax_force_retaddr
13307 ret
13308 ENDPROC(aesni_gcm_enc)
13309
13310@@ -1722,6 +1725,7 @@ _key_expansion_256a:
13311 pxor %xmm1, %xmm0
13312 movaps %xmm0, (TKEYP)
13313 add $0x10, TKEYP
13314+ pax_force_retaddr
13315 ret
13316 ENDPROC(_key_expansion_128)
13317 ENDPROC(_key_expansion_256a)
13318@@ -1748,6 +1752,7 @@ _key_expansion_192a:
13319 shufps $0b01001110, %xmm2, %xmm1
13320 movaps %xmm1, 0x10(TKEYP)
13321 add $0x20, TKEYP
13322+ pax_force_retaddr
13323 ret
13324 ENDPROC(_key_expansion_192a)
13325
13326@@ -1768,6 +1773,7 @@ _key_expansion_192b:
13327
13328 movaps %xmm0, (TKEYP)
13329 add $0x10, TKEYP
13330+ pax_force_retaddr
13331 ret
13332 ENDPROC(_key_expansion_192b)
13333
13334@@ -1781,6 +1787,7 @@ _key_expansion_256b:
13335 pxor %xmm1, %xmm2
13336 movaps %xmm2, (TKEYP)
13337 add $0x10, TKEYP
13338+ pax_force_retaddr
13339 ret
13340 ENDPROC(_key_expansion_256b)
13341
13342@@ -1894,6 +1901,7 @@ ENTRY(aesni_set_key)
13343 #ifndef __x86_64__
13344 popl KEYP
13345 #endif
13346+ pax_force_retaddr
13347 ret
13348 ENDPROC(aesni_set_key)
13349
13350@@ -1916,6 +1924,7 @@ ENTRY(aesni_enc)
13351 popl KLEN
13352 popl KEYP
13353 #endif
13354+ pax_force_retaddr
13355 ret
13356 ENDPROC(aesni_enc)
13357
13358@@ -1974,6 +1983,7 @@ _aesni_enc1:
13359 AESENC KEY STATE
13360 movaps 0x70(TKEYP), KEY
13361 AESENCLAST KEY STATE
13362+ pax_force_retaddr
13363 ret
13364 ENDPROC(_aesni_enc1)
13365
13366@@ -2083,6 +2093,7 @@ _aesni_enc4:
13367 AESENCLAST KEY STATE2
13368 AESENCLAST KEY STATE3
13369 AESENCLAST KEY STATE4
13370+ pax_force_retaddr
13371 ret
13372 ENDPROC(_aesni_enc4)
13373
13374@@ -2106,6 +2117,7 @@ ENTRY(aesni_dec)
13375 popl KLEN
13376 popl KEYP
13377 #endif
13378+ pax_force_retaddr
13379 ret
13380 ENDPROC(aesni_dec)
13381
13382@@ -2164,6 +2176,7 @@ _aesni_dec1:
13383 AESDEC KEY STATE
13384 movaps 0x70(TKEYP), KEY
13385 AESDECLAST KEY STATE
13386+ pax_force_retaddr
13387 ret
13388 ENDPROC(_aesni_dec1)
13389
13390@@ -2273,6 +2286,7 @@ _aesni_dec4:
13391 AESDECLAST KEY STATE2
13392 AESDECLAST KEY STATE3
13393 AESDECLAST KEY STATE4
13394+ pax_force_retaddr
13395 ret
13396 ENDPROC(_aesni_dec4)
13397
13398@@ -2331,6 +2345,7 @@ ENTRY(aesni_ecb_enc)
13399 popl KEYP
13400 popl LEN
13401 #endif
13402+ pax_force_retaddr
13403 ret
13404 ENDPROC(aesni_ecb_enc)
13405
13406@@ -2390,6 +2405,7 @@ ENTRY(aesni_ecb_dec)
13407 popl KEYP
13408 popl LEN
13409 #endif
13410+ pax_force_retaddr
13411 ret
13412 ENDPROC(aesni_ecb_dec)
13413
13414@@ -2432,6 +2448,7 @@ ENTRY(aesni_cbc_enc)
13415 popl LEN
13416 popl IVP
13417 #endif
13418+ pax_force_retaddr
13419 ret
13420 ENDPROC(aesni_cbc_enc)
13421
13422@@ -2523,6 +2540,7 @@ ENTRY(aesni_cbc_dec)
13423 popl LEN
13424 popl IVP
13425 #endif
13426+ pax_force_retaddr
13427 ret
13428 ENDPROC(aesni_cbc_dec)
13429
13430@@ -2550,6 +2568,7 @@ _aesni_inc_init:
13431 mov $1, TCTR_LOW
13432 MOVQ_R64_XMM TCTR_LOW INC
13433 MOVQ_R64_XMM CTR TCTR_LOW
13434+ pax_force_retaddr
13435 ret
13436 ENDPROC(_aesni_inc_init)
13437
13438@@ -2579,6 +2598,7 @@ _aesni_inc:
13439 .Linc_low:
13440 movaps CTR, IV
13441 PSHUFB_XMM BSWAP_MASK IV
13442+ pax_force_retaddr
13443 ret
13444 ENDPROC(_aesni_inc)
13445
13446@@ -2640,6 +2660,7 @@ ENTRY(aesni_ctr_enc)
13447 .Lctr_enc_ret:
13448 movups IV, (IVP)
13449 .Lctr_enc_just_ret:
13450+ pax_force_retaddr
13451 ret
13452 ENDPROC(aesni_ctr_enc)
13453
13454@@ -2766,6 +2787,7 @@ ENTRY(aesni_xts_crypt8)
13455 pxor INC, STATE4
13456 movdqu STATE4, 0x70(OUTP)
13457
13458+ pax_force_retaddr
13459 ret
13460 ENDPROC(aesni_xts_crypt8)
13461
13462diff --git a/arch/x86/crypto/blowfish-x86_64-asm_64.S b/arch/x86/crypto/blowfish-x86_64-asm_64.S
13463index 246c670..466e2d6 100644
13464--- a/arch/x86/crypto/blowfish-x86_64-asm_64.S
13465+++ b/arch/x86/crypto/blowfish-x86_64-asm_64.S
13466@@ -21,6 +21,7 @@
13467 */
13468
13469 #include <linux/linkage.h>
13470+#include <asm/alternative-asm.h>
13471
13472 .file "blowfish-x86_64-asm.S"
13473 .text
13474@@ -149,9 +150,11 @@ ENTRY(__blowfish_enc_blk)
13475 jnz .L__enc_xor;
13476
13477 write_block();
13478+ pax_force_retaddr
13479 ret;
13480 .L__enc_xor:
13481 xor_block();
13482+ pax_force_retaddr
13483 ret;
13484 ENDPROC(__blowfish_enc_blk)
13485
13486@@ -183,6 +186,7 @@ ENTRY(blowfish_dec_blk)
13487
13488 movq %r11, %rbp;
13489
13490+ pax_force_retaddr
13491 ret;
13492 ENDPROC(blowfish_dec_blk)
13493
13494@@ -334,6 +338,7 @@ ENTRY(__blowfish_enc_blk_4way)
13495
13496 popq %rbx;
13497 popq %rbp;
13498+ pax_force_retaddr
13499 ret;
13500
13501 .L__enc_xor4:
13502@@ -341,6 +346,7 @@ ENTRY(__blowfish_enc_blk_4way)
13503
13504 popq %rbx;
13505 popq %rbp;
13506+ pax_force_retaddr
13507 ret;
13508 ENDPROC(__blowfish_enc_blk_4way)
13509
13510@@ -375,5 +381,6 @@ ENTRY(blowfish_dec_blk_4way)
13511 popq %rbx;
13512 popq %rbp;
13513
13514+ pax_force_retaddr
13515 ret;
13516 ENDPROC(blowfish_dec_blk_4way)
13517diff --git a/arch/x86/crypto/camellia-aesni-avx-asm_64.S b/arch/x86/crypto/camellia-aesni-avx-asm_64.S
13518index ce71f92..1dce7ec 100644
13519--- a/arch/x86/crypto/camellia-aesni-avx-asm_64.S
13520+++ b/arch/x86/crypto/camellia-aesni-avx-asm_64.S
13521@@ -16,6 +16,7 @@
13522 */
13523
13524 #include <linux/linkage.h>
13525+#include <asm/alternative-asm.h>
13526
13527 #define CAMELLIA_TABLE_BYTE_LEN 272
13528
13529@@ -191,6 +192,7 @@ roundsm16_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd:
13530 roundsm16(%xmm0, %xmm1, %xmm2, %xmm3, %xmm4, %xmm5, %xmm6, %xmm7,
13531 %xmm8, %xmm9, %xmm10, %xmm11, %xmm12, %xmm13, %xmm14, %xmm15,
13532 %rcx, (%r9));
13533+ pax_force_retaddr
13534 ret;
13535 ENDPROC(roundsm16_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd)
13536
13537@@ -199,6 +201,7 @@ roundsm16_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab:
13538 roundsm16(%xmm4, %xmm5, %xmm6, %xmm7, %xmm0, %xmm1, %xmm2, %xmm3,
13539 %xmm12, %xmm13, %xmm14, %xmm15, %xmm8, %xmm9, %xmm10, %xmm11,
13540 %rax, (%r9));
13541+ pax_force_retaddr
13542 ret;
13543 ENDPROC(roundsm16_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab)
13544
13545@@ -780,6 +783,7 @@ __camellia_enc_blk16:
13546 %xmm8, %xmm9, %xmm10, %xmm11, %xmm12, %xmm13, %xmm14,
13547 %xmm15, (key_table)(CTX, %r8, 8), (%rax), 1 * 16(%rax));
13548
13549+ pax_force_retaddr
13550 ret;
13551
13552 .align 8
13553@@ -865,6 +869,7 @@ __camellia_dec_blk16:
13554 %xmm8, %xmm9, %xmm10, %xmm11, %xmm12, %xmm13, %xmm14,
13555 %xmm15, (key_table)(CTX), (%rax), 1 * 16(%rax));
13556
13557+ pax_force_retaddr
13558 ret;
13559
13560 .align 8
13561@@ -904,6 +909,7 @@ ENTRY(camellia_ecb_enc_16way)
13562 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
13563 %xmm8, %rsi);
13564
13565+ pax_force_retaddr
13566 ret;
13567 ENDPROC(camellia_ecb_enc_16way)
13568
13569@@ -932,6 +938,7 @@ ENTRY(camellia_ecb_dec_16way)
13570 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
13571 %xmm8, %rsi);
13572
13573+ pax_force_retaddr
13574 ret;
13575 ENDPROC(camellia_ecb_dec_16way)
13576
13577@@ -981,6 +988,7 @@ ENTRY(camellia_cbc_dec_16way)
13578 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
13579 %xmm8, %rsi);
13580
13581+ pax_force_retaddr
13582 ret;
13583 ENDPROC(camellia_cbc_dec_16way)
13584
13585@@ -1092,6 +1100,7 @@ ENTRY(camellia_ctr_16way)
13586 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
13587 %xmm8, %rsi);
13588
13589+ pax_force_retaddr
13590 ret;
13591 ENDPROC(camellia_ctr_16way)
13592
13593@@ -1234,6 +1243,7 @@ camellia_xts_crypt_16way:
13594 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
13595 %xmm8, %rsi);
13596
13597+ pax_force_retaddr
13598 ret;
13599 ENDPROC(camellia_xts_crypt_16way)
13600
13601diff --git a/arch/x86/crypto/camellia-aesni-avx2-asm_64.S b/arch/x86/crypto/camellia-aesni-avx2-asm_64.S
13602index 0e0b886..5a3123c 100644
13603--- a/arch/x86/crypto/camellia-aesni-avx2-asm_64.S
13604+++ b/arch/x86/crypto/camellia-aesni-avx2-asm_64.S
13605@@ -11,6 +11,7 @@
13606 */
13607
13608 #include <linux/linkage.h>
13609+#include <asm/alternative-asm.h>
13610
13611 #define CAMELLIA_TABLE_BYTE_LEN 272
13612
13613@@ -230,6 +231,7 @@ roundsm32_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd:
13614 roundsm32(%ymm0, %ymm1, %ymm2, %ymm3, %ymm4, %ymm5, %ymm6, %ymm7,
13615 %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14, %ymm15,
13616 %rcx, (%r9));
13617+ pax_force_retaddr
13618 ret;
13619 ENDPROC(roundsm32_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd)
13620
13621@@ -238,6 +240,7 @@ roundsm32_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab:
13622 roundsm32(%ymm4, %ymm5, %ymm6, %ymm7, %ymm0, %ymm1, %ymm2, %ymm3,
13623 %ymm12, %ymm13, %ymm14, %ymm15, %ymm8, %ymm9, %ymm10, %ymm11,
13624 %rax, (%r9));
13625+ pax_force_retaddr
13626 ret;
13627 ENDPROC(roundsm32_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab)
13628
13629@@ -820,6 +823,7 @@ __camellia_enc_blk32:
13630 %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14,
13631 %ymm15, (key_table)(CTX, %r8, 8), (%rax), 1 * 32(%rax));
13632
13633+ pax_force_retaddr
13634 ret;
13635
13636 .align 8
13637@@ -905,6 +909,7 @@ __camellia_dec_blk32:
13638 %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14,
13639 %ymm15, (key_table)(CTX), (%rax), 1 * 32(%rax));
13640
13641+ pax_force_retaddr
13642 ret;
13643
13644 .align 8
13645@@ -948,6 +953,7 @@ ENTRY(camellia_ecb_enc_32way)
13646
13647 vzeroupper;
13648
13649+ pax_force_retaddr
13650 ret;
13651 ENDPROC(camellia_ecb_enc_32way)
13652
13653@@ -980,6 +986,7 @@ ENTRY(camellia_ecb_dec_32way)
13654
13655 vzeroupper;
13656
13657+ pax_force_retaddr
13658 ret;
13659 ENDPROC(camellia_ecb_dec_32way)
13660
13661@@ -1046,6 +1053,7 @@ ENTRY(camellia_cbc_dec_32way)
13662
13663 vzeroupper;
13664
13665+ pax_force_retaddr
13666 ret;
13667 ENDPROC(camellia_cbc_dec_32way)
13668
13669@@ -1184,6 +1192,7 @@ ENTRY(camellia_ctr_32way)
13670
13671 vzeroupper;
13672
13673+ pax_force_retaddr
13674 ret;
13675 ENDPROC(camellia_ctr_32way)
13676
13677@@ -1349,6 +1358,7 @@ camellia_xts_crypt_32way:
13678
13679 vzeroupper;
13680
13681+ pax_force_retaddr
13682 ret;
13683 ENDPROC(camellia_xts_crypt_32way)
13684
13685diff --git a/arch/x86/crypto/camellia-x86_64-asm_64.S b/arch/x86/crypto/camellia-x86_64-asm_64.S
13686index 310319c..db3d7b5 100644
13687--- a/arch/x86/crypto/camellia-x86_64-asm_64.S
13688+++ b/arch/x86/crypto/camellia-x86_64-asm_64.S
13689@@ -21,6 +21,7 @@
13690 */
13691
13692 #include <linux/linkage.h>
13693+#include <asm/alternative-asm.h>
13694
13695 .file "camellia-x86_64-asm_64.S"
13696 .text
13697@@ -228,12 +229,14 @@ ENTRY(__camellia_enc_blk)
13698 enc_outunpack(mov, RT1);
13699
13700 movq RRBP, %rbp;
13701+ pax_force_retaddr
13702 ret;
13703
13704 .L__enc_xor:
13705 enc_outunpack(xor, RT1);
13706
13707 movq RRBP, %rbp;
13708+ pax_force_retaddr
13709 ret;
13710 ENDPROC(__camellia_enc_blk)
13711
13712@@ -272,6 +275,7 @@ ENTRY(camellia_dec_blk)
13713 dec_outunpack();
13714
13715 movq RRBP, %rbp;
13716+ pax_force_retaddr
13717 ret;
13718 ENDPROC(camellia_dec_blk)
13719
13720@@ -463,6 +467,7 @@ ENTRY(__camellia_enc_blk_2way)
13721
13722 movq RRBP, %rbp;
13723 popq %rbx;
13724+ pax_force_retaddr
13725 ret;
13726
13727 .L__enc2_xor:
13728@@ -470,6 +475,7 @@ ENTRY(__camellia_enc_blk_2way)
13729
13730 movq RRBP, %rbp;
13731 popq %rbx;
13732+ pax_force_retaddr
13733 ret;
13734 ENDPROC(__camellia_enc_blk_2way)
13735
13736@@ -510,5 +516,6 @@ ENTRY(camellia_dec_blk_2way)
13737
13738 movq RRBP, %rbp;
13739 movq RXOR, %rbx;
13740+ pax_force_retaddr
13741 ret;
13742 ENDPROC(camellia_dec_blk_2way)
13743diff --git a/arch/x86/crypto/cast5-avx-x86_64-asm_64.S b/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
13744index c35fd5d..2d8c7db 100644
13745--- a/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
13746+++ b/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
13747@@ -24,6 +24,7 @@
13748 */
13749
13750 #include <linux/linkage.h>
13751+#include <asm/alternative-asm.h>
13752
13753 .file "cast5-avx-x86_64-asm_64.S"
13754
13755@@ -281,6 +282,7 @@ __cast5_enc_blk16:
13756 outunpack_blocks(RR3, RL3, RTMP, RX, RKM);
13757 outunpack_blocks(RR4, RL4, RTMP, RX, RKM);
13758
13759+ pax_force_retaddr
13760 ret;
13761 ENDPROC(__cast5_enc_blk16)
13762
13763@@ -352,6 +354,7 @@ __cast5_dec_blk16:
13764 outunpack_blocks(RR3, RL3, RTMP, RX, RKM);
13765 outunpack_blocks(RR4, RL4, RTMP, RX, RKM);
13766
13767+ pax_force_retaddr
13768 ret;
13769
13770 .L__skip_dec:
13771@@ -388,6 +391,7 @@ ENTRY(cast5_ecb_enc_16way)
13772 vmovdqu RR4, (6*4*4)(%r11);
13773 vmovdqu RL4, (7*4*4)(%r11);
13774
13775+ pax_force_retaddr
13776 ret;
13777 ENDPROC(cast5_ecb_enc_16way)
13778
13779@@ -420,6 +424,7 @@ ENTRY(cast5_ecb_dec_16way)
13780 vmovdqu RR4, (6*4*4)(%r11);
13781 vmovdqu RL4, (7*4*4)(%r11);
13782
13783+ pax_force_retaddr
13784 ret;
13785 ENDPROC(cast5_ecb_dec_16way)
13786
13787@@ -430,10 +435,10 @@ ENTRY(cast5_cbc_dec_16way)
13788 * %rdx: src
13789 */
13790
13791- pushq %r12;
13792+ pushq %r14;
13793
13794 movq %rsi, %r11;
13795- movq %rdx, %r12;
13796+ movq %rdx, %r14;
13797
13798 vmovdqu (0*16)(%rdx), RL1;
13799 vmovdqu (1*16)(%rdx), RR1;
13800@@ -447,16 +452,16 @@ ENTRY(cast5_cbc_dec_16way)
13801 call __cast5_dec_blk16;
13802
13803 /* xor with src */
13804- vmovq (%r12), RX;
13805+ vmovq (%r14), RX;
13806 vpshufd $0x4f, RX, RX;
13807 vpxor RX, RR1, RR1;
13808- vpxor 0*16+8(%r12), RL1, RL1;
13809- vpxor 1*16+8(%r12), RR2, RR2;
13810- vpxor 2*16+8(%r12), RL2, RL2;
13811- vpxor 3*16+8(%r12), RR3, RR3;
13812- vpxor 4*16+8(%r12), RL3, RL3;
13813- vpxor 5*16+8(%r12), RR4, RR4;
13814- vpxor 6*16+8(%r12), RL4, RL4;
13815+ vpxor 0*16+8(%r14), RL1, RL1;
13816+ vpxor 1*16+8(%r14), RR2, RR2;
13817+ vpxor 2*16+8(%r14), RL2, RL2;
13818+ vpxor 3*16+8(%r14), RR3, RR3;
13819+ vpxor 4*16+8(%r14), RL3, RL3;
13820+ vpxor 5*16+8(%r14), RR4, RR4;
13821+ vpxor 6*16+8(%r14), RL4, RL4;
13822
13823 vmovdqu RR1, (0*16)(%r11);
13824 vmovdqu RL1, (1*16)(%r11);
13825@@ -467,8 +472,9 @@ ENTRY(cast5_cbc_dec_16way)
13826 vmovdqu RR4, (6*16)(%r11);
13827 vmovdqu RL4, (7*16)(%r11);
13828
13829- popq %r12;
13830+ popq %r14;
13831
13832+ pax_force_retaddr
13833 ret;
13834 ENDPROC(cast5_cbc_dec_16way)
13835
13836@@ -480,10 +486,10 @@ ENTRY(cast5_ctr_16way)
13837 * %rcx: iv (big endian, 64bit)
13838 */
13839
13840- pushq %r12;
13841+ pushq %r14;
13842
13843 movq %rsi, %r11;
13844- movq %rdx, %r12;
13845+ movq %rdx, %r14;
13846
13847 vpcmpeqd RTMP, RTMP, RTMP;
13848 vpsrldq $8, RTMP, RTMP; /* low: -1, high: 0 */
13849@@ -523,14 +529,14 @@ ENTRY(cast5_ctr_16way)
13850 call __cast5_enc_blk16;
13851
13852 /* dst = src ^ iv */
13853- vpxor (0*16)(%r12), RR1, RR1;
13854- vpxor (1*16)(%r12), RL1, RL1;
13855- vpxor (2*16)(%r12), RR2, RR2;
13856- vpxor (3*16)(%r12), RL2, RL2;
13857- vpxor (4*16)(%r12), RR3, RR3;
13858- vpxor (5*16)(%r12), RL3, RL3;
13859- vpxor (6*16)(%r12), RR4, RR4;
13860- vpxor (7*16)(%r12), RL4, RL4;
13861+ vpxor (0*16)(%r14), RR1, RR1;
13862+ vpxor (1*16)(%r14), RL1, RL1;
13863+ vpxor (2*16)(%r14), RR2, RR2;
13864+ vpxor (3*16)(%r14), RL2, RL2;
13865+ vpxor (4*16)(%r14), RR3, RR3;
13866+ vpxor (5*16)(%r14), RL3, RL3;
13867+ vpxor (6*16)(%r14), RR4, RR4;
13868+ vpxor (7*16)(%r14), RL4, RL4;
13869 vmovdqu RR1, (0*16)(%r11);
13870 vmovdqu RL1, (1*16)(%r11);
13871 vmovdqu RR2, (2*16)(%r11);
13872@@ -540,7 +546,8 @@ ENTRY(cast5_ctr_16way)
13873 vmovdqu RR4, (6*16)(%r11);
13874 vmovdqu RL4, (7*16)(%r11);
13875
13876- popq %r12;
13877+ popq %r14;
13878
13879+ pax_force_retaddr
13880 ret;
13881 ENDPROC(cast5_ctr_16way)
13882diff --git a/arch/x86/crypto/cast6-avx-x86_64-asm_64.S b/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
13883index e3531f8..e123f35 100644
13884--- a/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
13885+++ b/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
13886@@ -24,6 +24,7 @@
13887 */
13888
13889 #include <linux/linkage.h>
13890+#include <asm/alternative-asm.h>
13891 #include "glue_helper-asm-avx.S"
13892
13893 .file "cast6-avx-x86_64-asm_64.S"
13894@@ -295,6 +296,7 @@ __cast6_enc_blk8:
13895 outunpack_blocks(RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
13896 outunpack_blocks(RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
13897
13898+ pax_force_retaddr
13899 ret;
13900 ENDPROC(__cast6_enc_blk8)
13901
13902@@ -340,6 +342,7 @@ __cast6_dec_blk8:
13903 outunpack_blocks(RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
13904 outunpack_blocks(RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
13905
13906+ pax_force_retaddr
13907 ret;
13908 ENDPROC(__cast6_dec_blk8)
13909
13910@@ -358,6 +361,7 @@ ENTRY(cast6_ecb_enc_8way)
13911
13912 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13913
13914+ pax_force_retaddr
13915 ret;
13916 ENDPROC(cast6_ecb_enc_8way)
13917
13918@@ -376,6 +380,7 @@ ENTRY(cast6_ecb_dec_8way)
13919
13920 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13921
13922+ pax_force_retaddr
13923 ret;
13924 ENDPROC(cast6_ecb_dec_8way)
13925
13926@@ -386,19 +391,20 @@ ENTRY(cast6_cbc_dec_8way)
13927 * %rdx: src
13928 */
13929
13930- pushq %r12;
13931+ pushq %r14;
13932
13933 movq %rsi, %r11;
13934- movq %rdx, %r12;
13935+ movq %rdx, %r14;
13936
13937 load_8way(%rdx, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13938
13939 call __cast6_dec_blk8;
13940
13941- store_cbc_8way(%r12, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13942+ store_cbc_8way(%r14, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13943
13944- popq %r12;
13945+ popq %r14;
13946
13947+ pax_force_retaddr
13948 ret;
13949 ENDPROC(cast6_cbc_dec_8way)
13950
13951@@ -410,20 +416,21 @@ ENTRY(cast6_ctr_8way)
13952 * %rcx: iv (little endian, 128bit)
13953 */
13954
13955- pushq %r12;
13956+ pushq %r14;
13957
13958 movq %rsi, %r11;
13959- movq %rdx, %r12;
13960+ movq %rdx, %r14;
13961
13962 load_ctr_8way(%rcx, .Lbswap128_mask, RA1, RB1, RC1, RD1, RA2, RB2, RC2,
13963 RD2, RX, RKR, RKM);
13964
13965 call __cast6_enc_blk8;
13966
13967- store_ctr_8way(%r12, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13968+ store_ctr_8way(%r14, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13969
13970- popq %r12;
13971+ popq %r14;
13972
13973+ pax_force_retaddr
13974 ret;
13975 ENDPROC(cast6_ctr_8way)
13976
13977@@ -446,6 +453,7 @@ ENTRY(cast6_xts_enc_8way)
13978 /* dst <= regs xor IVs(in dst) */
13979 store_xts_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13980
13981+ pax_force_retaddr
13982 ret;
13983 ENDPROC(cast6_xts_enc_8way)
13984
13985@@ -468,5 +476,6 @@ ENTRY(cast6_xts_dec_8way)
13986 /* dst <= regs xor IVs(in dst) */
13987 store_xts_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13988
13989+ pax_force_retaddr
13990 ret;
13991 ENDPROC(cast6_xts_dec_8way)
13992diff --git a/arch/x86/crypto/crc32c-pcl-intel-asm_64.S b/arch/x86/crypto/crc32c-pcl-intel-asm_64.S
13993index dbc4339..de6e120 100644
13994--- a/arch/x86/crypto/crc32c-pcl-intel-asm_64.S
13995+++ b/arch/x86/crypto/crc32c-pcl-intel-asm_64.S
13996@@ -45,6 +45,7 @@
13997
13998 #include <asm/inst.h>
13999 #include <linux/linkage.h>
14000+#include <asm/alternative-asm.h>
14001
14002 ## ISCSI CRC 32 Implementation with crc32 and pclmulqdq Instruction
14003
14004@@ -312,6 +313,7 @@ do_return:
14005 popq %rsi
14006 popq %rdi
14007 popq %rbx
14008+ pax_force_retaddr
14009 ret
14010
14011 ################################################################
14012diff --git a/arch/x86/crypto/ghash-clmulni-intel_asm.S b/arch/x86/crypto/ghash-clmulni-intel_asm.S
14013index 185fad4..ff4cd36 100644
14014--- a/arch/x86/crypto/ghash-clmulni-intel_asm.S
14015+++ b/arch/x86/crypto/ghash-clmulni-intel_asm.S
14016@@ -18,6 +18,7 @@
14017
14018 #include <linux/linkage.h>
14019 #include <asm/inst.h>
14020+#include <asm/alternative-asm.h>
14021
14022 .data
14023
14024@@ -89,6 +90,7 @@ __clmul_gf128mul_ble:
14025 psrlq $1, T2
14026 pxor T2, T1
14027 pxor T1, DATA
14028+ pax_force_retaddr
14029 ret
14030 ENDPROC(__clmul_gf128mul_ble)
14031
14032@@ -101,6 +103,7 @@ ENTRY(clmul_ghash_mul)
14033 call __clmul_gf128mul_ble
14034 PSHUFB_XMM BSWAP DATA
14035 movups DATA, (%rdi)
14036+ pax_force_retaddr
14037 ret
14038 ENDPROC(clmul_ghash_mul)
14039
14040@@ -128,5 +131,6 @@ ENTRY(clmul_ghash_update)
14041 PSHUFB_XMM BSWAP DATA
14042 movups DATA, (%rdi)
14043 .Lupdate_just_ret:
14044+ pax_force_retaddr
14045 ret
14046 ENDPROC(clmul_ghash_update)
14047diff --git a/arch/x86/crypto/salsa20-x86_64-asm_64.S b/arch/x86/crypto/salsa20-x86_64-asm_64.S
14048index 9279e0b..c4b3d2c 100644
14049--- a/arch/x86/crypto/salsa20-x86_64-asm_64.S
14050+++ b/arch/x86/crypto/salsa20-x86_64-asm_64.S
14051@@ -1,4 +1,5 @@
14052 #include <linux/linkage.h>
14053+#include <asm/alternative-asm.h>
14054
14055 # enter salsa20_encrypt_bytes
14056 ENTRY(salsa20_encrypt_bytes)
14057@@ -789,6 +790,7 @@ ENTRY(salsa20_encrypt_bytes)
14058 add %r11,%rsp
14059 mov %rdi,%rax
14060 mov %rsi,%rdx
14061+ pax_force_retaddr
14062 ret
14063 # bytesatleast65:
14064 ._bytesatleast65:
14065@@ -889,6 +891,7 @@ ENTRY(salsa20_keysetup)
14066 add %r11,%rsp
14067 mov %rdi,%rax
14068 mov %rsi,%rdx
14069+ pax_force_retaddr
14070 ret
14071 ENDPROC(salsa20_keysetup)
14072
14073@@ -914,5 +917,6 @@ ENTRY(salsa20_ivsetup)
14074 add %r11,%rsp
14075 mov %rdi,%rax
14076 mov %rsi,%rdx
14077+ pax_force_retaddr
14078 ret
14079 ENDPROC(salsa20_ivsetup)
14080diff --git a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
14081index 2f202f4..d9164d6 100644
14082--- a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
14083+++ b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
14084@@ -24,6 +24,7 @@
14085 */
14086
14087 #include <linux/linkage.h>
14088+#include <asm/alternative-asm.h>
14089 #include "glue_helper-asm-avx.S"
14090
14091 .file "serpent-avx-x86_64-asm_64.S"
14092@@ -618,6 +619,7 @@ __serpent_enc_blk8_avx:
14093 write_blocks(RA1, RB1, RC1, RD1, RK0, RK1, RK2);
14094 write_blocks(RA2, RB2, RC2, RD2, RK0, RK1, RK2);
14095
14096+ pax_force_retaddr
14097 ret;
14098 ENDPROC(__serpent_enc_blk8_avx)
14099
14100@@ -672,6 +674,7 @@ __serpent_dec_blk8_avx:
14101 write_blocks(RC1, RD1, RB1, RE1, RK0, RK1, RK2);
14102 write_blocks(RC2, RD2, RB2, RE2, RK0, RK1, RK2);
14103
14104+ pax_force_retaddr
14105 ret;
14106 ENDPROC(__serpent_dec_blk8_avx)
14107
14108@@ -688,6 +691,7 @@ ENTRY(serpent_ecb_enc_8way_avx)
14109
14110 store_8way(%rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14111
14112+ pax_force_retaddr
14113 ret;
14114 ENDPROC(serpent_ecb_enc_8way_avx)
14115
14116@@ -704,6 +708,7 @@ ENTRY(serpent_ecb_dec_8way_avx)
14117
14118 store_8way(%rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
14119
14120+ pax_force_retaddr
14121 ret;
14122 ENDPROC(serpent_ecb_dec_8way_avx)
14123
14124@@ -720,6 +725,7 @@ ENTRY(serpent_cbc_dec_8way_avx)
14125
14126 store_cbc_8way(%rdx, %rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
14127
14128+ pax_force_retaddr
14129 ret;
14130 ENDPROC(serpent_cbc_dec_8way_avx)
14131
14132@@ -738,6 +744,7 @@ ENTRY(serpent_ctr_8way_avx)
14133
14134 store_ctr_8way(%rdx, %rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14135
14136+ pax_force_retaddr
14137 ret;
14138 ENDPROC(serpent_ctr_8way_avx)
14139
14140@@ -758,6 +765,7 @@ ENTRY(serpent_xts_enc_8way_avx)
14141 /* dst <= regs xor IVs(in dst) */
14142 store_xts_8way(%rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14143
14144+ pax_force_retaddr
14145 ret;
14146 ENDPROC(serpent_xts_enc_8way_avx)
14147
14148@@ -778,5 +786,6 @@ ENTRY(serpent_xts_dec_8way_avx)
14149 /* dst <= regs xor IVs(in dst) */
14150 store_xts_8way(%rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
14151
14152+ pax_force_retaddr
14153 ret;
14154 ENDPROC(serpent_xts_dec_8way_avx)
14155diff --git a/arch/x86/crypto/serpent-avx2-asm_64.S b/arch/x86/crypto/serpent-avx2-asm_64.S
14156index b222085..abd483c 100644
14157--- a/arch/x86/crypto/serpent-avx2-asm_64.S
14158+++ b/arch/x86/crypto/serpent-avx2-asm_64.S
14159@@ -15,6 +15,7 @@
14160 */
14161
14162 #include <linux/linkage.h>
14163+#include <asm/alternative-asm.h>
14164 #include "glue_helper-asm-avx2.S"
14165
14166 .file "serpent-avx2-asm_64.S"
14167@@ -610,6 +611,7 @@ __serpent_enc_blk16:
14168 write_blocks(RA1, RB1, RC1, RD1, RK0, RK1, RK2);
14169 write_blocks(RA2, RB2, RC2, RD2, RK0, RK1, RK2);
14170
14171+ pax_force_retaddr
14172 ret;
14173 ENDPROC(__serpent_enc_blk16)
14174
14175@@ -664,6 +666,7 @@ __serpent_dec_blk16:
14176 write_blocks(RC1, RD1, RB1, RE1, RK0, RK1, RK2);
14177 write_blocks(RC2, RD2, RB2, RE2, RK0, RK1, RK2);
14178
14179+ pax_force_retaddr
14180 ret;
14181 ENDPROC(__serpent_dec_blk16)
14182
14183@@ -684,6 +687,7 @@ ENTRY(serpent_ecb_enc_16way)
14184
14185 vzeroupper;
14186
14187+ pax_force_retaddr
14188 ret;
14189 ENDPROC(serpent_ecb_enc_16way)
14190
14191@@ -704,6 +708,7 @@ ENTRY(serpent_ecb_dec_16way)
14192
14193 vzeroupper;
14194
14195+ pax_force_retaddr
14196 ret;
14197 ENDPROC(serpent_ecb_dec_16way)
14198
14199@@ -725,6 +730,7 @@ ENTRY(serpent_cbc_dec_16way)
14200
14201 vzeroupper;
14202
14203+ pax_force_retaddr
14204 ret;
14205 ENDPROC(serpent_cbc_dec_16way)
14206
14207@@ -748,6 +754,7 @@ ENTRY(serpent_ctr_16way)
14208
14209 vzeroupper;
14210
14211+ pax_force_retaddr
14212 ret;
14213 ENDPROC(serpent_ctr_16way)
14214
14215@@ -772,6 +779,7 @@ ENTRY(serpent_xts_enc_16way)
14216
14217 vzeroupper;
14218
14219+ pax_force_retaddr
14220 ret;
14221 ENDPROC(serpent_xts_enc_16way)
14222
14223@@ -796,5 +804,6 @@ ENTRY(serpent_xts_dec_16way)
14224
14225 vzeroupper;
14226
14227+ pax_force_retaddr
14228 ret;
14229 ENDPROC(serpent_xts_dec_16way)
14230diff --git a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
14231index acc066c..1559cc4 100644
14232--- a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
14233+++ b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
14234@@ -25,6 +25,7 @@
14235 */
14236
14237 #include <linux/linkage.h>
14238+#include <asm/alternative-asm.h>
14239
14240 .file "serpent-sse2-x86_64-asm_64.S"
14241 .text
14242@@ -690,12 +691,14 @@ ENTRY(__serpent_enc_blk_8way)
14243 write_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
14244 write_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
14245
14246+ pax_force_retaddr
14247 ret;
14248
14249 .L__enc_xor8:
14250 xor_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
14251 xor_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
14252
14253+ pax_force_retaddr
14254 ret;
14255 ENDPROC(__serpent_enc_blk_8way)
14256
14257@@ -750,5 +753,6 @@ ENTRY(serpent_dec_blk_8way)
14258 write_blocks(%rsi, RC1, RD1, RB1, RE1, RK0, RK1, RK2);
14259 write_blocks(%rax, RC2, RD2, RB2, RE2, RK0, RK1, RK2);
14260
14261+ pax_force_retaddr
14262 ret;
14263 ENDPROC(serpent_dec_blk_8way)
14264diff --git a/arch/x86/crypto/sha1_ssse3_asm.S b/arch/x86/crypto/sha1_ssse3_asm.S
14265index a410950..9dfe7ad 100644
14266--- a/arch/x86/crypto/sha1_ssse3_asm.S
14267+++ b/arch/x86/crypto/sha1_ssse3_asm.S
14268@@ -29,6 +29,7 @@
14269 */
14270
14271 #include <linux/linkage.h>
14272+#include <asm/alternative-asm.h>
14273
14274 #define CTX %rdi // arg1
14275 #define BUF %rsi // arg2
14276@@ -75,9 +76,9 @@
14277
14278 push %rbx
14279 push %rbp
14280- push %r12
14281+ push %r14
14282
14283- mov %rsp, %r12
14284+ mov %rsp, %r14
14285 sub $64, %rsp # allocate workspace
14286 and $~15, %rsp # align stack
14287
14288@@ -99,11 +100,12 @@
14289 xor %rax, %rax
14290 rep stosq
14291
14292- mov %r12, %rsp # deallocate workspace
14293+ mov %r14, %rsp # deallocate workspace
14294
14295- pop %r12
14296+ pop %r14
14297 pop %rbp
14298 pop %rbx
14299+ pax_force_retaddr
14300 ret
14301
14302 ENDPROC(\name)
14303diff --git a/arch/x86/crypto/sha256-avx-asm.S b/arch/x86/crypto/sha256-avx-asm.S
14304index 642f156..51a513c 100644
14305--- a/arch/x86/crypto/sha256-avx-asm.S
14306+++ b/arch/x86/crypto/sha256-avx-asm.S
14307@@ -49,6 +49,7 @@
14308
14309 #ifdef CONFIG_AS_AVX
14310 #include <linux/linkage.h>
14311+#include <asm/alternative-asm.h>
14312
14313 ## assume buffers not aligned
14314 #define VMOVDQ vmovdqu
14315@@ -460,6 +461,7 @@ done_hash:
14316 popq %r13
14317 popq %rbp
14318 popq %rbx
14319+ pax_force_retaddr
14320 ret
14321 ENDPROC(sha256_transform_avx)
14322
14323diff --git a/arch/x86/crypto/sha256-avx2-asm.S b/arch/x86/crypto/sha256-avx2-asm.S
14324index 9e86944..3795e6a 100644
14325--- a/arch/x86/crypto/sha256-avx2-asm.S
14326+++ b/arch/x86/crypto/sha256-avx2-asm.S
14327@@ -50,6 +50,7 @@
14328
14329 #ifdef CONFIG_AS_AVX2
14330 #include <linux/linkage.h>
14331+#include <asm/alternative-asm.h>
14332
14333 ## assume buffers not aligned
14334 #define VMOVDQ vmovdqu
14335@@ -720,6 +721,7 @@ done_hash:
14336 popq %r12
14337 popq %rbp
14338 popq %rbx
14339+ pax_force_retaddr
14340 ret
14341 ENDPROC(sha256_transform_rorx)
14342
14343diff --git a/arch/x86/crypto/sha256-ssse3-asm.S b/arch/x86/crypto/sha256-ssse3-asm.S
14344index f833b74..8c62a9e 100644
14345--- a/arch/x86/crypto/sha256-ssse3-asm.S
14346+++ b/arch/x86/crypto/sha256-ssse3-asm.S
14347@@ -47,6 +47,7 @@
14348 ########################################################################
14349
14350 #include <linux/linkage.h>
14351+#include <asm/alternative-asm.h>
14352
14353 ## assume buffers not aligned
14354 #define MOVDQ movdqu
14355@@ -471,6 +472,7 @@ done_hash:
14356 popq %rbp
14357 popq %rbx
14358
14359+ pax_force_retaddr
14360 ret
14361 ENDPROC(sha256_transform_ssse3)
14362
14363diff --git a/arch/x86/crypto/sha512-avx-asm.S b/arch/x86/crypto/sha512-avx-asm.S
14364index 974dde9..a823ff9 100644
14365--- a/arch/x86/crypto/sha512-avx-asm.S
14366+++ b/arch/x86/crypto/sha512-avx-asm.S
14367@@ -49,6 +49,7 @@
14368
14369 #ifdef CONFIG_AS_AVX
14370 #include <linux/linkage.h>
14371+#include <asm/alternative-asm.h>
14372
14373 .text
14374
14375@@ -364,6 +365,7 @@ updateblock:
14376 mov frame_RSPSAVE(%rsp), %rsp
14377
14378 nowork:
14379+ pax_force_retaddr
14380 ret
14381 ENDPROC(sha512_transform_avx)
14382
14383diff --git a/arch/x86/crypto/sha512-avx2-asm.S b/arch/x86/crypto/sha512-avx2-asm.S
14384index 568b961..ed20c37 100644
14385--- a/arch/x86/crypto/sha512-avx2-asm.S
14386+++ b/arch/x86/crypto/sha512-avx2-asm.S
14387@@ -51,6 +51,7 @@
14388
14389 #ifdef CONFIG_AS_AVX2
14390 #include <linux/linkage.h>
14391+#include <asm/alternative-asm.h>
14392
14393 .text
14394
14395@@ -678,6 +679,7 @@ done_hash:
14396
14397 # Restore Stack Pointer
14398 mov frame_RSPSAVE(%rsp), %rsp
14399+ pax_force_retaddr
14400 ret
14401 ENDPROC(sha512_transform_rorx)
14402
14403diff --git a/arch/x86/crypto/sha512-ssse3-asm.S b/arch/x86/crypto/sha512-ssse3-asm.S
14404index fb56855..6edd768 100644
14405--- a/arch/x86/crypto/sha512-ssse3-asm.S
14406+++ b/arch/x86/crypto/sha512-ssse3-asm.S
14407@@ -48,6 +48,7 @@
14408 ########################################################################
14409
14410 #include <linux/linkage.h>
14411+#include <asm/alternative-asm.h>
14412
14413 .text
14414
14415@@ -363,6 +364,7 @@ updateblock:
14416 mov frame_RSPSAVE(%rsp), %rsp
14417
14418 nowork:
14419+ pax_force_retaddr
14420 ret
14421 ENDPROC(sha512_transform_ssse3)
14422
14423diff --git a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
14424index 0505813..b067311 100644
14425--- a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
14426+++ b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
14427@@ -24,6 +24,7 @@
14428 */
14429
14430 #include <linux/linkage.h>
14431+#include <asm/alternative-asm.h>
14432 #include "glue_helper-asm-avx.S"
14433
14434 .file "twofish-avx-x86_64-asm_64.S"
14435@@ -284,6 +285,7 @@ __twofish_enc_blk8:
14436 outunpack_blocks(RC1, RD1, RA1, RB1, RK1, RX0, RY0, RK2);
14437 outunpack_blocks(RC2, RD2, RA2, RB2, RK1, RX0, RY0, RK2);
14438
14439+ pax_force_retaddr
14440 ret;
14441 ENDPROC(__twofish_enc_blk8)
14442
14443@@ -324,6 +326,7 @@ __twofish_dec_blk8:
14444 outunpack_blocks(RA1, RB1, RC1, RD1, RK1, RX0, RY0, RK2);
14445 outunpack_blocks(RA2, RB2, RC2, RD2, RK1, RX0, RY0, RK2);
14446
14447+ pax_force_retaddr
14448 ret;
14449 ENDPROC(__twofish_dec_blk8)
14450
14451@@ -342,6 +345,7 @@ ENTRY(twofish_ecb_enc_8way)
14452
14453 store_8way(%r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
14454
14455+ pax_force_retaddr
14456 ret;
14457 ENDPROC(twofish_ecb_enc_8way)
14458
14459@@ -360,6 +364,7 @@ ENTRY(twofish_ecb_dec_8way)
14460
14461 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14462
14463+ pax_force_retaddr
14464 ret;
14465 ENDPROC(twofish_ecb_dec_8way)
14466
14467@@ -370,19 +375,20 @@ ENTRY(twofish_cbc_dec_8way)
14468 * %rdx: src
14469 */
14470
14471- pushq %r12;
14472+ pushq %r14;
14473
14474 movq %rsi, %r11;
14475- movq %rdx, %r12;
14476+ movq %rdx, %r14;
14477
14478 load_8way(%rdx, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
14479
14480 call __twofish_dec_blk8;
14481
14482- store_cbc_8way(%r12, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14483+ store_cbc_8way(%r14, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14484
14485- popq %r12;
14486+ popq %r14;
14487
14488+ pax_force_retaddr
14489 ret;
14490 ENDPROC(twofish_cbc_dec_8way)
14491
14492@@ -394,20 +400,21 @@ ENTRY(twofish_ctr_8way)
14493 * %rcx: iv (little endian, 128bit)
14494 */
14495
14496- pushq %r12;
14497+ pushq %r14;
14498
14499 movq %rsi, %r11;
14500- movq %rdx, %r12;
14501+ movq %rdx, %r14;
14502
14503 load_ctr_8way(%rcx, .Lbswap128_mask, RA1, RB1, RC1, RD1, RA2, RB2, RC2,
14504 RD2, RX0, RX1, RY0);
14505
14506 call __twofish_enc_blk8;
14507
14508- store_ctr_8way(%r12, %r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
14509+ store_ctr_8way(%r14, %r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
14510
14511- popq %r12;
14512+ popq %r14;
14513
14514+ pax_force_retaddr
14515 ret;
14516 ENDPROC(twofish_ctr_8way)
14517
14518@@ -430,6 +437,7 @@ ENTRY(twofish_xts_enc_8way)
14519 /* dst <= regs xor IVs(in dst) */
14520 store_xts_8way(%r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
14521
14522+ pax_force_retaddr
14523 ret;
14524 ENDPROC(twofish_xts_enc_8way)
14525
14526@@ -452,5 +460,6 @@ ENTRY(twofish_xts_dec_8way)
14527 /* dst <= regs xor IVs(in dst) */
14528 store_xts_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14529
14530+ pax_force_retaddr
14531 ret;
14532 ENDPROC(twofish_xts_dec_8way)
14533diff --git a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
14534index 1c3b7ce..02f578d 100644
14535--- a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
14536+++ b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
14537@@ -21,6 +21,7 @@
14538 */
14539
14540 #include <linux/linkage.h>
14541+#include <asm/alternative-asm.h>
14542
14543 .file "twofish-x86_64-asm-3way.S"
14544 .text
14545@@ -258,6 +259,7 @@ ENTRY(__twofish_enc_blk_3way)
14546 popq %r13;
14547 popq %r14;
14548 popq %r15;
14549+ pax_force_retaddr
14550 ret;
14551
14552 .L__enc_xor3:
14553@@ -269,6 +271,7 @@ ENTRY(__twofish_enc_blk_3way)
14554 popq %r13;
14555 popq %r14;
14556 popq %r15;
14557+ pax_force_retaddr
14558 ret;
14559 ENDPROC(__twofish_enc_blk_3way)
14560
14561@@ -308,5 +311,6 @@ ENTRY(twofish_dec_blk_3way)
14562 popq %r13;
14563 popq %r14;
14564 popq %r15;
14565+ pax_force_retaddr
14566 ret;
14567 ENDPROC(twofish_dec_blk_3way)
14568diff --git a/arch/x86/crypto/twofish-x86_64-asm_64.S b/arch/x86/crypto/twofish-x86_64-asm_64.S
14569index a039d21..524b8b2 100644
14570--- a/arch/x86/crypto/twofish-x86_64-asm_64.S
14571+++ b/arch/x86/crypto/twofish-x86_64-asm_64.S
14572@@ -22,6 +22,7 @@
14573
14574 #include <linux/linkage.h>
14575 #include <asm/asm-offsets.h>
14576+#include <asm/alternative-asm.h>
14577
14578 #define a_offset 0
14579 #define b_offset 4
14580@@ -265,6 +266,7 @@ ENTRY(twofish_enc_blk)
14581
14582 popq R1
14583 movq $1,%rax
14584+ pax_force_retaddr
14585 ret
14586 ENDPROC(twofish_enc_blk)
14587
14588@@ -317,5 +319,6 @@ ENTRY(twofish_dec_blk)
14589
14590 popq R1
14591 movq $1,%rax
14592+ pax_force_retaddr
14593 ret
14594 ENDPROC(twofish_dec_blk)
14595diff --git a/arch/x86/ia32/ia32_aout.c b/arch/x86/ia32/ia32_aout.c
14596index d21ff89..6da8e6e 100644
14597--- a/arch/x86/ia32/ia32_aout.c
14598+++ b/arch/x86/ia32/ia32_aout.c
14599@@ -153,6 +153,8 @@ static int aout_core_dump(struct coredump_params *cprm)
14600 unsigned long dump_start, dump_size;
14601 struct user32 dump;
14602
14603+ memset(&dump, 0, sizeof(dump));
14604+
14605 fs = get_fs();
14606 set_fs(KERNEL_DS);
14607 has_dumped = 1;
14608diff --git a/arch/x86/ia32/ia32_signal.c b/arch/x86/ia32/ia32_signal.c
14609index 2206757..85cbcfa 100644
14610--- a/arch/x86/ia32/ia32_signal.c
14611+++ b/arch/x86/ia32/ia32_signal.c
14612@@ -218,7 +218,7 @@ asmlinkage long sys32_sigreturn(void)
14613 if (__get_user(set.sig[0], &frame->sc.oldmask)
14614 || (_COMPAT_NSIG_WORDS > 1
14615 && __copy_from_user((((char *) &set.sig) + 4),
14616- &frame->extramask,
14617+ frame->extramask,
14618 sizeof(frame->extramask))))
14619 goto badframe;
14620
14621@@ -338,7 +338,7 @@ static void __user *get_sigframe(struct ksignal *ksig, struct pt_regs *regs,
14622 sp -= frame_size;
14623 /* Align the stack pointer according to the i386 ABI,
14624 * i.e. so that on function entry ((sp + 4) & 15) == 0. */
14625- sp = ((sp + 4) & -16ul) - 4;
14626+ sp = ((sp - 12) & -16ul) - 4;
14627 return (void __user *) sp;
14628 }
14629
14630@@ -386,7 +386,7 @@ int ia32_setup_frame(int sig, struct ksignal *ksig,
14631 restorer = VDSO32_SYMBOL(current->mm->context.vdso,
14632 sigreturn);
14633 else
14634- restorer = &frame->retcode;
14635+ restorer = frame->retcode;
14636 }
14637
14638 put_user_try {
14639@@ -396,7 +396,7 @@ int ia32_setup_frame(int sig, struct ksignal *ksig,
14640 * These are actually not used anymore, but left because some
14641 * gdb versions depend on them as a marker.
14642 */
14643- put_user_ex(*((u64 *)&code), (u64 __user *)frame->retcode);
14644+ put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
14645 } put_user_catch(err);
14646
14647 if (err)
14648@@ -438,7 +438,7 @@ int ia32_setup_rt_frame(int sig, struct ksignal *ksig,
14649 0xb8,
14650 __NR_ia32_rt_sigreturn,
14651 0x80cd,
14652- 0,
14653+ 0
14654 };
14655
14656 frame = get_sigframe(ksig, regs, sizeof(*frame), &fpstate);
14657@@ -461,16 +461,18 @@ int ia32_setup_rt_frame(int sig, struct ksignal *ksig,
14658
14659 if (ksig->ka.sa.sa_flags & SA_RESTORER)
14660 restorer = ksig->ka.sa.sa_restorer;
14661+ else if (current->mm->context.vdso)
14662+ /* Return stub is in 32bit vsyscall page */
14663+ restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
14664 else
14665- restorer = VDSO32_SYMBOL(current->mm->context.vdso,
14666- rt_sigreturn);
14667+ restorer = frame->retcode;
14668 put_user_ex(ptr_to_compat(restorer), &frame->pretcode);
14669
14670 /*
14671 * Not actually used anymore, but left because some gdb
14672 * versions need it.
14673 */
14674- put_user_ex(*((u64 *)&code), (u64 __user *)frame->retcode);
14675+ put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
14676 } put_user_catch(err);
14677
14678 err |= copy_siginfo_to_user32(&frame->info, &ksig->info);
14679diff --git a/arch/x86/ia32/ia32entry.S b/arch/x86/ia32/ia32entry.S
14680index 4299eb0..c0687a7 100644
14681--- a/arch/x86/ia32/ia32entry.S
14682+++ b/arch/x86/ia32/ia32entry.S
14683@@ -15,8 +15,10 @@
14684 #include <asm/irqflags.h>
14685 #include <asm/asm.h>
14686 #include <asm/smap.h>
14687+#include <asm/pgtable.h>
14688 #include <linux/linkage.h>
14689 #include <linux/err.h>
14690+#include <asm/alternative-asm.h>
14691
14692 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
14693 #include <linux/elf-em.h>
14694@@ -62,12 +64,12 @@
14695 */
14696 .macro LOAD_ARGS32 offset, _r9=0
14697 .if \_r9
14698- movl \offset+16(%rsp),%r9d
14699+ movl \offset+R9(%rsp),%r9d
14700 .endif
14701- movl \offset+40(%rsp),%ecx
14702- movl \offset+48(%rsp),%edx
14703- movl \offset+56(%rsp),%esi
14704- movl \offset+64(%rsp),%edi
14705+ movl \offset+RCX(%rsp),%ecx
14706+ movl \offset+RDX(%rsp),%edx
14707+ movl \offset+RSI(%rsp),%esi
14708+ movl \offset+RDI(%rsp),%edi
14709 movl %eax,%eax /* zero extension */
14710 .endm
14711
14712@@ -96,6 +98,32 @@ ENTRY(native_irq_enable_sysexit)
14713 ENDPROC(native_irq_enable_sysexit)
14714 #endif
14715
14716+ .macro pax_enter_kernel_user
14717+ pax_set_fptr_mask
14718+#ifdef CONFIG_PAX_MEMORY_UDEREF
14719+ call pax_enter_kernel_user
14720+#endif
14721+ .endm
14722+
14723+ .macro pax_exit_kernel_user
14724+#ifdef CONFIG_PAX_MEMORY_UDEREF
14725+ call pax_exit_kernel_user
14726+#endif
14727+#ifdef CONFIG_PAX_RANDKSTACK
14728+ pushq %rax
14729+ pushq %r11
14730+ call pax_randomize_kstack
14731+ popq %r11
14732+ popq %rax
14733+#endif
14734+ .endm
14735+
14736+ .macro pax_erase_kstack
14737+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
14738+ call pax_erase_kstack
14739+#endif
14740+ .endm
14741+
14742 /*
14743 * 32bit SYSENTER instruction entry.
14744 *
14745@@ -122,12 +150,6 @@ ENTRY(ia32_sysenter_target)
14746 CFI_REGISTER rsp,rbp
14747 SWAPGS_UNSAFE_STACK
14748 movq PER_CPU_VAR(kernel_stack), %rsp
14749- addq $(KERNEL_STACK_OFFSET),%rsp
14750- /*
14751- * No need to follow this irqs on/off section: the syscall
14752- * disabled irqs, here we enable it straight after entry:
14753- */
14754- ENABLE_INTERRUPTS(CLBR_NONE)
14755 movl %ebp,%ebp /* zero extension */
14756 pushq_cfi $__USER32_DS
14757 /*CFI_REL_OFFSET ss,0*/
14758@@ -135,24 +157,49 @@ ENTRY(ia32_sysenter_target)
14759 CFI_REL_OFFSET rsp,0
14760 pushfq_cfi
14761 /*CFI_REL_OFFSET rflags,0*/
14762- movl TI_sysenter_return+THREAD_INFO(%rsp,3*8-KERNEL_STACK_OFFSET),%r10d
14763- CFI_REGISTER rip,r10
14764+ orl $X86_EFLAGS_IF,(%rsp)
14765+ GET_THREAD_INFO(%r11)
14766+ movl TI_sysenter_return(%r11), %r11d
14767+ CFI_REGISTER rip,r11
14768 pushq_cfi $__USER32_CS
14769 /*CFI_REL_OFFSET cs,0*/
14770 movl %eax, %eax
14771- pushq_cfi %r10
14772+ pushq_cfi %r11
14773 CFI_REL_OFFSET rip,0
14774 pushq_cfi %rax
14775 cld
14776 SAVE_ARGS 0,1,0
14777+ pax_enter_kernel_user
14778+
14779+#ifdef CONFIG_PAX_RANDKSTACK
14780+ pax_erase_kstack
14781+#endif
14782+
14783+ /*
14784+ * No need to follow this irqs on/off section: the syscall
14785+ * disabled irqs, here we enable it straight after entry:
14786+ */
14787+ ENABLE_INTERRUPTS(CLBR_NONE)
14788 /* no need to do an access_ok check here because rbp has been
14789 32bit zero extended */
14790+
14791+#ifdef CONFIG_PAX_MEMORY_UDEREF
14792+ addq pax_user_shadow_base,%rbp
14793+ ASM_PAX_OPEN_USERLAND
14794+#endif
14795+
14796 ASM_STAC
14797 1: movl (%rbp),%ebp
14798 _ASM_EXTABLE(1b,ia32_badarg)
14799 ASM_CLAC
14800- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14801- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14802+
14803+#ifdef CONFIG_PAX_MEMORY_UDEREF
14804+ ASM_PAX_CLOSE_USERLAND
14805+#endif
14806+
14807+ GET_THREAD_INFO(%r11)
14808+ orl $TS_COMPAT,TI_status(%r11)
14809+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
14810 CFI_REMEMBER_STATE
14811 jnz sysenter_tracesys
14812 cmpq $(IA32_NR_syscalls-1),%rax
14813@@ -162,15 +209,18 @@ sysenter_do_call:
14814 sysenter_dispatch:
14815 call *ia32_sys_call_table(,%rax,8)
14816 movq %rax,RAX-ARGOFFSET(%rsp)
14817+ GET_THREAD_INFO(%r11)
14818 DISABLE_INTERRUPTS(CLBR_NONE)
14819 TRACE_IRQS_OFF
14820- testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14821+ testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
14822 jnz sysexit_audit
14823 sysexit_from_sys_call:
14824- andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14825+ pax_exit_kernel_user
14826+ pax_erase_kstack
14827+ andl $~TS_COMPAT,TI_status(%r11)
14828 /* clear IF, that popfq doesn't enable interrupts early */
14829- andl $~0x200,EFLAGS-R11(%rsp)
14830- movl RIP-R11(%rsp),%edx /* User %eip */
14831+ andl $~X86_EFLAGS_IF,EFLAGS(%rsp)
14832+ movl RIP(%rsp),%edx /* User %eip */
14833 CFI_REGISTER rip,rdx
14834 RESTORE_ARGS 0,24,0,0,0,0
14835 xorq %r8,%r8
14836@@ -193,6 +243,9 @@ sysexit_from_sys_call:
14837 movl %eax,%esi /* 2nd arg: syscall number */
14838 movl $AUDIT_ARCH_I386,%edi /* 1st arg: audit arch */
14839 call __audit_syscall_entry
14840+
14841+ pax_erase_kstack
14842+
14843 movl RAX-ARGOFFSET(%rsp),%eax /* reload syscall number */
14844 cmpq $(IA32_NR_syscalls-1),%rax
14845 ja ia32_badsys
14846@@ -204,7 +257,7 @@ sysexit_from_sys_call:
14847 .endm
14848
14849 .macro auditsys_exit exit
14850- testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14851+ testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
14852 jnz ia32_ret_from_sys_call
14853 TRACE_IRQS_ON
14854 ENABLE_INTERRUPTS(CLBR_NONE)
14855@@ -215,11 +268,12 @@ sysexit_from_sys_call:
14856 1: setbe %al /* 1 if error, 0 if not */
14857 movzbl %al,%edi /* zero-extend that into %edi */
14858 call __audit_syscall_exit
14859+ GET_THREAD_INFO(%r11)
14860 movq RAX-ARGOFFSET(%rsp),%rax /* reload syscall return value */
14861 movl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),%edi
14862 DISABLE_INTERRUPTS(CLBR_NONE)
14863 TRACE_IRQS_OFF
14864- testl %edi,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14865+ testl %edi,TI_flags(%r11)
14866 jz \exit
14867 CLEAR_RREGS -ARGOFFSET
14868 jmp int_with_check
14869@@ -237,7 +291,7 @@ sysexit_audit:
14870
14871 sysenter_tracesys:
14872 #ifdef CONFIG_AUDITSYSCALL
14873- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14874+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
14875 jz sysenter_auditsys
14876 #endif
14877 SAVE_REST
14878@@ -249,6 +303,9 @@ sysenter_tracesys:
14879 RESTORE_REST
14880 cmpq $(IA32_NR_syscalls-1),%rax
14881 ja int_ret_from_sys_call /* sysenter_tracesys has set RAX(%rsp) */
14882+
14883+ pax_erase_kstack
14884+
14885 jmp sysenter_do_call
14886 CFI_ENDPROC
14887 ENDPROC(ia32_sysenter_target)
14888@@ -276,19 +333,25 @@ ENDPROC(ia32_sysenter_target)
14889 ENTRY(ia32_cstar_target)
14890 CFI_STARTPROC32 simple
14891 CFI_SIGNAL_FRAME
14892- CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
14893+ CFI_DEF_CFA rsp,0
14894 CFI_REGISTER rip,rcx
14895 /*CFI_REGISTER rflags,r11*/
14896 SWAPGS_UNSAFE_STACK
14897 movl %esp,%r8d
14898 CFI_REGISTER rsp,r8
14899 movq PER_CPU_VAR(kernel_stack),%rsp
14900+ SAVE_ARGS 8*6,0,0
14901+ pax_enter_kernel_user
14902+
14903+#ifdef CONFIG_PAX_RANDKSTACK
14904+ pax_erase_kstack
14905+#endif
14906+
14907 /*
14908 * No need to follow this irqs on/off section: the syscall
14909 * disabled irqs and here we enable it straight after entry:
14910 */
14911 ENABLE_INTERRUPTS(CLBR_NONE)
14912- SAVE_ARGS 8,0,0
14913 movl %eax,%eax /* zero extension */
14914 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
14915 movq %rcx,RIP-ARGOFFSET(%rsp)
14916@@ -304,12 +367,25 @@ ENTRY(ia32_cstar_target)
14917 /* no need to do an access_ok check here because r8 has been
14918 32bit zero extended */
14919 /* hardware stack frame is complete now */
14920+
14921+#ifdef CONFIG_PAX_MEMORY_UDEREF
14922+ ASM_PAX_OPEN_USERLAND
14923+ movq pax_user_shadow_base,%r8
14924+ addq RSP-ARGOFFSET(%rsp),%r8
14925+#endif
14926+
14927 ASM_STAC
14928 1: movl (%r8),%r9d
14929 _ASM_EXTABLE(1b,ia32_badarg)
14930 ASM_CLAC
14931- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14932- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14933+
14934+#ifdef CONFIG_PAX_MEMORY_UDEREF
14935+ ASM_PAX_CLOSE_USERLAND
14936+#endif
14937+
14938+ GET_THREAD_INFO(%r11)
14939+ orl $TS_COMPAT,TI_status(%r11)
14940+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
14941 CFI_REMEMBER_STATE
14942 jnz cstar_tracesys
14943 cmpq $IA32_NR_syscalls-1,%rax
14944@@ -319,13 +395,16 @@ cstar_do_call:
14945 cstar_dispatch:
14946 call *ia32_sys_call_table(,%rax,8)
14947 movq %rax,RAX-ARGOFFSET(%rsp)
14948+ GET_THREAD_INFO(%r11)
14949 DISABLE_INTERRUPTS(CLBR_NONE)
14950 TRACE_IRQS_OFF
14951- testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14952+ testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
14953 jnz sysretl_audit
14954 sysretl_from_sys_call:
14955- andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14956- RESTORE_ARGS 0,-ARG_SKIP,0,0,0
14957+ pax_exit_kernel_user
14958+ pax_erase_kstack
14959+ andl $~TS_COMPAT,TI_status(%r11)
14960+ RESTORE_ARGS 0,-ORIG_RAX,0,0,0
14961 movl RIP-ARGOFFSET(%rsp),%ecx
14962 CFI_REGISTER rip,rcx
14963 movl EFLAGS-ARGOFFSET(%rsp),%r11d
14964@@ -352,7 +431,7 @@ sysretl_audit:
14965
14966 cstar_tracesys:
14967 #ifdef CONFIG_AUDITSYSCALL
14968- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14969+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
14970 jz cstar_auditsys
14971 #endif
14972 xchgl %r9d,%ebp
14973@@ -366,11 +445,19 @@ cstar_tracesys:
14974 xchgl %ebp,%r9d
14975 cmpq $(IA32_NR_syscalls-1),%rax
14976 ja int_ret_from_sys_call /* cstar_tracesys has set RAX(%rsp) */
14977+
14978+ pax_erase_kstack
14979+
14980 jmp cstar_do_call
14981 END(ia32_cstar_target)
14982
14983 ia32_badarg:
14984 ASM_CLAC
14985+
14986+#ifdef CONFIG_PAX_MEMORY_UDEREF
14987+ ASM_PAX_CLOSE_USERLAND
14988+#endif
14989+
14990 movq $-EFAULT,%rax
14991 jmp ia32_sysret
14992 CFI_ENDPROC
14993@@ -407,19 +494,26 @@ ENTRY(ia32_syscall)
14994 CFI_REL_OFFSET rip,RIP-RIP
14995 PARAVIRT_ADJUST_EXCEPTION_FRAME
14996 SWAPGS
14997- /*
14998- * No need to follow this irqs on/off section: the syscall
14999- * disabled irqs and here we enable it straight after entry:
15000- */
15001- ENABLE_INTERRUPTS(CLBR_NONE)
15002 movl %eax,%eax
15003 pushq_cfi %rax
15004 cld
15005 /* note the registers are not zero extended to the sf.
15006 this could be a problem. */
15007 SAVE_ARGS 0,1,0
15008- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
15009- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
15010+ pax_enter_kernel_user
15011+
15012+#ifdef CONFIG_PAX_RANDKSTACK
15013+ pax_erase_kstack
15014+#endif
15015+
15016+ /*
15017+ * No need to follow this irqs on/off section: the syscall
15018+ * disabled irqs and here we enable it straight after entry:
15019+ */
15020+ ENABLE_INTERRUPTS(CLBR_NONE)
15021+ GET_THREAD_INFO(%r11)
15022+ orl $TS_COMPAT,TI_status(%r11)
15023+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
15024 jnz ia32_tracesys
15025 cmpq $(IA32_NR_syscalls-1),%rax
15026 ja ia32_badsys
15027@@ -442,6 +536,9 @@ ia32_tracesys:
15028 RESTORE_REST
15029 cmpq $(IA32_NR_syscalls-1),%rax
15030 ja int_ret_from_sys_call /* ia32_tracesys has set RAX(%rsp) */
15031+
15032+ pax_erase_kstack
15033+
15034 jmp ia32_do_call
15035 END(ia32_syscall)
15036
15037diff --git a/arch/x86/ia32/sys_ia32.c b/arch/x86/ia32/sys_ia32.c
15038index 8e0ceec..af13504 100644
15039--- a/arch/x86/ia32/sys_ia32.c
15040+++ b/arch/x86/ia32/sys_ia32.c
15041@@ -69,8 +69,8 @@ asmlinkage long sys32_ftruncate64(unsigned int fd, unsigned long offset_low,
15042 */
15043 static int cp_stat64(struct stat64 __user *ubuf, struct kstat *stat)
15044 {
15045- typeof(ubuf->st_uid) uid = 0;
15046- typeof(ubuf->st_gid) gid = 0;
15047+ typeof(((struct stat64 *)0)->st_uid) uid = 0;
15048+ typeof(((struct stat64 *)0)->st_gid) gid = 0;
15049 SET_UID(uid, from_kuid_munged(current_user_ns(), stat->uid));
15050 SET_GID(gid, from_kgid_munged(current_user_ns(), stat->gid));
15051 if (!access_ok(VERIFY_WRITE, ubuf, sizeof(struct stat64)) ||
15052diff --git a/arch/x86/include/asm/alternative-asm.h b/arch/x86/include/asm/alternative-asm.h
15053index 372231c..51b537d 100644
15054--- a/arch/x86/include/asm/alternative-asm.h
15055+++ b/arch/x86/include/asm/alternative-asm.h
15056@@ -18,6 +18,45 @@
15057 .endm
15058 #endif
15059
15060+#ifdef KERNEXEC_PLUGIN
15061+ .macro pax_force_retaddr_bts rip=0
15062+ btsq $63,\rip(%rsp)
15063+ .endm
15064+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
15065+ .macro pax_force_retaddr rip=0, reload=0
15066+ btsq $63,\rip(%rsp)
15067+ .endm
15068+ .macro pax_force_fptr ptr
15069+ btsq $63,\ptr
15070+ .endm
15071+ .macro pax_set_fptr_mask
15072+ .endm
15073+#endif
15074+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
15075+ .macro pax_force_retaddr rip=0, reload=0
15076+ .if \reload
15077+ pax_set_fptr_mask
15078+ .endif
15079+ orq %r12,\rip(%rsp)
15080+ .endm
15081+ .macro pax_force_fptr ptr
15082+ orq %r12,\ptr
15083+ .endm
15084+ .macro pax_set_fptr_mask
15085+ movabs $0x8000000000000000,%r12
15086+ .endm
15087+#endif
15088+#else
15089+ .macro pax_force_retaddr rip=0, reload=0
15090+ .endm
15091+ .macro pax_force_fptr ptr
15092+ .endm
15093+ .macro pax_force_retaddr_bts rip=0
15094+ .endm
15095+ .macro pax_set_fptr_mask
15096+ .endm
15097+#endif
15098+
15099 .macro altinstruction_entry orig alt feature orig_len alt_len
15100 .long \orig - .
15101 .long \alt - .
15102diff --git a/arch/x86/include/asm/alternative.h b/arch/x86/include/asm/alternative.h
15103index 0a3f9c9..c9d081d 100644
15104--- a/arch/x86/include/asm/alternative.h
15105+++ b/arch/x86/include/asm/alternative.h
15106@@ -106,7 +106,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
15107 ".pushsection .discard,\"aw\",@progbits\n" \
15108 DISCARD_ENTRY(1) \
15109 ".popsection\n" \
15110- ".pushsection .altinstr_replacement, \"ax\"\n" \
15111+ ".pushsection .altinstr_replacement, \"a\"\n" \
15112 ALTINSTR_REPLACEMENT(newinstr, feature, 1) \
15113 ".popsection"
15114
15115@@ -120,7 +120,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
15116 DISCARD_ENTRY(1) \
15117 DISCARD_ENTRY(2) \
15118 ".popsection\n" \
15119- ".pushsection .altinstr_replacement, \"ax\"\n" \
15120+ ".pushsection .altinstr_replacement, \"a\"\n" \
15121 ALTINSTR_REPLACEMENT(newinstr1, feature1, 1) \
15122 ALTINSTR_REPLACEMENT(newinstr2, feature2, 2) \
15123 ".popsection"
15124diff --git a/arch/x86/include/asm/apic.h b/arch/x86/include/asm/apic.h
15125index 1d2091a..f5074c1 100644
15126--- a/arch/x86/include/asm/apic.h
15127+++ b/arch/x86/include/asm/apic.h
15128@@ -45,7 +45,7 @@ static inline void generic_apic_probe(void)
15129
15130 #ifdef CONFIG_X86_LOCAL_APIC
15131
15132-extern unsigned int apic_verbosity;
15133+extern int apic_verbosity;
15134 extern int local_apic_timer_c2_ok;
15135
15136 extern int disable_apic;
15137diff --git a/arch/x86/include/asm/apm.h b/arch/x86/include/asm/apm.h
15138index 20370c6..a2eb9b0 100644
15139--- a/arch/x86/include/asm/apm.h
15140+++ b/arch/x86/include/asm/apm.h
15141@@ -34,7 +34,7 @@ static inline void apm_bios_call_asm(u32 func, u32 ebx_in, u32 ecx_in,
15142 __asm__ __volatile__(APM_DO_ZERO_SEGS
15143 "pushl %%edi\n\t"
15144 "pushl %%ebp\n\t"
15145- "lcall *%%cs:apm_bios_entry\n\t"
15146+ "lcall *%%ss:apm_bios_entry\n\t"
15147 "setc %%al\n\t"
15148 "popl %%ebp\n\t"
15149 "popl %%edi\n\t"
15150@@ -58,7 +58,7 @@ static inline u8 apm_bios_call_simple_asm(u32 func, u32 ebx_in,
15151 __asm__ __volatile__(APM_DO_ZERO_SEGS
15152 "pushl %%edi\n\t"
15153 "pushl %%ebp\n\t"
15154- "lcall *%%cs:apm_bios_entry\n\t"
15155+ "lcall *%%ss:apm_bios_entry\n\t"
15156 "setc %%bl\n\t"
15157 "popl %%ebp\n\t"
15158 "popl %%edi\n\t"
15159diff --git a/arch/x86/include/asm/atomic.h b/arch/x86/include/asm/atomic.h
15160index b17f4f4..9620151 100644
15161--- a/arch/x86/include/asm/atomic.h
15162+++ b/arch/x86/include/asm/atomic.h
15163@@ -23,7 +23,18 @@
15164 */
15165 static inline int atomic_read(const atomic_t *v)
15166 {
15167- return (*(volatile int *)&(v)->counter);
15168+ return (*(volatile const int *)&(v)->counter);
15169+}
15170+
15171+/**
15172+ * atomic_read_unchecked - read atomic variable
15173+ * @v: pointer of type atomic_unchecked_t
15174+ *
15175+ * Atomically reads the value of @v.
15176+ */
15177+static inline int __intentional_overflow(-1) atomic_read_unchecked(const atomic_unchecked_t *v)
15178+{
15179+ return (*(volatile const int *)&(v)->counter);
15180 }
15181
15182 /**
15183@@ -39,6 +50,18 @@ static inline void atomic_set(atomic_t *v, int i)
15184 }
15185
15186 /**
15187+ * atomic_set_unchecked - set atomic variable
15188+ * @v: pointer of type atomic_unchecked_t
15189+ * @i: required value
15190+ *
15191+ * Atomically sets the value of @v to @i.
15192+ */
15193+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
15194+{
15195+ v->counter = i;
15196+}
15197+
15198+/**
15199 * atomic_add - add integer to atomic variable
15200 * @i: integer value to add
15201 * @v: pointer of type atomic_t
15202@@ -47,7 +70,29 @@ static inline void atomic_set(atomic_t *v, int i)
15203 */
15204 static inline void atomic_add(int i, atomic_t *v)
15205 {
15206- asm volatile(LOCK_PREFIX "addl %1,%0"
15207+ asm volatile(LOCK_PREFIX "addl %1,%0\n"
15208+
15209+#ifdef CONFIG_PAX_REFCOUNT
15210+ "jno 0f\n"
15211+ LOCK_PREFIX "subl %1,%0\n"
15212+ "int $4\n0:\n"
15213+ _ASM_EXTABLE(0b, 0b)
15214+#endif
15215+
15216+ : "+m" (v->counter)
15217+ : "ir" (i));
15218+}
15219+
15220+/**
15221+ * atomic_add_unchecked - add integer to atomic variable
15222+ * @i: integer value to add
15223+ * @v: pointer of type atomic_unchecked_t
15224+ *
15225+ * Atomically adds @i to @v.
15226+ */
15227+static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
15228+{
15229+ asm volatile(LOCK_PREFIX "addl %1,%0\n"
15230 : "+m" (v->counter)
15231 : "ir" (i));
15232 }
15233@@ -61,7 +106,29 @@ static inline void atomic_add(int i, atomic_t *v)
15234 */
15235 static inline void atomic_sub(int i, atomic_t *v)
15236 {
15237- asm volatile(LOCK_PREFIX "subl %1,%0"
15238+ asm volatile(LOCK_PREFIX "subl %1,%0\n"
15239+
15240+#ifdef CONFIG_PAX_REFCOUNT
15241+ "jno 0f\n"
15242+ LOCK_PREFIX "addl %1,%0\n"
15243+ "int $4\n0:\n"
15244+ _ASM_EXTABLE(0b, 0b)
15245+#endif
15246+
15247+ : "+m" (v->counter)
15248+ : "ir" (i));
15249+}
15250+
15251+/**
15252+ * atomic_sub_unchecked - subtract integer from atomic variable
15253+ * @i: integer value to subtract
15254+ * @v: pointer of type atomic_unchecked_t
15255+ *
15256+ * Atomically subtracts @i from @v.
15257+ */
15258+static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
15259+{
15260+ asm volatile(LOCK_PREFIX "subl %1,%0\n"
15261 : "+m" (v->counter)
15262 : "ir" (i));
15263 }
15264@@ -77,7 +144,7 @@ static inline void atomic_sub(int i, atomic_t *v)
15265 */
15266 static inline int atomic_sub_and_test(int i, atomic_t *v)
15267 {
15268- GEN_BINARY_RMWcc(LOCK_PREFIX "subl", v->counter, "er", i, "%0", "e");
15269+ GEN_BINARY_RMWcc(LOCK_PREFIX "subl", LOCK_PREFIX "addl", v->counter, "er", i, "%0", "e");
15270 }
15271
15272 /**
15273@@ -88,7 +155,27 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
15274 */
15275 static inline void atomic_inc(atomic_t *v)
15276 {
15277- asm volatile(LOCK_PREFIX "incl %0"
15278+ asm volatile(LOCK_PREFIX "incl %0\n"
15279+
15280+#ifdef CONFIG_PAX_REFCOUNT
15281+ "jno 0f\n"
15282+ LOCK_PREFIX "decl %0\n"
15283+ "int $4\n0:\n"
15284+ _ASM_EXTABLE(0b, 0b)
15285+#endif
15286+
15287+ : "+m" (v->counter));
15288+}
15289+
15290+/**
15291+ * atomic_inc_unchecked - increment atomic variable
15292+ * @v: pointer of type atomic_unchecked_t
15293+ *
15294+ * Atomically increments @v by 1.
15295+ */
15296+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
15297+{
15298+ asm volatile(LOCK_PREFIX "incl %0\n"
15299 : "+m" (v->counter));
15300 }
15301
15302@@ -100,7 +187,27 @@ static inline void atomic_inc(atomic_t *v)
15303 */
15304 static inline void atomic_dec(atomic_t *v)
15305 {
15306- asm volatile(LOCK_PREFIX "decl %0"
15307+ asm volatile(LOCK_PREFIX "decl %0\n"
15308+
15309+#ifdef CONFIG_PAX_REFCOUNT
15310+ "jno 0f\n"
15311+ LOCK_PREFIX "incl %0\n"
15312+ "int $4\n0:\n"
15313+ _ASM_EXTABLE(0b, 0b)
15314+#endif
15315+
15316+ : "+m" (v->counter));
15317+}
15318+
15319+/**
15320+ * atomic_dec_unchecked - decrement atomic variable
15321+ * @v: pointer of type atomic_unchecked_t
15322+ *
15323+ * Atomically decrements @v by 1.
15324+ */
15325+static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
15326+{
15327+ asm volatile(LOCK_PREFIX "decl %0\n"
15328 : "+m" (v->counter));
15329 }
15330
15331@@ -114,7 +221,7 @@ static inline void atomic_dec(atomic_t *v)
15332 */
15333 static inline int atomic_dec_and_test(atomic_t *v)
15334 {
15335- GEN_UNARY_RMWcc(LOCK_PREFIX "decl", v->counter, "%0", "e");
15336+ GEN_UNARY_RMWcc(LOCK_PREFIX "decl", LOCK_PREFIX "incl", v->counter, "%0", "e");
15337 }
15338
15339 /**
15340@@ -127,7 +234,20 @@ static inline int atomic_dec_and_test(atomic_t *v)
15341 */
15342 static inline int atomic_inc_and_test(atomic_t *v)
15343 {
15344- GEN_UNARY_RMWcc(LOCK_PREFIX "incl", v->counter, "%0", "e");
15345+ GEN_UNARY_RMWcc(LOCK_PREFIX "incl", LOCK_PREFIX "decl", v->counter, "%0", "e");
15346+}
15347+
15348+/**
15349+ * atomic_inc_and_test_unchecked - increment and test
15350+ * @v: pointer of type atomic_unchecked_t
15351+ *
15352+ * Atomically increments @v by 1
15353+ * and returns true if the result is zero, or false for all
15354+ * other cases.
15355+ */
15356+static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
15357+{
15358+ GEN_UNARY_RMWcc_unchecked(LOCK_PREFIX "incl", v->counter, "%0", "e");
15359 }
15360
15361 /**
15362@@ -141,7 +261,7 @@ static inline int atomic_inc_and_test(atomic_t *v)
15363 */
15364 static inline int atomic_add_negative(int i, atomic_t *v)
15365 {
15366- GEN_BINARY_RMWcc(LOCK_PREFIX "addl", v->counter, "er", i, "%0", "s");
15367+ GEN_BINARY_RMWcc(LOCK_PREFIX "addl", LOCK_PREFIX "subl", v->counter, "er", i, "%0", "s");
15368 }
15369
15370 /**
15371@@ -153,6 +273,18 @@ static inline int atomic_add_negative(int i, atomic_t *v)
15372 */
15373 static inline int atomic_add_return(int i, atomic_t *v)
15374 {
15375+ return i + xadd_check_overflow(&v->counter, i);
15376+}
15377+
15378+/**
15379+ * atomic_add_return_unchecked - add integer and return
15380+ * @i: integer value to add
15381+ * @v: pointer of type atomic_unchecked_t
15382+ *
15383+ * Atomically adds @i to @v and returns @i + @v
15384+ */
15385+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
15386+{
15387 return i + xadd(&v->counter, i);
15388 }
15389
15390@@ -169,9 +301,18 @@ static inline int atomic_sub_return(int i, atomic_t *v)
15391 }
15392
15393 #define atomic_inc_return(v) (atomic_add_return(1, v))
15394+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
15395+{
15396+ return atomic_add_return_unchecked(1, v);
15397+}
15398 #define atomic_dec_return(v) (atomic_sub_return(1, v))
15399
15400-static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
15401+static inline int __intentional_overflow(-1) atomic_cmpxchg(atomic_t *v, int old, int new)
15402+{
15403+ return cmpxchg(&v->counter, old, new);
15404+}
15405+
15406+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
15407 {
15408 return cmpxchg(&v->counter, old, new);
15409 }
15410@@ -181,6 +322,11 @@ static inline int atomic_xchg(atomic_t *v, int new)
15411 return xchg(&v->counter, new);
15412 }
15413
15414+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
15415+{
15416+ return xchg(&v->counter, new);
15417+}
15418+
15419 /**
15420 * __atomic_add_unless - add unless the number is already a given value
15421 * @v: pointer of type atomic_t
15422@@ -190,14 +336,27 @@ static inline int atomic_xchg(atomic_t *v, int new)
15423 * Atomically adds @a to @v, so long as @v was not already @u.
15424 * Returns the old value of @v.
15425 */
15426-static inline int __atomic_add_unless(atomic_t *v, int a, int u)
15427+static inline int __intentional_overflow(-1) __atomic_add_unless(atomic_t *v, int a, int u)
15428 {
15429- int c, old;
15430+ int c, old, new;
15431 c = atomic_read(v);
15432 for (;;) {
15433- if (unlikely(c == (u)))
15434+ if (unlikely(c == u))
15435 break;
15436- old = atomic_cmpxchg((v), c, c + (a));
15437+
15438+ asm volatile("addl %2,%0\n"
15439+
15440+#ifdef CONFIG_PAX_REFCOUNT
15441+ "jno 0f\n"
15442+ "subl %2,%0\n"
15443+ "int $4\n0:\n"
15444+ _ASM_EXTABLE(0b, 0b)
15445+#endif
15446+
15447+ : "=r" (new)
15448+ : "0" (c), "ir" (a));
15449+
15450+ old = atomic_cmpxchg(v, c, new);
15451 if (likely(old == c))
15452 break;
15453 c = old;
15454@@ -206,6 +365,49 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
15455 }
15456
15457 /**
15458+ * atomic_inc_not_zero_hint - increment if not null
15459+ * @v: pointer of type atomic_t
15460+ * @hint: probable value of the atomic before the increment
15461+ *
15462+ * This version of atomic_inc_not_zero() gives a hint of probable
15463+ * value of the atomic. This helps processor to not read the memory
15464+ * before doing the atomic read/modify/write cycle, lowering
15465+ * number of bus transactions on some arches.
15466+ *
15467+ * Returns: 0 if increment was not done, 1 otherwise.
15468+ */
15469+#define atomic_inc_not_zero_hint atomic_inc_not_zero_hint
15470+static inline int atomic_inc_not_zero_hint(atomic_t *v, int hint)
15471+{
15472+ int val, c = hint, new;
15473+
15474+ /* sanity test, should be removed by compiler if hint is a constant */
15475+ if (!hint)
15476+ return __atomic_add_unless(v, 1, 0);
15477+
15478+ do {
15479+ asm volatile("incl %0\n"
15480+
15481+#ifdef CONFIG_PAX_REFCOUNT
15482+ "jno 0f\n"
15483+ "decl %0\n"
15484+ "int $4\n0:\n"
15485+ _ASM_EXTABLE(0b, 0b)
15486+#endif
15487+
15488+ : "=r" (new)
15489+ : "0" (c));
15490+
15491+ val = atomic_cmpxchg(v, c, new);
15492+ if (val == c)
15493+ return 1;
15494+ c = val;
15495+ } while (c);
15496+
15497+ return 0;
15498+}
15499+
15500+/**
15501 * atomic_inc_short - increment of a short integer
15502 * @v: pointer to type int
15503 *
15504@@ -234,14 +436,37 @@ static inline void atomic_or_long(unsigned long *v1, unsigned long v2)
15505 #endif
15506
15507 /* These are x86-specific, used by some header files */
15508-#define atomic_clear_mask(mask, addr) \
15509- asm volatile(LOCK_PREFIX "andl %0,%1" \
15510- : : "r" (~(mask)), "m" (*(addr)) : "memory")
15511+static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
15512+{
15513+ asm volatile(LOCK_PREFIX "andl %1,%0"
15514+ : "+m" (v->counter)
15515+ : "r" (~(mask))
15516+ : "memory");
15517+}
15518
15519-#define atomic_set_mask(mask, addr) \
15520- asm volatile(LOCK_PREFIX "orl %0,%1" \
15521- : : "r" ((unsigned)(mask)), "m" (*(addr)) \
15522- : "memory")
15523+static inline void atomic_clear_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
15524+{
15525+ asm volatile(LOCK_PREFIX "andl %1,%0"
15526+ : "+m" (v->counter)
15527+ : "r" (~(mask))
15528+ : "memory");
15529+}
15530+
15531+static inline void atomic_set_mask(unsigned int mask, atomic_t *v)
15532+{
15533+ asm volatile(LOCK_PREFIX "orl %1,%0"
15534+ : "+m" (v->counter)
15535+ : "r" (mask)
15536+ : "memory");
15537+}
15538+
15539+static inline void atomic_set_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
15540+{
15541+ asm volatile(LOCK_PREFIX "orl %1,%0"
15542+ : "+m" (v->counter)
15543+ : "r" (mask)
15544+ : "memory");
15545+}
15546
15547 /* Atomic operations are already serializing on x86 */
15548 #define smp_mb__before_atomic_dec() barrier()
15549diff --git a/arch/x86/include/asm/atomic64_32.h b/arch/x86/include/asm/atomic64_32.h
15550index b154de7..bf18a5a 100644
15551--- a/arch/x86/include/asm/atomic64_32.h
15552+++ b/arch/x86/include/asm/atomic64_32.h
15553@@ -12,6 +12,14 @@ typedef struct {
15554 u64 __aligned(8) counter;
15555 } atomic64_t;
15556
15557+#ifdef CONFIG_PAX_REFCOUNT
15558+typedef struct {
15559+ u64 __aligned(8) counter;
15560+} atomic64_unchecked_t;
15561+#else
15562+typedef atomic64_t atomic64_unchecked_t;
15563+#endif
15564+
15565 #define ATOMIC64_INIT(val) { (val) }
15566
15567 #define __ATOMIC64_DECL(sym) void atomic64_##sym(atomic64_t *, ...)
15568@@ -37,21 +45,31 @@ typedef struct {
15569 ATOMIC64_DECL_ONE(sym##_386)
15570
15571 ATOMIC64_DECL_ONE(add_386);
15572+ATOMIC64_DECL_ONE(add_unchecked_386);
15573 ATOMIC64_DECL_ONE(sub_386);
15574+ATOMIC64_DECL_ONE(sub_unchecked_386);
15575 ATOMIC64_DECL_ONE(inc_386);
15576+ATOMIC64_DECL_ONE(inc_unchecked_386);
15577 ATOMIC64_DECL_ONE(dec_386);
15578+ATOMIC64_DECL_ONE(dec_unchecked_386);
15579 #endif
15580
15581 #define alternative_atomic64(f, out, in...) \
15582 __alternative_atomic64(f, f, ASM_OUTPUT2(out), ## in)
15583
15584 ATOMIC64_DECL(read);
15585+ATOMIC64_DECL(read_unchecked);
15586 ATOMIC64_DECL(set);
15587+ATOMIC64_DECL(set_unchecked);
15588 ATOMIC64_DECL(xchg);
15589 ATOMIC64_DECL(add_return);
15590+ATOMIC64_DECL(add_return_unchecked);
15591 ATOMIC64_DECL(sub_return);
15592+ATOMIC64_DECL(sub_return_unchecked);
15593 ATOMIC64_DECL(inc_return);
15594+ATOMIC64_DECL(inc_return_unchecked);
15595 ATOMIC64_DECL(dec_return);
15596+ATOMIC64_DECL(dec_return_unchecked);
15597 ATOMIC64_DECL(dec_if_positive);
15598 ATOMIC64_DECL(inc_not_zero);
15599 ATOMIC64_DECL(add_unless);
15600@@ -77,6 +95,21 @@ static inline long long atomic64_cmpxchg(atomic64_t *v, long long o, long long n
15601 }
15602
15603 /**
15604+ * atomic64_cmpxchg_unchecked - cmpxchg atomic64 variable
15605+ * @p: pointer to type atomic64_unchecked_t
15606+ * @o: expected value
15607+ * @n: new value
15608+ *
15609+ * Atomically sets @v to @n if it was equal to @o and returns
15610+ * the old value.
15611+ */
15612+
15613+static inline long long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long long o, long long n)
15614+{
15615+ return cmpxchg64(&v->counter, o, n);
15616+}
15617+
15618+/**
15619 * atomic64_xchg - xchg atomic64 variable
15620 * @v: pointer to type atomic64_t
15621 * @n: value to assign
15622@@ -112,6 +145,22 @@ static inline void atomic64_set(atomic64_t *v, long long i)
15623 }
15624
15625 /**
15626+ * atomic64_set_unchecked - set atomic64 variable
15627+ * @v: pointer to type atomic64_unchecked_t
15628+ * @n: value to assign
15629+ *
15630+ * Atomically sets the value of @v to @n.
15631+ */
15632+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
15633+{
15634+ unsigned high = (unsigned)(i >> 32);
15635+ unsigned low = (unsigned)i;
15636+ alternative_atomic64(set, /* no output */,
15637+ "S" (v), "b" (low), "c" (high)
15638+ : "eax", "edx", "memory");
15639+}
15640+
15641+/**
15642 * atomic64_read - read atomic64 variable
15643 * @v: pointer to type atomic64_t
15644 *
15645@@ -125,6 +174,19 @@ static inline long long atomic64_read(const atomic64_t *v)
15646 }
15647
15648 /**
15649+ * atomic64_read_unchecked - read atomic64 variable
15650+ * @v: pointer to type atomic64_unchecked_t
15651+ *
15652+ * Atomically reads the value of @v and returns it.
15653+ */
15654+static inline long long __intentional_overflow(-1) atomic64_read_unchecked(atomic64_unchecked_t *v)
15655+{
15656+ long long r;
15657+ alternative_atomic64(read, "=&A" (r), "c" (v) : "memory");
15658+ return r;
15659+ }
15660+
15661+/**
15662 * atomic64_add_return - add and return
15663 * @i: integer value to add
15664 * @v: pointer to type atomic64_t
15665@@ -139,6 +201,21 @@ static inline long long atomic64_add_return(long long i, atomic64_t *v)
15666 return i;
15667 }
15668
15669+/**
15670+ * atomic64_add_return_unchecked - add and return
15671+ * @i: integer value to add
15672+ * @v: pointer to type atomic64_unchecked_t
15673+ *
15674+ * Atomically adds @i to @v and returns @i + *@v
15675+ */
15676+static inline long long atomic64_add_return_unchecked(long long i, atomic64_unchecked_t *v)
15677+{
15678+ alternative_atomic64(add_return_unchecked,
15679+ ASM_OUTPUT2("+A" (i), "+c" (v)),
15680+ ASM_NO_INPUT_CLOBBER("memory"));
15681+ return i;
15682+}
15683+
15684 /*
15685 * Other variants with different arithmetic operators:
15686 */
15687@@ -158,6 +235,14 @@ static inline long long atomic64_inc_return(atomic64_t *v)
15688 return a;
15689 }
15690
15691+static inline long long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
15692+{
15693+ long long a;
15694+ alternative_atomic64(inc_return_unchecked, "=&A" (a),
15695+ "S" (v) : "memory", "ecx");
15696+ return a;
15697+}
15698+
15699 static inline long long atomic64_dec_return(atomic64_t *v)
15700 {
15701 long long a;
15702@@ -182,6 +267,21 @@ static inline long long atomic64_add(long long i, atomic64_t *v)
15703 }
15704
15705 /**
15706+ * atomic64_add_unchecked - add integer to atomic64 variable
15707+ * @i: integer value to add
15708+ * @v: pointer to type atomic64_unchecked_t
15709+ *
15710+ * Atomically adds @i to @v.
15711+ */
15712+static inline long long atomic64_add_unchecked(long long i, atomic64_unchecked_t *v)
15713+{
15714+ __alternative_atomic64(add_unchecked, add_return_unchecked,
15715+ ASM_OUTPUT2("+A" (i), "+c" (v)),
15716+ ASM_NO_INPUT_CLOBBER("memory"));
15717+ return i;
15718+}
15719+
15720+/**
15721 * atomic64_sub - subtract the atomic64 variable
15722 * @i: integer value to subtract
15723 * @v: pointer to type atomic64_t
15724diff --git a/arch/x86/include/asm/atomic64_64.h b/arch/x86/include/asm/atomic64_64.h
15725index 46e9052..ae45136 100644
15726--- a/arch/x86/include/asm/atomic64_64.h
15727+++ b/arch/x86/include/asm/atomic64_64.h
15728@@ -18,7 +18,19 @@
15729 */
15730 static inline long atomic64_read(const atomic64_t *v)
15731 {
15732- return (*(volatile long *)&(v)->counter);
15733+ return (*(volatile const long *)&(v)->counter);
15734+}
15735+
15736+/**
15737+ * atomic64_read_unchecked - read atomic64 variable
15738+ * @v: pointer of type atomic64_unchecked_t
15739+ *
15740+ * Atomically reads the value of @v.
15741+ * Doesn't imply a read memory barrier.
15742+ */
15743+static inline long __intentional_overflow(-1) atomic64_read_unchecked(const atomic64_unchecked_t *v)
15744+{
15745+ return (*(volatile const long *)&(v)->counter);
15746 }
15747
15748 /**
15749@@ -34,6 +46,18 @@ static inline void atomic64_set(atomic64_t *v, long i)
15750 }
15751
15752 /**
15753+ * atomic64_set_unchecked - set atomic64 variable
15754+ * @v: pointer to type atomic64_unchecked_t
15755+ * @i: required value
15756+ *
15757+ * Atomically sets the value of @v to @i.
15758+ */
15759+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
15760+{
15761+ v->counter = i;
15762+}
15763+
15764+/**
15765 * atomic64_add - add integer to atomic64 variable
15766 * @i: integer value to add
15767 * @v: pointer to type atomic64_t
15768@@ -42,6 +66,28 @@ static inline void atomic64_set(atomic64_t *v, long i)
15769 */
15770 static inline void atomic64_add(long i, atomic64_t *v)
15771 {
15772+ asm volatile(LOCK_PREFIX "addq %1,%0\n"
15773+
15774+#ifdef CONFIG_PAX_REFCOUNT
15775+ "jno 0f\n"
15776+ LOCK_PREFIX "subq %1,%0\n"
15777+ "int $4\n0:\n"
15778+ _ASM_EXTABLE(0b, 0b)
15779+#endif
15780+
15781+ : "=m" (v->counter)
15782+ : "er" (i), "m" (v->counter));
15783+}
15784+
15785+/**
15786+ * atomic64_add_unchecked - add integer to atomic64 variable
15787+ * @i: integer value to add
15788+ * @v: pointer to type atomic64_unchecked_t
15789+ *
15790+ * Atomically adds @i to @v.
15791+ */
15792+static inline void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
15793+{
15794 asm volatile(LOCK_PREFIX "addq %1,%0"
15795 : "=m" (v->counter)
15796 : "er" (i), "m" (v->counter));
15797@@ -56,7 +102,29 @@ static inline void atomic64_add(long i, atomic64_t *v)
15798 */
15799 static inline void atomic64_sub(long i, atomic64_t *v)
15800 {
15801- asm volatile(LOCK_PREFIX "subq %1,%0"
15802+ asm volatile(LOCK_PREFIX "subq %1,%0\n"
15803+
15804+#ifdef CONFIG_PAX_REFCOUNT
15805+ "jno 0f\n"
15806+ LOCK_PREFIX "addq %1,%0\n"
15807+ "int $4\n0:\n"
15808+ _ASM_EXTABLE(0b, 0b)
15809+#endif
15810+
15811+ : "=m" (v->counter)
15812+ : "er" (i), "m" (v->counter));
15813+}
15814+
15815+/**
15816+ * atomic64_sub_unchecked - subtract the atomic64 variable
15817+ * @i: integer value to subtract
15818+ * @v: pointer to type atomic64_unchecked_t
15819+ *
15820+ * Atomically subtracts @i from @v.
15821+ */
15822+static inline void atomic64_sub_unchecked(long i, atomic64_unchecked_t *v)
15823+{
15824+ asm volatile(LOCK_PREFIX "subq %1,%0\n"
15825 : "=m" (v->counter)
15826 : "er" (i), "m" (v->counter));
15827 }
15828@@ -72,7 +140,7 @@ static inline void atomic64_sub(long i, atomic64_t *v)
15829 */
15830 static inline int atomic64_sub_and_test(long i, atomic64_t *v)
15831 {
15832- GEN_BINARY_RMWcc(LOCK_PREFIX "subq", v->counter, "er", i, "%0", "e");
15833+ GEN_BINARY_RMWcc(LOCK_PREFIX "subq", LOCK_PREFIX "addq", v->counter, "er", i, "%0", "e");
15834 }
15835
15836 /**
15837@@ -83,6 +151,27 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
15838 */
15839 static inline void atomic64_inc(atomic64_t *v)
15840 {
15841+ asm volatile(LOCK_PREFIX "incq %0\n"
15842+
15843+#ifdef CONFIG_PAX_REFCOUNT
15844+ "jno 0f\n"
15845+ LOCK_PREFIX "decq %0\n"
15846+ "int $4\n0:\n"
15847+ _ASM_EXTABLE(0b, 0b)
15848+#endif
15849+
15850+ : "=m" (v->counter)
15851+ : "m" (v->counter));
15852+}
15853+
15854+/**
15855+ * atomic64_inc_unchecked - increment atomic64 variable
15856+ * @v: pointer to type atomic64_unchecked_t
15857+ *
15858+ * Atomically increments @v by 1.
15859+ */
15860+static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
15861+{
15862 asm volatile(LOCK_PREFIX "incq %0"
15863 : "=m" (v->counter)
15864 : "m" (v->counter));
15865@@ -96,7 +185,28 @@ static inline void atomic64_inc(atomic64_t *v)
15866 */
15867 static inline void atomic64_dec(atomic64_t *v)
15868 {
15869- asm volatile(LOCK_PREFIX "decq %0"
15870+ asm volatile(LOCK_PREFIX "decq %0\n"
15871+
15872+#ifdef CONFIG_PAX_REFCOUNT
15873+ "jno 0f\n"
15874+ LOCK_PREFIX "incq %0\n"
15875+ "int $4\n0:\n"
15876+ _ASM_EXTABLE(0b, 0b)
15877+#endif
15878+
15879+ : "=m" (v->counter)
15880+ : "m" (v->counter));
15881+}
15882+
15883+/**
15884+ * atomic64_dec_unchecked - decrement atomic64 variable
15885+ * @v: pointer to type atomic64_t
15886+ *
15887+ * Atomically decrements @v by 1.
15888+ */
15889+static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
15890+{
15891+ asm volatile(LOCK_PREFIX "decq %0\n"
15892 : "=m" (v->counter)
15893 : "m" (v->counter));
15894 }
15895@@ -111,7 +221,7 @@ static inline void atomic64_dec(atomic64_t *v)
15896 */
15897 static inline int atomic64_dec_and_test(atomic64_t *v)
15898 {
15899- GEN_UNARY_RMWcc(LOCK_PREFIX "decq", v->counter, "%0", "e");
15900+ GEN_UNARY_RMWcc(LOCK_PREFIX "decq", LOCK_PREFIX "incq", v->counter, "%0", "e");
15901 }
15902
15903 /**
15904@@ -124,7 +234,7 @@ static inline int atomic64_dec_and_test(atomic64_t *v)
15905 */
15906 static inline int atomic64_inc_and_test(atomic64_t *v)
15907 {
15908- GEN_UNARY_RMWcc(LOCK_PREFIX "incq", v->counter, "%0", "e");
15909+ GEN_UNARY_RMWcc(LOCK_PREFIX "incq", LOCK_PREFIX "decq", v->counter, "%0", "e");
15910 }
15911
15912 /**
15913@@ -138,7 +248,7 @@ static inline int atomic64_inc_and_test(atomic64_t *v)
15914 */
15915 static inline int atomic64_add_negative(long i, atomic64_t *v)
15916 {
15917- GEN_BINARY_RMWcc(LOCK_PREFIX "addq", v->counter, "er", i, "%0", "s");
15918+ GEN_BINARY_RMWcc(LOCK_PREFIX "addq", LOCK_PREFIX "subq", v->counter, "er", i, "%0", "s");
15919 }
15920
15921 /**
15922@@ -150,6 +260,18 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
15923 */
15924 static inline long atomic64_add_return(long i, atomic64_t *v)
15925 {
15926+ return i + xadd_check_overflow(&v->counter, i);
15927+}
15928+
15929+/**
15930+ * atomic64_add_return_unchecked - add and return
15931+ * @i: integer value to add
15932+ * @v: pointer to type atomic64_unchecked_t
15933+ *
15934+ * Atomically adds @i to @v and returns @i + @v
15935+ */
15936+static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
15937+{
15938 return i + xadd(&v->counter, i);
15939 }
15940
15941@@ -159,6 +281,10 @@ static inline long atomic64_sub_return(long i, atomic64_t *v)
15942 }
15943
15944 #define atomic64_inc_return(v) (atomic64_add_return(1, (v)))
15945+static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
15946+{
15947+ return atomic64_add_return_unchecked(1, v);
15948+}
15949 #define atomic64_dec_return(v) (atomic64_sub_return(1, (v)))
15950
15951 static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
15952@@ -166,6 +292,11 @@ static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
15953 return cmpxchg(&v->counter, old, new);
15954 }
15955
15956+static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old, long new)
15957+{
15958+ return cmpxchg(&v->counter, old, new);
15959+}
15960+
15961 static inline long atomic64_xchg(atomic64_t *v, long new)
15962 {
15963 return xchg(&v->counter, new);
15964@@ -182,17 +313,30 @@ static inline long atomic64_xchg(atomic64_t *v, long new)
15965 */
15966 static inline int atomic64_add_unless(atomic64_t *v, long a, long u)
15967 {
15968- long c, old;
15969+ long c, old, new;
15970 c = atomic64_read(v);
15971 for (;;) {
15972- if (unlikely(c == (u)))
15973+ if (unlikely(c == u))
15974 break;
15975- old = atomic64_cmpxchg((v), c, c + (a));
15976+
15977+ asm volatile("add %2,%0\n"
15978+
15979+#ifdef CONFIG_PAX_REFCOUNT
15980+ "jno 0f\n"
15981+ "sub %2,%0\n"
15982+ "int $4\n0:\n"
15983+ _ASM_EXTABLE(0b, 0b)
15984+#endif
15985+
15986+ : "=r" (new)
15987+ : "0" (c), "ir" (a));
15988+
15989+ old = atomic64_cmpxchg(v, c, new);
15990 if (likely(old == c))
15991 break;
15992 c = old;
15993 }
15994- return c != (u);
15995+ return c != u;
15996 }
15997
15998 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
15999diff --git a/arch/x86/include/asm/bitops.h b/arch/x86/include/asm/bitops.h
16000index 9fc1af7..fc71228 100644
16001--- a/arch/x86/include/asm/bitops.h
16002+++ b/arch/x86/include/asm/bitops.h
16003@@ -49,7 +49,7 @@
16004 * a mask operation on a byte.
16005 */
16006 #define IS_IMMEDIATE(nr) (__builtin_constant_p(nr))
16007-#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((void *)(addr) + ((nr)>>3))
16008+#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((volatile void *)(addr) + ((nr)>>3))
16009 #define CONST_MASK(nr) (1 << ((nr) & 7))
16010
16011 /**
16012@@ -205,7 +205,7 @@ static inline void change_bit(long nr, volatile unsigned long *addr)
16013 */
16014 static inline int test_and_set_bit(long nr, volatile unsigned long *addr)
16015 {
16016- GEN_BINARY_RMWcc(LOCK_PREFIX "bts", *addr, "Ir", nr, "%0", "c");
16017+ GEN_BINARY_RMWcc_unchecked(LOCK_PREFIX "bts", *addr, "Ir", nr, "%0", "c");
16018 }
16019
16020 /**
16021@@ -251,7 +251,7 @@ static inline int __test_and_set_bit(long nr, volatile unsigned long *addr)
16022 */
16023 static inline int test_and_clear_bit(long nr, volatile unsigned long *addr)
16024 {
16025- GEN_BINARY_RMWcc(LOCK_PREFIX "btr", *addr, "Ir", nr, "%0", "c");
16026+ GEN_BINARY_RMWcc_unchecked(LOCK_PREFIX "btr", *addr, "Ir", nr, "%0", "c");
16027 }
16028
16029 /**
16030@@ -304,7 +304,7 @@ static inline int __test_and_change_bit(long nr, volatile unsigned long *addr)
16031 */
16032 static inline int test_and_change_bit(long nr, volatile unsigned long *addr)
16033 {
16034- GEN_BINARY_RMWcc(LOCK_PREFIX "btc", *addr, "Ir", nr, "%0", "c");
16035+ GEN_BINARY_RMWcc_unchecked(LOCK_PREFIX "btc", *addr, "Ir", nr, "%0", "c");
16036 }
16037
16038 static __always_inline int constant_test_bit(long nr, const volatile unsigned long *addr)
16039@@ -345,7 +345,7 @@ static int test_bit(int nr, const volatile unsigned long *addr);
16040 *
16041 * Undefined if no bit exists, so code should check against 0 first.
16042 */
16043-static inline unsigned long __ffs(unsigned long word)
16044+static inline unsigned long __intentional_overflow(-1) __ffs(unsigned long word)
16045 {
16046 asm("rep; bsf %1,%0"
16047 : "=r" (word)
16048@@ -359,7 +359,7 @@ static inline unsigned long __ffs(unsigned long word)
16049 *
16050 * Undefined if no zero exists, so code should check against ~0UL first.
16051 */
16052-static inline unsigned long ffz(unsigned long word)
16053+static inline unsigned long __intentional_overflow(-1) ffz(unsigned long word)
16054 {
16055 asm("rep; bsf %1,%0"
16056 : "=r" (word)
16057@@ -373,7 +373,7 @@ static inline unsigned long ffz(unsigned long word)
16058 *
16059 * Undefined if no set bit exists, so code should check against 0 first.
16060 */
16061-static inline unsigned long __fls(unsigned long word)
16062+static inline unsigned long __intentional_overflow(-1) __fls(unsigned long word)
16063 {
16064 asm("bsr %1,%0"
16065 : "=r" (word)
16066@@ -436,7 +436,7 @@ static inline int ffs(int x)
16067 * set bit if value is nonzero. The last (most significant) bit is
16068 * at position 32.
16069 */
16070-static inline int fls(int x)
16071+static inline int __intentional_overflow(-1) fls(int x)
16072 {
16073 int r;
16074
16075@@ -478,7 +478,7 @@ static inline int fls(int x)
16076 * at position 64.
16077 */
16078 #ifdef CONFIG_X86_64
16079-static __always_inline int fls64(__u64 x)
16080+static __always_inline long fls64(__u64 x)
16081 {
16082 int bitpos = -1;
16083 /*
16084diff --git a/arch/x86/include/asm/boot.h b/arch/x86/include/asm/boot.h
16085index 4fa687a..60f2d39 100644
16086--- a/arch/x86/include/asm/boot.h
16087+++ b/arch/x86/include/asm/boot.h
16088@@ -6,10 +6,15 @@
16089 #include <uapi/asm/boot.h>
16090
16091 /* Physical address where kernel should be loaded. */
16092-#define LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
16093+#define ____LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
16094 + (CONFIG_PHYSICAL_ALIGN - 1)) \
16095 & ~(CONFIG_PHYSICAL_ALIGN - 1))
16096
16097+#ifndef __ASSEMBLY__
16098+extern unsigned char __LOAD_PHYSICAL_ADDR[];
16099+#define LOAD_PHYSICAL_ADDR ((unsigned long)__LOAD_PHYSICAL_ADDR)
16100+#endif
16101+
16102 /* Minimum kernel alignment, as a power of two */
16103 #ifdef CONFIG_X86_64
16104 #define MIN_KERNEL_ALIGN_LG2 PMD_SHIFT
16105diff --git a/arch/x86/include/asm/cache.h b/arch/x86/include/asm/cache.h
16106index 48f99f1..d78ebf9 100644
16107--- a/arch/x86/include/asm/cache.h
16108+++ b/arch/x86/include/asm/cache.h
16109@@ -5,12 +5,13 @@
16110
16111 /* L1 cache line size */
16112 #define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
16113-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
16114+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
16115
16116 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
16117+#define __read_only __attribute__((__section__(".data..read_only")))
16118
16119 #define INTERNODE_CACHE_SHIFT CONFIG_X86_INTERNODE_CACHE_SHIFT
16120-#define INTERNODE_CACHE_BYTES (1 << INTERNODE_CACHE_SHIFT)
16121+#define INTERNODE_CACHE_BYTES (_AC(1,UL) << INTERNODE_CACHE_SHIFT)
16122
16123 #ifdef CONFIG_X86_VSMP
16124 #ifdef CONFIG_SMP
16125diff --git a/arch/x86/include/asm/cacheflush.h b/arch/x86/include/asm/cacheflush.h
16126index 9863ee3..4a1f8e1 100644
16127--- a/arch/x86/include/asm/cacheflush.h
16128+++ b/arch/x86/include/asm/cacheflush.h
16129@@ -27,7 +27,7 @@ static inline unsigned long get_page_memtype(struct page *pg)
16130 unsigned long pg_flags = pg->flags & _PGMT_MASK;
16131
16132 if (pg_flags == _PGMT_DEFAULT)
16133- return -1;
16134+ return ~0UL;
16135 else if (pg_flags == _PGMT_WC)
16136 return _PAGE_CACHE_WC;
16137 else if (pg_flags == _PGMT_UC_MINUS)
16138diff --git a/arch/x86/include/asm/calling.h b/arch/x86/include/asm/calling.h
16139index cb4c73b..c473c29 100644
16140--- a/arch/x86/include/asm/calling.h
16141+++ b/arch/x86/include/asm/calling.h
16142@@ -82,103 +82,113 @@ For 32-bit we have the following conventions - kernel is built with
16143 #define RSP 152
16144 #define SS 160
16145
16146-#define ARGOFFSET R11
16147-#define SWFRAME ORIG_RAX
16148+#define ARGOFFSET R15
16149
16150 .macro SAVE_ARGS addskip=0, save_rcx=1, save_r891011=1
16151- subq $9*8+\addskip, %rsp
16152- CFI_ADJUST_CFA_OFFSET 9*8+\addskip
16153- movq_cfi rdi, 8*8
16154- movq_cfi rsi, 7*8
16155- movq_cfi rdx, 6*8
16156+ subq $ORIG_RAX-ARGOFFSET+\addskip, %rsp
16157+ CFI_ADJUST_CFA_OFFSET ORIG_RAX-ARGOFFSET+\addskip
16158+ movq_cfi rdi, RDI
16159+ movq_cfi rsi, RSI
16160+ movq_cfi rdx, RDX
16161
16162 .if \save_rcx
16163- movq_cfi rcx, 5*8
16164+ movq_cfi rcx, RCX
16165 .endif
16166
16167- movq_cfi rax, 4*8
16168+ movq_cfi rax, RAX
16169
16170 .if \save_r891011
16171- movq_cfi r8, 3*8
16172- movq_cfi r9, 2*8
16173- movq_cfi r10, 1*8
16174- movq_cfi r11, 0*8
16175+ movq_cfi r8, R8
16176+ movq_cfi r9, R9
16177+ movq_cfi r10, R10
16178+ movq_cfi r11, R11
16179 .endif
16180
16181+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
16182+ movq_cfi r12, R12
16183+#endif
16184+
16185 .endm
16186
16187-#define ARG_SKIP (9*8)
16188+#define ARG_SKIP ORIG_RAX
16189
16190 .macro RESTORE_ARGS rstor_rax=1, addskip=0, rstor_rcx=1, rstor_r11=1, \
16191 rstor_r8910=1, rstor_rdx=1
16192+
16193+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
16194+ movq_cfi_restore R12, r12
16195+#endif
16196+
16197 .if \rstor_r11
16198- movq_cfi_restore 0*8, r11
16199+ movq_cfi_restore R11, r11
16200 .endif
16201
16202 .if \rstor_r8910
16203- movq_cfi_restore 1*8, r10
16204- movq_cfi_restore 2*8, r9
16205- movq_cfi_restore 3*8, r8
16206+ movq_cfi_restore R10, r10
16207+ movq_cfi_restore R9, r9
16208+ movq_cfi_restore R8, r8
16209 .endif
16210
16211 .if \rstor_rax
16212- movq_cfi_restore 4*8, rax
16213+ movq_cfi_restore RAX, rax
16214 .endif
16215
16216 .if \rstor_rcx
16217- movq_cfi_restore 5*8, rcx
16218+ movq_cfi_restore RCX, rcx
16219 .endif
16220
16221 .if \rstor_rdx
16222- movq_cfi_restore 6*8, rdx
16223+ movq_cfi_restore RDX, rdx
16224 .endif
16225
16226- movq_cfi_restore 7*8, rsi
16227- movq_cfi_restore 8*8, rdi
16228+ movq_cfi_restore RSI, rsi
16229+ movq_cfi_restore RDI, rdi
16230
16231- .if ARG_SKIP+\addskip > 0
16232- addq $ARG_SKIP+\addskip, %rsp
16233- CFI_ADJUST_CFA_OFFSET -(ARG_SKIP+\addskip)
16234+ .if ORIG_RAX+\addskip > 0
16235+ addq $ORIG_RAX+\addskip, %rsp
16236+ CFI_ADJUST_CFA_OFFSET -(ORIG_RAX+\addskip)
16237 .endif
16238 .endm
16239
16240- .macro LOAD_ARGS offset, skiprax=0
16241- movq \offset(%rsp), %r11
16242- movq \offset+8(%rsp), %r10
16243- movq \offset+16(%rsp), %r9
16244- movq \offset+24(%rsp), %r8
16245- movq \offset+40(%rsp), %rcx
16246- movq \offset+48(%rsp), %rdx
16247- movq \offset+56(%rsp), %rsi
16248- movq \offset+64(%rsp), %rdi
16249+ .macro LOAD_ARGS skiprax=0
16250+ movq R11(%rsp), %r11
16251+ movq R10(%rsp), %r10
16252+ movq R9(%rsp), %r9
16253+ movq R8(%rsp), %r8
16254+ movq RCX(%rsp), %rcx
16255+ movq RDX(%rsp), %rdx
16256+ movq RSI(%rsp), %rsi
16257+ movq RDI(%rsp), %rdi
16258 .if \skiprax
16259 .else
16260- movq \offset+72(%rsp), %rax
16261+ movq RAX(%rsp), %rax
16262 .endif
16263 .endm
16264
16265-#define REST_SKIP (6*8)
16266-
16267 .macro SAVE_REST
16268- subq $REST_SKIP, %rsp
16269- CFI_ADJUST_CFA_OFFSET REST_SKIP
16270- movq_cfi rbx, 5*8
16271- movq_cfi rbp, 4*8
16272- movq_cfi r12, 3*8
16273- movq_cfi r13, 2*8
16274- movq_cfi r14, 1*8
16275- movq_cfi r15, 0*8
16276+ movq_cfi rbx, RBX
16277+ movq_cfi rbp, RBP
16278+
16279+#ifndef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
16280+ movq_cfi r12, R12
16281+#endif
16282+
16283+ movq_cfi r13, R13
16284+ movq_cfi r14, R14
16285+ movq_cfi r15, R15
16286 .endm
16287
16288 .macro RESTORE_REST
16289- movq_cfi_restore 0*8, r15
16290- movq_cfi_restore 1*8, r14
16291- movq_cfi_restore 2*8, r13
16292- movq_cfi_restore 3*8, r12
16293- movq_cfi_restore 4*8, rbp
16294- movq_cfi_restore 5*8, rbx
16295- addq $REST_SKIP, %rsp
16296- CFI_ADJUST_CFA_OFFSET -(REST_SKIP)
16297+ movq_cfi_restore R15, r15
16298+ movq_cfi_restore R14, r14
16299+ movq_cfi_restore R13, r13
16300+
16301+#ifndef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
16302+ movq_cfi_restore R12, r12
16303+#endif
16304+
16305+ movq_cfi_restore RBP, rbp
16306+ movq_cfi_restore RBX, rbx
16307 .endm
16308
16309 .macro SAVE_ALL
16310diff --git a/arch/x86/include/asm/checksum_32.h b/arch/x86/include/asm/checksum_32.h
16311index f50de69..2b0a458 100644
16312--- a/arch/x86/include/asm/checksum_32.h
16313+++ b/arch/x86/include/asm/checksum_32.h
16314@@ -31,6 +31,14 @@ asmlinkage __wsum csum_partial_copy_generic(const void *src, void *dst,
16315 int len, __wsum sum,
16316 int *src_err_ptr, int *dst_err_ptr);
16317
16318+asmlinkage __wsum csum_partial_copy_generic_to_user(const void *src, void *dst,
16319+ int len, __wsum sum,
16320+ int *src_err_ptr, int *dst_err_ptr);
16321+
16322+asmlinkage __wsum csum_partial_copy_generic_from_user(const void *src, void *dst,
16323+ int len, __wsum sum,
16324+ int *src_err_ptr, int *dst_err_ptr);
16325+
16326 /*
16327 * Note: when you get a NULL pointer exception here this means someone
16328 * passed in an incorrect kernel address to one of these functions.
16329@@ -53,7 +61,7 @@ static inline __wsum csum_partial_copy_from_user(const void __user *src,
16330
16331 might_sleep();
16332 stac();
16333- ret = csum_partial_copy_generic((__force void *)src, dst,
16334+ ret = csum_partial_copy_generic_from_user((__force void *)src, dst,
16335 len, sum, err_ptr, NULL);
16336 clac();
16337
16338@@ -187,7 +195,7 @@ static inline __wsum csum_and_copy_to_user(const void *src,
16339 might_sleep();
16340 if (access_ok(VERIFY_WRITE, dst, len)) {
16341 stac();
16342- ret = csum_partial_copy_generic(src, (__force void *)dst,
16343+ ret = csum_partial_copy_generic_to_user(src, (__force void *)dst,
16344 len, sum, NULL, err_ptr);
16345 clac();
16346 return ret;
16347diff --git a/arch/x86/include/asm/cmpxchg.h b/arch/x86/include/asm/cmpxchg.h
16348index d47786a..2d8883e 100644
16349--- a/arch/x86/include/asm/cmpxchg.h
16350+++ b/arch/x86/include/asm/cmpxchg.h
16351@@ -14,8 +14,12 @@ extern void __cmpxchg_wrong_size(void)
16352 __compiletime_error("Bad argument size for cmpxchg");
16353 extern void __xadd_wrong_size(void)
16354 __compiletime_error("Bad argument size for xadd");
16355+extern void __xadd_check_overflow_wrong_size(void)
16356+ __compiletime_error("Bad argument size for xadd_check_overflow");
16357 extern void __add_wrong_size(void)
16358 __compiletime_error("Bad argument size for add");
16359+extern void __add_check_overflow_wrong_size(void)
16360+ __compiletime_error("Bad argument size for add_check_overflow");
16361
16362 /*
16363 * Constants for operation sizes. On 32-bit, the 64-bit size it set to
16364@@ -67,6 +71,38 @@ extern void __add_wrong_size(void)
16365 __ret; \
16366 })
16367
16368+#ifdef CONFIG_PAX_REFCOUNT
16369+#define __xchg_op_check_overflow(ptr, arg, op, lock) \
16370+ ({ \
16371+ __typeof__ (*(ptr)) __ret = (arg); \
16372+ switch (sizeof(*(ptr))) { \
16373+ case __X86_CASE_L: \
16374+ asm volatile (lock #op "l %0, %1\n" \
16375+ "jno 0f\n" \
16376+ "mov %0,%1\n" \
16377+ "int $4\n0:\n" \
16378+ _ASM_EXTABLE(0b, 0b) \
16379+ : "+r" (__ret), "+m" (*(ptr)) \
16380+ : : "memory", "cc"); \
16381+ break; \
16382+ case __X86_CASE_Q: \
16383+ asm volatile (lock #op "q %q0, %1\n" \
16384+ "jno 0f\n" \
16385+ "mov %0,%1\n" \
16386+ "int $4\n0:\n" \
16387+ _ASM_EXTABLE(0b, 0b) \
16388+ : "+r" (__ret), "+m" (*(ptr)) \
16389+ : : "memory", "cc"); \
16390+ break; \
16391+ default: \
16392+ __ ## op ## _check_overflow_wrong_size(); \
16393+ } \
16394+ __ret; \
16395+ })
16396+#else
16397+#define __xchg_op_check_overflow(ptr, arg, op, lock) __xchg_op(ptr, arg, op, lock)
16398+#endif
16399+
16400 /*
16401 * Note: no "lock" prefix even on SMP: xchg always implies lock anyway.
16402 * Since this is generally used to protect other memory information, we
16403@@ -167,6 +203,9 @@ extern void __add_wrong_size(void)
16404 #define xadd_sync(ptr, inc) __xadd((ptr), (inc), "lock; ")
16405 #define xadd_local(ptr, inc) __xadd((ptr), (inc), "")
16406
16407+#define __xadd_check_overflow(ptr, inc, lock) __xchg_op_check_overflow((ptr), (inc), xadd, lock)
16408+#define xadd_check_overflow(ptr, inc) __xadd_check_overflow((ptr), (inc), LOCK_PREFIX)
16409+
16410 #define __add(ptr, inc, lock) \
16411 ({ \
16412 __typeof__ (*(ptr)) __ret = (inc); \
16413diff --git a/arch/x86/include/asm/compat.h b/arch/x86/include/asm/compat.h
16414index 59c6c40..5e0b22c 100644
16415--- a/arch/x86/include/asm/compat.h
16416+++ b/arch/x86/include/asm/compat.h
16417@@ -41,7 +41,7 @@ typedef s64 __attribute__((aligned(4))) compat_s64;
16418 typedef u32 compat_uint_t;
16419 typedef u32 compat_ulong_t;
16420 typedef u64 __attribute__((aligned(4))) compat_u64;
16421-typedef u32 compat_uptr_t;
16422+typedef u32 __user compat_uptr_t;
16423
16424 struct compat_timespec {
16425 compat_time_t tv_sec;
16426diff --git a/arch/x86/include/asm/cpufeature.h b/arch/x86/include/asm/cpufeature.h
16427index 5f12968..a383517 100644
16428--- a/arch/x86/include/asm/cpufeature.h
16429+++ b/arch/x86/include/asm/cpufeature.h
16430@@ -203,7 +203,7 @@
16431 #define X86_FEATURE_DECODEASSISTS (8*32+12) /* AMD Decode Assists support */
16432 #define X86_FEATURE_PAUSEFILTER (8*32+13) /* AMD filtered pause intercept */
16433 #define X86_FEATURE_PFTHRESHOLD (8*32+14) /* AMD pause filter threshold */
16434-
16435+#define X86_FEATURE_STRONGUDEREF (8*32+31) /* PaX PCID based strong UDEREF */
16436
16437 /* Intel-defined CPU features, CPUID level 0x00000007:0 (ebx), word 9 */
16438 #define X86_FEATURE_FSGSBASE (9*32+ 0) /* {RD/WR}{FS/GS}BASE instructions*/
16439@@ -211,7 +211,7 @@
16440 #define X86_FEATURE_BMI1 (9*32+ 3) /* 1st group bit manipulation extensions */
16441 #define X86_FEATURE_HLE (9*32+ 4) /* Hardware Lock Elision */
16442 #define X86_FEATURE_AVX2 (9*32+ 5) /* AVX2 instructions */
16443-#define X86_FEATURE_SMEP (9*32+ 7) /* Supervisor Mode Execution Protection */
16444+#define X86_FEATURE_SMEP (9*32+ 7) /* Supervisor Mode Execution Prevention */
16445 #define X86_FEATURE_BMI2 (9*32+ 8) /* 2nd group bit manipulation extensions */
16446 #define X86_FEATURE_ERMS (9*32+ 9) /* Enhanced REP MOVSB/STOSB */
16447 #define X86_FEATURE_INVPCID (9*32+10) /* Invalidate Processor Context ID */
16448@@ -358,6 +358,7 @@ extern const char * const x86_power_flags[32];
16449 #undef cpu_has_centaur_mcr
16450 #define cpu_has_centaur_mcr 0
16451
16452+#define cpu_has_pcid boot_cpu_has(X86_FEATURE_PCID)
16453 #endif /* CONFIG_X86_64 */
16454
16455 #if __GNUC__ >= 4
16456@@ -410,7 +411,8 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
16457
16458 #ifdef CONFIG_X86_DEBUG_STATIC_CPU_HAS
16459 t_warn:
16460- warn_pre_alternatives();
16461+ if (bit != X86_FEATURE_PCID && bit != X86_FEATURE_INVPCID)
16462+ warn_pre_alternatives();
16463 return false;
16464 #endif
16465
16466@@ -430,7 +432,7 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
16467 ".section .discard,\"aw\",@progbits\n"
16468 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
16469 ".previous\n"
16470- ".section .altinstr_replacement,\"ax\"\n"
16471+ ".section .altinstr_replacement,\"a\"\n"
16472 "3: movb $1,%0\n"
16473 "4:\n"
16474 ".previous\n"
16475@@ -467,7 +469,7 @@ static __always_inline __pure bool _static_cpu_has_safe(u16 bit)
16476 " .byte 2b - 1b\n" /* src len */
16477 " .byte 4f - 3f\n" /* repl len */
16478 ".previous\n"
16479- ".section .altinstr_replacement,\"ax\"\n"
16480+ ".section .altinstr_replacement,\"a\"\n"
16481 "3: .byte 0xe9\n .long %l[t_no] - 2b\n"
16482 "4:\n"
16483 ".previous\n"
16484@@ -500,7 +502,7 @@ static __always_inline __pure bool _static_cpu_has_safe(u16 bit)
16485 ".section .discard,\"aw\",@progbits\n"
16486 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
16487 ".previous\n"
16488- ".section .altinstr_replacement,\"ax\"\n"
16489+ ".section .altinstr_replacement,\"a\"\n"
16490 "3: movb $0,%0\n"
16491 "4:\n"
16492 ".previous\n"
16493@@ -514,7 +516,7 @@ static __always_inline __pure bool _static_cpu_has_safe(u16 bit)
16494 ".section .discard,\"aw\",@progbits\n"
16495 " .byte 0xff + (6f-5f) - (4b-3b)\n" /* size check */
16496 ".previous\n"
16497- ".section .altinstr_replacement,\"ax\"\n"
16498+ ".section .altinstr_replacement,\"a\"\n"
16499 "5: movb $1,%0\n"
16500 "6:\n"
16501 ".previous\n"
16502diff --git a/arch/x86/include/asm/desc.h b/arch/x86/include/asm/desc.h
16503index 50d033a..37deb26 100644
16504--- a/arch/x86/include/asm/desc.h
16505+++ b/arch/x86/include/asm/desc.h
16506@@ -4,6 +4,7 @@
16507 #include <asm/desc_defs.h>
16508 #include <asm/ldt.h>
16509 #include <asm/mmu.h>
16510+#include <asm/pgtable.h>
16511
16512 #include <linux/smp.h>
16513 #include <linux/percpu.h>
16514@@ -17,6 +18,7 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
16515
16516 desc->type = (info->read_exec_only ^ 1) << 1;
16517 desc->type |= info->contents << 2;
16518+ desc->type |= info->seg_not_present ^ 1;
16519
16520 desc->s = 1;
16521 desc->dpl = 0x3;
16522@@ -35,19 +37,14 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
16523 }
16524
16525 extern struct desc_ptr idt_descr;
16526-extern gate_desc idt_table[];
16527-extern struct desc_ptr debug_idt_descr;
16528-extern gate_desc debug_idt_table[];
16529-
16530-struct gdt_page {
16531- struct desc_struct gdt[GDT_ENTRIES];
16532-} __attribute__((aligned(PAGE_SIZE)));
16533-
16534-DECLARE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page);
16535+extern gate_desc idt_table[IDT_ENTRIES];
16536+extern const struct desc_ptr debug_idt_descr;
16537+extern gate_desc debug_idt_table[IDT_ENTRIES];
16538
16539+extern struct desc_struct cpu_gdt_table[NR_CPUS][PAGE_SIZE / sizeof(struct desc_struct)];
16540 static inline struct desc_struct *get_cpu_gdt_table(unsigned int cpu)
16541 {
16542- return per_cpu(gdt_page, cpu).gdt;
16543+ return cpu_gdt_table[cpu];
16544 }
16545
16546 #ifdef CONFIG_X86_64
16547@@ -72,8 +69,14 @@ static inline void pack_gate(gate_desc *gate, unsigned char type,
16548 unsigned long base, unsigned dpl, unsigned flags,
16549 unsigned short seg)
16550 {
16551- gate->a = (seg << 16) | (base & 0xffff);
16552- gate->b = (base & 0xffff0000) | (((0x80 | type | (dpl << 5)) & 0xff) << 8);
16553+ gate->gate.offset_low = base;
16554+ gate->gate.seg = seg;
16555+ gate->gate.reserved = 0;
16556+ gate->gate.type = type;
16557+ gate->gate.s = 0;
16558+ gate->gate.dpl = dpl;
16559+ gate->gate.p = 1;
16560+ gate->gate.offset_high = base >> 16;
16561 }
16562
16563 #endif
16564@@ -118,12 +121,16 @@ static inline void paravirt_free_ldt(struct desc_struct *ldt, unsigned entries)
16565
16566 static inline void native_write_idt_entry(gate_desc *idt, int entry, const gate_desc *gate)
16567 {
16568+ pax_open_kernel();
16569 memcpy(&idt[entry], gate, sizeof(*gate));
16570+ pax_close_kernel();
16571 }
16572
16573 static inline void native_write_ldt_entry(struct desc_struct *ldt, int entry, const void *desc)
16574 {
16575+ pax_open_kernel();
16576 memcpy(&ldt[entry], desc, 8);
16577+ pax_close_kernel();
16578 }
16579
16580 static inline void
16581@@ -137,7 +144,9 @@ native_write_gdt_entry(struct desc_struct *gdt, int entry, const void *desc, int
16582 default: size = sizeof(*gdt); break;
16583 }
16584
16585+ pax_open_kernel();
16586 memcpy(&gdt[entry], desc, size);
16587+ pax_close_kernel();
16588 }
16589
16590 static inline void pack_descriptor(struct desc_struct *desc, unsigned long base,
16591@@ -210,7 +219,9 @@ static inline void native_set_ldt(const void *addr, unsigned int entries)
16592
16593 static inline void native_load_tr_desc(void)
16594 {
16595+ pax_open_kernel();
16596 asm volatile("ltr %w0"::"q" (GDT_ENTRY_TSS*8));
16597+ pax_close_kernel();
16598 }
16599
16600 static inline void native_load_gdt(const struct desc_ptr *dtr)
16601@@ -247,8 +258,10 @@ static inline void native_load_tls(struct thread_struct *t, unsigned int cpu)
16602 struct desc_struct *gdt = get_cpu_gdt_table(cpu);
16603 unsigned int i;
16604
16605+ pax_open_kernel();
16606 for (i = 0; i < GDT_ENTRY_TLS_ENTRIES; i++)
16607 gdt[GDT_ENTRY_TLS_MIN + i] = t->tls_array[i];
16608+ pax_close_kernel();
16609 }
16610
16611 #define _LDT_empty(info) \
16612@@ -287,7 +300,7 @@ static inline void load_LDT(mm_context_t *pc)
16613 preempt_enable();
16614 }
16615
16616-static inline unsigned long get_desc_base(const struct desc_struct *desc)
16617+static inline unsigned long __intentional_overflow(-1) get_desc_base(const struct desc_struct *desc)
16618 {
16619 return (unsigned)(desc->base0 | ((desc->base1) << 16) | ((desc->base2) << 24));
16620 }
16621@@ -311,7 +324,7 @@ static inline void set_desc_limit(struct desc_struct *desc, unsigned long limit)
16622 }
16623
16624 #ifdef CONFIG_X86_64
16625-static inline void set_nmi_gate(int gate, void *addr)
16626+static inline void set_nmi_gate(int gate, const void *addr)
16627 {
16628 gate_desc s;
16629
16630@@ -321,14 +334,14 @@ static inline void set_nmi_gate(int gate, void *addr)
16631 #endif
16632
16633 #ifdef CONFIG_TRACING
16634-extern struct desc_ptr trace_idt_descr;
16635-extern gate_desc trace_idt_table[];
16636+extern const struct desc_ptr trace_idt_descr;
16637+extern gate_desc trace_idt_table[IDT_ENTRIES];
16638 static inline void write_trace_idt_entry(int entry, const gate_desc *gate)
16639 {
16640 write_idt_entry(trace_idt_table, entry, gate);
16641 }
16642
16643-static inline void _trace_set_gate(int gate, unsigned type, void *addr,
16644+static inline void _trace_set_gate(int gate, unsigned type, const void *addr,
16645 unsigned dpl, unsigned ist, unsigned seg)
16646 {
16647 gate_desc s;
16648@@ -348,7 +361,7 @@ static inline void write_trace_idt_entry(int entry, const gate_desc *gate)
16649 #define _trace_set_gate(gate, type, addr, dpl, ist, seg)
16650 #endif
16651
16652-static inline void _set_gate(int gate, unsigned type, void *addr,
16653+static inline void _set_gate(int gate, unsigned type, const void *addr,
16654 unsigned dpl, unsigned ist, unsigned seg)
16655 {
16656 gate_desc s;
16657@@ -371,9 +384,9 @@ static inline void _set_gate(int gate, unsigned type, void *addr,
16658 #define set_intr_gate(n, addr) \
16659 do { \
16660 BUG_ON((unsigned)n > 0xFF); \
16661- _set_gate(n, GATE_INTERRUPT, (void *)addr, 0, 0, \
16662+ _set_gate(n, GATE_INTERRUPT, (const void *)addr, 0, 0, \
16663 __KERNEL_CS); \
16664- _trace_set_gate(n, GATE_INTERRUPT, (void *)trace_##addr,\
16665+ _trace_set_gate(n, GATE_INTERRUPT, (const void *)trace_##addr,\
16666 0, 0, __KERNEL_CS); \
16667 } while (0)
16668
16669@@ -401,19 +414,19 @@ static inline void alloc_system_vector(int vector)
16670 /*
16671 * This routine sets up an interrupt gate at directory privilege level 3.
16672 */
16673-static inline void set_system_intr_gate(unsigned int n, void *addr)
16674+static inline void set_system_intr_gate(unsigned int n, const void *addr)
16675 {
16676 BUG_ON((unsigned)n > 0xFF);
16677 _set_gate(n, GATE_INTERRUPT, addr, 0x3, 0, __KERNEL_CS);
16678 }
16679
16680-static inline void set_system_trap_gate(unsigned int n, void *addr)
16681+static inline void set_system_trap_gate(unsigned int n, const void *addr)
16682 {
16683 BUG_ON((unsigned)n > 0xFF);
16684 _set_gate(n, GATE_TRAP, addr, 0x3, 0, __KERNEL_CS);
16685 }
16686
16687-static inline void set_trap_gate(unsigned int n, void *addr)
16688+static inline void set_trap_gate(unsigned int n, const void *addr)
16689 {
16690 BUG_ON((unsigned)n > 0xFF);
16691 _set_gate(n, GATE_TRAP, addr, 0, 0, __KERNEL_CS);
16692@@ -422,16 +435,16 @@ static inline void set_trap_gate(unsigned int n, void *addr)
16693 static inline void set_task_gate(unsigned int n, unsigned int gdt_entry)
16694 {
16695 BUG_ON((unsigned)n > 0xFF);
16696- _set_gate(n, GATE_TASK, (void *)0, 0, 0, (gdt_entry<<3));
16697+ _set_gate(n, GATE_TASK, (const void *)0, 0, 0, (gdt_entry<<3));
16698 }
16699
16700-static inline void set_intr_gate_ist(int n, void *addr, unsigned ist)
16701+static inline void set_intr_gate_ist(int n, const void *addr, unsigned ist)
16702 {
16703 BUG_ON((unsigned)n > 0xFF);
16704 _set_gate(n, GATE_INTERRUPT, addr, 0, ist, __KERNEL_CS);
16705 }
16706
16707-static inline void set_system_intr_gate_ist(int n, void *addr, unsigned ist)
16708+static inline void set_system_intr_gate_ist(int n, const void *addr, unsigned ist)
16709 {
16710 BUG_ON((unsigned)n > 0xFF);
16711 _set_gate(n, GATE_INTERRUPT, addr, 0x3, ist, __KERNEL_CS);
16712@@ -503,4 +516,17 @@ static inline void load_current_idt(void)
16713 else
16714 load_idt((const struct desc_ptr *)&idt_descr);
16715 }
16716+
16717+#ifdef CONFIG_X86_32
16718+static inline void set_user_cs(unsigned long base, unsigned long limit, int cpu)
16719+{
16720+ struct desc_struct d;
16721+
16722+ if (likely(limit))
16723+ limit = (limit - 1UL) >> PAGE_SHIFT;
16724+ pack_descriptor(&d, base, limit, 0xFB, 0xC);
16725+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_DEFAULT_USER_CS, &d, DESCTYPE_S);
16726+}
16727+#endif
16728+
16729 #endif /* _ASM_X86_DESC_H */
16730diff --git a/arch/x86/include/asm/desc_defs.h b/arch/x86/include/asm/desc_defs.h
16731index 278441f..b95a174 100644
16732--- a/arch/x86/include/asm/desc_defs.h
16733+++ b/arch/x86/include/asm/desc_defs.h
16734@@ -31,6 +31,12 @@ struct desc_struct {
16735 unsigned base1: 8, type: 4, s: 1, dpl: 2, p: 1;
16736 unsigned limit: 4, avl: 1, l: 1, d: 1, g: 1, base2: 8;
16737 };
16738+ struct {
16739+ u16 offset_low;
16740+ u16 seg;
16741+ unsigned reserved: 8, type: 4, s: 1, dpl: 2, p: 1;
16742+ unsigned offset_high: 16;
16743+ } gate;
16744 };
16745 } __attribute__((packed));
16746
16747diff --git a/arch/x86/include/asm/div64.h b/arch/x86/include/asm/div64.h
16748index ced283a..ffe04cc 100644
16749--- a/arch/x86/include/asm/div64.h
16750+++ b/arch/x86/include/asm/div64.h
16751@@ -39,7 +39,7 @@
16752 __mod; \
16753 })
16754
16755-static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
16756+static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
16757 {
16758 union {
16759 u64 v64;
16760diff --git a/arch/x86/include/asm/elf.h b/arch/x86/include/asm/elf.h
16761index 9c999c1..3860cb8 100644
16762--- a/arch/x86/include/asm/elf.h
16763+++ b/arch/x86/include/asm/elf.h
16764@@ -243,7 +243,25 @@ extern int force_personality32;
16765 the loader. We need to make sure that it is out of the way of the program
16766 that it will "exec", and that there is sufficient room for the brk. */
16767
16768+#ifdef CONFIG_PAX_SEGMEXEC
16769+#define ELF_ET_DYN_BASE ((current->mm->pax_flags & MF_PAX_SEGMEXEC) ? SEGMEXEC_TASK_SIZE/3*2 : TASK_SIZE/3*2)
16770+#else
16771 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
16772+#endif
16773+
16774+#ifdef CONFIG_PAX_ASLR
16775+#ifdef CONFIG_X86_32
16776+#define PAX_ELF_ET_DYN_BASE 0x10000000UL
16777+
16778+#define PAX_DELTA_MMAP_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
16779+#define PAX_DELTA_STACK_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
16780+#else
16781+#define PAX_ELF_ET_DYN_BASE 0x400000UL
16782+
16783+#define PAX_DELTA_MMAP_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
16784+#define PAX_DELTA_STACK_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
16785+#endif
16786+#endif
16787
16788 /* This yields a mask that user programs can use to figure out what
16789 instruction set this CPU supports. This could be done in user space,
16790@@ -296,16 +314,12 @@ do { \
16791
16792 #define ARCH_DLINFO \
16793 do { \
16794- if (vdso_enabled) \
16795- NEW_AUX_ENT(AT_SYSINFO_EHDR, \
16796- (unsigned long)current->mm->context.vdso); \
16797+ NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
16798 } while (0)
16799
16800 #define ARCH_DLINFO_X32 \
16801 do { \
16802- if (vdso_enabled) \
16803- NEW_AUX_ENT(AT_SYSINFO_EHDR, \
16804- (unsigned long)current->mm->context.vdso); \
16805+ NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
16806 } while (0)
16807
16808 #define AT_SYSINFO 32
16809@@ -320,7 +334,7 @@ else \
16810
16811 #endif /* !CONFIG_X86_32 */
16812
16813-#define VDSO_CURRENT_BASE ((unsigned long)current->mm->context.vdso)
16814+#define VDSO_CURRENT_BASE (current->mm->context.vdso)
16815
16816 #define VDSO_ENTRY \
16817 ((unsigned long)VDSO32_SYMBOL(VDSO_CURRENT_BASE, vsyscall))
16818@@ -336,9 +350,6 @@ extern int x32_setup_additional_pages(struct linux_binprm *bprm,
16819 extern int syscall32_setup_pages(struct linux_binprm *, int exstack);
16820 #define compat_arch_setup_additional_pages syscall32_setup_pages
16821
16822-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
16823-#define arch_randomize_brk arch_randomize_brk
16824-
16825 /*
16826 * True on X86_32 or when emulating IA32 on X86_64
16827 */
16828diff --git a/arch/x86/include/asm/emergency-restart.h b/arch/x86/include/asm/emergency-restart.h
16829index 77a99ac..39ff7f5 100644
16830--- a/arch/x86/include/asm/emergency-restart.h
16831+++ b/arch/x86/include/asm/emergency-restart.h
16832@@ -1,6 +1,6 @@
16833 #ifndef _ASM_X86_EMERGENCY_RESTART_H
16834 #define _ASM_X86_EMERGENCY_RESTART_H
16835
16836-extern void machine_emergency_restart(void);
16837+extern void machine_emergency_restart(void) __noreturn;
16838
16839 #endif /* _ASM_X86_EMERGENCY_RESTART_H */
16840diff --git a/arch/x86/include/asm/floppy.h b/arch/x86/include/asm/floppy.h
16841index d3d7469..677ef72 100644
16842--- a/arch/x86/include/asm/floppy.h
16843+++ b/arch/x86/include/asm/floppy.h
16844@@ -229,18 +229,18 @@ static struct fd_routine_l {
16845 int (*_dma_setup)(char *addr, unsigned long size, int mode, int io);
16846 } fd_routine[] = {
16847 {
16848- request_dma,
16849- free_dma,
16850- get_dma_residue,
16851- dma_mem_alloc,
16852- hard_dma_setup
16853+ ._request_dma = request_dma,
16854+ ._free_dma = free_dma,
16855+ ._get_dma_residue = get_dma_residue,
16856+ ._dma_mem_alloc = dma_mem_alloc,
16857+ ._dma_setup = hard_dma_setup
16858 },
16859 {
16860- vdma_request_dma,
16861- vdma_nop,
16862- vdma_get_dma_residue,
16863- vdma_mem_alloc,
16864- vdma_dma_setup
16865+ ._request_dma = vdma_request_dma,
16866+ ._free_dma = vdma_nop,
16867+ ._get_dma_residue = vdma_get_dma_residue,
16868+ ._dma_mem_alloc = vdma_mem_alloc,
16869+ ._dma_setup = vdma_dma_setup
16870 }
16871 };
16872
16873diff --git a/arch/x86/include/asm/fpu-internal.h b/arch/x86/include/asm/fpu-internal.h
16874index cea1c76..6c0d79b 100644
16875--- a/arch/x86/include/asm/fpu-internal.h
16876+++ b/arch/x86/include/asm/fpu-internal.h
16877@@ -124,8 +124,11 @@ static inline void sanitize_i387_state(struct task_struct *tsk)
16878 #define user_insn(insn, output, input...) \
16879 ({ \
16880 int err; \
16881+ pax_open_userland(); \
16882 asm volatile(ASM_STAC "\n" \
16883- "1:" #insn "\n\t" \
16884+ "1:" \
16885+ __copyuser_seg \
16886+ #insn "\n\t" \
16887 "2: " ASM_CLAC "\n" \
16888 ".section .fixup,\"ax\"\n" \
16889 "3: movl $-1,%[err]\n" \
16890@@ -134,6 +137,7 @@ static inline void sanitize_i387_state(struct task_struct *tsk)
16891 _ASM_EXTABLE(1b, 3b) \
16892 : [err] "=r" (err), output \
16893 : "0"(0), input); \
16894+ pax_close_userland(); \
16895 err; \
16896 })
16897
16898@@ -298,7 +302,7 @@ static inline int restore_fpu_checking(struct task_struct *tsk)
16899 "fnclex\n\t"
16900 "emms\n\t"
16901 "fildl %P[addr]" /* set F?P to defined value */
16902- : : [addr] "m" (tsk->thread.fpu.has_fpu));
16903+ : : [addr] "m" (init_tss[raw_smp_processor_id()].x86_tss.sp0));
16904 }
16905
16906 return fpu_restore_checking(&tsk->thread.fpu);
16907diff --git a/arch/x86/include/asm/futex.h b/arch/x86/include/asm/futex.h
16908index b4c1f54..e290c08 100644
16909--- a/arch/x86/include/asm/futex.h
16910+++ b/arch/x86/include/asm/futex.h
16911@@ -12,6 +12,7 @@
16912 #include <asm/smap.h>
16913
16914 #define __futex_atomic_op1(insn, ret, oldval, uaddr, oparg) \
16915+ typecheck(u32 __user *, uaddr); \
16916 asm volatile("\t" ASM_STAC "\n" \
16917 "1:\t" insn "\n" \
16918 "2:\t" ASM_CLAC "\n" \
16919@@ -20,15 +21,16 @@
16920 "\tjmp\t2b\n" \
16921 "\t.previous\n" \
16922 _ASM_EXTABLE(1b, 3b) \
16923- : "=r" (oldval), "=r" (ret), "+m" (*uaddr) \
16924+ : "=r" (oldval), "=r" (ret), "+m" (*(u32 __user *)____m(uaddr)) \
16925 : "i" (-EFAULT), "0" (oparg), "1" (0))
16926
16927 #define __futex_atomic_op2(insn, ret, oldval, uaddr, oparg) \
16928+ typecheck(u32 __user *, uaddr); \
16929 asm volatile("\t" ASM_STAC "\n" \
16930 "1:\tmovl %2, %0\n" \
16931 "\tmovl\t%0, %3\n" \
16932 "\t" insn "\n" \
16933- "2:\t" LOCK_PREFIX "cmpxchgl %3, %2\n" \
16934+ "2:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %3, %2\n" \
16935 "\tjnz\t1b\n" \
16936 "3:\t" ASM_CLAC "\n" \
16937 "\t.section .fixup,\"ax\"\n" \
16938@@ -38,7 +40,7 @@
16939 _ASM_EXTABLE(1b, 4b) \
16940 _ASM_EXTABLE(2b, 4b) \
16941 : "=&a" (oldval), "=&r" (ret), \
16942- "+m" (*uaddr), "=&r" (tem) \
16943+ "+m" (*(u32 __user *)____m(uaddr)), "=&r" (tem) \
16944 : "r" (oparg), "i" (-EFAULT), "1" (0))
16945
16946 static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
16947@@ -57,12 +59,13 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
16948
16949 pagefault_disable();
16950
16951+ pax_open_userland();
16952 switch (op) {
16953 case FUTEX_OP_SET:
16954- __futex_atomic_op1("xchgl %0, %2", ret, oldval, uaddr, oparg);
16955+ __futex_atomic_op1(__copyuser_seg"xchgl %0, %2", ret, oldval, uaddr, oparg);
16956 break;
16957 case FUTEX_OP_ADD:
16958- __futex_atomic_op1(LOCK_PREFIX "xaddl %0, %2", ret, oldval,
16959+ __futex_atomic_op1(LOCK_PREFIX __copyuser_seg"xaddl %0, %2", ret, oldval,
16960 uaddr, oparg);
16961 break;
16962 case FUTEX_OP_OR:
16963@@ -77,6 +80,7 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
16964 default:
16965 ret = -ENOSYS;
16966 }
16967+ pax_close_userland();
16968
16969 pagefault_enable();
16970
16971diff --git a/arch/x86/include/asm/hw_irq.h b/arch/x86/include/asm/hw_irq.h
16972index 67d69b8..50e4b77 100644
16973--- a/arch/x86/include/asm/hw_irq.h
16974+++ b/arch/x86/include/asm/hw_irq.h
16975@@ -165,8 +165,8 @@ extern void setup_ioapic_dest(void);
16976 extern void enable_IO_APIC(void);
16977
16978 /* Statistics */
16979-extern atomic_t irq_err_count;
16980-extern atomic_t irq_mis_count;
16981+extern atomic_unchecked_t irq_err_count;
16982+extern atomic_unchecked_t irq_mis_count;
16983
16984 /* EISA */
16985 extern void eisa_set_level_irq(unsigned int irq);
16986diff --git a/arch/x86/include/asm/i8259.h b/arch/x86/include/asm/i8259.h
16987index a203659..9889f1c 100644
16988--- a/arch/x86/include/asm/i8259.h
16989+++ b/arch/x86/include/asm/i8259.h
16990@@ -62,7 +62,7 @@ struct legacy_pic {
16991 void (*init)(int auto_eoi);
16992 int (*irq_pending)(unsigned int irq);
16993 void (*make_irq)(unsigned int irq);
16994-};
16995+} __do_const;
16996
16997 extern struct legacy_pic *legacy_pic;
16998 extern struct legacy_pic null_legacy_pic;
16999diff --git a/arch/x86/include/asm/io.h b/arch/x86/include/asm/io.h
17000index 91d9c69..dfae7d0 100644
17001--- a/arch/x86/include/asm/io.h
17002+++ b/arch/x86/include/asm/io.h
17003@@ -51,12 +51,12 @@ static inline void name(type val, volatile void __iomem *addr) \
17004 "m" (*(volatile type __force *)addr) barrier); }
17005
17006 build_mmio_read(readb, "b", unsigned char, "=q", :"memory")
17007-build_mmio_read(readw, "w", unsigned short, "=r", :"memory")
17008-build_mmio_read(readl, "l", unsigned int, "=r", :"memory")
17009+build_mmio_read(__intentional_overflow(-1) readw, "w", unsigned short, "=r", :"memory")
17010+build_mmio_read(__intentional_overflow(-1) readl, "l", unsigned int, "=r", :"memory")
17011
17012 build_mmio_read(__readb, "b", unsigned char, "=q", )
17013-build_mmio_read(__readw, "w", unsigned short, "=r", )
17014-build_mmio_read(__readl, "l", unsigned int, "=r", )
17015+build_mmio_read(__intentional_overflow(-1) __readw, "w", unsigned short, "=r", )
17016+build_mmio_read(__intentional_overflow(-1) __readl, "l", unsigned int, "=r", )
17017
17018 build_mmio_write(writeb, "b", unsigned char, "q", :"memory")
17019 build_mmio_write(writew, "w", unsigned short, "r", :"memory")
17020@@ -184,7 +184,7 @@ static inline void __iomem *ioremap(resource_size_t offset, unsigned long size)
17021 return ioremap_nocache(offset, size);
17022 }
17023
17024-extern void iounmap(volatile void __iomem *addr);
17025+extern void iounmap(const volatile void __iomem *addr);
17026
17027 extern void set_iounmap_nonlazy(void);
17028
17029@@ -194,6 +194,17 @@ extern void set_iounmap_nonlazy(void);
17030
17031 #include <linux/vmalloc.h>
17032
17033+#define ARCH_HAS_VALID_PHYS_ADDR_RANGE
17034+static inline int valid_phys_addr_range(unsigned long addr, size_t count)
17035+{
17036+ return ((addr + count + PAGE_SIZE - 1) >> PAGE_SHIFT) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
17037+}
17038+
17039+static inline int valid_mmap_phys_addr_range(unsigned long pfn, size_t count)
17040+{
17041+ return (pfn + (count >> PAGE_SHIFT)) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
17042+}
17043+
17044 /*
17045 * Convert a virtual cached pointer to an uncached pointer
17046 */
17047diff --git a/arch/x86/include/asm/irqflags.h b/arch/x86/include/asm/irqflags.h
17048index bba3cf8..06bc8da 100644
17049--- a/arch/x86/include/asm/irqflags.h
17050+++ b/arch/x86/include/asm/irqflags.h
17051@@ -141,6 +141,11 @@ static inline notrace unsigned long arch_local_irq_save(void)
17052 sti; \
17053 sysexit
17054
17055+#define GET_CR0_INTO_RDI mov %cr0, %rdi
17056+#define SET_RDI_INTO_CR0 mov %rdi, %cr0
17057+#define GET_CR3_INTO_RDI mov %cr3, %rdi
17058+#define SET_RDI_INTO_CR3 mov %rdi, %cr3
17059+
17060 #else
17061 #define INTERRUPT_RETURN iret
17062 #define ENABLE_INTERRUPTS_SYSEXIT sti; sysexit
17063diff --git a/arch/x86/include/asm/kprobes.h b/arch/x86/include/asm/kprobes.h
17064index 9454c16..e4100e3 100644
17065--- a/arch/x86/include/asm/kprobes.h
17066+++ b/arch/x86/include/asm/kprobes.h
17067@@ -38,13 +38,8 @@ typedef u8 kprobe_opcode_t;
17068 #define RELATIVEJUMP_SIZE 5
17069 #define RELATIVECALL_OPCODE 0xe8
17070 #define RELATIVE_ADDR_SIZE 4
17071-#define MAX_STACK_SIZE 64
17072-#define MIN_STACK_SIZE(ADDR) \
17073- (((MAX_STACK_SIZE) < (((unsigned long)current_thread_info()) + \
17074- THREAD_SIZE - (unsigned long)(ADDR))) \
17075- ? (MAX_STACK_SIZE) \
17076- : (((unsigned long)current_thread_info()) + \
17077- THREAD_SIZE - (unsigned long)(ADDR)))
17078+#define MAX_STACK_SIZE 64UL
17079+#define MIN_STACK_SIZE(ADDR) min(MAX_STACK_SIZE, current->thread.sp0 - (unsigned long)(ADDR))
17080
17081 #define flush_insn_slot(p) do { } while (0)
17082
17083diff --git a/arch/x86/include/asm/local.h b/arch/x86/include/asm/local.h
17084index 4ad6560..75c7bdd 100644
17085--- a/arch/x86/include/asm/local.h
17086+++ b/arch/x86/include/asm/local.h
17087@@ -10,33 +10,97 @@ typedef struct {
17088 atomic_long_t a;
17089 } local_t;
17090
17091+typedef struct {
17092+ atomic_long_unchecked_t a;
17093+} local_unchecked_t;
17094+
17095 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
17096
17097 #define local_read(l) atomic_long_read(&(l)->a)
17098+#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
17099 #define local_set(l, i) atomic_long_set(&(l)->a, (i))
17100+#define local_set_unchecked(l, i) atomic_long_set_unchecked(&(l)->a, (i))
17101
17102 static inline void local_inc(local_t *l)
17103 {
17104- asm volatile(_ASM_INC "%0"
17105+ asm volatile(_ASM_INC "%0\n"
17106+
17107+#ifdef CONFIG_PAX_REFCOUNT
17108+ "jno 0f\n"
17109+ _ASM_DEC "%0\n"
17110+ "int $4\n0:\n"
17111+ _ASM_EXTABLE(0b, 0b)
17112+#endif
17113+
17114+ : "+m" (l->a.counter));
17115+}
17116+
17117+static inline void local_inc_unchecked(local_unchecked_t *l)
17118+{
17119+ asm volatile(_ASM_INC "%0\n"
17120 : "+m" (l->a.counter));
17121 }
17122
17123 static inline void local_dec(local_t *l)
17124 {
17125- asm volatile(_ASM_DEC "%0"
17126+ asm volatile(_ASM_DEC "%0\n"
17127+
17128+#ifdef CONFIG_PAX_REFCOUNT
17129+ "jno 0f\n"
17130+ _ASM_INC "%0\n"
17131+ "int $4\n0:\n"
17132+ _ASM_EXTABLE(0b, 0b)
17133+#endif
17134+
17135+ : "+m" (l->a.counter));
17136+}
17137+
17138+static inline void local_dec_unchecked(local_unchecked_t *l)
17139+{
17140+ asm volatile(_ASM_DEC "%0\n"
17141 : "+m" (l->a.counter));
17142 }
17143
17144 static inline void local_add(long i, local_t *l)
17145 {
17146- asm volatile(_ASM_ADD "%1,%0"
17147+ asm volatile(_ASM_ADD "%1,%0\n"
17148+
17149+#ifdef CONFIG_PAX_REFCOUNT
17150+ "jno 0f\n"
17151+ _ASM_SUB "%1,%0\n"
17152+ "int $4\n0:\n"
17153+ _ASM_EXTABLE(0b, 0b)
17154+#endif
17155+
17156+ : "+m" (l->a.counter)
17157+ : "ir" (i));
17158+}
17159+
17160+static inline void local_add_unchecked(long i, local_unchecked_t *l)
17161+{
17162+ asm volatile(_ASM_ADD "%1,%0\n"
17163 : "+m" (l->a.counter)
17164 : "ir" (i));
17165 }
17166
17167 static inline void local_sub(long i, local_t *l)
17168 {
17169- asm volatile(_ASM_SUB "%1,%0"
17170+ asm volatile(_ASM_SUB "%1,%0\n"
17171+
17172+#ifdef CONFIG_PAX_REFCOUNT
17173+ "jno 0f\n"
17174+ _ASM_ADD "%1,%0\n"
17175+ "int $4\n0:\n"
17176+ _ASM_EXTABLE(0b, 0b)
17177+#endif
17178+
17179+ : "+m" (l->a.counter)
17180+ : "ir" (i));
17181+}
17182+
17183+static inline void local_sub_unchecked(long i, local_unchecked_t *l)
17184+{
17185+ asm volatile(_ASM_SUB "%1,%0\n"
17186 : "+m" (l->a.counter)
17187 : "ir" (i));
17188 }
17189@@ -52,7 +116,7 @@ static inline void local_sub(long i, local_t *l)
17190 */
17191 static inline int local_sub_and_test(long i, local_t *l)
17192 {
17193- GEN_BINARY_RMWcc(_ASM_SUB, l->a.counter, "er", i, "%0", "e");
17194+ GEN_BINARY_RMWcc(_ASM_SUB, _ASM_ADD, l->a.counter, "er", i, "%0", "e");
17195 }
17196
17197 /**
17198@@ -65,7 +129,7 @@ static inline int local_sub_and_test(long i, local_t *l)
17199 */
17200 static inline int local_dec_and_test(local_t *l)
17201 {
17202- GEN_UNARY_RMWcc(_ASM_DEC, l->a.counter, "%0", "e");
17203+ GEN_UNARY_RMWcc(_ASM_DEC, _ASM_INC, l->a.counter, "%0", "e");
17204 }
17205
17206 /**
17207@@ -78,7 +142,7 @@ static inline int local_dec_and_test(local_t *l)
17208 */
17209 static inline int local_inc_and_test(local_t *l)
17210 {
17211- GEN_UNARY_RMWcc(_ASM_INC, l->a.counter, "%0", "e");
17212+ GEN_UNARY_RMWcc(_ASM_INC, _ASM_DEC, l->a.counter, "%0", "e");
17213 }
17214
17215 /**
17216@@ -92,7 +156,7 @@ static inline int local_inc_and_test(local_t *l)
17217 */
17218 static inline int local_add_negative(long i, local_t *l)
17219 {
17220- GEN_BINARY_RMWcc(_ASM_ADD, l->a.counter, "er", i, "%0", "s");
17221+ GEN_BINARY_RMWcc(_ASM_ADD, _ASM_SUB, l->a.counter, "er", i, "%0", "s");
17222 }
17223
17224 /**
17225@@ -105,6 +169,30 @@ static inline int local_add_negative(long i, local_t *l)
17226 static inline long local_add_return(long i, local_t *l)
17227 {
17228 long __i = i;
17229+ asm volatile(_ASM_XADD "%0, %1\n"
17230+
17231+#ifdef CONFIG_PAX_REFCOUNT
17232+ "jno 0f\n"
17233+ _ASM_MOV "%0,%1\n"
17234+ "int $4\n0:\n"
17235+ _ASM_EXTABLE(0b, 0b)
17236+#endif
17237+
17238+ : "+r" (i), "+m" (l->a.counter)
17239+ : : "memory");
17240+ return i + __i;
17241+}
17242+
17243+/**
17244+ * local_add_return_unchecked - add and return
17245+ * @i: integer value to add
17246+ * @l: pointer to type local_unchecked_t
17247+ *
17248+ * Atomically adds @i to @l and returns @i + @l
17249+ */
17250+static inline long local_add_return_unchecked(long i, local_unchecked_t *l)
17251+{
17252+ long __i = i;
17253 asm volatile(_ASM_XADD "%0, %1;"
17254 : "+r" (i), "+m" (l->a.counter)
17255 : : "memory");
17256@@ -121,6 +209,8 @@ static inline long local_sub_return(long i, local_t *l)
17257
17258 #define local_cmpxchg(l, o, n) \
17259 (cmpxchg_local(&((l)->a.counter), (o), (n)))
17260+#define local_cmpxchg_unchecked(l, o, n) \
17261+ (cmpxchg_local(&((l)->a.counter), (o), (n)))
17262 /* Always has a lock prefix */
17263 #define local_xchg(l, n) (xchg(&((l)->a.counter), (n)))
17264
17265diff --git a/arch/x86/include/asm/mman.h b/arch/x86/include/asm/mman.h
17266new file mode 100644
17267index 0000000..2bfd3ba
17268--- /dev/null
17269+++ b/arch/x86/include/asm/mman.h
17270@@ -0,0 +1,15 @@
17271+#ifndef _X86_MMAN_H
17272+#define _X86_MMAN_H
17273+
17274+#include <uapi/asm/mman.h>
17275+
17276+#ifdef __KERNEL__
17277+#ifndef __ASSEMBLY__
17278+#ifdef CONFIG_X86_32
17279+#define arch_mmap_check i386_mmap_check
17280+int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags);
17281+#endif
17282+#endif
17283+#endif
17284+
17285+#endif /* X86_MMAN_H */
17286diff --git a/arch/x86/include/asm/mmu.h b/arch/x86/include/asm/mmu.h
17287index 5f55e69..e20bfb1 100644
17288--- a/arch/x86/include/asm/mmu.h
17289+++ b/arch/x86/include/asm/mmu.h
17290@@ -9,7 +9,7 @@
17291 * we put the segment information here.
17292 */
17293 typedef struct {
17294- void *ldt;
17295+ struct desc_struct *ldt;
17296 int size;
17297
17298 #ifdef CONFIG_X86_64
17299@@ -18,7 +18,19 @@ typedef struct {
17300 #endif
17301
17302 struct mutex lock;
17303- void *vdso;
17304+ unsigned long vdso;
17305+
17306+#ifdef CONFIG_X86_32
17307+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
17308+ unsigned long user_cs_base;
17309+ unsigned long user_cs_limit;
17310+
17311+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
17312+ cpumask_t cpu_user_cs_mask;
17313+#endif
17314+
17315+#endif
17316+#endif
17317 } mm_context_t;
17318
17319 #ifdef CONFIG_SMP
17320diff --git a/arch/x86/include/asm/mmu_context.h b/arch/x86/include/asm/mmu_context.h
17321index be12c53..4d24039 100644
17322--- a/arch/x86/include/asm/mmu_context.h
17323+++ b/arch/x86/include/asm/mmu_context.h
17324@@ -24,6 +24,20 @@ void destroy_context(struct mm_struct *mm);
17325
17326 static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
17327 {
17328+
17329+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17330+ if (!(static_cpu_has(X86_FEATURE_PCID))) {
17331+ unsigned int i;
17332+ pgd_t *pgd;
17333+
17334+ pax_open_kernel();
17335+ pgd = get_cpu_pgd(smp_processor_id(), kernel);
17336+ for (i = USER_PGD_PTRS; i < 2 * USER_PGD_PTRS; ++i)
17337+ set_pgd_batched(pgd+i, native_make_pgd(0));
17338+ pax_close_kernel();
17339+ }
17340+#endif
17341+
17342 #ifdef CONFIG_SMP
17343 if (this_cpu_read(cpu_tlbstate.state) == TLBSTATE_OK)
17344 this_cpu_write(cpu_tlbstate.state, TLBSTATE_LAZY);
17345@@ -34,16 +48,59 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
17346 struct task_struct *tsk)
17347 {
17348 unsigned cpu = smp_processor_id();
17349+#if defined(CONFIG_X86_32) && defined(CONFIG_SMP) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
17350+ int tlbstate = TLBSTATE_OK;
17351+#endif
17352
17353 if (likely(prev != next)) {
17354 #ifdef CONFIG_SMP
17355+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
17356+ tlbstate = this_cpu_read(cpu_tlbstate.state);
17357+#endif
17358 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
17359 this_cpu_write(cpu_tlbstate.active_mm, next);
17360 #endif
17361 cpumask_set_cpu(cpu, mm_cpumask(next));
17362
17363 /* Re-load page tables */
17364+#ifdef CONFIG_PAX_PER_CPU_PGD
17365+ pax_open_kernel();
17366+
17367+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17368+ if (static_cpu_has(X86_FEATURE_PCID))
17369+ __clone_user_pgds(get_cpu_pgd(cpu, user), next->pgd);
17370+ else
17371+#endif
17372+
17373+ __clone_user_pgds(get_cpu_pgd(cpu, kernel), next->pgd);
17374+ __shadow_user_pgds(get_cpu_pgd(cpu, kernel) + USER_PGD_PTRS, next->pgd);
17375+ pax_close_kernel();
17376+ 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));
17377+
17378+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17379+ if (static_cpu_has(X86_FEATURE_PCID)) {
17380+ if (static_cpu_has(X86_FEATURE_INVPCID)) {
17381+ u64 descriptor[2];
17382+ descriptor[0] = PCID_USER;
17383+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
17384+ if (!static_cpu_has(X86_FEATURE_STRONGUDEREF)) {
17385+ descriptor[0] = PCID_KERNEL;
17386+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
17387+ }
17388+ } else {
17389+ write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER);
17390+ if (static_cpu_has(X86_FEATURE_STRONGUDEREF))
17391+ write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
17392+ else
17393+ write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL);
17394+ }
17395+ } else
17396+#endif
17397+
17398+ load_cr3(get_cpu_pgd(cpu, kernel));
17399+#else
17400 load_cr3(next->pgd);
17401+#endif
17402
17403 /* Stop flush ipis for the previous mm */
17404 cpumask_clear_cpu(cpu, mm_cpumask(prev));
17405@@ -51,9 +108,67 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
17406 /* Load the LDT, if the LDT is different: */
17407 if (unlikely(prev->context.ldt != next->context.ldt))
17408 load_LDT_nolock(&next->context);
17409+
17410+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
17411+ if (!(__supported_pte_mask & _PAGE_NX)) {
17412+ smp_mb__before_clear_bit();
17413+ cpu_clear(cpu, prev->context.cpu_user_cs_mask);
17414+ smp_mb__after_clear_bit();
17415+ cpu_set(cpu, next->context.cpu_user_cs_mask);
17416+ }
17417+#endif
17418+
17419+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
17420+ if (unlikely(prev->context.user_cs_base != next->context.user_cs_base ||
17421+ prev->context.user_cs_limit != next->context.user_cs_limit))
17422+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
17423+#ifdef CONFIG_SMP
17424+ else if (unlikely(tlbstate != TLBSTATE_OK))
17425+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
17426+#endif
17427+#endif
17428+
17429 }
17430+ else {
17431+
17432+#ifdef CONFIG_PAX_PER_CPU_PGD
17433+ pax_open_kernel();
17434+
17435+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17436+ if (static_cpu_has(X86_FEATURE_PCID))
17437+ __clone_user_pgds(get_cpu_pgd(cpu, user), next->pgd);
17438+ else
17439+#endif
17440+
17441+ __clone_user_pgds(get_cpu_pgd(cpu, kernel), next->pgd);
17442+ __shadow_user_pgds(get_cpu_pgd(cpu, kernel) + USER_PGD_PTRS, next->pgd);
17443+ pax_close_kernel();
17444+ 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));
17445+
17446+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17447+ if (static_cpu_has(X86_FEATURE_PCID)) {
17448+ if (static_cpu_has(X86_FEATURE_INVPCID)) {
17449+ u64 descriptor[2];
17450+ descriptor[0] = PCID_USER;
17451+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
17452+ if (!static_cpu_has(X86_FEATURE_STRONGUDEREF)) {
17453+ descriptor[0] = PCID_KERNEL;
17454+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
17455+ }
17456+ } else {
17457+ write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER);
17458+ if (static_cpu_has(X86_FEATURE_STRONGUDEREF))
17459+ write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
17460+ else
17461+ write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL);
17462+ }
17463+ } else
17464+#endif
17465+
17466+ load_cr3(get_cpu_pgd(cpu, kernel));
17467+#endif
17468+
17469 #ifdef CONFIG_SMP
17470- else {
17471 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
17472 BUG_ON(this_cpu_read(cpu_tlbstate.active_mm) != next);
17473
17474@@ -70,11 +185,28 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
17475 * tlb flush IPI delivery. We must reload CR3
17476 * to make sure to use no freed page tables.
17477 */
17478+
17479+#ifndef CONFIG_PAX_PER_CPU_PGD
17480 load_cr3(next->pgd);
17481+#endif
17482+
17483 load_LDT_nolock(&next->context);
17484+
17485+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
17486+ if (!(__supported_pte_mask & _PAGE_NX))
17487+ cpu_set(cpu, next->context.cpu_user_cs_mask);
17488+#endif
17489+
17490+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
17491+#ifdef CONFIG_PAX_PAGEEXEC
17492+ if (!((next->pax_flags & MF_PAX_PAGEEXEC) && (__supported_pte_mask & _PAGE_NX)))
17493+#endif
17494+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
17495+#endif
17496+
17497 }
17498+#endif
17499 }
17500-#endif
17501 }
17502
17503 #define activate_mm(prev, next) \
17504diff --git a/arch/x86/include/asm/module.h b/arch/x86/include/asm/module.h
17505index e3b7819..b257c64 100644
17506--- a/arch/x86/include/asm/module.h
17507+++ b/arch/x86/include/asm/module.h
17508@@ -5,6 +5,7 @@
17509
17510 #ifdef CONFIG_X86_64
17511 /* X86_64 does not define MODULE_PROC_FAMILY */
17512+#define MODULE_PROC_FAMILY ""
17513 #elif defined CONFIG_M486
17514 #define MODULE_PROC_FAMILY "486 "
17515 #elif defined CONFIG_M586
17516@@ -57,8 +58,20 @@
17517 #error unknown processor family
17518 #endif
17519
17520-#ifdef CONFIG_X86_32
17521-# define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY
17522+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
17523+#define MODULE_PAX_KERNEXEC "KERNEXEC_BTS "
17524+#elif defined(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR)
17525+#define MODULE_PAX_KERNEXEC "KERNEXEC_OR "
17526+#else
17527+#define MODULE_PAX_KERNEXEC ""
17528 #endif
17529
17530+#ifdef CONFIG_PAX_MEMORY_UDEREF
17531+#define MODULE_PAX_UDEREF "UDEREF "
17532+#else
17533+#define MODULE_PAX_UDEREF ""
17534+#endif
17535+
17536+#define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY MODULE_PAX_KERNEXEC MODULE_PAX_UDEREF
17537+
17538 #endif /* _ASM_X86_MODULE_H */
17539diff --git a/arch/x86/include/asm/nmi.h b/arch/x86/include/asm/nmi.h
17540index 86f9301..b365cda 100644
17541--- a/arch/x86/include/asm/nmi.h
17542+++ b/arch/x86/include/asm/nmi.h
17543@@ -40,11 +40,11 @@ struct nmiaction {
17544 nmi_handler_t handler;
17545 unsigned long flags;
17546 const char *name;
17547-};
17548+} __do_const;
17549
17550 #define register_nmi_handler(t, fn, fg, n, init...) \
17551 ({ \
17552- static struct nmiaction init fn##_na = { \
17553+ static const struct nmiaction init fn##_na = { \
17554 .handler = (fn), \
17555 .name = (n), \
17556 .flags = (fg), \
17557@@ -52,7 +52,7 @@ struct nmiaction {
17558 __register_nmi_handler((t), &fn##_na); \
17559 })
17560
17561-int __register_nmi_handler(unsigned int, struct nmiaction *);
17562+int __register_nmi_handler(unsigned int, const struct nmiaction *);
17563
17564 void unregister_nmi_handler(unsigned int, const char *);
17565
17566diff --git a/arch/x86/include/asm/page.h b/arch/x86/include/asm/page.h
17567index 775873d..de5f0304 100644
17568--- a/arch/x86/include/asm/page.h
17569+++ b/arch/x86/include/asm/page.h
17570@@ -52,6 +52,7 @@ static inline void copy_user_page(void *to, void *from, unsigned long vaddr,
17571 __phys_addr_symbol(__phys_reloc_hide((unsigned long)(x)))
17572
17573 #define __va(x) ((void *)((unsigned long)(x)+PAGE_OFFSET))
17574+#define __early_va(x) ((void *)((unsigned long)(x)+__START_KERNEL_map - phys_base))
17575
17576 #define __boot_va(x) __va(x)
17577 #define __boot_pa(x) __pa(x)
17578diff --git a/arch/x86/include/asm/page_64.h b/arch/x86/include/asm/page_64.h
17579index 0f1ddee..e2fc3d1 100644
17580--- a/arch/x86/include/asm/page_64.h
17581+++ b/arch/x86/include/asm/page_64.h
17582@@ -7,9 +7,9 @@
17583
17584 /* duplicated to the one in bootmem.h */
17585 extern unsigned long max_pfn;
17586-extern unsigned long phys_base;
17587+extern const unsigned long phys_base;
17588
17589-static inline unsigned long __phys_addr_nodebug(unsigned long x)
17590+static inline unsigned long __intentional_overflow(-1) __phys_addr_nodebug(unsigned long x)
17591 {
17592 unsigned long y = x - __START_KERNEL_map;
17593
17594diff --git a/arch/x86/include/asm/paravirt.h b/arch/x86/include/asm/paravirt.h
17595index cd6e1610..70f4418 100644
17596--- a/arch/x86/include/asm/paravirt.h
17597+++ b/arch/x86/include/asm/paravirt.h
17598@@ -560,7 +560,7 @@ static inline pmd_t __pmd(pmdval_t val)
17599 return (pmd_t) { ret };
17600 }
17601
17602-static inline pmdval_t pmd_val(pmd_t pmd)
17603+static inline __intentional_overflow(-1) pmdval_t pmd_val(pmd_t pmd)
17604 {
17605 pmdval_t ret;
17606
17607@@ -626,6 +626,18 @@ static inline void set_pgd(pgd_t *pgdp, pgd_t pgd)
17608 val);
17609 }
17610
17611+static inline void set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
17612+{
17613+ pgdval_t val = native_pgd_val(pgd);
17614+
17615+ if (sizeof(pgdval_t) > sizeof(long))
17616+ PVOP_VCALL3(pv_mmu_ops.set_pgd_batched, pgdp,
17617+ val, (u64)val >> 32);
17618+ else
17619+ PVOP_VCALL2(pv_mmu_ops.set_pgd_batched, pgdp,
17620+ val);
17621+}
17622+
17623 static inline void pgd_clear(pgd_t *pgdp)
17624 {
17625 set_pgd(pgdp, __pgd(0));
17626@@ -710,6 +722,21 @@ static inline void __set_fixmap(unsigned /* enum fixed_addresses */ idx,
17627 pv_mmu_ops.set_fixmap(idx, phys, flags);
17628 }
17629
17630+#ifdef CONFIG_PAX_KERNEXEC
17631+static inline unsigned long pax_open_kernel(void)
17632+{
17633+ return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_open_kernel);
17634+}
17635+
17636+static inline unsigned long pax_close_kernel(void)
17637+{
17638+ return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_close_kernel);
17639+}
17640+#else
17641+static inline unsigned long pax_open_kernel(void) { return 0; }
17642+static inline unsigned long pax_close_kernel(void) { return 0; }
17643+#endif
17644+
17645 #if defined(CONFIG_SMP) && defined(CONFIG_PARAVIRT_SPINLOCKS)
17646
17647 static __always_inline void __ticket_lock_spinning(struct arch_spinlock *lock,
17648@@ -906,7 +933,7 @@ extern void default_banner(void);
17649
17650 #define PARA_PATCH(struct, off) ((PARAVIRT_PATCH_##struct + (off)) / 4)
17651 #define PARA_SITE(ptype, clobbers, ops) _PVSITE(ptype, clobbers, ops, .long, 4)
17652-#define PARA_INDIRECT(addr) *%cs:addr
17653+#define PARA_INDIRECT(addr) *%ss:addr
17654 #endif
17655
17656 #define INTERRUPT_RETURN \
17657@@ -981,6 +1008,21 @@ extern void default_banner(void);
17658 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_irq_enable_sysexit), \
17659 CLBR_NONE, \
17660 jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_irq_enable_sysexit))
17661+
17662+#define GET_CR0_INTO_RDI \
17663+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0); \
17664+ mov %rax,%rdi
17665+
17666+#define SET_RDI_INTO_CR0 \
17667+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
17668+
17669+#define GET_CR3_INTO_RDI \
17670+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_read_cr3); \
17671+ mov %rax,%rdi
17672+
17673+#define SET_RDI_INTO_CR3 \
17674+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_write_cr3)
17675+
17676 #endif /* CONFIG_X86_32 */
17677
17678 #endif /* __ASSEMBLY__ */
17679diff --git a/arch/x86/include/asm/paravirt_types.h b/arch/x86/include/asm/paravirt_types.h
17680index 7549b8b..f0edfda 100644
17681--- a/arch/x86/include/asm/paravirt_types.h
17682+++ b/arch/x86/include/asm/paravirt_types.h
17683@@ -84,7 +84,7 @@ struct pv_init_ops {
17684 */
17685 unsigned (*patch)(u8 type, u16 clobber, void *insnbuf,
17686 unsigned long addr, unsigned len);
17687-};
17688+} __no_const __no_randomize_layout;
17689
17690
17691 struct pv_lazy_ops {
17692@@ -92,13 +92,13 @@ struct pv_lazy_ops {
17693 void (*enter)(void);
17694 void (*leave)(void);
17695 void (*flush)(void);
17696-};
17697+} __no_randomize_layout;
17698
17699 struct pv_time_ops {
17700 unsigned long long (*sched_clock)(void);
17701 unsigned long long (*steal_clock)(int cpu);
17702 unsigned long (*get_tsc_khz)(void);
17703-};
17704+} __no_const __no_randomize_layout;
17705
17706 struct pv_cpu_ops {
17707 /* hooks for various privileged instructions */
17708@@ -192,7 +192,7 @@ struct pv_cpu_ops {
17709
17710 void (*start_context_switch)(struct task_struct *prev);
17711 void (*end_context_switch)(struct task_struct *next);
17712-};
17713+} __no_const __no_randomize_layout;
17714
17715 struct pv_irq_ops {
17716 /*
17717@@ -215,7 +215,7 @@ struct pv_irq_ops {
17718 #ifdef CONFIG_X86_64
17719 void (*adjust_exception_frame)(void);
17720 #endif
17721-};
17722+} __no_randomize_layout;
17723
17724 struct pv_apic_ops {
17725 #ifdef CONFIG_X86_LOCAL_APIC
17726@@ -223,7 +223,7 @@ struct pv_apic_ops {
17727 unsigned long start_eip,
17728 unsigned long start_esp);
17729 #endif
17730-};
17731+} __no_const __no_randomize_layout;
17732
17733 struct pv_mmu_ops {
17734 unsigned long (*read_cr2)(void);
17735@@ -313,6 +313,7 @@ struct pv_mmu_ops {
17736 struct paravirt_callee_save make_pud;
17737
17738 void (*set_pgd)(pgd_t *pudp, pgd_t pgdval);
17739+ void (*set_pgd_batched)(pgd_t *pudp, pgd_t pgdval);
17740 #endif /* PAGETABLE_LEVELS == 4 */
17741 #endif /* PAGETABLE_LEVELS >= 3 */
17742
17743@@ -324,7 +325,13 @@ struct pv_mmu_ops {
17744 an mfn. We can tell which is which from the index. */
17745 void (*set_fixmap)(unsigned /* enum fixed_addresses */ idx,
17746 phys_addr_t phys, pgprot_t flags);
17747-};
17748+
17749+#ifdef CONFIG_PAX_KERNEXEC
17750+ unsigned long (*pax_open_kernel)(void);
17751+ unsigned long (*pax_close_kernel)(void);
17752+#endif
17753+
17754+} __no_randomize_layout;
17755
17756 struct arch_spinlock;
17757 #ifdef CONFIG_SMP
17758@@ -336,11 +343,14 @@ typedef u16 __ticket_t;
17759 struct pv_lock_ops {
17760 struct paravirt_callee_save lock_spinning;
17761 void (*unlock_kick)(struct arch_spinlock *lock, __ticket_t ticket);
17762-};
17763+} __no_randomize_layout;
17764
17765 /* This contains all the paravirt structures: we get a convenient
17766 * number for each function using the offset which we use to indicate
17767- * what to patch. */
17768+ * what to patch.
17769+ * shouldn't be randomized due to the "NEAT TRICK" in paravirt.c
17770+ */
17771+
17772 struct paravirt_patch_template {
17773 struct pv_init_ops pv_init_ops;
17774 struct pv_time_ops pv_time_ops;
17775@@ -349,7 +359,7 @@ struct paravirt_patch_template {
17776 struct pv_apic_ops pv_apic_ops;
17777 struct pv_mmu_ops pv_mmu_ops;
17778 struct pv_lock_ops pv_lock_ops;
17779-};
17780+} __no_randomize_layout;
17781
17782 extern struct pv_info pv_info;
17783 extern struct pv_init_ops pv_init_ops;
17784diff --git a/arch/x86/include/asm/pgalloc.h b/arch/x86/include/asm/pgalloc.h
17785index c4412e9..90e88c5 100644
17786--- a/arch/x86/include/asm/pgalloc.h
17787+++ b/arch/x86/include/asm/pgalloc.h
17788@@ -63,6 +63,13 @@ static inline void pmd_populate_kernel(struct mm_struct *mm,
17789 pmd_t *pmd, pte_t *pte)
17790 {
17791 paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
17792+ set_pmd(pmd, __pmd(__pa(pte) | _KERNPG_TABLE));
17793+}
17794+
17795+static inline void pmd_populate_user(struct mm_struct *mm,
17796+ pmd_t *pmd, pte_t *pte)
17797+{
17798+ paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
17799 set_pmd(pmd, __pmd(__pa(pte) | _PAGE_TABLE));
17800 }
17801
17802@@ -108,12 +115,22 @@ static inline void __pmd_free_tlb(struct mmu_gather *tlb, pmd_t *pmd,
17803
17804 #ifdef CONFIG_X86_PAE
17805 extern void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd);
17806+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
17807+{
17808+ pud_populate(mm, pudp, pmd);
17809+}
17810 #else /* !CONFIG_X86_PAE */
17811 static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
17812 {
17813 paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
17814 set_pud(pud, __pud(_PAGE_TABLE | __pa(pmd)));
17815 }
17816+
17817+static inline void pud_populate_kernel(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(_KERNPG_TABLE | __pa(pmd)));
17821+}
17822 #endif /* CONFIG_X86_PAE */
17823
17824 #if PAGETABLE_LEVELS > 3
17825@@ -123,6 +140,12 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
17826 set_pgd(pgd, __pgd(_PAGE_TABLE | __pa(pud)));
17827 }
17828
17829+static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
17830+{
17831+ paravirt_alloc_pud(mm, __pa(pud) >> PAGE_SHIFT);
17832+ set_pgd(pgd, __pgd(_KERNPG_TABLE | __pa(pud)));
17833+}
17834+
17835 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
17836 {
17837 return (pud_t *)get_zeroed_page(GFP_KERNEL|__GFP_REPEAT);
17838diff --git a/arch/x86/include/asm/pgtable-2level.h b/arch/x86/include/asm/pgtable-2level.h
17839index 0d193e2..bf59aeb 100644
17840--- a/arch/x86/include/asm/pgtable-2level.h
17841+++ b/arch/x86/include/asm/pgtable-2level.h
17842@@ -18,7 +18,9 @@ static inline void native_set_pte(pte_t *ptep , pte_t pte)
17843
17844 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
17845 {
17846+ pax_open_kernel();
17847 *pmdp = pmd;
17848+ pax_close_kernel();
17849 }
17850
17851 static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
17852diff --git a/arch/x86/include/asm/pgtable-3level.h b/arch/x86/include/asm/pgtable-3level.h
17853index 81bb91b..9392125 100644
17854--- a/arch/x86/include/asm/pgtable-3level.h
17855+++ b/arch/x86/include/asm/pgtable-3level.h
17856@@ -92,12 +92,16 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
17857
17858 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
17859 {
17860+ pax_open_kernel();
17861 set_64bit((unsigned long long *)(pmdp), native_pmd_val(pmd));
17862+ pax_close_kernel();
17863 }
17864
17865 static inline void native_set_pud(pud_t *pudp, pud_t pud)
17866 {
17867+ pax_open_kernel();
17868 set_64bit((unsigned long long *)(pudp), native_pud_val(pud));
17869+ pax_close_kernel();
17870 }
17871
17872 /*
17873diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h
17874index bbc8b12..f228861 100644
17875--- a/arch/x86/include/asm/pgtable.h
17876+++ b/arch/x86/include/asm/pgtable.h
17877@@ -45,6 +45,7 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
17878
17879 #ifndef __PAGETABLE_PUD_FOLDED
17880 #define set_pgd(pgdp, pgd) native_set_pgd(pgdp, pgd)
17881+#define set_pgd_batched(pgdp, pgd) native_set_pgd_batched(pgdp, pgd)
17882 #define pgd_clear(pgd) native_pgd_clear(pgd)
17883 #endif
17884
17885@@ -82,12 +83,51 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
17886
17887 #define arch_end_context_switch(prev) do {} while(0)
17888
17889+#define pax_open_kernel() native_pax_open_kernel()
17890+#define pax_close_kernel() native_pax_close_kernel()
17891 #endif /* CONFIG_PARAVIRT */
17892
17893+#define __HAVE_ARCH_PAX_OPEN_KERNEL
17894+#define __HAVE_ARCH_PAX_CLOSE_KERNEL
17895+
17896+#ifdef CONFIG_PAX_KERNEXEC
17897+static inline unsigned long native_pax_open_kernel(void)
17898+{
17899+ unsigned long cr0;
17900+
17901+ preempt_disable();
17902+ barrier();
17903+ cr0 = read_cr0() ^ X86_CR0_WP;
17904+ BUG_ON(cr0 & X86_CR0_WP);
17905+ write_cr0(cr0);
17906+ return cr0 ^ X86_CR0_WP;
17907+}
17908+
17909+static inline unsigned long native_pax_close_kernel(void)
17910+{
17911+ unsigned long cr0;
17912+
17913+ cr0 = read_cr0() ^ X86_CR0_WP;
17914+ BUG_ON(!(cr0 & X86_CR0_WP));
17915+ write_cr0(cr0);
17916+ barrier();
17917+ preempt_enable_no_resched();
17918+ return cr0 ^ X86_CR0_WP;
17919+}
17920+#else
17921+static inline unsigned long native_pax_open_kernel(void) { return 0; }
17922+static inline unsigned long native_pax_close_kernel(void) { return 0; }
17923+#endif
17924+
17925 /*
17926 * The following only work if pte_present() is true.
17927 * Undefined behaviour if not..
17928 */
17929+static inline int pte_user(pte_t pte)
17930+{
17931+ return pte_val(pte) & _PAGE_USER;
17932+}
17933+
17934 static inline int pte_dirty(pte_t pte)
17935 {
17936 return pte_flags(pte) & _PAGE_DIRTY;
17937@@ -148,6 +188,11 @@ static inline unsigned long pud_pfn(pud_t pud)
17938 return (pud_val(pud) & PTE_PFN_MASK) >> PAGE_SHIFT;
17939 }
17940
17941+static inline unsigned long pgd_pfn(pgd_t pgd)
17942+{
17943+ return (pgd_val(pgd) & PTE_PFN_MASK) >> PAGE_SHIFT;
17944+}
17945+
17946 #define pte_page(pte) pfn_to_page(pte_pfn(pte))
17947
17948 static inline int pmd_large(pmd_t pte)
17949@@ -201,9 +246,29 @@ static inline pte_t pte_wrprotect(pte_t pte)
17950 return pte_clear_flags(pte, _PAGE_RW);
17951 }
17952
17953+static inline pte_t pte_mkread(pte_t pte)
17954+{
17955+ return __pte(pte_val(pte) | _PAGE_USER);
17956+}
17957+
17958 static inline pte_t pte_mkexec(pte_t pte)
17959 {
17960- return pte_clear_flags(pte, _PAGE_NX);
17961+#ifdef CONFIG_X86_PAE
17962+ if (__supported_pte_mask & _PAGE_NX)
17963+ return pte_clear_flags(pte, _PAGE_NX);
17964+ else
17965+#endif
17966+ return pte_set_flags(pte, _PAGE_USER);
17967+}
17968+
17969+static inline pte_t pte_exprotect(pte_t pte)
17970+{
17971+#ifdef CONFIG_X86_PAE
17972+ if (__supported_pte_mask & _PAGE_NX)
17973+ return pte_set_flags(pte, _PAGE_NX);
17974+ else
17975+#endif
17976+ return pte_clear_flags(pte, _PAGE_USER);
17977 }
17978
17979 static inline pte_t pte_mkdirty(pte_t pte)
17980@@ -430,6 +495,16 @@ pte_t *populate_extra_pte(unsigned long vaddr);
17981 #endif
17982
17983 #ifndef __ASSEMBLY__
17984+
17985+#ifdef CONFIG_PAX_PER_CPU_PGD
17986+extern pgd_t cpu_pgd[NR_CPUS][2][PTRS_PER_PGD];
17987+enum cpu_pgd_type {kernel = 0, user = 1};
17988+static inline pgd_t *get_cpu_pgd(unsigned int cpu, enum cpu_pgd_type type)
17989+{
17990+ return cpu_pgd[cpu][type];
17991+}
17992+#endif
17993+
17994 #include <linux/mm_types.h>
17995 #include <linux/mmdebug.h>
17996 #include <linux/log2.h>
17997@@ -570,7 +645,7 @@ static inline unsigned long pud_page_vaddr(pud_t pud)
17998 * Currently stuck as a macro due to indirect forward reference to
17999 * linux/mmzone.h's __section_mem_map_addr() definition:
18000 */
18001-#define pud_page(pud) pfn_to_page(pud_val(pud) >> PAGE_SHIFT)
18002+#define pud_page(pud) pfn_to_page((pud_val(pud) & PTE_PFN_MASK) >> PAGE_SHIFT)
18003
18004 /* Find an entry in the second-level page table.. */
18005 static inline pmd_t *pmd_offset(pud_t *pud, unsigned long address)
18006@@ -610,7 +685,7 @@ static inline unsigned long pgd_page_vaddr(pgd_t pgd)
18007 * Currently stuck as a macro due to indirect forward reference to
18008 * linux/mmzone.h's __section_mem_map_addr() definition:
18009 */
18010-#define pgd_page(pgd) pfn_to_page(pgd_val(pgd) >> PAGE_SHIFT)
18011+#define pgd_page(pgd) pfn_to_page((pgd_val(pgd) & PTE_PFN_MASK) >> PAGE_SHIFT)
18012
18013 /* to find an entry in a page-table-directory. */
18014 static inline unsigned long pud_index(unsigned long address)
18015@@ -625,7 +700,7 @@ static inline pud_t *pud_offset(pgd_t *pgd, unsigned long address)
18016
18017 static inline int pgd_bad(pgd_t pgd)
18018 {
18019- return (pgd_flags(pgd) & ~_PAGE_USER) != _KERNPG_TABLE;
18020+ return (pgd_flags(pgd) & ~(_PAGE_USER | _PAGE_NX)) != _KERNPG_TABLE;
18021 }
18022
18023 static inline int pgd_none(pgd_t pgd)
18024@@ -648,7 +723,12 @@ static inline int pgd_none(pgd_t pgd)
18025 * pgd_offset() returns a (pgd_t *)
18026 * pgd_index() is used get the offset into the pgd page's array of pgd_t's;
18027 */
18028-#define pgd_offset(mm, address) ((mm)->pgd + pgd_index((address)))
18029+#define pgd_offset(mm, address) ((mm)->pgd + pgd_index(address))
18030+
18031+#ifdef CONFIG_PAX_PER_CPU_PGD
18032+#define pgd_offset_cpu(cpu, type, address) (get_cpu_pgd(cpu, type) + pgd_index(address))
18033+#endif
18034+
18035 /*
18036 * a shortcut which implies the use of the kernel's pgd, instead
18037 * of a process's
18038@@ -659,6 +739,23 @@ static inline int pgd_none(pgd_t pgd)
18039 #define KERNEL_PGD_BOUNDARY pgd_index(PAGE_OFFSET)
18040 #define KERNEL_PGD_PTRS (PTRS_PER_PGD - KERNEL_PGD_BOUNDARY)
18041
18042+#ifdef CONFIG_X86_32
18043+#define USER_PGD_PTRS KERNEL_PGD_BOUNDARY
18044+#else
18045+#define TASK_SIZE_MAX_SHIFT CONFIG_TASK_SIZE_MAX_SHIFT
18046+#define USER_PGD_PTRS (_AC(1,UL) << (TASK_SIZE_MAX_SHIFT - PGDIR_SHIFT))
18047+
18048+#ifdef CONFIG_PAX_MEMORY_UDEREF
18049+#ifdef __ASSEMBLY__
18050+#define pax_user_shadow_base pax_user_shadow_base(%rip)
18051+#else
18052+extern unsigned long pax_user_shadow_base;
18053+extern pgdval_t clone_pgd_mask;
18054+#endif
18055+#endif
18056+
18057+#endif
18058+
18059 #ifndef __ASSEMBLY__
18060
18061 extern int direct_gbpages;
18062@@ -825,11 +922,24 @@ static inline void pmdp_set_wrprotect(struct mm_struct *mm,
18063 * dst and src can be on the same page, but the range must not overlap,
18064 * and must not cross a page boundary.
18065 */
18066-static inline void clone_pgd_range(pgd_t *dst, pgd_t *src, int count)
18067+static inline void clone_pgd_range(pgd_t *dst, const pgd_t *src, int count)
18068 {
18069- memcpy(dst, src, count * sizeof(pgd_t));
18070+ pax_open_kernel();
18071+ while (count--)
18072+ *dst++ = *src++;
18073+ pax_close_kernel();
18074 }
18075
18076+#ifdef CONFIG_PAX_PER_CPU_PGD
18077+extern void __clone_user_pgds(pgd_t *dst, const pgd_t *src);
18078+#endif
18079+
18080+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18081+extern void __shadow_user_pgds(pgd_t *dst, const pgd_t *src);
18082+#else
18083+static inline void __shadow_user_pgds(pgd_t *dst, const pgd_t *src) {}
18084+#endif
18085+
18086 #define PTE_SHIFT ilog2(PTRS_PER_PTE)
18087 static inline int page_level_shift(enum pg_level level)
18088 {
18089diff --git a/arch/x86/include/asm/pgtable_32.h b/arch/x86/include/asm/pgtable_32.h
18090index 9ee3221..b979c6b 100644
18091--- a/arch/x86/include/asm/pgtable_32.h
18092+++ b/arch/x86/include/asm/pgtable_32.h
18093@@ -25,9 +25,6 @@
18094 struct mm_struct;
18095 struct vm_area_struct;
18096
18097-extern pgd_t swapper_pg_dir[1024];
18098-extern pgd_t initial_page_table[1024];
18099-
18100 static inline void pgtable_cache_init(void) { }
18101 static inline void check_pgt_cache(void) { }
18102 void paging_init(void);
18103@@ -48,6 +45,12 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
18104 # include <asm/pgtable-2level.h>
18105 #endif
18106
18107+extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
18108+extern pgd_t initial_page_table[PTRS_PER_PGD];
18109+#ifdef CONFIG_X86_PAE
18110+extern pmd_t swapper_pm_dir[PTRS_PER_PGD][PTRS_PER_PMD];
18111+#endif
18112+
18113 #if defined(CONFIG_HIGHPTE)
18114 #define pte_offset_map(dir, address) \
18115 ((pte_t *)kmap_atomic(pmd_page(*(dir))) + \
18116@@ -62,12 +65,17 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
18117 /* Clear a kernel PTE and flush it from the TLB */
18118 #define kpte_clear_flush(ptep, vaddr) \
18119 do { \
18120+ pax_open_kernel(); \
18121 pte_clear(&init_mm, (vaddr), (ptep)); \
18122+ pax_close_kernel(); \
18123 __flush_tlb_one((vaddr)); \
18124 } while (0)
18125
18126 #endif /* !__ASSEMBLY__ */
18127
18128+#define HAVE_ARCH_UNMAPPED_AREA
18129+#define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
18130+
18131 /*
18132 * kern_addr_valid() is (1) for FLATMEM and (0) for
18133 * SPARSEMEM and DISCONTIGMEM
18134diff --git a/arch/x86/include/asm/pgtable_32_types.h b/arch/x86/include/asm/pgtable_32_types.h
18135index ed5903b..c7fe163 100644
18136--- a/arch/x86/include/asm/pgtable_32_types.h
18137+++ b/arch/x86/include/asm/pgtable_32_types.h
18138@@ -8,7 +8,7 @@
18139 */
18140 #ifdef CONFIG_X86_PAE
18141 # include <asm/pgtable-3level_types.h>
18142-# define PMD_SIZE (1UL << PMD_SHIFT)
18143+# define PMD_SIZE (_AC(1, UL) << PMD_SHIFT)
18144 # define PMD_MASK (~(PMD_SIZE - 1))
18145 #else
18146 # include <asm/pgtable-2level_types.h>
18147@@ -46,6 +46,19 @@ extern bool __vmalloc_start_set; /* set once high_memory is set */
18148 # define VMALLOC_END (FIXADDR_START - 2 * PAGE_SIZE)
18149 #endif
18150
18151+#ifdef CONFIG_PAX_KERNEXEC
18152+#ifndef __ASSEMBLY__
18153+extern unsigned char MODULES_EXEC_VADDR[];
18154+extern unsigned char MODULES_EXEC_END[];
18155+#endif
18156+#include <asm/boot.h>
18157+#define ktla_ktva(addr) (addr + LOAD_PHYSICAL_ADDR + PAGE_OFFSET)
18158+#define ktva_ktla(addr) (addr - LOAD_PHYSICAL_ADDR - PAGE_OFFSET)
18159+#else
18160+#define ktla_ktva(addr) (addr)
18161+#define ktva_ktla(addr) (addr)
18162+#endif
18163+
18164 #define MODULES_VADDR VMALLOC_START
18165 #define MODULES_END VMALLOC_END
18166 #define MODULES_LEN (MODULES_VADDR - MODULES_END)
18167diff --git a/arch/x86/include/asm/pgtable_64.h b/arch/x86/include/asm/pgtable_64.h
18168index e22c1db..23a625a 100644
18169--- a/arch/x86/include/asm/pgtable_64.h
18170+++ b/arch/x86/include/asm/pgtable_64.h
18171@@ -16,10 +16,14 @@
18172
18173 extern pud_t level3_kernel_pgt[512];
18174 extern pud_t level3_ident_pgt[512];
18175+extern pud_t level3_vmalloc_start_pgt[512];
18176+extern pud_t level3_vmalloc_end_pgt[512];
18177+extern pud_t level3_vmemmap_pgt[512];
18178+extern pud_t level2_vmemmap_pgt[512];
18179 extern pmd_t level2_kernel_pgt[512];
18180 extern pmd_t level2_fixmap_pgt[512];
18181-extern pmd_t level2_ident_pgt[512];
18182-extern pgd_t init_level4_pgt[];
18183+extern pmd_t level2_ident_pgt[512*2];
18184+extern pgd_t init_level4_pgt[512];
18185
18186 #define swapper_pg_dir init_level4_pgt
18187
18188@@ -61,7 +65,9 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
18189
18190 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
18191 {
18192+ pax_open_kernel();
18193 *pmdp = pmd;
18194+ pax_close_kernel();
18195 }
18196
18197 static inline void native_pmd_clear(pmd_t *pmd)
18198@@ -97,7 +103,9 @@ static inline pmd_t native_pmdp_get_and_clear(pmd_t *xp)
18199
18200 static inline void native_set_pud(pud_t *pudp, pud_t pud)
18201 {
18202+ pax_open_kernel();
18203 *pudp = pud;
18204+ pax_close_kernel();
18205 }
18206
18207 static inline void native_pud_clear(pud_t *pud)
18208@@ -107,6 +115,13 @@ static inline void native_pud_clear(pud_t *pud)
18209
18210 static inline void native_set_pgd(pgd_t *pgdp, pgd_t pgd)
18211 {
18212+ pax_open_kernel();
18213+ *pgdp = pgd;
18214+ pax_close_kernel();
18215+}
18216+
18217+static inline void native_set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
18218+{
18219 *pgdp = pgd;
18220 }
18221
18222diff --git a/arch/x86/include/asm/pgtable_64_types.h b/arch/x86/include/asm/pgtable_64_types.h
18223index c883bf7..19970b3 100644
18224--- a/arch/x86/include/asm/pgtable_64_types.h
18225+++ b/arch/x86/include/asm/pgtable_64_types.h
18226@@ -61,6 +61,11 @@ typedef struct { pteval_t pte; } pte_t;
18227 #define MODULES_VADDR (__START_KERNEL_map + KERNEL_IMAGE_SIZE)
18228 #define MODULES_END _AC(0xffffffffff000000, UL)
18229 #define MODULES_LEN (MODULES_END - MODULES_VADDR)
18230+#define MODULES_EXEC_VADDR MODULES_VADDR
18231+#define MODULES_EXEC_END MODULES_END
18232+
18233+#define ktla_ktva(addr) (addr)
18234+#define ktva_ktla(addr) (addr)
18235
18236 #define EARLY_DYNAMIC_PAGE_TABLES 64
18237
18238diff --git a/arch/x86/include/asm/pgtable_types.h b/arch/x86/include/asm/pgtable_types.h
18239index 94e40f1..ebd03e4 100644
18240--- a/arch/x86/include/asm/pgtable_types.h
18241+++ b/arch/x86/include/asm/pgtable_types.h
18242@@ -16,13 +16,12 @@
18243 #define _PAGE_BIT_PSE 7 /* 4 MB (or 2MB) page */
18244 #define _PAGE_BIT_PAT 7 /* on 4KB pages */
18245 #define _PAGE_BIT_GLOBAL 8 /* Global TLB entry PPro+ */
18246-#define _PAGE_BIT_UNUSED1 9 /* available for programmer */
18247+#define _PAGE_BIT_SPECIAL 9 /* special mappings, no associated struct page */
18248 #define _PAGE_BIT_IOMAP 10 /* flag used to indicate IO mapping */
18249 #define _PAGE_BIT_HIDDEN 11 /* hidden by kmemcheck */
18250 #define _PAGE_BIT_PAT_LARGE 12 /* On 2MB or 1GB pages */
18251-#define _PAGE_BIT_SPECIAL _PAGE_BIT_UNUSED1
18252-#define _PAGE_BIT_CPA_TEST _PAGE_BIT_UNUSED1
18253-#define _PAGE_BIT_SPLITTING _PAGE_BIT_UNUSED1 /* only valid on a PSE pmd */
18254+#define _PAGE_BIT_CPA_TEST _PAGE_BIT_SPECIAL
18255+#define _PAGE_BIT_SPLITTING _PAGE_BIT_SPECIAL /* only valid on a PSE pmd */
18256 #define _PAGE_BIT_NX 63 /* No execute: only valid after cpuid check */
18257
18258 /* If _PAGE_BIT_PRESENT is clear, we use these: */
18259@@ -40,7 +39,6 @@
18260 #define _PAGE_DIRTY (_AT(pteval_t, 1) << _PAGE_BIT_DIRTY)
18261 #define _PAGE_PSE (_AT(pteval_t, 1) << _PAGE_BIT_PSE)
18262 #define _PAGE_GLOBAL (_AT(pteval_t, 1) << _PAGE_BIT_GLOBAL)
18263-#define _PAGE_UNUSED1 (_AT(pteval_t, 1) << _PAGE_BIT_UNUSED1)
18264 #define _PAGE_IOMAP (_AT(pteval_t, 1) << _PAGE_BIT_IOMAP)
18265 #define _PAGE_PAT (_AT(pteval_t, 1) << _PAGE_BIT_PAT)
18266 #define _PAGE_PAT_LARGE (_AT(pteval_t, 1) << _PAGE_BIT_PAT_LARGE)
18267@@ -87,8 +85,10 @@
18268
18269 #if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
18270 #define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_NX)
18271-#else
18272+#elif defined(CONFIG_KMEMCHECK) || defined(CONFIG_MEM_SOFT_DIRTY)
18273 #define _PAGE_NX (_AT(pteval_t, 0))
18274+#else
18275+#define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_HIDDEN)
18276 #endif
18277
18278 #define _PAGE_FILE (_AT(pteval_t, 1) << _PAGE_BIT_FILE)
18279@@ -147,6 +147,9 @@
18280 #define PAGE_READONLY_EXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | \
18281 _PAGE_ACCESSED)
18282
18283+#define PAGE_READONLY_NOEXEC PAGE_READONLY
18284+#define PAGE_SHARED_NOEXEC PAGE_SHARED
18285+
18286 #define __PAGE_KERNEL_EXEC \
18287 (_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_GLOBAL)
18288 #define __PAGE_KERNEL (__PAGE_KERNEL_EXEC | _PAGE_NX)
18289@@ -157,7 +160,7 @@
18290 #define __PAGE_KERNEL_WC (__PAGE_KERNEL | _PAGE_CACHE_WC)
18291 #define __PAGE_KERNEL_NOCACHE (__PAGE_KERNEL | _PAGE_PCD | _PAGE_PWT)
18292 #define __PAGE_KERNEL_UC_MINUS (__PAGE_KERNEL | _PAGE_PCD)
18293-#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RX | _PAGE_USER)
18294+#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RO | _PAGE_USER)
18295 #define __PAGE_KERNEL_VVAR (__PAGE_KERNEL_RO | _PAGE_USER)
18296 #define __PAGE_KERNEL_VVAR_NOCACHE (__PAGE_KERNEL_VVAR | _PAGE_PCD | _PAGE_PWT)
18297 #define __PAGE_KERNEL_LARGE (__PAGE_KERNEL | _PAGE_PSE)
18298@@ -219,8 +222,8 @@
18299 * bits are combined, this will alow user to access the high address mapped
18300 * VDSO in the presence of CONFIG_COMPAT_VDSO
18301 */
18302-#define PTE_IDENT_ATTR 0x003 /* PRESENT+RW */
18303-#define PDE_IDENT_ATTR 0x067 /* PRESENT+RW+USER+DIRTY+ACCESSED */
18304+#define PTE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
18305+#define PDE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
18306 #define PGD_IDENT_ATTR 0x001 /* PRESENT (no other attributes) */
18307 #endif
18308
18309@@ -258,7 +261,17 @@ static inline pgdval_t pgd_flags(pgd_t pgd)
18310 {
18311 return native_pgd_val(pgd) & PTE_FLAGS_MASK;
18312 }
18313+#endif
18314
18315+#if PAGETABLE_LEVELS == 3
18316+#include <asm-generic/pgtable-nopud.h>
18317+#endif
18318+
18319+#if PAGETABLE_LEVELS == 2
18320+#include <asm-generic/pgtable-nopmd.h>
18321+#endif
18322+
18323+#ifndef __ASSEMBLY__
18324 #if PAGETABLE_LEVELS > 3
18325 typedef struct { pudval_t pud; } pud_t;
18326
18327@@ -272,8 +285,6 @@ static inline pudval_t native_pud_val(pud_t pud)
18328 return pud.pud;
18329 }
18330 #else
18331-#include <asm-generic/pgtable-nopud.h>
18332-
18333 static inline pudval_t native_pud_val(pud_t pud)
18334 {
18335 return native_pgd_val(pud.pgd);
18336@@ -293,8 +304,6 @@ static inline pmdval_t native_pmd_val(pmd_t pmd)
18337 return pmd.pmd;
18338 }
18339 #else
18340-#include <asm-generic/pgtable-nopmd.h>
18341-
18342 static inline pmdval_t native_pmd_val(pmd_t pmd)
18343 {
18344 return native_pgd_val(pmd.pud.pgd);
18345@@ -334,7 +343,6 @@ typedef struct page *pgtable_t;
18346
18347 extern pteval_t __supported_pte_mask;
18348 extern void set_nx(void);
18349-extern int nx_enabled;
18350
18351 #define pgprot_writecombine pgprot_writecombine
18352 extern pgprot_t pgprot_writecombine(pgprot_t prot);
18353diff --git a/arch/x86/include/asm/preempt.h b/arch/x86/include/asm/preempt.h
18354index c8b0519..fd29e73 100644
18355--- a/arch/x86/include/asm/preempt.h
18356+++ b/arch/x86/include/asm/preempt.h
18357@@ -87,7 +87,7 @@ static __always_inline void __preempt_count_sub(int val)
18358 */
18359 static __always_inline bool __preempt_count_dec_and_test(void)
18360 {
18361- GEN_UNARY_RMWcc("decl", __preempt_count, __percpu_arg(0), "e");
18362+ GEN_UNARY_RMWcc("decl", "incl", __preempt_count, __percpu_arg(0), "e");
18363 }
18364
18365 /*
18366diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
18367index fdedd38..95c02c2 100644
18368--- a/arch/x86/include/asm/processor.h
18369+++ b/arch/x86/include/asm/processor.h
18370@@ -128,7 +128,7 @@ struct cpuinfo_x86 {
18371 /* Index into per_cpu list: */
18372 u16 cpu_index;
18373 u32 microcode;
18374-} __attribute__((__aligned__(SMP_CACHE_BYTES)));
18375+} __attribute__((__aligned__(SMP_CACHE_BYTES))) __randomize_layout;
18376
18377 #define X86_VENDOR_INTEL 0
18378 #define X86_VENDOR_CYRIX 1
18379@@ -199,9 +199,21 @@ static inline void native_cpuid(unsigned int *eax, unsigned int *ebx,
18380 : "memory");
18381 }
18382
18383+/* invpcid (%rdx),%rax */
18384+#define __ASM_INVPCID ".byte 0x66,0x0f,0x38,0x82,0x02"
18385+
18386+#define INVPCID_SINGLE_ADDRESS 0UL
18387+#define INVPCID_SINGLE_CONTEXT 1UL
18388+#define INVPCID_ALL_GLOBAL 2UL
18389+#define INVPCID_ALL_MONGLOBAL 3UL
18390+
18391+#define PCID_KERNEL 0UL
18392+#define PCID_USER 1UL
18393+#define PCID_NOFLUSH (1UL << 63)
18394+
18395 static inline void load_cr3(pgd_t *pgdir)
18396 {
18397- write_cr3(__pa(pgdir));
18398+ write_cr3(__pa(pgdir) | PCID_KERNEL);
18399 }
18400
18401 #ifdef CONFIG_X86_32
18402@@ -283,7 +295,7 @@ struct tss_struct {
18403
18404 } ____cacheline_aligned;
18405
18406-DECLARE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss);
18407+extern struct tss_struct init_tss[NR_CPUS];
18408
18409 /*
18410 * Save the original ist values for checking stack pointers during debugging
18411@@ -470,6 +482,7 @@ struct thread_struct {
18412 unsigned short ds;
18413 unsigned short fsindex;
18414 unsigned short gsindex;
18415+ unsigned short ss;
18416 #endif
18417 #ifdef CONFIG_X86_32
18418 unsigned long ip;
18419@@ -579,29 +592,8 @@ static inline void load_sp0(struct tss_struct *tss,
18420 extern unsigned long mmu_cr4_features;
18421 extern u32 *trampoline_cr4_features;
18422
18423-static inline void set_in_cr4(unsigned long mask)
18424-{
18425- unsigned long cr4;
18426-
18427- mmu_cr4_features |= mask;
18428- if (trampoline_cr4_features)
18429- *trampoline_cr4_features = mmu_cr4_features;
18430- cr4 = read_cr4();
18431- cr4 |= mask;
18432- write_cr4(cr4);
18433-}
18434-
18435-static inline void clear_in_cr4(unsigned long mask)
18436-{
18437- unsigned long cr4;
18438-
18439- mmu_cr4_features &= ~mask;
18440- if (trampoline_cr4_features)
18441- *trampoline_cr4_features = mmu_cr4_features;
18442- cr4 = read_cr4();
18443- cr4 &= ~mask;
18444- write_cr4(cr4);
18445-}
18446+extern void set_in_cr4(unsigned long mask);
18447+extern void clear_in_cr4(unsigned long mask);
18448
18449 typedef struct {
18450 unsigned long seg;
18451@@ -827,11 +819,18 @@ static inline void spin_lock_prefetch(const void *x)
18452 */
18453 #define TASK_SIZE PAGE_OFFSET
18454 #define TASK_SIZE_MAX TASK_SIZE
18455+
18456+#ifdef CONFIG_PAX_SEGMEXEC
18457+#define SEGMEXEC_TASK_SIZE (TASK_SIZE / 2)
18458+#define STACK_TOP ((current->mm->pax_flags & MF_PAX_SEGMEXEC)?SEGMEXEC_TASK_SIZE:TASK_SIZE)
18459+#else
18460 #define STACK_TOP TASK_SIZE
18461-#define STACK_TOP_MAX STACK_TOP
18462+#endif
18463+
18464+#define STACK_TOP_MAX TASK_SIZE
18465
18466 #define INIT_THREAD { \
18467- .sp0 = sizeof(init_stack) + (long)&init_stack, \
18468+ .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
18469 .vm86_info = NULL, \
18470 .sysenter_cs = __KERNEL_CS, \
18471 .io_bitmap_ptr = NULL, \
18472@@ -845,7 +844,7 @@ static inline void spin_lock_prefetch(const void *x)
18473 */
18474 #define INIT_TSS { \
18475 .x86_tss = { \
18476- .sp0 = sizeof(init_stack) + (long)&init_stack, \
18477+ .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
18478 .ss0 = __KERNEL_DS, \
18479 .ss1 = __KERNEL_CS, \
18480 .io_bitmap_base = INVALID_IO_BITMAP_OFFSET, \
18481@@ -856,11 +855,7 @@ static inline void spin_lock_prefetch(const void *x)
18482 extern unsigned long thread_saved_pc(struct task_struct *tsk);
18483
18484 #define THREAD_SIZE_LONGS (THREAD_SIZE/sizeof(unsigned long))
18485-#define KSTK_TOP(info) \
18486-({ \
18487- unsigned long *__ptr = (unsigned long *)(info); \
18488- (unsigned long)(&__ptr[THREAD_SIZE_LONGS]); \
18489-})
18490+#define KSTK_TOP(info) ((container_of(info, struct task_struct, tinfo))->thread.sp0)
18491
18492 /*
18493 * The below -8 is to reserve 8 bytes on top of the ring0 stack.
18494@@ -875,7 +870,7 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
18495 #define task_pt_regs(task) \
18496 ({ \
18497 struct pt_regs *__regs__; \
18498- __regs__ = (struct pt_regs *)(KSTK_TOP(task_stack_page(task))-8); \
18499+ __regs__ = (struct pt_regs *)((task)->thread.sp0); \
18500 __regs__ - 1; \
18501 })
18502
18503@@ -885,13 +880,13 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
18504 /*
18505 * User space process size. 47bits minus one guard page.
18506 */
18507-#define TASK_SIZE_MAX ((1UL << 47) - PAGE_SIZE)
18508+#define TASK_SIZE_MAX ((1UL << TASK_SIZE_MAX_SHIFT) - PAGE_SIZE)
18509
18510 /* This decides where the kernel will search for a free chunk of vm
18511 * space during mmap's.
18512 */
18513 #define IA32_PAGE_OFFSET ((current->personality & ADDR_LIMIT_3GB) ? \
18514- 0xc0000000 : 0xFFFFe000)
18515+ 0xc0000000 : 0xFFFFf000)
18516
18517 #define TASK_SIZE (test_thread_flag(TIF_ADDR32) ? \
18518 IA32_PAGE_OFFSET : TASK_SIZE_MAX)
18519@@ -902,11 +897,11 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
18520 #define STACK_TOP_MAX TASK_SIZE_MAX
18521
18522 #define INIT_THREAD { \
18523- .sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
18524+ .sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
18525 }
18526
18527 #define INIT_TSS { \
18528- .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
18529+ .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
18530 }
18531
18532 /*
18533@@ -934,6 +929,10 @@ extern void start_thread(struct pt_regs *regs, unsigned long new_ip,
18534 */
18535 #define TASK_UNMAPPED_BASE (PAGE_ALIGN(TASK_SIZE / 3))
18536
18537+#ifdef CONFIG_PAX_SEGMEXEC
18538+#define SEGMEXEC_TASK_UNMAPPED_BASE (PAGE_ALIGN(SEGMEXEC_TASK_SIZE / 3))
18539+#endif
18540+
18541 #define KSTK_EIP(task) (task_pt_regs(task)->ip)
18542
18543 /* Get/set a process' ability to use the timestamp counter instruction */
18544@@ -960,7 +959,7 @@ static inline uint32_t hypervisor_cpuid_base(const char *sig, uint32_t leaves)
18545 return 0;
18546 }
18547
18548-extern unsigned long arch_align_stack(unsigned long sp);
18549+#define arch_align_stack(x) ((x) & ~0xfUL)
18550 extern void free_init_pages(char *what, unsigned long begin, unsigned long end);
18551
18552 void default_idle(void);
18553@@ -970,6 +969,6 @@ bool xen_set_default_idle(void);
18554 #define xen_set_default_idle 0
18555 #endif
18556
18557-void stop_this_cpu(void *dummy);
18558+void stop_this_cpu(void *dummy) __noreturn;
18559 void df_debug(struct pt_regs *regs, long error_code);
18560 #endif /* _ASM_X86_PROCESSOR_H */
18561diff --git a/arch/x86/include/asm/ptrace.h b/arch/x86/include/asm/ptrace.h
18562index 14fd6fd..6740420 100644
18563--- a/arch/x86/include/asm/ptrace.h
18564+++ b/arch/x86/include/asm/ptrace.h
18565@@ -84,28 +84,29 @@ static inline unsigned long regs_return_value(struct pt_regs *regs)
18566 }
18567
18568 /*
18569- * user_mode_vm(regs) determines whether a register set came from user mode.
18570+ * user_mode(regs) determines whether a register set came from user mode.
18571 * This is true if V8086 mode was enabled OR if the register set was from
18572 * protected mode with RPL-3 CS value. This tricky test checks that with
18573 * one comparison. Many places in the kernel can bypass this full check
18574- * if they have already ruled out V8086 mode, so user_mode(regs) can be used.
18575+ * if they have already ruled out V8086 mode, so user_mode_novm(regs) can
18576+ * be used.
18577 */
18578-static inline int user_mode(struct pt_regs *regs)
18579+static inline int user_mode_novm(struct pt_regs *regs)
18580 {
18581 #ifdef CONFIG_X86_32
18582 return (regs->cs & SEGMENT_RPL_MASK) == USER_RPL;
18583 #else
18584- return !!(regs->cs & 3);
18585+ return !!(regs->cs & SEGMENT_RPL_MASK);
18586 #endif
18587 }
18588
18589-static inline int user_mode_vm(struct pt_regs *regs)
18590+static inline int user_mode(struct pt_regs *regs)
18591 {
18592 #ifdef CONFIG_X86_32
18593 return ((regs->cs & SEGMENT_RPL_MASK) | (regs->flags & X86_VM_MASK)) >=
18594 USER_RPL;
18595 #else
18596- return user_mode(regs);
18597+ return user_mode_novm(regs);
18598 #endif
18599 }
18600
18601@@ -121,15 +122,16 @@ static inline int v8086_mode(struct pt_regs *regs)
18602 #ifdef CONFIG_X86_64
18603 static inline bool user_64bit_mode(struct pt_regs *regs)
18604 {
18605+ unsigned long cs = regs->cs & 0xffff;
18606 #ifndef CONFIG_PARAVIRT
18607 /*
18608 * On non-paravirt systems, this is the only long mode CPL 3
18609 * selector. We do not allow long mode selectors in the LDT.
18610 */
18611- return regs->cs == __USER_CS;
18612+ return cs == __USER_CS;
18613 #else
18614 /* Headers are too twisted for this to go in paravirt.h. */
18615- return regs->cs == __USER_CS || regs->cs == pv_info.extra_user_64bit_cs;
18616+ return cs == __USER_CS || cs == pv_info.extra_user_64bit_cs;
18617 #endif
18618 }
18619
18620@@ -180,9 +182,11 @@ static inline unsigned long regs_get_register(struct pt_regs *regs,
18621 * Traps from the kernel do not save sp and ss.
18622 * Use the helper function to retrieve sp.
18623 */
18624- if (offset == offsetof(struct pt_regs, sp) &&
18625- regs->cs == __KERNEL_CS)
18626- return kernel_stack_pointer(regs);
18627+ if (offset == offsetof(struct pt_regs, sp)) {
18628+ unsigned long cs = regs->cs & 0xffff;
18629+ if (cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS)
18630+ return kernel_stack_pointer(regs);
18631+ }
18632 #endif
18633 return *(unsigned long *)((unsigned long)regs + offset);
18634 }
18635diff --git a/arch/x86/include/asm/realmode.h b/arch/x86/include/asm/realmode.h
18636index 9c6b890..5305f53 100644
18637--- a/arch/x86/include/asm/realmode.h
18638+++ b/arch/x86/include/asm/realmode.h
18639@@ -22,16 +22,14 @@ struct real_mode_header {
18640 #endif
18641 /* APM/BIOS reboot */
18642 u32 machine_real_restart_asm;
18643-#ifdef CONFIG_X86_64
18644 u32 machine_real_restart_seg;
18645-#endif
18646 };
18647
18648 /* This must match data at trampoline_32/64.S */
18649 struct trampoline_header {
18650 #ifdef CONFIG_X86_32
18651 u32 start;
18652- u16 gdt_pad;
18653+ u16 boot_cs;
18654 u16 gdt_limit;
18655 u32 gdt_base;
18656 #else
18657diff --git a/arch/x86/include/asm/reboot.h b/arch/x86/include/asm/reboot.h
18658index a82c4f1..ac45053 100644
18659--- a/arch/x86/include/asm/reboot.h
18660+++ b/arch/x86/include/asm/reboot.h
18661@@ -6,13 +6,13 @@
18662 struct pt_regs;
18663
18664 struct machine_ops {
18665- void (*restart)(char *cmd);
18666- void (*halt)(void);
18667- void (*power_off)(void);
18668+ void (* __noreturn restart)(char *cmd);
18669+ void (* __noreturn halt)(void);
18670+ void (* __noreturn power_off)(void);
18671 void (*shutdown)(void);
18672 void (*crash_shutdown)(struct pt_regs *);
18673- void (*emergency_restart)(void);
18674-};
18675+ void (* __noreturn emergency_restart)(void);
18676+} __no_const;
18677
18678 extern struct machine_ops machine_ops;
18679
18680diff --git a/arch/x86/include/asm/rmwcc.h b/arch/x86/include/asm/rmwcc.h
18681index 8f7866a..e442f20 100644
18682--- a/arch/x86/include/asm/rmwcc.h
18683+++ b/arch/x86/include/asm/rmwcc.h
18684@@ -3,7 +3,34 @@
18685
18686 #ifdef CC_HAVE_ASM_GOTO
18687
18688-#define __GEN_RMWcc(fullop, var, cc, ...) \
18689+#ifdef CONFIG_PAX_REFCOUNT
18690+#define __GEN_RMWcc(fullop, fullantiop, var, cc, ...) \
18691+do { \
18692+ asm_volatile_goto (fullop \
18693+ ";jno 0f\n" \
18694+ fullantiop \
18695+ ";int $4\n0:\n" \
18696+ _ASM_EXTABLE(0b, 0b) \
18697+ ";j" cc " %l[cc_label]" \
18698+ : : "m" (var), ## __VA_ARGS__ \
18699+ : "memory" : cc_label); \
18700+ return 0; \
18701+cc_label: \
18702+ return 1; \
18703+} while (0)
18704+#else
18705+#define __GEN_RMWcc(fullop, fullantiop, var, cc, ...) \
18706+do { \
18707+ asm_volatile_goto (fullop ";j" cc " %l[cc_label]" \
18708+ : : "m" (var), ## __VA_ARGS__ \
18709+ : "memory" : cc_label); \
18710+ return 0; \
18711+cc_label: \
18712+ return 1; \
18713+} while (0)
18714+#endif
18715+
18716+#define __GEN_RMWcc_unchecked(fullop, var, cc, ...) \
18717 do { \
18718 asm_volatile_goto (fullop "; j" cc " %l[cc_label]" \
18719 : : "m" (var), ## __VA_ARGS__ \
18720@@ -13,15 +40,46 @@ cc_label: \
18721 return 1; \
18722 } while (0)
18723
18724-#define GEN_UNARY_RMWcc(op, var, arg0, cc) \
18725- __GEN_RMWcc(op " " arg0, var, cc)
18726+#define GEN_UNARY_RMWcc(op, antiop, var, arg0, cc) \
18727+ __GEN_RMWcc(op " " arg0, antiop " " arg0, var, cc)
18728
18729-#define GEN_BINARY_RMWcc(op, var, vcon, val, arg0, cc) \
18730- __GEN_RMWcc(op " %1, " arg0, var, cc, vcon (val))
18731+#define GEN_UNARY_RMWcc_unchecked(op, var, arg0, cc) \
18732+ __GEN_RMWcc_unchecked(op " " arg0, var, cc)
18733+
18734+#define GEN_BINARY_RMWcc(op, antiop, var, vcon, val, arg0, cc) \
18735+ __GEN_RMWcc(op " %1, " arg0, antiop " %1, " arg0, var, cc, vcon (val))
18736+
18737+#define GEN_BINARY_RMWcc_unchecked(op, var, vcon, val, arg0, cc) \
18738+ __GEN_RMWcc_unchecked(op " %1, " arg0, var, cc, vcon (val))
18739
18740 #else /* !CC_HAVE_ASM_GOTO */
18741
18742-#define __GEN_RMWcc(fullop, var, cc, ...) \
18743+#ifdef CONFIG_PAX_REFCOUNT
18744+#define __GEN_RMWcc(fullop, fullantiop, var, cc, ...) \
18745+do { \
18746+ char c; \
18747+ asm volatile (fullop \
18748+ ";jno 0f\n" \
18749+ fullantiop \
18750+ ";int $4\n0:\n" \
18751+ _ASM_EXTABLE(0b, 0b) \
18752+ "; set" cc " %1" \
18753+ : "+m" (var), "=qm" (c) \
18754+ : __VA_ARGS__ : "memory"); \
18755+ return c != 0; \
18756+} while (0)
18757+#else
18758+#define __GEN_RMWcc(fullop, fullantiop, var, cc, ...) \
18759+do { \
18760+ char c; \
18761+ asm volatile (fullop "; set" cc " %1" \
18762+ : "+m" (var), "=qm" (c) \
18763+ : __VA_ARGS__ : "memory"); \
18764+ return c != 0; \
18765+} while (0)
18766+#endif
18767+
18768+#define __GEN_RMWcc_unchecked(fullop, var, cc, ...) \
18769 do { \
18770 char c; \
18771 asm volatile (fullop "; set" cc " %1" \
18772@@ -30,11 +88,17 @@ do { \
18773 return c != 0; \
18774 } while (0)
18775
18776-#define GEN_UNARY_RMWcc(op, var, arg0, cc) \
18777- __GEN_RMWcc(op " " arg0, var, cc)
18778+#define GEN_UNARY_RMWcc(op, antiop, var, arg0, cc) \
18779+ __GEN_RMWcc(op " " arg0, antiop " " arg0, var, cc)
18780+
18781+#define GEN_UNARY_RMWcc_unchecked(op, var, arg0, cc) \
18782+ __GEN_RMWcc_unchecked(op " " arg0, var, cc)
18783+
18784+#define GEN_BINARY_RMWcc(op, antiop, var, vcon, val, arg0, cc) \
18785+ __GEN_RMWcc(op " %2, " arg0, antiop " %2, " arg0, var, cc, vcon (val))
18786
18787-#define GEN_BINARY_RMWcc(op, var, vcon, val, arg0, cc) \
18788- __GEN_RMWcc(op " %2, " arg0, var, cc, vcon (val))
18789+#define GEN_BINARY_RMWcc_unchecked(op, var, vcon, val, arg0, cc) \
18790+ __GEN_RMWcc_unchecked(op " %2, " arg0, var, cc, vcon (val))
18791
18792 #endif /* CC_HAVE_ASM_GOTO */
18793
18794diff --git a/arch/x86/include/asm/rwsem.h b/arch/x86/include/asm/rwsem.h
18795index cad82c9..2e5c5c1 100644
18796--- a/arch/x86/include/asm/rwsem.h
18797+++ b/arch/x86/include/asm/rwsem.h
18798@@ -64,6 +64,14 @@ static inline void __down_read(struct rw_semaphore *sem)
18799 {
18800 asm volatile("# beginning down_read\n\t"
18801 LOCK_PREFIX _ASM_INC "(%1)\n\t"
18802+
18803+#ifdef CONFIG_PAX_REFCOUNT
18804+ "jno 0f\n"
18805+ LOCK_PREFIX _ASM_DEC "(%1)\n"
18806+ "int $4\n0:\n"
18807+ _ASM_EXTABLE(0b, 0b)
18808+#endif
18809+
18810 /* adds 0x00000001 */
18811 " jns 1f\n"
18812 " call call_rwsem_down_read_failed\n"
18813@@ -85,6 +93,14 @@ static inline int __down_read_trylock(struct rw_semaphore *sem)
18814 "1:\n\t"
18815 " mov %1,%2\n\t"
18816 " add %3,%2\n\t"
18817+
18818+#ifdef CONFIG_PAX_REFCOUNT
18819+ "jno 0f\n"
18820+ "sub %3,%2\n"
18821+ "int $4\n0:\n"
18822+ _ASM_EXTABLE(0b, 0b)
18823+#endif
18824+
18825 " jle 2f\n\t"
18826 LOCK_PREFIX " cmpxchg %2,%0\n\t"
18827 " jnz 1b\n\t"
18828@@ -104,6 +120,14 @@ static inline void __down_write_nested(struct rw_semaphore *sem, int subclass)
18829 long tmp;
18830 asm volatile("# beginning down_write\n\t"
18831 LOCK_PREFIX " xadd %1,(%2)\n\t"
18832+
18833+#ifdef CONFIG_PAX_REFCOUNT
18834+ "jno 0f\n"
18835+ "mov %1,(%2)\n"
18836+ "int $4\n0:\n"
18837+ _ASM_EXTABLE(0b, 0b)
18838+#endif
18839+
18840 /* adds 0xffff0001, returns the old value */
18841 " test " __ASM_SEL(%w1,%k1) "," __ASM_SEL(%w1,%k1) "\n\t"
18842 /* was the active mask 0 before? */
18843@@ -155,6 +179,14 @@ static inline void __up_read(struct rw_semaphore *sem)
18844 long tmp;
18845 asm volatile("# beginning __up_read\n\t"
18846 LOCK_PREFIX " xadd %1,(%2)\n\t"
18847+
18848+#ifdef CONFIG_PAX_REFCOUNT
18849+ "jno 0f\n"
18850+ "mov %1,(%2)\n"
18851+ "int $4\n0:\n"
18852+ _ASM_EXTABLE(0b, 0b)
18853+#endif
18854+
18855 /* subtracts 1, returns the old value */
18856 " jns 1f\n\t"
18857 " call call_rwsem_wake\n" /* expects old value in %edx */
18858@@ -173,6 +205,14 @@ static inline void __up_write(struct rw_semaphore *sem)
18859 long tmp;
18860 asm volatile("# beginning __up_write\n\t"
18861 LOCK_PREFIX " xadd %1,(%2)\n\t"
18862+
18863+#ifdef CONFIG_PAX_REFCOUNT
18864+ "jno 0f\n"
18865+ "mov %1,(%2)\n"
18866+ "int $4\n0:\n"
18867+ _ASM_EXTABLE(0b, 0b)
18868+#endif
18869+
18870 /* subtracts 0xffff0001, returns the old value */
18871 " jns 1f\n\t"
18872 " call call_rwsem_wake\n" /* expects old value in %edx */
18873@@ -190,6 +230,14 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
18874 {
18875 asm volatile("# beginning __downgrade_write\n\t"
18876 LOCK_PREFIX _ASM_ADD "%2,(%1)\n\t"
18877+
18878+#ifdef CONFIG_PAX_REFCOUNT
18879+ "jno 0f\n"
18880+ LOCK_PREFIX _ASM_SUB "%2,(%1)\n"
18881+ "int $4\n0:\n"
18882+ _ASM_EXTABLE(0b, 0b)
18883+#endif
18884+
18885 /*
18886 * transitions 0xZZZZ0001 -> 0xYYYY0001 (i386)
18887 * 0xZZZZZZZZ00000001 -> 0xYYYYYYYY00000001 (x86_64)
18888@@ -208,7 +256,15 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
18889 */
18890 static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
18891 {
18892- asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0"
18893+ asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0\n"
18894+
18895+#ifdef CONFIG_PAX_REFCOUNT
18896+ "jno 0f\n"
18897+ LOCK_PREFIX _ASM_SUB "%1,%0\n"
18898+ "int $4\n0:\n"
18899+ _ASM_EXTABLE(0b, 0b)
18900+#endif
18901+
18902 : "+m" (sem->count)
18903 : "er" (delta));
18904 }
18905@@ -218,7 +274,7 @@ static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
18906 */
18907 static inline long rwsem_atomic_update(long delta, struct rw_semaphore *sem)
18908 {
18909- return delta + xadd(&sem->count, delta);
18910+ return delta + xadd_check_overflow(&sem->count, delta);
18911 }
18912
18913 #endif /* __KERNEL__ */
18914diff --git a/arch/x86/include/asm/segment.h b/arch/x86/include/asm/segment.h
18915index 6f1c3a8..7744f19 100644
18916--- a/arch/x86/include/asm/segment.h
18917+++ b/arch/x86/include/asm/segment.h
18918@@ -64,10 +64,15 @@
18919 * 26 - ESPFIX small SS
18920 * 27 - per-cpu [ offset to per-cpu data area ]
18921 * 28 - stack_canary-20 [ for stack protector ]
18922- * 29 - unused
18923- * 30 - unused
18924+ * 29 - PCI BIOS CS
18925+ * 30 - PCI BIOS DS
18926 * 31 - TSS for double fault handler
18927 */
18928+#define GDT_ENTRY_KERNEXEC_EFI_CS (1)
18929+#define GDT_ENTRY_KERNEXEC_EFI_DS (2)
18930+#define __KERNEXEC_EFI_CS (GDT_ENTRY_KERNEXEC_EFI_CS*8)
18931+#define __KERNEXEC_EFI_DS (GDT_ENTRY_KERNEXEC_EFI_DS*8)
18932+
18933 #define GDT_ENTRY_TLS_MIN 6
18934 #define GDT_ENTRY_TLS_MAX (GDT_ENTRY_TLS_MIN + GDT_ENTRY_TLS_ENTRIES - 1)
18935
18936@@ -79,6 +84,8 @@
18937
18938 #define GDT_ENTRY_KERNEL_CS (GDT_ENTRY_KERNEL_BASE+0)
18939
18940+#define GDT_ENTRY_KERNEXEC_KERNEL_CS (4)
18941+
18942 #define GDT_ENTRY_KERNEL_DS (GDT_ENTRY_KERNEL_BASE+1)
18943
18944 #define GDT_ENTRY_TSS (GDT_ENTRY_KERNEL_BASE+4)
18945@@ -104,6 +111,12 @@
18946 #define __KERNEL_STACK_CANARY 0
18947 #endif
18948
18949+#define GDT_ENTRY_PCIBIOS_CS (GDT_ENTRY_KERNEL_BASE+17)
18950+#define __PCIBIOS_CS (GDT_ENTRY_PCIBIOS_CS * 8)
18951+
18952+#define GDT_ENTRY_PCIBIOS_DS (GDT_ENTRY_KERNEL_BASE+18)
18953+#define __PCIBIOS_DS (GDT_ENTRY_PCIBIOS_DS * 8)
18954+
18955 #define GDT_ENTRY_DOUBLEFAULT_TSS 31
18956
18957 /*
18958@@ -141,7 +154,7 @@
18959 */
18960
18961 /* Matches PNP_CS32 and PNP_CS16 (they must be consecutive) */
18962-#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xf4) == GDT_ENTRY_PNPBIOS_BASE * 8)
18963+#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xFFFCU) == PNP_CS32 || ((x) & 0xFFFCU) == PNP_CS16)
18964
18965
18966 #else
18967@@ -165,6 +178,8 @@
18968 #define __USER32_CS (GDT_ENTRY_DEFAULT_USER32_CS*8+3)
18969 #define __USER32_DS __USER_DS
18970
18971+#define GDT_ENTRY_KERNEXEC_KERNEL_CS 7
18972+
18973 #define GDT_ENTRY_TSS 8 /* needs two entries */
18974 #define GDT_ENTRY_LDT 10 /* needs two entries */
18975 #define GDT_ENTRY_TLS_MIN 12
18976@@ -173,6 +188,8 @@
18977 #define GDT_ENTRY_PER_CPU 15 /* Abused to load per CPU data from limit */
18978 #define __PER_CPU_SEG (GDT_ENTRY_PER_CPU * 8 + 3)
18979
18980+#define GDT_ENTRY_UDEREF_KERNEL_DS 16
18981+
18982 /* TLS indexes for 64bit - hardcoded in arch_prctl */
18983 #define FS_TLS 0
18984 #define GS_TLS 1
18985@@ -180,12 +197,14 @@
18986 #define GS_TLS_SEL ((GDT_ENTRY_TLS_MIN+GS_TLS)*8 + 3)
18987 #define FS_TLS_SEL ((GDT_ENTRY_TLS_MIN+FS_TLS)*8 + 3)
18988
18989-#define GDT_ENTRIES 16
18990+#define GDT_ENTRIES 17
18991
18992 #endif
18993
18994 #define __KERNEL_CS (GDT_ENTRY_KERNEL_CS*8)
18995+#define __KERNEXEC_KERNEL_CS (GDT_ENTRY_KERNEXEC_KERNEL_CS*8)
18996 #define __KERNEL_DS (GDT_ENTRY_KERNEL_DS*8)
18997+#define __UDEREF_KERNEL_DS (GDT_ENTRY_UDEREF_KERNEL_DS*8)
18998 #define __USER_DS (GDT_ENTRY_DEFAULT_USER_DS*8+3)
18999 #define __USER_CS (GDT_ENTRY_DEFAULT_USER_CS*8+3)
19000 #ifndef CONFIG_PARAVIRT
19001@@ -268,7 +287,7 @@ static inline unsigned long get_limit(unsigned long segment)
19002 {
19003 unsigned long __limit;
19004 asm("lsll %1,%0" : "=r" (__limit) : "r" (segment));
19005- return __limit + 1;
19006+ return __limit;
19007 }
19008
19009 #endif /* !__ASSEMBLY__ */
19010diff --git a/arch/x86/include/asm/smap.h b/arch/x86/include/asm/smap.h
19011index 8d3120f..352b440 100644
19012--- a/arch/x86/include/asm/smap.h
19013+++ b/arch/x86/include/asm/smap.h
19014@@ -25,11 +25,40 @@
19015
19016 #include <asm/alternative-asm.h>
19017
19018+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19019+#define ASM_PAX_OPEN_USERLAND \
19020+ 661: jmp 663f; \
19021+ .pushsection .altinstr_replacement, "a" ; \
19022+ 662: pushq %rax; nop; \
19023+ .popsection ; \
19024+ .pushsection .altinstructions, "a" ; \
19025+ altinstruction_entry 661b, 662b, X86_FEATURE_STRONGUDEREF, 2, 2;\
19026+ .popsection ; \
19027+ call __pax_open_userland; \
19028+ popq %rax; \
19029+ 663:
19030+
19031+#define ASM_PAX_CLOSE_USERLAND \
19032+ 661: jmp 663f; \
19033+ .pushsection .altinstr_replacement, "a" ; \
19034+ 662: pushq %rax; nop; \
19035+ .popsection; \
19036+ .pushsection .altinstructions, "a" ; \
19037+ altinstruction_entry 661b, 662b, X86_FEATURE_STRONGUDEREF, 2, 2;\
19038+ .popsection; \
19039+ call __pax_close_userland; \
19040+ popq %rax; \
19041+ 663:
19042+#else
19043+#define ASM_PAX_OPEN_USERLAND
19044+#define ASM_PAX_CLOSE_USERLAND
19045+#endif
19046+
19047 #ifdef CONFIG_X86_SMAP
19048
19049 #define ASM_CLAC \
19050 661: ASM_NOP3 ; \
19051- .pushsection .altinstr_replacement, "ax" ; \
19052+ .pushsection .altinstr_replacement, "a" ; \
19053 662: __ASM_CLAC ; \
19054 .popsection ; \
19055 .pushsection .altinstructions, "a" ; \
19056@@ -38,7 +67,7 @@
19057
19058 #define ASM_STAC \
19059 661: ASM_NOP3 ; \
19060- .pushsection .altinstr_replacement, "ax" ; \
19061+ .pushsection .altinstr_replacement, "a" ; \
19062 662: __ASM_STAC ; \
19063 .popsection ; \
19064 .pushsection .altinstructions, "a" ; \
19065@@ -56,6 +85,37 @@
19066
19067 #include <asm/alternative.h>
19068
19069+#define __HAVE_ARCH_PAX_OPEN_USERLAND
19070+#define __HAVE_ARCH_PAX_CLOSE_USERLAND
19071+
19072+extern void __pax_open_userland(void);
19073+static __always_inline unsigned long pax_open_userland(void)
19074+{
19075+
19076+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19077+ asm volatile(ALTERNATIVE(ASM_NOP5, "call %P[open]", X86_FEATURE_STRONGUDEREF)
19078+ :
19079+ : [open] "i" (__pax_open_userland)
19080+ : "memory", "rax");
19081+#endif
19082+
19083+ return 0;
19084+}
19085+
19086+extern void __pax_close_userland(void);
19087+static __always_inline unsigned long pax_close_userland(void)
19088+{
19089+
19090+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19091+ asm volatile(ALTERNATIVE(ASM_NOP5, "call %P[close]", X86_FEATURE_STRONGUDEREF)
19092+ :
19093+ : [close] "i" (__pax_close_userland)
19094+ : "memory", "rax");
19095+#endif
19096+
19097+ return 0;
19098+}
19099+
19100 #ifdef CONFIG_X86_SMAP
19101
19102 static __always_inline void clac(void)
19103diff --git a/arch/x86/include/asm/smp.h b/arch/x86/include/asm/smp.h
19104index 8cd27e0..7f05ec8 100644
19105--- a/arch/x86/include/asm/smp.h
19106+++ b/arch/x86/include/asm/smp.h
19107@@ -35,7 +35,7 @@ DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_core_map);
19108 /* cpus sharing the last level cache: */
19109 DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_llc_shared_map);
19110 DECLARE_PER_CPU_READ_MOSTLY(u16, cpu_llc_id);
19111-DECLARE_PER_CPU_READ_MOSTLY(int, cpu_number);
19112+DECLARE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
19113
19114 static inline struct cpumask *cpu_sibling_mask(int cpu)
19115 {
19116@@ -78,7 +78,7 @@ struct smp_ops {
19117
19118 void (*send_call_func_ipi)(const struct cpumask *mask);
19119 void (*send_call_func_single_ipi)(int cpu);
19120-};
19121+} __no_const;
19122
19123 /* Globals due to paravirt */
19124 extern void set_cpu_sibling_map(int cpu);
19125@@ -190,14 +190,8 @@ extern unsigned disabled_cpus;
19126 extern int safe_smp_processor_id(void);
19127
19128 #elif defined(CONFIG_X86_64_SMP)
19129-#define raw_smp_processor_id() (this_cpu_read(cpu_number))
19130-
19131-#define stack_smp_processor_id() \
19132-({ \
19133- struct thread_info *ti; \
19134- __asm__("andq %%rsp,%0; ":"=r" (ti) : "0" (CURRENT_MASK)); \
19135- ti->cpu; \
19136-})
19137+#define raw_smp_processor_id() (this_cpu_read(cpu_number))
19138+#define stack_smp_processor_id() raw_smp_processor_id()
19139 #define safe_smp_processor_id() smp_processor_id()
19140
19141 #endif
19142diff --git a/arch/x86/include/asm/spinlock.h b/arch/x86/include/asm/spinlock.h
19143index 0f62f54..cb5d0dd 100644
19144--- a/arch/x86/include/asm/spinlock.h
19145+++ b/arch/x86/include/asm/spinlock.h
19146@@ -222,6 +222,14 @@ static inline int arch_write_can_lock(arch_rwlock_t *lock)
19147 static inline void arch_read_lock(arch_rwlock_t *rw)
19148 {
19149 asm volatile(LOCK_PREFIX READ_LOCK_SIZE(dec) " (%0)\n\t"
19150+
19151+#ifdef CONFIG_PAX_REFCOUNT
19152+ "jno 0f\n"
19153+ LOCK_PREFIX READ_LOCK_SIZE(inc) " (%0)\n"
19154+ "int $4\n0:\n"
19155+ _ASM_EXTABLE(0b, 0b)
19156+#endif
19157+
19158 "jns 1f\n"
19159 "call __read_lock_failed\n\t"
19160 "1:\n"
19161@@ -231,6 +239,14 @@ static inline void arch_read_lock(arch_rwlock_t *rw)
19162 static inline void arch_write_lock(arch_rwlock_t *rw)
19163 {
19164 asm volatile(LOCK_PREFIX WRITE_LOCK_SUB(%1) "(%0)\n\t"
19165+
19166+#ifdef CONFIG_PAX_REFCOUNT
19167+ "jno 0f\n"
19168+ LOCK_PREFIX WRITE_LOCK_ADD(%1) "(%0)\n"
19169+ "int $4\n0:\n"
19170+ _ASM_EXTABLE(0b, 0b)
19171+#endif
19172+
19173 "jz 1f\n"
19174 "call __write_lock_failed\n\t"
19175 "1:\n"
19176@@ -260,13 +276,29 @@ static inline int arch_write_trylock(arch_rwlock_t *lock)
19177
19178 static inline void arch_read_unlock(arch_rwlock_t *rw)
19179 {
19180- asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0"
19181+ asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0\n"
19182+
19183+#ifdef CONFIG_PAX_REFCOUNT
19184+ "jno 0f\n"
19185+ LOCK_PREFIX READ_LOCK_SIZE(dec) " %0\n"
19186+ "int $4\n0:\n"
19187+ _ASM_EXTABLE(0b, 0b)
19188+#endif
19189+
19190 :"+m" (rw->lock) : : "memory");
19191 }
19192
19193 static inline void arch_write_unlock(arch_rwlock_t *rw)
19194 {
19195- asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0"
19196+ asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0\n"
19197+
19198+#ifdef CONFIG_PAX_REFCOUNT
19199+ "jno 0f\n"
19200+ LOCK_PREFIX WRITE_LOCK_SUB(%1) "%0\n"
19201+ "int $4\n0:\n"
19202+ _ASM_EXTABLE(0b, 0b)
19203+#endif
19204+
19205 : "+m" (rw->write) : "i" (RW_LOCK_BIAS) : "memory");
19206 }
19207
19208diff --git a/arch/x86/include/asm/stackprotector.h b/arch/x86/include/asm/stackprotector.h
19209index 6a99859..03cb807 100644
19210--- a/arch/x86/include/asm/stackprotector.h
19211+++ b/arch/x86/include/asm/stackprotector.h
19212@@ -47,7 +47,7 @@
19213 * head_32 for boot CPU and setup_per_cpu_areas() for others.
19214 */
19215 #define GDT_STACK_CANARY_INIT \
19216- [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x18),
19217+ [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x17),
19218
19219 /*
19220 * Initialize the stackprotector canary value.
19221@@ -112,7 +112,7 @@ static inline void setup_stack_canary_segment(int cpu)
19222
19223 static inline void load_stack_canary_segment(void)
19224 {
19225-#ifdef CONFIG_X86_32
19226+#if defined(CONFIG_X86_32) && !defined(CONFIG_PAX_MEMORY_UDEREF)
19227 asm volatile ("mov %0, %%gs" : : "r" (0));
19228 #endif
19229 }
19230diff --git a/arch/x86/include/asm/stacktrace.h b/arch/x86/include/asm/stacktrace.h
19231index 70bbe39..4ae2bd4 100644
19232--- a/arch/x86/include/asm/stacktrace.h
19233+++ b/arch/x86/include/asm/stacktrace.h
19234@@ -11,28 +11,20 @@
19235
19236 extern int kstack_depth_to_print;
19237
19238-struct thread_info;
19239+struct task_struct;
19240 struct stacktrace_ops;
19241
19242-typedef unsigned long (*walk_stack_t)(struct thread_info *tinfo,
19243- unsigned long *stack,
19244- unsigned long bp,
19245- const struct stacktrace_ops *ops,
19246- void *data,
19247- unsigned long *end,
19248- int *graph);
19249+typedef unsigned long walk_stack_t(struct task_struct *task,
19250+ void *stack_start,
19251+ unsigned long *stack,
19252+ unsigned long bp,
19253+ const struct stacktrace_ops *ops,
19254+ void *data,
19255+ unsigned long *end,
19256+ int *graph);
19257
19258-extern unsigned long
19259-print_context_stack(struct thread_info *tinfo,
19260- unsigned long *stack, unsigned long bp,
19261- const struct stacktrace_ops *ops, void *data,
19262- unsigned long *end, int *graph);
19263-
19264-extern unsigned long
19265-print_context_stack_bp(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+extern walk_stack_t print_context_stack;
19270+extern walk_stack_t print_context_stack_bp;
19271
19272 /* Generic stack tracer with callbacks */
19273
19274@@ -40,7 +32,7 @@ struct stacktrace_ops {
19275 void (*address)(void *data, unsigned long address, int reliable);
19276 /* On negative return stop dumping */
19277 int (*stack)(void *data, char *name);
19278- walk_stack_t walk_stack;
19279+ walk_stack_t *walk_stack;
19280 };
19281
19282 void dump_trace(struct task_struct *tsk, struct pt_regs *regs,
19283diff --git a/arch/x86/include/asm/switch_to.h b/arch/x86/include/asm/switch_to.h
19284index d7f3b3b..3cc39f1 100644
19285--- a/arch/x86/include/asm/switch_to.h
19286+++ b/arch/x86/include/asm/switch_to.h
19287@@ -108,7 +108,7 @@ do { \
19288 "call __switch_to\n\t" \
19289 "movq "__percpu_arg([current_task])",%%rsi\n\t" \
19290 __switch_canary \
19291- "movq %P[thread_info](%%rsi),%%r8\n\t" \
19292+ "movq "__percpu_arg([thread_info])",%%r8\n\t" \
19293 "movq %%rax,%%rdi\n\t" \
19294 "testl %[_tif_fork],%P[ti_flags](%%r8)\n\t" \
19295 "jnz ret_from_fork\n\t" \
19296@@ -119,7 +119,7 @@ do { \
19297 [threadrsp] "i" (offsetof(struct task_struct, thread.sp)), \
19298 [ti_flags] "i" (offsetof(struct thread_info, flags)), \
19299 [_tif_fork] "i" (_TIF_FORK), \
19300- [thread_info] "i" (offsetof(struct task_struct, stack)), \
19301+ [thread_info] "m" (current_tinfo), \
19302 [current_task] "m" (current_task) \
19303 __switch_canary_iparam \
19304 : "memory", "cc" __EXTRA_CLOBBER)
19305diff --git a/arch/x86/include/asm/thread_info.h b/arch/x86/include/asm/thread_info.h
19306index e1940c0..ac50dd8 100644
19307--- a/arch/x86/include/asm/thread_info.h
19308+++ b/arch/x86/include/asm/thread_info.h
19309@@ -10,6 +10,7 @@
19310 #include <linux/compiler.h>
19311 #include <asm/page.h>
19312 #include <asm/types.h>
19313+#include <asm/percpu.h>
19314
19315 /*
19316 * low level task data that entry.S needs immediate access to
19317@@ -23,7 +24,6 @@ struct exec_domain;
19318 #include <linux/atomic.h>
19319
19320 struct thread_info {
19321- struct task_struct *task; /* main task structure */
19322 struct exec_domain *exec_domain; /* execution domain */
19323 __u32 flags; /* low level flags */
19324 __u32 status; /* thread synchronous flags */
19325@@ -32,19 +32,13 @@ struct thread_info {
19326 mm_segment_t addr_limit;
19327 struct restart_block restart_block;
19328 void __user *sysenter_return;
19329-#ifdef CONFIG_X86_32
19330- unsigned long previous_esp; /* ESP of the previous stack in
19331- case of nested (IRQ) stacks
19332- */
19333- __u8 supervisor_stack[0];
19334-#endif
19335+ unsigned long lowest_stack;
19336 unsigned int sig_on_uaccess_error:1;
19337 unsigned int uaccess_err:1; /* uaccess failed */
19338 };
19339
19340-#define INIT_THREAD_INFO(tsk) \
19341+#define INIT_THREAD_INFO \
19342 { \
19343- .task = &tsk, \
19344 .exec_domain = &default_exec_domain, \
19345 .flags = 0, \
19346 .cpu = 0, \
19347@@ -55,7 +49,7 @@ struct thread_info {
19348 }, \
19349 }
19350
19351-#define init_thread_info (init_thread_union.thread_info)
19352+#define init_thread_info (init_thread_union.stack)
19353 #define init_stack (init_thread_union.stack)
19354
19355 #else /* !__ASSEMBLY__ */
19356@@ -95,6 +89,7 @@ struct thread_info {
19357 #define TIF_SYSCALL_TRACEPOINT 28 /* syscall tracepoint instrumentation */
19358 #define TIF_ADDR32 29 /* 32-bit address space on 64 bits */
19359 #define TIF_X32 30 /* 32-bit native x86-64 binary */
19360+#define TIF_GRSEC_SETXID 31 /* update credentials on syscall entry/exit */
19361
19362 #define _TIF_SYSCALL_TRACE (1 << TIF_SYSCALL_TRACE)
19363 #define _TIF_NOTIFY_RESUME (1 << TIF_NOTIFY_RESUME)
19364@@ -118,17 +113,18 @@ struct thread_info {
19365 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
19366 #define _TIF_ADDR32 (1 << TIF_ADDR32)
19367 #define _TIF_X32 (1 << TIF_X32)
19368+#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
19369
19370 /* work to do in syscall_trace_enter() */
19371 #define _TIF_WORK_SYSCALL_ENTRY \
19372 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_EMU | _TIF_SYSCALL_AUDIT | \
19373 _TIF_SECCOMP | _TIF_SINGLESTEP | _TIF_SYSCALL_TRACEPOINT | \
19374- _TIF_NOHZ)
19375+ _TIF_NOHZ | _TIF_GRSEC_SETXID)
19376
19377 /* work to do in syscall_trace_leave() */
19378 #define _TIF_WORK_SYSCALL_EXIT \
19379 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_SINGLESTEP | \
19380- _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ)
19381+ _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ | _TIF_GRSEC_SETXID)
19382
19383 /* work to do on interrupt/exception return */
19384 #define _TIF_WORK_MASK \
19385@@ -139,7 +135,7 @@ struct thread_info {
19386 /* work to do on any return to user space */
19387 #define _TIF_ALLWORK_MASK \
19388 ((0x0000FFFF & ~_TIF_SECCOMP) | _TIF_SYSCALL_TRACEPOINT | \
19389- _TIF_NOHZ)
19390+ _TIF_NOHZ | _TIF_GRSEC_SETXID)
19391
19392 /* Only used for 64 bit */
19393 #define _TIF_DO_NOTIFY_MASK \
19394@@ -153,6 +149,23 @@ struct thread_info {
19395 #define _TIF_WORK_CTXSW_PREV (_TIF_WORK_CTXSW|_TIF_USER_RETURN_NOTIFY)
19396 #define _TIF_WORK_CTXSW_NEXT (_TIF_WORK_CTXSW)
19397
19398+#ifdef __ASSEMBLY__
19399+/* how to get the thread information struct from ASM */
19400+#define GET_THREAD_INFO(reg) \
19401+ mov PER_CPU_VAR(current_tinfo), reg
19402+
19403+/* use this one if reg already contains %esp */
19404+#define GET_THREAD_INFO_WITH_ESP(reg) GET_THREAD_INFO(reg)
19405+#else
19406+/* how to get the thread information struct from C */
19407+DECLARE_PER_CPU(struct thread_info *, current_tinfo);
19408+
19409+static __always_inline struct thread_info *current_thread_info(void)
19410+{
19411+ return this_cpu_read_stable(current_tinfo);
19412+}
19413+#endif
19414+
19415 #ifdef CONFIG_X86_32
19416
19417 #define STACK_WARN (THREAD_SIZE/8)
19418@@ -169,31 +182,10 @@ struct thread_info {
19419 sp; \
19420 })
19421
19422-/* how to get the thread information struct from C */
19423-static inline struct thread_info *current_thread_info(void)
19424-{
19425- return (struct thread_info *)
19426- (current_stack_pointer & ~(THREAD_SIZE - 1));
19427-}
19428-
19429-#else /* !__ASSEMBLY__ */
19430-
19431-/* how to get the thread information struct from ASM */
19432-#define GET_THREAD_INFO(reg) \
19433- movl $-THREAD_SIZE, reg; \
19434- andl %esp, reg
19435-
19436-/* use this one if reg already contains %esp */
19437-#define GET_THREAD_INFO_WITH_ESP(reg) \
19438- andl $-THREAD_SIZE, reg
19439-
19440 #endif
19441
19442 #else /* X86_32 */
19443
19444-#include <asm/percpu.h>
19445-#define KERNEL_STACK_OFFSET (5*8)
19446-
19447 /*
19448 * macros/functions for gaining access to the thread information structure
19449 * preempt_count needs to be 1 initially, until the scheduler is functional.
19450@@ -201,27 +193,8 @@ static inline struct thread_info *current_thread_info(void)
19451 #ifndef __ASSEMBLY__
19452 DECLARE_PER_CPU(unsigned long, kernel_stack);
19453
19454-static inline struct thread_info *current_thread_info(void)
19455-{
19456- struct thread_info *ti;
19457- ti = (void *)(this_cpu_read_stable(kernel_stack) +
19458- KERNEL_STACK_OFFSET - THREAD_SIZE);
19459- return ti;
19460-}
19461-
19462-#else /* !__ASSEMBLY__ */
19463-
19464-/* how to get the thread information struct from ASM */
19465-#define GET_THREAD_INFO(reg) \
19466- movq PER_CPU_VAR(kernel_stack),reg ; \
19467- subq $(THREAD_SIZE-KERNEL_STACK_OFFSET),reg
19468-
19469-/*
19470- * Same if PER_CPU_VAR(kernel_stack) is, perhaps with some offset, already in
19471- * a certain register (to be used in assembler memory operands).
19472- */
19473-#define THREAD_INFO(reg, off) KERNEL_STACK_OFFSET+(off)-THREAD_SIZE(reg)
19474-
19475+/* how to get the current stack pointer from C */
19476+register unsigned long current_stack_pointer asm("rsp") __used;
19477 #endif
19478
19479 #endif /* !X86_32 */
19480@@ -280,5 +253,12 @@ static inline bool is_ia32_task(void)
19481 extern void arch_task_cache_init(void);
19482 extern int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src);
19483 extern void arch_release_task_struct(struct task_struct *tsk);
19484+
19485+#define __HAVE_THREAD_FUNCTIONS
19486+#define task_thread_info(task) (&(task)->tinfo)
19487+#define task_stack_page(task) ((task)->stack)
19488+#define setup_thread_stack(p, org) do {} while (0)
19489+#define end_of_stack(p) ((unsigned long *)task_stack_page(p) + 1)
19490+
19491 #endif
19492 #endif /* _ASM_X86_THREAD_INFO_H */
19493diff --git a/arch/x86/include/asm/tlbflush.h b/arch/x86/include/asm/tlbflush.h
19494index 04905bf..49203ca 100644
19495--- a/arch/x86/include/asm/tlbflush.h
19496+++ b/arch/x86/include/asm/tlbflush.h
19497@@ -17,18 +17,44 @@
19498
19499 static inline void __native_flush_tlb(void)
19500 {
19501+ if (static_cpu_has(X86_FEATURE_INVPCID)) {
19502+ u64 descriptor[2];
19503+
19504+ descriptor[0] = PCID_KERNEL;
19505+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_ALL_MONGLOBAL) : "memory");
19506+ return;
19507+ }
19508+
19509+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19510+ if (static_cpu_has(X86_FEATURE_PCID)) {
19511+ unsigned int cpu = raw_get_cpu();
19512+
19513+ native_write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER);
19514+ native_write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL);
19515+ raw_put_cpu_no_resched();
19516+ return;
19517+ }
19518+#endif
19519+
19520 native_write_cr3(native_read_cr3());
19521 }
19522
19523 static inline void __native_flush_tlb_global_irq_disabled(void)
19524 {
19525- unsigned long cr4;
19526+ if (static_cpu_has(X86_FEATURE_INVPCID)) {
19527+ u64 descriptor[2];
19528
19529- cr4 = native_read_cr4();
19530- /* clear PGE */
19531- native_write_cr4(cr4 & ~X86_CR4_PGE);
19532- /* write old PGE again and flush TLBs */
19533- native_write_cr4(cr4);
19534+ descriptor[0] = PCID_KERNEL;
19535+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_ALL_GLOBAL) : "memory");
19536+ } else {
19537+ unsigned long cr4;
19538+
19539+ cr4 = native_read_cr4();
19540+ /* clear PGE */
19541+ native_write_cr4(cr4 & ~X86_CR4_PGE);
19542+ /* write old PGE again and flush TLBs */
19543+ native_write_cr4(cr4);
19544+ }
19545 }
19546
19547 static inline void __native_flush_tlb_global(void)
19548@@ -49,6 +75,41 @@ static inline void __native_flush_tlb_global(void)
19549
19550 static inline void __native_flush_tlb_single(unsigned long addr)
19551 {
19552+ if (static_cpu_has(X86_FEATURE_INVPCID)) {
19553+ u64 descriptor[2];
19554+
19555+ descriptor[0] = PCID_KERNEL;
19556+ descriptor[1] = addr;
19557+
19558+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19559+ if (!static_cpu_has(X86_FEATURE_STRONGUDEREF) || addr >= TASK_SIZE_MAX) {
19560+ if (addr < TASK_SIZE_MAX)
19561+ descriptor[1] += pax_user_shadow_base;
19562+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_ADDRESS) : "memory");
19563+ }
19564+
19565+ descriptor[0] = PCID_USER;
19566+ descriptor[1] = addr;
19567+#endif
19568+
19569+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_ADDRESS) : "memory");
19570+ return;
19571+ }
19572+
19573+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19574+ if (static_cpu_has(X86_FEATURE_PCID)) {
19575+ unsigned int cpu = raw_get_cpu();
19576+
19577+ native_write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER | PCID_NOFLUSH);
19578+ asm volatile("invlpg (%0)" ::"r" (addr) : "memory");
19579+ native_write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
19580+ raw_put_cpu_no_resched();
19581+
19582+ if (!static_cpu_has(X86_FEATURE_STRONGUDEREF) && addr < TASK_SIZE_MAX)
19583+ addr += pax_user_shadow_base;
19584+ }
19585+#endif
19586+
19587 asm volatile("invlpg (%0)" ::"r" (addr) : "memory");
19588 }
19589
19590diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h
19591index 0d592e0..f58a222 100644
19592--- a/arch/x86/include/asm/uaccess.h
19593+++ b/arch/x86/include/asm/uaccess.h
19594@@ -7,6 +7,7 @@
19595 #include <linux/compiler.h>
19596 #include <linux/thread_info.h>
19597 #include <linux/string.h>
19598+#include <linux/spinlock.h>
19599 #include <asm/asm.h>
19600 #include <asm/page.h>
19601 #include <asm/smap.h>
19602@@ -29,7 +30,12 @@
19603
19604 #define get_ds() (KERNEL_DS)
19605 #define get_fs() (current_thread_info()->addr_limit)
19606+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
19607+void __set_fs(mm_segment_t x);
19608+void set_fs(mm_segment_t x);
19609+#else
19610 #define set_fs(x) (current_thread_info()->addr_limit = (x))
19611+#endif
19612
19613 #define segment_eq(a, b) ((a).seg == (b).seg)
19614
19615@@ -85,8 +91,34 @@ static inline bool __chk_range_not_ok(unsigned long addr, unsigned long size, un
19616 * checks that the pointer is in the user space range - after calling
19617 * this function, memory access functions may still return -EFAULT.
19618 */
19619-#define access_ok(type, addr, size) \
19620- likely(!__range_not_ok(addr, size, user_addr_max()))
19621+extern int _cond_resched(void);
19622+#define access_ok_noprefault(type, addr, size) (likely(!__range_not_ok(addr, size, user_addr_max())))
19623+#define access_ok(type, addr, size) \
19624+({ \
19625+ long __size = size; \
19626+ unsigned long __addr = (unsigned long)addr; \
19627+ unsigned long __addr_ao = __addr & PAGE_MASK; \
19628+ unsigned long __end_ao = __addr + __size - 1; \
19629+ bool __ret_ao = __range_not_ok(__addr, __size, user_addr_max()) == 0;\
19630+ if (__ret_ao && unlikely((__end_ao ^ __addr_ao) & PAGE_MASK)) { \
19631+ while(__addr_ao <= __end_ao) { \
19632+ char __c_ao; \
19633+ __addr_ao += PAGE_SIZE; \
19634+ if (__size > PAGE_SIZE) \
19635+ _cond_resched(); \
19636+ if (__get_user(__c_ao, (char __user *)__addr)) \
19637+ break; \
19638+ if (type != VERIFY_WRITE) { \
19639+ __addr = __addr_ao; \
19640+ continue; \
19641+ } \
19642+ if (__put_user(__c_ao, (char __user *)__addr)) \
19643+ break; \
19644+ __addr = __addr_ao; \
19645+ } \
19646+ } \
19647+ __ret_ao; \
19648+})
19649
19650 /*
19651 * The exception table consists of pairs of addresses relative to the
19652@@ -176,10 +208,12 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
19653 register __inttype(*(ptr)) __val_gu asm("%"_ASM_DX); \
19654 __chk_user_ptr(ptr); \
19655 might_fault(); \
19656+ pax_open_userland(); \
19657 asm volatile("call __get_user_%P3" \
19658 : "=a" (__ret_gu), "=r" (__val_gu) \
19659 : "0" (ptr), "i" (sizeof(*(ptr)))); \
19660 (x) = (__typeof__(*(ptr))) __val_gu; \
19661+ pax_close_userland(); \
19662 __ret_gu; \
19663 })
19664
19665@@ -187,13 +221,21 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
19666 asm volatile("call __put_user_" #size : "=a" (__ret_pu) \
19667 : "0" ((typeof(*(ptr)))(x)), "c" (ptr) : "ebx")
19668
19669-
19670+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
19671+#define __copyuser_seg "gs;"
19672+#define __COPYUSER_SET_ES "pushl %%gs; popl %%es\n"
19673+#define __COPYUSER_RESTORE_ES "pushl %%ss; popl %%es\n"
19674+#else
19675+#define __copyuser_seg
19676+#define __COPYUSER_SET_ES
19677+#define __COPYUSER_RESTORE_ES
19678+#endif
19679
19680 #ifdef CONFIG_X86_32
19681 #define __put_user_asm_u64(x, addr, err, errret) \
19682 asm volatile(ASM_STAC "\n" \
19683- "1: movl %%eax,0(%2)\n" \
19684- "2: movl %%edx,4(%2)\n" \
19685+ "1: "__copyuser_seg"movl %%eax,0(%2)\n" \
19686+ "2: "__copyuser_seg"movl %%edx,4(%2)\n" \
19687 "3: " ASM_CLAC "\n" \
19688 ".section .fixup,\"ax\"\n" \
19689 "4: movl %3,%0\n" \
19690@@ -206,8 +248,8 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
19691
19692 #define __put_user_asm_ex_u64(x, addr) \
19693 asm volatile(ASM_STAC "\n" \
19694- "1: movl %%eax,0(%1)\n" \
19695- "2: movl %%edx,4(%1)\n" \
19696+ "1: "__copyuser_seg"movl %%eax,0(%1)\n" \
19697+ "2: "__copyuser_seg"movl %%edx,4(%1)\n" \
19698 "3: " ASM_CLAC "\n" \
19699 _ASM_EXTABLE_EX(1b, 2b) \
19700 _ASM_EXTABLE_EX(2b, 3b) \
19701@@ -257,7 +299,8 @@ extern void __put_user_8(void);
19702 __typeof__(*(ptr)) __pu_val; \
19703 __chk_user_ptr(ptr); \
19704 might_fault(); \
19705- __pu_val = x; \
19706+ __pu_val = (x); \
19707+ pax_open_userland(); \
19708 switch (sizeof(*(ptr))) { \
19709 case 1: \
19710 __put_user_x(1, __pu_val, ptr, __ret_pu); \
19711@@ -275,6 +318,7 @@ extern void __put_user_8(void);
19712 __put_user_x(X, __pu_val, ptr, __ret_pu); \
19713 break; \
19714 } \
19715+ pax_close_userland(); \
19716 __ret_pu; \
19717 })
19718
19719@@ -355,8 +399,10 @@ do { \
19720 } while (0)
19721
19722 #define __get_user_asm(x, addr, err, itype, rtype, ltype, errret) \
19723+do { \
19724+ pax_open_userland(); \
19725 asm volatile(ASM_STAC "\n" \
19726- "1: mov"itype" %2,%"rtype"1\n" \
19727+ "1: "__copyuser_seg"mov"itype" %2,%"rtype"1\n"\
19728 "2: " ASM_CLAC "\n" \
19729 ".section .fixup,\"ax\"\n" \
19730 "3: mov %3,%0\n" \
19731@@ -364,8 +410,10 @@ do { \
19732 " jmp 2b\n" \
19733 ".previous\n" \
19734 _ASM_EXTABLE(1b, 3b) \
19735- : "=r" (err), ltype(x) \
19736- : "m" (__m(addr)), "i" (errret), "0" (err))
19737+ : "=r" (err), ltype (x) \
19738+ : "m" (__m(addr)), "i" (errret), "0" (err)); \
19739+ pax_close_userland(); \
19740+} while (0)
19741
19742 #define __get_user_size_ex(x, ptr, size) \
19743 do { \
19744@@ -389,7 +437,7 @@ do { \
19745 } while (0)
19746
19747 #define __get_user_asm_ex(x, addr, itype, rtype, ltype) \
19748- asm volatile("1: mov"itype" %1,%"rtype"0\n" \
19749+ asm volatile("1: "__copyuser_seg"mov"itype" %1,%"rtype"0\n"\
19750 "2:\n" \
19751 _ASM_EXTABLE_EX(1b, 2b) \
19752 : ltype(x) : "m" (__m(addr)))
19753@@ -406,13 +454,24 @@ do { \
19754 int __gu_err; \
19755 unsigned long __gu_val; \
19756 __get_user_size(__gu_val, (ptr), (size), __gu_err, -EFAULT); \
19757- (x) = (__force __typeof__(*(ptr)))__gu_val; \
19758+ (x) = (__typeof__(*(ptr)))__gu_val; \
19759 __gu_err; \
19760 })
19761
19762 /* FIXME: this hack is definitely wrong -AK */
19763 struct __large_struct { unsigned long buf[100]; };
19764-#define __m(x) (*(struct __large_struct __user *)(x))
19765+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19766+#define ____m(x) \
19767+({ \
19768+ unsigned long ____x = (unsigned long)(x); \
19769+ if (____x < pax_user_shadow_base) \
19770+ ____x += pax_user_shadow_base; \
19771+ (typeof(x))____x; \
19772+})
19773+#else
19774+#define ____m(x) (x)
19775+#endif
19776+#define __m(x) (*(struct __large_struct __user *)____m(x))
19777
19778 /*
19779 * Tell gcc we read from memory instead of writing: this is because
19780@@ -420,8 +479,10 @@ struct __large_struct { unsigned long buf[100]; };
19781 * aliasing issues.
19782 */
19783 #define __put_user_asm(x, addr, err, itype, rtype, ltype, errret) \
19784+do { \
19785+ pax_open_userland(); \
19786 asm volatile(ASM_STAC "\n" \
19787- "1: mov"itype" %"rtype"1,%2\n" \
19788+ "1: "__copyuser_seg"mov"itype" %"rtype"1,%2\n"\
19789 "2: " ASM_CLAC "\n" \
19790 ".section .fixup,\"ax\"\n" \
19791 "3: mov %3,%0\n" \
19792@@ -429,10 +490,12 @@ struct __large_struct { unsigned long buf[100]; };
19793 ".previous\n" \
19794 _ASM_EXTABLE(1b, 3b) \
19795 : "=r"(err) \
19796- : ltype(x), "m" (__m(addr)), "i" (errret), "0" (err))
19797+ : ltype (x), "m" (__m(addr)), "i" (errret), "0" (err));\
19798+ pax_close_userland(); \
19799+} while (0)
19800
19801 #define __put_user_asm_ex(x, addr, itype, rtype, ltype) \
19802- asm volatile("1: mov"itype" %"rtype"0,%1\n" \
19803+ asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"0,%1\n"\
19804 "2:\n" \
19805 _ASM_EXTABLE_EX(1b, 2b) \
19806 : : ltype(x), "m" (__m(addr)))
19807@@ -442,11 +505,13 @@ struct __large_struct { unsigned long buf[100]; };
19808 */
19809 #define uaccess_try do { \
19810 current_thread_info()->uaccess_err = 0; \
19811+ pax_open_userland(); \
19812 stac(); \
19813 barrier();
19814
19815 #define uaccess_catch(err) \
19816 clac(); \
19817+ pax_close_userland(); \
19818 (err) |= (current_thread_info()->uaccess_err ? -EFAULT : 0); \
19819 } while (0)
19820
19821@@ -471,8 +536,12 @@ struct __large_struct { unsigned long buf[100]; };
19822 * On error, the variable @x is set to zero.
19823 */
19824
19825+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19826+#define __get_user(x, ptr) get_user((x), (ptr))
19827+#else
19828 #define __get_user(x, ptr) \
19829 __get_user_nocheck((x), (ptr), sizeof(*(ptr)))
19830+#endif
19831
19832 /**
19833 * __put_user: - Write a simple value into user space, with less checking.
19834@@ -494,8 +563,12 @@ struct __large_struct { unsigned long buf[100]; };
19835 * Returns zero on success, or -EFAULT on error.
19836 */
19837
19838+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19839+#define __put_user(x, ptr) put_user((x), (ptr))
19840+#else
19841 #define __put_user(x, ptr) \
19842 __put_user_nocheck((__typeof__(*(ptr)))(x), (ptr), sizeof(*(ptr)))
19843+#endif
19844
19845 #define __get_user_unaligned __get_user
19846 #define __put_user_unaligned __put_user
19847@@ -513,7 +586,7 @@ struct __large_struct { unsigned long buf[100]; };
19848 #define get_user_ex(x, ptr) do { \
19849 unsigned long __gue_val; \
19850 __get_user_size_ex((__gue_val), (ptr), (sizeof(*(ptr)))); \
19851- (x) = (__force __typeof__(*(ptr)))__gue_val; \
19852+ (x) = (__typeof__(*(ptr)))__gue_val; \
19853 } while (0)
19854
19855 #define put_user_try uaccess_try
19856@@ -542,18 +615,19 @@ extern void __cmpxchg_wrong_size(void)
19857 __typeof__(ptr) __uval = (uval); \
19858 __typeof__(*(ptr)) __old = (old); \
19859 __typeof__(*(ptr)) __new = (new); \
19860+ pax_open_userland(); \
19861 switch (size) { \
19862 case 1: \
19863 { \
19864 asm volatile("\t" ASM_STAC "\n" \
19865- "1:\t" LOCK_PREFIX "cmpxchgb %4, %2\n" \
19866+ "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgb %4, %2\n"\
19867 "2:\t" ASM_CLAC "\n" \
19868 "\t.section .fixup, \"ax\"\n" \
19869 "3:\tmov %3, %0\n" \
19870 "\tjmp 2b\n" \
19871 "\t.previous\n" \
19872 _ASM_EXTABLE(1b, 3b) \
19873- : "+r" (__ret), "=a" (__old), "+m" (*(ptr)) \
19874+ : "+r" (__ret), "=a" (__old), "+m" (*____m(ptr))\
19875 : "i" (-EFAULT), "q" (__new), "1" (__old) \
19876 : "memory" \
19877 ); \
19878@@ -562,14 +636,14 @@ extern void __cmpxchg_wrong_size(void)
19879 case 2: \
19880 { \
19881 asm volatile("\t" ASM_STAC "\n" \
19882- "1:\t" LOCK_PREFIX "cmpxchgw %4, %2\n" \
19883+ "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgw %4, %2\n"\
19884 "2:\t" ASM_CLAC "\n" \
19885 "\t.section .fixup, \"ax\"\n" \
19886 "3:\tmov %3, %0\n" \
19887 "\tjmp 2b\n" \
19888 "\t.previous\n" \
19889 _ASM_EXTABLE(1b, 3b) \
19890- : "+r" (__ret), "=a" (__old), "+m" (*(ptr)) \
19891+ : "+r" (__ret), "=a" (__old), "+m" (*____m(ptr))\
19892 : "i" (-EFAULT), "r" (__new), "1" (__old) \
19893 : "memory" \
19894 ); \
19895@@ -578,14 +652,14 @@ extern void __cmpxchg_wrong_size(void)
19896 case 4: \
19897 { \
19898 asm volatile("\t" ASM_STAC "\n" \
19899- "1:\t" LOCK_PREFIX "cmpxchgl %4, %2\n" \
19900+ "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %4, %2\n"\
19901 "2:\t" ASM_CLAC "\n" \
19902 "\t.section .fixup, \"ax\"\n" \
19903 "3:\tmov %3, %0\n" \
19904 "\tjmp 2b\n" \
19905 "\t.previous\n" \
19906 _ASM_EXTABLE(1b, 3b) \
19907- : "+r" (__ret), "=a" (__old), "+m" (*(ptr)) \
19908+ : "+r" (__ret), "=a" (__old), "+m" (*____m(ptr))\
19909 : "i" (-EFAULT), "r" (__new), "1" (__old) \
19910 : "memory" \
19911 ); \
19912@@ -597,14 +671,14 @@ extern void __cmpxchg_wrong_size(void)
19913 __cmpxchg_wrong_size(); \
19914 \
19915 asm volatile("\t" ASM_STAC "\n" \
19916- "1:\t" LOCK_PREFIX "cmpxchgq %4, %2\n" \
19917+ "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgq %4, %2\n"\
19918 "2:\t" ASM_CLAC "\n" \
19919 "\t.section .fixup, \"ax\"\n" \
19920 "3:\tmov %3, %0\n" \
19921 "\tjmp 2b\n" \
19922 "\t.previous\n" \
19923 _ASM_EXTABLE(1b, 3b) \
19924- : "+r" (__ret), "=a" (__old), "+m" (*(ptr)) \
19925+ : "+r" (__ret), "=a" (__old), "+m" (*____m(ptr))\
19926 : "i" (-EFAULT), "r" (__new), "1" (__old) \
19927 : "memory" \
19928 ); \
19929@@ -613,6 +687,7 @@ extern void __cmpxchg_wrong_size(void)
19930 default: \
19931 __cmpxchg_wrong_size(); \
19932 } \
19933+ pax_close_userland(); \
19934 *__uval = __old; \
19935 __ret; \
19936 })
19937@@ -636,17 +711,6 @@ extern struct movsl_mask {
19938
19939 #define ARCH_HAS_NOCACHE_UACCESS 1
19940
19941-#ifdef CONFIG_X86_32
19942-# include <asm/uaccess_32.h>
19943-#else
19944-# include <asm/uaccess_64.h>
19945-#endif
19946-
19947-unsigned long __must_check _copy_from_user(void *to, const void __user *from,
19948- unsigned n);
19949-unsigned long __must_check _copy_to_user(void __user *to, const void *from,
19950- unsigned n);
19951-
19952 #ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
19953 # define copy_user_diag __compiletime_error
19954 #else
19955@@ -656,7 +720,7 @@ unsigned long __must_check _copy_to_user(void __user *to, const void *from,
19956 extern void copy_user_diag("copy_from_user() buffer size is too small")
19957 copy_from_user_overflow(void);
19958 extern void copy_user_diag("copy_to_user() buffer size is too small")
19959-copy_to_user_overflow(void) __asm__("copy_from_user_overflow");
19960+copy_to_user_overflow(void);
19961
19962 #undef copy_user_diag
19963
19964@@ -669,7 +733,7 @@ __copy_from_user_overflow(void) __asm__("copy_from_user_overflow");
19965
19966 extern void
19967 __compiletime_warning("copy_to_user() buffer size is not provably correct")
19968-__copy_to_user_overflow(void) __asm__("copy_from_user_overflow");
19969+__copy_to_user_overflow(void) __asm__("copy_to_user_overflow");
19970 #define __copy_to_user_overflow(size, count) __copy_to_user_overflow()
19971
19972 #else
19973@@ -684,10 +748,16 @@ __copy_from_user_overflow(int size, unsigned long count)
19974
19975 #endif
19976
19977+#ifdef CONFIG_X86_32
19978+# include <asm/uaccess_32.h>
19979+#else
19980+# include <asm/uaccess_64.h>
19981+#endif
19982+
19983 static inline unsigned long __must_check
19984 copy_from_user(void *to, const void __user *from, unsigned long n)
19985 {
19986- int sz = __compiletime_object_size(to);
19987+ size_t sz = __compiletime_object_size(to);
19988
19989 might_fault();
19990
19991@@ -709,12 +779,15 @@ copy_from_user(void *to, const void __user *from, unsigned long n)
19992 * case, and do only runtime checking for non-constant sizes.
19993 */
19994
19995- if (likely(sz < 0 || sz >= n))
19996- n = _copy_from_user(to, from, n);
19997- else if(__builtin_constant_p(n))
19998- copy_from_user_overflow();
19999- else
20000- __copy_from_user_overflow(sz, n);
20001+ if (likely(sz != (size_t)-1 && sz < n)) {
20002+ if(__builtin_constant_p(n))
20003+ copy_from_user_overflow();
20004+ else
20005+ __copy_from_user_overflow(sz, n);
20006+ } if (access_ok(VERIFY_READ, from, n))
20007+ n = __copy_from_user(to, from, n);
20008+ else if ((long)n > 0)
20009+ memset(to, 0, n);
20010
20011 return n;
20012 }
20013@@ -722,17 +795,18 @@ copy_from_user(void *to, const void __user *from, unsigned long n)
20014 static inline unsigned long __must_check
20015 copy_to_user(void __user *to, const void *from, unsigned long n)
20016 {
20017- int sz = __compiletime_object_size(from);
20018+ size_t sz = __compiletime_object_size(from);
20019
20020 might_fault();
20021
20022 /* See the comment in copy_from_user() above. */
20023- if (likely(sz < 0 || sz >= n))
20024- n = _copy_to_user(to, from, n);
20025- else if(__builtin_constant_p(n))
20026- copy_to_user_overflow();
20027- else
20028- __copy_to_user_overflow(sz, n);
20029+ if (likely(sz != (size_t)-1 && sz < n)) {
20030+ if(__builtin_constant_p(n))
20031+ copy_to_user_overflow();
20032+ else
20033+ __copy_to_user_overflow(sz, n);
20034+ } else if (access_ok(VERIFY_WRITE, to, n))
20035+ n = __copy_to_user(to, from, n);
20036
20037 return n;
20038 }
20039diff --git a/arch/x86/include/asm/uaccess_32.h b/arch/x86/include/asm/uaccess_32.h
20040index 3c03a5d..1071638 100644
20041--- a/arch/x86/include/asm/uaccess_32.h
20042+++ b/arch/x86/include/asm/uaccess_32.h
20043@@ -43,6 +43,11 @@ unsigned long __must_check __copy_from_user_ll_nocache_nozero
20044 static __always_inline unsigned long __must_check
20045 __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
20046 {
20047+ if ((long)n < 0)
20048+ return n;
20049+
20050+ check_object_size(from, n, true);
20051+
20052 if (__builtin_constant_p(n)) {
20053 unsigned long ret;
20054
20055@@ -82,12 +87,16 @@ static __always_inline unsigned long __must_check
20056 __copy_to_user(void __user *to, const void *from, unsigned long n)
20057 {
20058 might_fault();
20059+
20060 return __copy_to_user_inatomic(to, from, n);
20061 }
20062
20063 static __always_inline unsigned long
20064 __copy_from_user_inatomic(void *to, const void __user *from, unsigned long n)
20065 {
20066+ if ((long)n < 0)
20067+ return n;
20068+
20069 /* Avoid zeroing the tail if the copy fails..
20070 * If 'n' is constant and 1, 2, or 4, we do still zero on a failure,
20071 * but as the zeroing behaviour is only significant when n is not
20072@@ -137,6 +146,12 @@ static __always_inline unsigned long
20073 __copy_from_user(void *to, const void __user *from, unsigned long n)
20074 {
20075 might_fault();
20076+
20077+ if ((long)n < 0)
20078+ return n;
20079+
20080+ check_object_size(to, n, false);
20081+
20082 if (__builtin_constant_p(n)) {
20083 unsigned long ret;
20084
20085@@ -159,6 +174,10 @@ static __always_inline unsigned long __copy_from_user_nocache(void *to,
20086 const void __user *from, unsigned long n)
20087 {
20088 might_fault();
20089+
20090+ if ((long)n < 0)
20091+ return n;
20092+
20093 if (__builtin_constant_p(n)) {
20094 unsigned long ret;
20095
20096@@ -181,7 +200,10 @@ static __always_inline unsigned long
20097 __copy_from_user_inatomic_nocache(void *to, const void __user *from,
20098 unsigned long n)
20099 {
20100- return __copy_from_user_ll_nocache_nozero(to, from, n);
20101+ if ((long)n < 0)
20102+ return n;
20103+
20104+ return __copy_from_user_ll_nocache_nozero(to, from, n);
20105 }
20106
20107 #endif /* _ASM_X86_UACCESS_32_H */
20108diff --git a/arch/x86/include/asm/uaccess_64.h b/arch/x86/include/asm/uaccess_64.h
20109index 12a26b9..206c200 100644
20110--- a/arch/x86/include/asm/uaccess_64.h
20111+++ b/arch/x86/include/asm/uaccess_64.h
20112@@ -10,6 +10,9 @@
20113 #include <asm/alternative.h>
20114 #include <asm/cpufeature.h>
20115 #include <asm/page.h>
20116+#include <asm/pgtable.h>
20117+
20118+#define set_fs(x) (current_thread_info()->addr_limit = (x))
20119
20120 /*
20121 * Copy To/From Userspace
20122@@ -17,14 +20,14 @@
20123
20124 /* Handles exceptions in both to and from, but doesn't do access_ok */
20125 __must_check unsigned long
20126-copy_user_enhanced_fast_string(void *to, const void *from, unsigned len);
20127+copy_user_enhanced_fast_string(void *to, const void *from, unsigned len) __size_overflow(3);
20128 __must_check unsigned long
20129-copy_user_generic_string(void *to, const void *from, unsigned len);
20130+copy_user_generic_string(void *to, const void *from, unsigned len) __size_overflow(3);
20131 __must_check unsigned long
20132-copy_user_generic_unrolled(void *to, const void *from, unsigned len);
20133+copy_user_generic_unrolled(void *to, const void *from, unsigned len) __size_overflow(3);
20134
20135 static __always_inline __must_check unsigned long
20136-copy_user_generic(void *to, const void *from, unsigned len)
20137+copy_user_generic(void *to, const void *from, unsigned long len)
20138 {
20139 unsigned ret;
20140
20141@@ -46,121 +49,170 @@ copy_user_generic(void *to, const void *from, unsigned len)
20142 }
20143
20144 __must_check unsigned long
20145-copy_in_user(void __user *to, const void __user *from, unsigned len);
20146+copy_in_user(void __user *to, const void __user *from, unsigned long len);
20147
20148 static __always_inline __must_check
20149-int __copy_from_user_nocheck(void *dst, const void __user *src, unsigned size)
20150+unsigned long __copy_from_user_nocheck(void *dst, const void __user *src, unsigned long size)
20151 {
20152- int ret = 0;
20153+ size_t sz = __compiletime_object_size(dst);
20154+ unsigned ret = 0;
20155+
20156+ if (size > INT_MAX)
20157+ return size;
20158+
20159+ check_object_size(dst, size, false);
20160+
20161+#ifdef CONFIG_PAX_MEMORY_UDEREF
20162+ if (!access_ok_noprefault(VERIFY_READ, src, size))
20163+ return size;
20164+#endif
20165+
20166+ if (unlikely(sz != (size_t)-1 && sz < size)) {
20167+ if(__builtin_constant_p(size))
20168+ copy_from_user_overflow();
20169+ else
20170+ __copy_from_user_overflow(sz, size);
20171+ return size;
20172+ }
20173
20174 if (!__builtin_constant_p(size))
20175- return copy_user_generic(dst, (__force void *)src, size);
20176+ return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
20177 switch (size) {
20178- case 1:__get_user_asm(*(u8 *)dst, (u8 __user *)src,
20179+ case 1:__get_user_asm(*(u8 *)dst, (const u8 __user *)src,
20180 ret, "b", "b", "=q", 1);
20181 return ret;
20182- case 2:__get_user_asm(*(u16 *)dst, (u16 __user *)src,
20183+ case 2:__get_user_asm(*(u16 *)dst, (const u16 __user *)src,
20184 ret, "w", "w", "=r", 2);
20185 return ret;
20186- case 4:__get_user_asm(*(u32 *)dst, (u32 __user *)src,
20187+ case 4:__get_user_asm(*(u32 *)dst, (const u32 __user *)src,
20188 ret, "l", "k", "=r", 4);
20189 return ret;
20190- case 8:__get_user_asm(*(u64 *)dst, (u64 __user *)src,
20191+ case 8:__get_user_asm(*(u64 *)dst, (const u64 __user *)src,
20192 ret, "q", "", "=r", 8);
20193 return ret;
20194 case 10:
20195- __get_user_asm(*(u64 *)dst, (u64 __user *)src,
20196+ __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
20197 ret, "q", "", "=r", 10);
20198 if (unlikely(ret))
20199 return ret;
20200 __get_user_asm(*(u16 *)(8 + (char *)dst),
20201- (u16 __user *)(8 + (char __user *)src),
20202+ (const u16 __user *)(8 + (const char __user *)src),
20203 ret, "w", "w", "=r", 2);
20204 return ret;
20205 case 16:
20206- __get_user_asm(*(u64 *)dst, (u64 __user *)src,
20207+ __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
20208 ret, "q", "", "=r", 16);
20209 if (unlikely(ret))
20210 return ret;
20211 __get_user_asm(*(u64 *)(8 + (char *)dst),
20212- (u64 __user *)(8 + (char __user *)src),
20213+ (const u64 __user *)(8 + (const char __user *)src),
20214 ret, "q", "", "=r", 8);
20215 return ret;
20216 default:
20217- return copy_user_generic(dst, (__force void *)src, size);
20218+ return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
20219 }
20220 }
20221
20222 static __always_inline __must_check
20223-int __copy_from_user(void *dst, const void __user *src, unsigned size)
20224+unsigned long __copy_from_user(void *dst, const void __user *src, unsigned long size)
20225 {
20226 might_fault();
20227 return __copy_from_user_nocheck(dst, src, size);
20228 }
20229
20230 static __always_inline __must_check
20231-int __copy_to_user_nocheck(void __user *dst, const void *src, unsigned size)
20232+unsigned long __copy_to_user_nocheck(void __user *dst, const void *src, unsigned long size)
20233 {
20234- int ret = 0;
20235+ size_t sz = __compiletime_object_size(src);
20236+ unsigned ret = 0;
20237+
20238+ if (size > INT_MAX)
20239+ return size;
20240+
20241+ check_object_size(src, size, true);
20242+
20243+#ifdef CONFIG_PAX_MEMORY_UDEREF
20244+ if (!access_ok_noprefault(VERIFY_WRITE, dst, size))
20245+ return size;
20246+#endif
20247+
20248+ if (unlikely(sz != (size_t)-1 && sz < size)) {
20249+ if(__builtin_constant_p(size))
20250+ copy_to_user_overflow();
20251+ else
20252+ __copy_to_user_overflow(sz, size);
20253+ return size;
20254+ }
20255
20256 if (!__builtin_constant_p(size))
20257- return copy_user_generic((__force void *)dst, src, size);
20258+ return copy_user_generic((__force_kernel void *)____m(dst), src, size);
20259 switch (size) {
20260- case 1:__put_user_asm(*(u8 *)src, (u8 __user *)dst,
20261+ case 1:__put_user_asm(*(const u8 *)src, (u8 __user *)dst,
20262 ret, "b", "b", "iq", 1);
20263 return ret;
20264- case 2:__put_user_asm(*(u16 *)src, (u16 __user *)dst,
20265+ case 2:__put_user_asm(*(const u16 *)src, (u16 __user *)dst,
20266 ret, "w", "w", "ir", 2);
20267 return ret;
20268- case 4:__put_user_asm(*(u32 *)src, (u32 __user *)dst,
20269+ case 4:__put_user_asm(*(const u32 *)src, (u32 __user *)dst,
20270 ret, "l", "k", "ir", 4);
20271 return ret;
20272- case 8:__put_user_asm(*(u64 *)src, (u64 __user *)dst,
20273+ case 8:__put_user_asm(*(const u64 *)src, (u64 __user *)dst,
20274 ret, "q", "", "er", 8);
20275 return ret;
20276 case 10:
20277- __put_user_asm(*(u64 *)src, (u64 __user *)dst,
20278+ __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
20279 ret, "q", "", "er", 10);
20280 if (unlikely(ret))
20281 return ret;
20282 asm("":::"memory");
20283- __put_user_asm(4[(u16 *)src], 4 + (u16 __user *)dst,
20284+ __put_user_asm(4[(const u16 *)src], 4 + (u16 __user *)dst,
20285 ret, "w", "w", "ir", 2);
20286 return ret;
20287 case 16:
20288- __put_user_asm(*(u64 *)src, (u64 __user *)dst,
20289+ __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
20290 ret, "q", "", "er", 16);
20291 if (unlikely(ret))
20292 return ret;
20293 asm("":::"memory");
20294- __put_user_asm(1[(u64 *)src], 1 + (u64 __user *)dst,
20295+ __put_user_asm(1[(const u64 *)src], 1 + (u64 __user *)dst,
20296 ret, "q", "", "er", 8);
20297 return ret;
20298 default:
20299- return copy_user_generic((__force void *)dst, src, size);
20300+ return copy_user_generic((__force_kernel void *)____m(dst), src, size);
20301 }
20302 }
20303
20304 static __always_inline __must_check
20305-int __copy_to_user(void __user *dst, const void *src, unsigned size)
20306+unsigned long __copy_to_user(void __user *dst, const void *src, unsigned long size)
20307 {
20308 might_fault();
20309 return __copy_to_user_nocheck(dst, src, size);
20310 }
20311
20312 static __always_inline __must_check
20313-int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
20314+unsigned long __copy_in_user(void __user *dst, const void __user *src, unsigned size)
20315 {
20316- int ret = 0;
20317+ unsigned ret = 0;
20318
20319 might_fault();
20320+
20321+ if (size > INT_MAX)
20322+ return size;
20323+
20324+#ifdef CONFIG_PAX_MEMORY_UDEREF
20325+ if (!access_ok_noprefault(VERIFY_READ, src, size))
20326+ return size;
20327+ if (!access_ok_noprefault(VERIFY_WRITE, dst, size))
20328+ return size;
20329+#endif
20330+
20331 if (!__builtin_constant_p(size))
20332- return copy_user_generic((__force void *)dst,
20333- (__force void *)src, size);
20334+ return copy_user_generic((__force_kernel void *)____m(dst),
20335+ (__force_kernel const void *)____m(src), size);
20336 switch (size) {
20337 case 1: {
20338 u8 tmp;
20339- __get_user_asm(tmp, (u8 __user *)src,
20340+ __get_user_asm(tmp, (const u8 __user *)src,
20341 ret, "b", "b", "=q", 1);
20342 if (likely(!ret))
20343 __put_user_asm(tmp, (u8 __user *)dst,
20344@@ -169,7 +221,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
20345 }
20346 case 2: {
20347 u16 tmp;
20348- __get_user_asm(tmp, (u16 __user *)src,
20349+ __get_user_asm(tmp, (const u16 __user *)src,
20350 ret, "w", "w", "=r", 2);
20351 if (likely(!ret))
20352 __put_user_asm(tmp, (u16 __user *)dst,
20353@@ -179,7 +231,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
20354
20355 case 4: {
20356 u32 tmp;
20357- __get_user_asm(tmp, (u32 __user *)src,
20358+ __get_user_asm(tmp, (const u32 __user *)src,
20359 ret, "l", "k", "=r", 4);
20360 if (likely(!ret))
20361 __put_user_asm(tmp, (u32 __user *)dst,
20362@@ -188,7 +240,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
20363 }
20364 case 8: {
20365 u64 tmp;
20366- __get_user_asm(tmp, (u64 __user *)src,
20367+ __get_user_asm(tmp, (const u64 __user *)src,
20368 ret, "q", "", "=r", 8);
20369 if (likely(!ret))
20370 __put_user_asm(tmp, (u64 __user *)dst,
20371@@ -196,41 +248,58 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
20372 return ret;
20373 }
20374 default:
20375- return copy_user_generic((__force void *)dst,
20376- (__force void *)src, size);
20377+ return copy_user_generic((__force_kernel void *)____m(dst),
20378+ (__force_kernel const void *)____m(src), size);
20379 }
20380 }
20381
20382-static __must_check __always_inline int
20383-__copy_from_user_inatomic(void *dst, const void __user *src, unsigned size)
20384+static __must_check __always_inline unsigned long
20385+__copy_from_user_inatomic(void *dst, const void __user *src, unsigned long size)
20386 {
20387 return __copy_from_user_nocheck(dst, src, size);
20388 }
20389
20390-static __must_check __always_inline int
20391-__copy_to_user_inatomic(void __user *dst, const void *src, unsigned size)
20392+static __must_check __always_inline unsigned long
20393+__copy_to_user_inatomic(void __user *dst, const void *src, unsigned long size)
20394 {
20395 return __copy_to_user_nocheck(dst, src, size);
20396 }
20397
20398-extern long __copy_user_nocache(void *dst, const void __user *src,
20399- unsigned size, int zerorest);
20400+extern unsigned long __copy_user_nocache(void *dst, const void __user *src,
20401+ unsigned long size, int zerorest);
20402
20403-static inline int
20404-__copy_from_user_nocache(void *dst, const void __user *src, unsigned size)
20405+static inline unsigned long
20406+__copy_from_user_nocache(void *dst, const void __user *src, unsigned long size)
20407 {
20408 might_fault();
20409+
20410+ if (size > INT_MAX)
20411+ return size;
20412+
20413+#ifdef CONFIG_PAX_MEMORY_UDEREF
20414+ if (!access_ok_noprefault(VERIFY_READ, src, size))
20415+ return size;
20416+#endif
20417+
20418 return __copy_user_nocache(dst, src, size, 1);
20419 }
20420
20421-static inline int
20422+static inline unsigned long
20423 __copy_from_user_inatomic_nocache(void *dst, const void __user *src,
20424- unsigned size)
20425+ unsigned long size)
20426 {
20427+ if (size > INT_MAX)
20428+ return size;
20429+
20430+#ifdef CONFIG_PAX_MEMORY_UDEREF
20431+ if (!access_ok_noprefault(VERIFY_READ, src, size))
20432+ return size;
20433+#endif
20434+
20435 return __copy_user_nocache(dst, src, size, 0);
20436 }
20437
20438 unsigned long
20439-copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest);
20440+copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest) __size_overflow(3);
20441
20442 #endif /* _ASM_X86_UACCESS_64_H */
20443diff --git a/arch/x86/include/asm/word-at-a-time.h b/arch/x86/include/asm/word-at-a-time.h
20444index 5b238981..77fdd78 100644
20445--- a/arch/x86/include/asm/word-at-a-time.h
20446+++ b/arch/x86/include/asm/word-at-a-time.h
20447@@ -11,7 +11,7 @@
20448 * and shift, for example.
20449 */
20450 struct word_at_a_time {
20451- const unsigned long one_bits, high_bits;
20452+ unsigned long one_bits, high_bits;
20453 };
20454
20455 #define WORD_AT_A_TIME_CONSTANTS { REPEAT_BYTE(0x01), REPEAT_BYTE(0x80) }
20456diff --git a/arch/x86/include/asm/x86_init.h b/arch/x86/include/asm/x86_init.h
20457index e45e4da..44e8572 100644
20458--- a/arch/x86/include/asm/x86_init.h
20459+++ b/arch/x86/include/asm/x86_init.h
20460@@ -129,7 +129,7 @@ struct x86_init_ops {
20461 struct x86_init_timers timers;
20462 struct x86_init_iommu iommu;
20463 struct x86_init_pci pci;
20464-};
20465+} __no_const;
20466
20467 /**
20468 * struct x86_cpuinit_ops - platform specific cpu hotplug setups
20469@@ -140,7 +140,7 @@ struct x86_cpuinit_ops {
20470 void (*setup_percpu_clockev)(void);
20471 void (*early_percpu_clock_init)(void);
20472 void (*fixup_cpu_id)(struct cpuinfo_x86 *c, int node);
20473-};
20474+} __no_const;
20475
20476 struct timespec;
20477
20478@@ -168,7 +168,7 @@ struct x86_platform_ops {
20479 void (*save_sched_clock_state)(void);
20480 void (*restore_sched_clock_state)(void);
20481 void (*apic_post_init)(void);
20482-};
20483+} __no_const;
20484
20485 struct pci_dev;
20486 struct msi_msg;
20487@@ -185,7 +185,7 @@ struct x86_msi_ops {
20488 int (*setup_hpet_msi)(unsigned int irq, unsigned int id);
20489 u32 (*msi_mask_irq)(struct msi_desc *desc, u32 mask, u32 flag);
20490 u32 (*msix_mask_irq)(struct msi_desc *desc, u32 flag);
20491-};
20492+} __no_const;
20493
20494 struct IO_APIC_route_entry;
20495 struct io_apic_irq_attr;
20496@@ -206,7 +206,7 @@ struct x86_io_apic_ops {
20497 unsigned int destination, int vector,
20498 struct io_apic_irq_attr *attr);
20499 void (*eoi_ioapic_pin)(int apic, int pin, int vector);
20500-};
20501+} __no_const;
20502
20503 extern struct x86_init_ops x86_init;
20504 extern struct x86_cpuinit_ops x86_cpuinit;
20505diff --git a/arch/x86/include/asm/xen/page.h b/arch/x86/include/asm/xen/page.h
20506index 3e276eb..2eb3c30 100644
20507--- a/arch/x86/include/asm/xen/page.h
20508+++ b/arch/x86/include/asm/xen/page.h
20509@@ -56,7 +56,7 @@ extern int m2p_remove_override(struct page *page,
20510 extern struct page *m2p_find_override(unsigned long mfn);
20511 extern unsigned long m2p_find_override_pfn(unsigned long mfn, unsigned long pfn);
20512
20513-static inline unsigned long pfn_to_mfn(unsigned long pfn)
20514+static inline unsigned long __intentional_overflow(-1) pfn_to_mfn(unsigned long pfn)
20515 {
20516 unsigned long mfn;
20517
20518diff --git a/arch/x86/include/asm/xsave.h b/arch/x86/include/asm/xsave.h
20519index 6c1d741..39e6ecf 100644
20520--- a/arch/x86/include/asm/xsave.h
20521+++ b/arch/x86/include/asm/xsave.h
20522@@ -80,8 +80,11 @@ static inline int xsave_user(struct xsave_struct __user *buf)
20523 if (unlikely(err))
20524 return -EFAULT;
20525
20526+ pax_open_userland();
20527 __asm__ __volatile__(ASM_STAC "\n"
20528- "1: .byte " REX_PREFIX "0x0f,0xae,0x27\n"
20529+ "1:"
20530+ __copyuser_seg
20531+ ".byte " REX_PREFIX "0x0f,0xae,0x27\n"
20532 "2: " ASM_CLAC "\n"
20533 ".section .fixup,\"ax\"\n"
20534 "3: movl $-1,%[err]\n"
20535@@ -91,18 +94,22 @@ static inline int xsave_user(struct xsave_struct __user *buf)
20536 : [err] "=r" (err)
20537 : "D" (buf), "a" (-1), "d" (-1), "0" (0)
20538 : "memory");
20539+ pax_close_userland();
20540 return err;
20541 }
20542
20543 static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
20544 {
20545 int err;
20546- struct xsave_struct *xstate = ((__force struct xsave_struct *)buf);
20547+ struct xsave_struct *xstate = ((__force_kernel struct xsave_struct *)buf);
20548 u32 lmask = mask;
20549 u32 hmask = mask >> 32;
20550
20551+ pax_open_userland();
20552 __asm__ __volatile__(ASM_STAC "\n"
20553- "1: .byte " REX_PREFIX "0x0f,0xae,0x2f\n"
20554+ "1:"
20555+ __copyuser_seg
20556+ ".byte " REX_PREFIX "0x0f,0xae,0x2f\n"
20557 "2: " ASM_CLAC "\n"
20558 ".section .fixup,\"ax\"\n"
20559 "3: movl $-1,%[err]\n"
20560@@ -112,6 +119,7 @@ static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
20561 : [err] "=r" (err)
20562 : "D" (xstate), "a" (lmask), "d" (hmask), "0" (0)
20563 : "memory"); /* memory required? */
20564+ pax_close_userland();
20565 return err;
20566 }
20567
20568diff --git a/arch/x86/include/uapi/asm/e820.h b/arch/x86/include/uapi/asm/e820.h
20569index bbae024..e1528f9 100644
20570--- a/arch/x86/include/uapi/asm/e820.h
20571+++ b/arch/x86/include/uapi/asm/e820.h
20572@@ -63,7 +63,7 @@ struct e820map {
20573 #define ISA_START_ADDRESS 0xa0000
20574 #define ISA_END_ADDRESS 0x100000
20575
20576-#define BIOS_BEGIN 0x000a0000
20577+#define BIOS_BEGIN 0x000c0000
20578 #define BIOS_END 0x00100000
20579
20580 #define BIOS_ROM_BASE 0xffe00000
20581diff --git a/arch/x86/include/uapi/asm/ptrace-abi.h b/arch/x86/include/uapi/asm/ptrace-abi.h
20582index 7b0a55a..ad115bf 100644
20583--- a/arch/x86/include/uapi/asm/ptrace-abi.h
20584+++ b/arch/x86/include/uapi/asm/ptrace-abi.h
20585@@ -49,7 +49,6 @@
20586 #define EFLAGS 144
20587 #define RSP 152
20588 #define SS 160
20589-#define ARGOFFSET R11
20590 #endif /* __ASSEMBLY__ */
20591
20592 /* top of stack page */
20593diff --git a/arch/x86/kernel/Makefile b/arch/x86/kernel/Makefile
20594index cb648c8..91cb07e 100644
20595--- a/arch/x86/kernel/Makefile
20596+++ b/arch/x86/kernel/Makefile
20597@@ -24,7 +24,7 @@ obj-y += time.o ioport.o ldt.o dumpstack.o nmi.o
20598 obj-y += setup.o x86_init.o i8259.o irqinit.o jump_label.o
20599 obj-$(CONFIG_IRQ_WORK) += irq_work.o
20600 obj-y += probe_roms.o
20601-obj-$(CONFIG_X86_32) += i386_ksyms_32.o
20602+obj-$(CONFIG_X86_32) += sys_i386_32.o i386_ksyms_32.o
20603 obj-$(CONFIG_X86_64) += sys_x86_64.o x8664_ksyms_64.o
20604 obj-y += syscall_$(BITS).o
20605 obj-$(CONFIG_X86_64) += vsyscall_64.o
20606diff --git a/arch/x86/kernel/acpi/boot.c b/arch/x86/kernel/acpi/boot.c
20607index 1dac942..19c8b0c 100644
20608--- a/arch/x86/kernel/acpi/boot.c
20609+++ b/arch/x86/kernel/acpi/boot.c
20610@@ -1312,7 +1312,7 @@ static int __init dmi_ignore_irq0_timer_override(const struct dmi_system_id *d)
20611 * If your system is blacklisted here, but you find that acpi=force
20612 * works for you, please contact linux-acpi@vger.kernel.org
20613 */
20614-static struct dmi_system_id __initdata acpi_dmi_table[] = {
20615+static const struct dmi_system_id __initconst acpi_dmi_table[] = {
20616 /*
20617 * Boxes that need ACPI disabled
20618 */
20619@@ -1387,7 +1387,7 @@ static struct dmi_system_id __initdata acpi_dmi_table[] = {
20620 };
20621
20622 /* second table for DMI checks that should run after early-quirks */
20623-static struct dmi_system_id __initdata acpi_dmi_table_late[] = {
20624+static const struct dmi_system_id __initconst acpi_dmi_table_late[] = {
20625 /*
20626 * HP laptops which use a DSDT reporting as HP/SB400/10000,
20627 * which includes some code which overrides all temperature
20628diff --git a/arch/x86/kernel/acpi/sleep.c b/arch/x86/kernel/acpi/sleep.c
20629index 3a2ae4c..9db31d6 100644
20630--- a/arch/x86/kernel/acpi/sleep.c
20631+++ b/arch/x86/kernel/acpi/sleep.c
20632@@ -99,8 +99,12 @@ int x86_acpi_suspend_lowlevel(void)
20633 #else /* CONFIG_64BIT */
20634 #ifdef CONFIG_SMP
20635 stack_start = (unsigned long)temp_stack + sizeof(temp_stack);
20636+
20637+ pax_open_kernel();
20638 early_gdt_descr.address =
20639 (unsigned long)get_cpu_gdt_table(smp_processor_id());
20640+ pax_close_kernel();
20641+
20642 initial_gs = per_cpu_offset(smp_processor_id());
20643 #endif
20644 initial_code = (unsigned long)wakeup_long64;
20645diff --git a/arch/x86/kernel/acpi/wakeup_32.S b/arch/x86/kernel/acpi/wakeup_32.S
20646index 665c6b7..eae4d56 100644
20647--- a/arch/x86/kernel/acpi/wakeup_32.S
20648+++ b/arch/x86/kernel/acpi/wakeup_32.S
20649@@ -29,13 +29,11 @@ wakeup_pmode_return:
20650 # and restore the stack ... but you need gdt for this to work
20651 movl saved_context_esp, %esp
20652
20653- movl %cs:saved_magic, %eax
20654- cmpl $0x12345678, %eax
20655+ cmpl $0x12345678, saved_magic
20656 jne bogus_magic
20657
20658 # jump to place where we left off
20659- movl saved_eip, %eax
20660- jmp *%eax
20661+ jmp *(saved_eip)
20662
20663 bogus_magic:
20664 jmp bogus_magic
20665diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c
20666index df94598..f3b29bf 100644
20667--- a/arch/x86/kernel/alternative.c
20668+++ b/arch/x86/kernel/alternative.c
20669@@ -269,6 +269,13 @@ void __init_or_module apply_alternatives(struct alt_instr *start,
20670 */
20671 for (a = start; a < end; a++) {
20672 instr = (u8 *)&a->instr_offset + a->instr_offset;
20673+
20674+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20675+ instr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20676+ if (instr < (u8 *)_text || (u8 *)_einittext <= instr)
20677+ instr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20678+#endif
20679+
20680 replacement = (u8 *)&a->repl_offset + a->repl_offset;
20681 BUG_ON(a->replacementlen > a->instrlen);
20682 BUG_ON(a->instrlen > sizeof(insnbuf));
20683@@ -300,10 +307,16 @@ static void alternatives_smp_lock(const s32 *start, const s32 *end,
20684 for (poff = start; poff < end; poff++) {
20685 u8 *ptr = (u8 *)poff + *poff;
20686
20687+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20688+ ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20689+ if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
20690+ ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20691+#endif
20692+
20693 if (!*poff || ptr < text || ptr >= text_end)
20694 continue;
20695 /* turn DS segment override prefix into lock prefix */
20696- if (*ptr == 0x3e)
20697+ if (*ktla_ktva(ptr) == 0x3e)
20698 text_poke(ptr, ((unsigned char []){0xf0}), 1);
20699 }
20700 mutex_unlock(&text_mutex);
20701@@ -318,10 +331,16 @@ static void alternatives_smp_unlock(const s32 *start, const s32 *end,
20702 for (poff = start; poff < end; poff++) {
20703 u8 *ptr = (u8 *)poff + *poff;
20704
20705+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20706+ ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20707+ if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
20708+ ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20709+#endif
20710+
20711 if (!*poff || ptr < text || ptr >= text_end)
20712 continue;
20713 /* turn lock prefix into DS segment override prefix */
20714- if (*ptr == 0xf0)
20715+ if (*ktla_ktva(ptr) == 0xf0)
20716 text_poke(ptr, ((unsigned char []){0x3E}), 1);
20717 }
20718 mutex_unlock(&text_mutex);
20719@@ -458,7 +477,7 @@ void __init_or_module apply_paravirt(struct paravirt_patch_site *start,
20720
20721 BUG_ON(p->len > MAX_PATCH_LEN);
20722 /* prep the buffer with the original instructions */
20723- memcpy(insnbuf, p->instr, p->len);
20724+ memcpy(insnbuf, ktla_ktva(p->instr), p->len);
20725 used = pv_init_ops.patch(p->instrtype, p->clobbers, insnbuf,
20726 (unsigned long)p->instr, p->len);
20727
20728@@ -505,7 +524,7 @@ void __init alternative_instructions(void)
20729 if (!uniproc_patched || num_possible_cpus() == 1)
20730 free_init_pages("SMP alternatives",
20731 (unsigned long)__smp_locks,
20732- (unsigned long)__smp_locks_end);
20733+ PAGE_ALIGN((unsigned long)__smp_locks_end));
20734 #endif
20735
20736 apply_paravirt(__parainstructions, __parainstructions_end);
20737@@ -525,13 +544,17 @@ void __init alternative_instructions(void)
20738 * instructions. And on the local CPU you need to be protected again NMI or MCE
20739 * handlers seeing an inconsistent instruction while you patch.
20740 */
20741-void *__init_or_module text_poke_early(void *addr, const void *opcode,
20742+void *__kprobes text_poke_early(void *addr, const void *opcode,
20743 size_t len)
20744 {
20745 unsigned long flags;
20746 local_irq_save(flags);
20747- memcpy(addr, opcode, len);
20748+
20749+ pax_open_kernel();
20750+ memcpy(ktla_ktva(addr), opcode, len);
20751 sync_core();
20752+ pax_close_kernel();
20753+
20754 local_irq_restore(flags);
20755 /* Could also do a CLFLUSH here to speed up CPU recovery; but
20756 that causes hangs on some VIA CPUs. */
20757@@ -553,36 +576,22 @@ void *__init_or_module text_poke_early(void *addr, const void *opcode,
20758 */
20759 void *__kprobes text_poke(void *addr, const void *opcode, size_t len)
20760 {
20761- unsigned long flags;
20762- char *vaddr;
20763+ unsigned char *vaddr = ktla_ktva(addr);
20764 struct page *pages[2];
20765- int i;
20766+ size_t i;
20767
20768 if (!core_kernel_text((unsigned long)addr)) {
20769- pages[0] = vmalloc_to_page(addr);
20770- pages[1] = vmalloc_to_page(addr + PAGE_SIZE);
20771+ pages[0] = vmalloc_to_page(vaddr);
20772+ pages[1] = vmalloc_to_page(vaddr + PAGE_SIZE);
20773 } else {
20774- pages[0] = virt_to_page(addr);
20775+ pages[0] = virt_to_page(vaddr);
20776 WARN_ON(!PageReserved(pages[0]));
20777- pages[1] = virt_to_page(addr + PAGE_SIZE);
20778+ pages[1] = virt_to_page(vaddr + PAGE_SIZE);
20779 }
20780 BUG_ON(!pages[0]);
20781- local_irq_save(flags);
20782- set_fixmap(FIX_TEXT_POKE0, page_to_phys(pages[0]));
20783- if (pages[1])
20784- set_fixmap(FIX_TEXT_POKE1, page_to_phys(pages[1]));
20785- vaddr = (char *)fix_to_virt(FIX_TEXT_POKE0);
20786- memcpy(&vaddr[(unsigned long)addr & ~PAGE_MASK], opcode, len);
20787- clear_fixmap(FIX_TEXT_POKE0);
20788- if (pages[1])
20789- clear_fixmap(FIX_TEXT_POKE1);
20790- local_flush_tlb();
20791- sync_core();
20792- /* Could also do a CLFLUSH here to speed up CPU recovery; but
20793- that causes hangs on some VIA CPUs. */
20794+ text_poke_early(addr, opcode, len);
20795 for (i = 0; i < len; i++)
20796- BUG_ON(((char *)addr)[i] != ((char *)opcode)[i]);
20797- local_irq_restore(flags);
20798+ BUG_ON((vaddr)[i] != ((const unsigned char *)opcode)[i]);
20799 return addr;
20800 }
20801
20802@@ -602,7 +611,7 @@ int poke_int3_handler(struct pt_regs *regs)
20803 if (likely(!bp_patching_in_progress))
20804 return 0;
20805
20806- if (user_mode_vm(regs) || regs->ip != (unsigned long)bp_int3_addr)
20807+ if (user_mode(regs) || regs->ip != (unsigned long)bp_int3_addr)
20808 return 0;
20809
20810 /* set up the specified breakpoint handler */
20811@@ -636,7 +645,7 @@ int poke_int3_handler(struct pt_regs *regs)
20812 */
20813 void *text_poke_bp(void *addr, const void *opcode, size_t len, void *handler)
20814 {
20815- unsigned char int3 = 0xcc;
20816+ const unsigned char int3 = 0xcc;
20817
20818 bp_int3_handler = handler;
20819 bp_int3_addr = (u8 *)addr + sizeof(int3);
20820diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
20821index 7f26c9a..694544e 100644
20822--- a/arch/x86/kernel/apic/apic.c
20823+++ b/arch/x86/kernel/apic/apic.c
20824@@ -198,7 +198,7 @@ int first_system_vector = 0xfe;
20825 /*
20826 * Debug level, exported for io_apic.c
20827 */
20828-unsigned int apic_verbosity;
20829+int apic_verbosity;
20830
20831 int pic_mode;
20832
20833@@ -1992,7 +1992,7 @@ static inline void __smp_error_interrupt(struct pt_regs *regs)
20834 apic_write(APIC_ESR, 0);
20835 v = apic_read(APIC_ESR);
20836 ack_APIC_irq();
20837- atomic_inc(&irq_err_count);
20838+ atomic_inc_unchecked(&irq_err_count);
20839
20840 apic_printk(APIC_DEBUG, KERN_DEBUG "APIC error on CPU%d: %02x",
20841 smp_processor_id(), v);
20842diff --git a/arch/x86/kernel/apic/apic_flat_64.c b/arch/x86/kernel/apic/apic_flat_64.c
20843index 2c621a6..fa2b1ae 100644
20844--- a/arch/x86/kernel/apic/apic_flat_64.c
20845+++ b/arch/x86/kernel/apic/apic_flat_64.c
20846@@ -154,7 +154,7 @@ static int flat_probe(void)
20847 return 1;
20848 }
20849
20850-static struct apic apic_flat = {
20851+static struct apic apic_flat __read_only = {
20852 .name = "flat",
20853 .probe = flat_probe,
20854 .acpi_madt_oem_check = flat_acpi_madt_oem_check,
20855@@ -268,7 +268,7 @@ static int physflat_probe(void)
20856 return 0;
20857 }
20858
20859-static struct apic apic_physflat = {
20860+static struct apic apic_physflat __read_only = {
20861
20862 .name = "physical flat",
20863 .probe = physflat_probe,
20864diff --git a/arch/x86/kernel/apic/apic_noop.c b/arch/x86/kernel/apic/apic_noop.c
20865index 191ce75..2db6d63 100644
20866--- a/arch/x86/kernel/apic/apic_noop.c
20867+++ b/arch/x86/kernel/apic/apic_noop.c
20868@@ -118,7 +118,7 @@ static void noop_apic_write(u32 reg, u32 v)
20869 WARN_ON_ONCE(cpu_has_apic && !disable_apic);
20870 }
20871
20872-struct apic apic_noop = {
20873+struct apic apic_noop __read_only = {
20874 .name = "noop",
20875 .probe = noop_probe,
20876 .acpi_madt_oem_check = NULL,
20877diff --git a/arch/x86/kernel/apic/bigsmp_32.c b/arch/x86/kernel/apic/bigsmp_32.c
20878index d50e364..543bee3 100644
20879--- a/arch/x86/kernel/apic/bigsmp_32.c
20880+++ b/arch/x86/kernel/apic/bigsmp_32.c
20881@@ -152,7 +152,7 @@ static int probe_bigsmp(void)
20882 return dmi_bigsmp;
20883 }
20884
20885-static struct apic apic_bigsmp = {
20886+static struct apic apic_bigsmp __read_only = {
20887
20888 .name = "bigsmp",
20889 .probe = probe_bigsmp,
20890diff --git a/arch/x86/kernel/apic/es7000_32.c b/arch/x86/kernel/apic/es7000_32.c
20891index c552247..587a316 100644
20892--- a/arch/x86/kernel/apic/es7000_32.c
20893+++ b/arch/x86/kernel/apic/es7000_32.c
20894@@ -608,8 +608,7 @@ static int es7000_mps_oem_check_cluster(struct mpc_table *mpc, char *oem,
20895 return ret && es7000_apic_is_cluster();
20896 }
20897
20898-/* We've been warned by a false positive warning.Use __refdata to keep calm. */
20899-static struct apic __refdata apic_es7000_cluster = {
20900+static struct apic apic_es7000_cluster __read_only = {
20901
20902 .name = "es7000",
20903 .probe = probe_es7000,
20904@@ -675,7 +674,7 @@ static struct apic __refdata apic_es7000_cluster = {
20905 .x86_32_early_logical_apicid = es7000_early_logical_apicid,
20906 };
20907
20908-static struct apic __refdata apic_es7000 = {
20909+static struct apic apic_es7000 __read_only = {
20910
20911 .name = "es7000",
20912 .probe = probe_es7000,
20913diff --git a/arch/x86/kernel/apic/io_apic.c b/arch/x86/kernel/apic/io_apic.c
20914index 6ad4658..38a7b5c 100644
20915--- a/arch/x86/kernel/apic/io_apic.c
20916+++ b/arch/x86/kernel/apic/io_apic.c
20917@@ -1057,7 +1057,7 @@ int IO_APIC_get_PCI_irq_vector(int bus, int slot, int pin,
20918 }
20919 EXPORT_SYMBOL(IO_APIC_get_PCI_irq_vector);
20920
20921-void lock_vector_lock(void)
20922+void lock_vector_lock(void) __acquires(vector_lock)
20923 {
20924 /* Used to the online set of cpus does not change
20925 * during assign_irq_vector.
20926@@ -1065,7 +1065,7 @@ void lock_vector_lock(void)
20927 raw_spin_lock(&vector_lock);
20928 }
20929
20930-void unlock_vector_lock(void)
20931+void unlock_vector_lock(void) __releases(vector_lock)
20932 {
20933 raw_spin_unlock(&vector_lock);
20934 }
20935@@ -2364,7 +2364,7 @@ static void ack_apic_edge(struct irq_data *data)
20936 ack_APIC_irq();
20937 }
20938
20939-atomic_t irq_mis_count;
20940+atomic_unchecked_t irq_mis_count;
20941
20942 #ifdef CONFIG_GENERIC_PENDING_IRQ
20943 static bool io_apic_level_ack_pending(struct irq_cfg *cfg)
20944@@ -2505,7 +2505,7 @@ static void ack_apic_level(struct irq_data *data)
20945 * at the cpu.
20946 */
20947 if (!(v & (1 << (i & 0x1f)))) {
20948- atomic_inc(&irq_mis_count);
20949+ atomic_inc_unchecked(&irq_mis_count);
20950
20951 eoi_ioapic_irq(irq, cfg);
20952 }
20953diff --git a/arch/x86/kernel/apic/numaq_32.c b/arch/x86/kernel/apic/numaq_32.c
20954index 1e42e8f..daacf44 100644
20955--- a/arch/x86/kernel/apic/numaq_32.c
20956+++ b/arch/x86/kernel/apic/numaq_32.c
20957@@ -455,8 +455,7 @@ static void numaq_setup_portio_remap(void)
20958 (u_long) xquad_portio, (u_long) num_quads*XQUAD_PORTIO_QUAD);
20959 }
20960
20961-/* Use __refdata to keep false positive warning calm. */
20962-static struct apic __refdata apic_numaq = {
20963+static struct apic apic_numaq __read_only = {
20964
20965 .name = "NUMAQ",
20966 .probe = probe_numaq,
20967diff --git a/arch/x86/kernel/apic/probe_32.c b/arch/x86/kernel/apic/probe_32.c
20968index eb35ef9..f184a21 100644
20969--- a/arch/x86/kernel/apic/probe_32.c
20970+++ b/arch/x86/kernel/apic/probe_32.c
20971@@ -72,7 +72,7 @@ static int probe_default(void)
20972 return 1;
20973 }
20974
20975-static struct apic apic_default = {
20976+static struct apic apic_default __read_only = {
20977
20978 .name = "default",
20979 .probe = probe_default,
20980diff --git a/arch/x86/kernel/apic/summit_32.c b/arch/x86/kernel/apic/summit_32.c
20981index 00146f9..5e299b8 100644
20982--- a/arch/x86/kernel/apic/summit_32.c
20983+++ b/arch/x86/kernel/apic/summit_32.c
20984@@ -485,7 +485,7 @@ void setup_summit(void)
20985 }
20986 #endif
20987
20988-static struct apic apic_summit = {
20989+static struct apic apic_summit __read_only = {
20990
20991 .name = "summit",
20992 .probe = probe_summit,
20993diff --git a/arch/x86/kernel/apic/x2apic_cluster.c b/arch/x86/kernel/apic/x2apic_cluster.c
20994index cac85ee..01fa741 100644
20995--- a/arch/x86/kernel/apic/x2apic_cluster.c
20996+++ b/arch/x86/kernel/apic/x2apic_cluster.c
20997@@ -182,7 +182,7 @@ update_clusterinfo(struct notifier_block *nfb, unsigned long action, void *hcpu)
20998 return notifier_from_errno(err);
20999 }
21000
21001-static struct notifier_block __refdata x2apic_cpu_notifier = {
21002+static struct notifier_block x2apic_cpu_notifier = {
21003 .notifier_call = update_clusterinfo,
21004 };
21005
21006@@ -234,7 +234,7 @@ static void cluster_vector_allocation_domain(int cpu, struct cpumask *retmask,
21007 cpumask_and(retmask, mask, per_cpu(cpus_in_cluster, cpu));
21008 }
21009
21010-static struct apic apic_x2apic_cluster = {
21011+static struct apic apic_x2apic_cluster __read_only = {
21012
21013 .name = "cluster x2apic",
21014 .probe = x2apic_cluster_probe,
21015diff --git a/arch/x86/kernel/apic/x2apic_phys.c b/arch/x86/kernel/apic/x2apic_phys.c
21016index de231e3..1d1b2ee 100644
21017--- a/arch/x86/kernel/apic/x2apic_phys.c
21018+++ b/arch/x86/kernel/apic/x2apic_phys.c
21019@@ -88,7 +88,7 @@ static int x2apic_phys_probe(void)
21020 return apic == &apic_x2apic_phys;
21021 }
21022
21023-static struct apic apic_x2apic_phys = {
21024+static struct apic apic_x2apic_phys __read_only = {
21025
21026 .name = "physical x2apic",
21027 .probe = x2apic_phys_probe,
21028diff --git a/arch/x86/kernel/apic/x2apic_uv_x.c b/arch/x86/kernel/apic/x2apic_uv_x.c
21029index d263b13..963258b 100644
21030--- a/arch/x86/kernel/apic/x2apic_uv_x.c
21031+++ b/arch/x86/kernel/apic/x2apic_uv_x.c
21032@@ -350,7 +350,7 @@ static int uv_probe(void)
21033 return apic == &apic_x2apic_uv_x;
21034 }
21035
21036-static struct apic __refdata apic_x2apic_uv_x = {
21037+static struct apic apic_x2apic_uv_x __read_only = {
21038
21039 .name = "UV large system",
21040 .probe = uv_probe,
21041diff --git a/arch/x86/kernel/apm_32.c b/arch/x86/kernel/apm_32.c
21042index 3ab0343..814c4787 100644
21043--- a/arch/x86/kernel/apm_32.c
21044+++ b/arch/x86/kernel/apm_32.c
21045@@ -433,7 +433,7 @@ static DEFINE_MUTEX(apm_mutex);
21046 * This is for buggy BIOS's that refer to (real mode) segment 0x40
21047 * even though they are called in protected mode.
21048 */
21049-static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
21050+static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
21051 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
21052
21053 static const char driver_version[] = "1.16ac"; /* no spaces */
21054@@ -611,7 +611,10 @@ static long __apm_bios_call(void *_call)
21055 BUG_ON(cpu != 0);
21056 gdt = get_cpu_gdt_table(cpu);
21057 save_desc_40 = gdt[0x40 / 8];
21058+
21059+ pax_open_kernel();
21060 gdt[0x40 / 8] = bad_bios_desc;
21061+ pax_close_kernel();
21062
21063 apm_irq_save(flags);
21064 APM_DO_SAVE_SEGS;
21065@@ -620,7 +623,11 @@ static long __apm_bios_call(void *_call)
21066 &call->esi);
21067 APM_DO_RESTORE_SEGS;
21068 apm_irq_restore(flags);
21069+
21070+ pax_open_kernel();
21071 gdt[0x40 / 8] = save_desc_40;
21072+ pax_close_kernel();
21073+
21074 put_cpu();
21075
21076 return call->eax & 0xff;
21077@@ -687,7 +694,10 @@ static long __apm_bios_call_simple(void *_call)
21078 BUG_ON(cpu != 0);
21079 gdt = get_cpu_gdt_table(cpu);
21080 save_desc_40 = gdt[0x40 / 8];
21081+
21082+ pax_open_kernel();
21083 gdt[0x40 / 8] = bad_bios_desc;
21084+ pax_close_kernel();
21085
21086 apm_irq_save(flags);
21087 APM_DO_SAVE_SEGS;
21088@@ -695,7 +705,11 @@ static long __apm_bios_call_simple(void *_call)
21089 &call->eax);
21090 APM_DO_RESTORE_SEGS;
21091 apm_irq_restore(flags);
21092+
21093+ pax_open_kernel();
21094 gdt[0x40 / 8] = save_desc_40;
21095+ pax_close_kernel();
21096+
21097 put_cpu();
21098 return error;
21099 }
21100@@ -2362,12 +2376,15 @@ static int __init apm_init(void)
21101 * code to that CPU.
21102 */
21103 gdt = get_cpu_gdt_table(0);
21104+
21105+ pax_open_kernel();
21106 set_desc_base(&gdt[APM_CS >> 3],
21107 (unsigned long)__va((unsigned long)apm_info.bios.cseg << 4));
21108 set_desc_base(&gdt[APM_CS_16 >> 3],
21109 (unsigned long)__va((unsigned long)apm_info.bios.cseg_16 << 4));
21110 set_desc_base(&gdt[APM_DS >> 3],
21111 (unsigned long)__va((unsigned long)apm_info.bios.dseg << 4));
21112+ pax_close_kernel();
21113
21114 proc_create("apm", 0, NULL, &apm_file_ops);
21115
21116diff --git a/arch/x86/kernel/asm-offsets.c b/arch/x86/kernel/asm-offsets.c
21117index 9f6b934..cf5ffb3 100644
21118--- a/arch/x86/kernel/asm-offsets.c
21119+++ b/arch/x86/kernel/asm-offsets.c
21120@@ -32,6 +32,8 @@ void common(void) {
21121 OFFSET(TI_flags, thread_info, flags);
21122 OFFSET(TI_status, thread_info, status);
21123 OFFSET(TI_addr_limit, thread_info, addr_limit);
21124+ OFFSET(TI_lowest_stack, thread_info, lowest_stack);
21125+ DEFINE(TI_task_thread_sp0, offsetof(struct task_struct, thread.sp0) - offsetof(struct task_struct, tinfo));
21126
21127 BLANK();
21128 OFFSET(crypto_tfm_ctx_offset, crypto_tfm, __crt_ctx);
21129@@ -52,8 +54,26 @@ void common(void) {
21130 OFFSET(PV_CPU_irq_enable_sysexit, pv_cpu_ops, irq_enable_sysexit);
21131 OFFSET(PV_CPU_read_cr0, pv_cpu_ops, read_cr0);
21132 OFFSET(PV_MMU_read_cr2, pv_mmu_ops, read_cr2);
21133+
21134+#ifdef CONFIG_PAX_KERNEXEC
21135+ OFFSET(PV_CPU_write_cr0, pv_cpu_ops, write_cr0);
21136 #endif
21137
21138+#ifdef CONFIG_PAX_MEMORY_UDEREF
21139+ OFFSET(PV_MMU_read_cr3, pv_mmu_ops, read_cr3);
21140+ OFFSET(PV_MMU_write_cr3, pv_mmu_ops, write_cr3);
21141+#ifdef CONFIG_X86_64
21142+ OFFSET(PV_MMU_set_pgd_batched, pv_mmu_ops, set_pgd_batched);
21143+#endif
21144+#endif
21145+
21146+#endif
21147+
21148+ BLANK();
21149+ DEFINE(PAGE_SIZE_asm, PAGE_SIZE);
21150+ DEFINE(PAGE_SHIFT_asm, PAGE_SHIFT);
21151+ DEFINE(THREAD_SIZE_asm, THREAD_SIZE);
21152+
21153 #ifdef CONFIG_XEN
21154 BLANK();
21155 OFFSET(XEN_vcpu_info_mask, vcpu_info, evtchn_upcall_mask);
21156diff --git a/arch/x86/kernel/asm-offsets_64.c b/arch/x86/kernel/asm-offsets_64.c
21157index e7c798b..2b2019b 100644
21158--- a/arch/x86/kernel/asm-offsets_64.c
21159+++ b/arch/x86/kernel/asm-offsets_64.c
21160@@ -77,6 +77,7 @@ int main(void)
21161 BLANK();
21162 #undef ENTRY
21163
21164+ DEFINE(TSS_size, sizeof(struct tss_struct));
21165 OFFSET(TSS_ist, tss_struct, x86_tss.ist);
21166 BLANK();
21167
21168diff --git a/arch/x86/kernel/cpu/Makefile b/arch/x86/kernel/cpu/Makefile
21169index 7fd54f0..0691410 100644
21170--- a/arch/x86/kernel/cpu/Makefile
21171+++ b/arch/x86/kernel/cpu/Makefile
21172@@ -8,10 +8,6 @@ CFLAGS_REMOVE_common.o = -pg
21173 CFLAGS_REMOVE_perf_event.o = -pg
21174 endif
21175
21176-# Make sure load_percpu_segment has no stackprotector
21177-nostackp := $(call cc-option, -fno-stack-protector)
21178-CFLAGS_common.o := $(nostackp)
21179-
21180 obj-y := intel_cacheinfo.o scattered.o topology.o
21181 obj-y += proc.o capflags.o powerflags.o common.o
21182 obj-y += rdrand.o
21183diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c
21184index c67ffa6..f41fbbf 100644
21185--- a/arch/x86/kernel/cpu/amd.c
21186+++ b/arch/x86/kernel/cpu/amd.c
21187@@ -752,7 +752,7 @@ static void init_amd(struct cpuinfo_x86 *c)
21188 static unsigned int amd_size_cache(struct cpuinfo_x86 *c, unsigned int size)
21189 {
21190 /* AMD errata T13 (order #21922) */
21191- if ((c->x86 == 6)) {
21192+ if (c->x86 == 6) {
21193 /* Duron Rev A0 */
21194 if (c->x86_model == 3 && c->x86_mask == 0)
21195 size = 64;
21196diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
21197index 8e28bf2..bf5c0d2 100644
21198--- a/arch/x86/kernel/cpu/common.c
21199+++ b/arch/x86/kernel/cpu/common.c
21200@@ -88,60 +88,6 @@ static const struct cpu_dev default_cpu = {
21201
21202 static const struct cpu_dev *this_cpu = &default_cpu;
21203
21204-DEFINE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page) = { .gdt = {
21205-#ifdef CONFIG_X86_64
21206- /*
21207- * We need valid kernel segments for data and code in long mode too
21208- * IRET will check the segment types kkeil 2000/10/28
21209- * Also sysret mandates a special GDT layout
21210- *
21211- * TLS descriptors are currently at a different place compared to i386.
21212- * Hopefully nobody expects them at a fixed place (Wine?)
21213- */
21214- [GDT_ENTRY_KERNEL32_CS] = GDT_ENTRY_INIT(0xc09b, 0, 0xfffff),
21215- [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xa09b, 0, 0xfffff),
21216- [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc093, 0, 0xfffff),
21217- [GDT_ENTRY_DEFAULT_USER32_CS] = GDT_ENTRY_INIT(0xc0fb, 0, 0xfffff),
21218- [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f3, 0, 0xfffff),
21219- [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xa0fb, 0, 0xfffff),
21220-#else
21221- [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xc09a, 0, 0xfffff),
21222- [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
21223- [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xc0fa, 0, 0xfffff),
21224- [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f2, 0, 0xfffff),
21225- /*
21226- * Segments used for calling PnP BIOS have byte granularity.
21227- * They code segments and data segments have fixed 64k limits,
21228- * the transfer segment sizes are set at run time.
21229- */
21230- /* 32-bit code */
21231- [GDT_ENTRY_PNPBIOS_CS32] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
21232- /* 16-bit code */
21233- [GDT_ENTRY_PNPBIOS_CS16] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
21234- /* 16-bit data */
21235- [GDT_ENTRY_PNPBIOS_DS] = GDT_ENTRY_INIT(0x0092, 0, 0xffff),
21236- /* 16-bit data */
21237- [GDT_ENTRY_PNPBIOS_TS1] = GDT_ENTRY_INIT(0x0092, 0, 0),
21238- /* 16-bit data */
21239- [GDT_ENTRY_PNPBIOS_TS2] = GDT_ENTRY_INIT(0x0092, 0, 0),
21240- /*
21241- * The APM segments have byte granularity and their bases
21242- * are set at run time. All have 64k limits.
21243- */
21244- /* 32-bit code */
21245- [GDT_ENTRY_APMBIOS_BASE] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
21246- /* 16-bit code */
21247- [GDT_ENTRY_APMBIOS_BASE+1] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
21248- /* data */
21249- [GDT_ENTRY_APMBIOS_BASE+2] = GDT_ENTRY_INIT(0x4092, 0, 0xffff),
21250-
21251- [GDT_ENTRY_ESPFIX_SS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
21252- [GDT_ENTRY_PERCPU] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
21253- GDT_STACK_CANARY_INIT
21254-#endif
21255-} };
21256-EXPORT_PER_CPU_SYMBOL_GPL(gdt_page);
21257-
21258 static int __init x86_xsave_setup(char *s)
21259 {
21260 setup_clear_cpu_cap(X86_FEATURE_XSAVE);
21261@@ -293,6 +239,59 @@ static __always_inline void setup_smap(struct cpuinfo_x86 *c)
21262 }
21263 }
21264
21265+#ifdef CONFIG_X86_64
21266+static __init int setup_disable_pcid(char *arg)
21267+{
21268+ setup_clear_cpu_cap(X86_FEATURE_PCID);
21269+ setup_clear_cpu_cap(X86_FEATURE_INVPCID);
21270+
21271+#ifdef CONFIG_PAX_MEMORY_UDEREF
21272+ if (clone_pgd_mask != ~(pgdval_t)0UL)
21273+ pax_user_shadow_base = 1UL << TASK_SIZE_MAX_SHIFT;
21274+#endif
21275+
21276+ return 1;
21277+}
21278+__setup("nopcid", setup_disable_pcid);
21279+
21280+static void setup_pcid(struct cpuinfo_x86 *c)
21281+{
21282+ if (!cpu_has(c, X86_FEATURE_PCID)) {
21283+ clear_cpu_cap(c, X86_FEATURE_INVPCID);
21284+
21285+#ifdef CONFIG_PAX_MEMORY_UDEREF
21286+ if (clone_pgd_mask != ~(pgdval_t)0UL) {
21287+ pax_open_kernel();
21288+ pax_user_shadow_base = 1UL << TASK_SIZE_MAX_SHIFT;
21289+ pax_close_kernel();
21290+ printk("PAX: slow and weak UDEREF enabled\n");
21291+ } else
21292+ printk("PAX: UDEREF disabled\n");
21293+#endif
21294+
21295+ return;
21296+ }
21297+
21298+ printk("PAX: PCID detected\n");
21299+ set_in_cr4(X86_CR4_PCIDE);
21300+
21301+#ifdef CONFIG_PAX_MEMORY_UDEREF
21302+ pax_open_kernel();
21303+ clone_pgd_mask = ~(pgdval_t)0UL;
21304+ pax_close_kernel();
21305+ if (pax_user_shadow_base)
21306+ printk("PAX: weak UDEREF enabled\n");
21307+ else {
21308+ set_cpu_cap(c, X86_FEATURE_STRONGUDEREF);
21309+ printk("PAX: strong UDEREF enabled\n");
21310+ }
21311+#endif
21312+
21313+ if (cpu_has(c, X86_FEATURE_INVPCID))
21314+ printk("PAX: INVPCID detected\n");
21315+}
21316+#endif
21317+
21318 /*
21319 * Some CPU features depend on higher CPUID levels, which may not always
21320 * be available due to CPUID level capping or broken virtualization
21321@@ -393,7 +392,7 @@ void switch_to_new_gdt(int cpu)
21322 {
21323 struct desc_ptr gdt_descr;
21324
21325- gdt_descr.address = (long)get_cpu_gdt_table(cpu);
21326+ gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
21327 gdt_descr.size = GDT_SIZE - 1;
21328 load_gdt(&gdt_descr);
21329 /* Reload the per-cpu base */
21330@@ -883,6 +882,10 @@ static void identify_cpu(struct cpuinfo_x86 *c)
21331 setup_smep(c);
21332 setup_smap(c);
21333
21334+#ifdef CONFIG_X86_64
21335+ setup_pcid(c);
21336+#endif
21337+
21338 /*
21339 * The vendor-specific functions might have changed features.
21340 * Now we do "generic changes."
21341@@ -891,6 +894,10 @@ static void identify_cpu(struct cpuinfo_x86 *c)
21342 /* Filter out anything that depends on CPUID levels we don't have */
21343 filter_cpuid_features(c, true);
21344
21345+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
21346+ setup_clear_cpu_cap(X86_FEATURE_SEP);
21347+#endif
21348+
21349 /* If the model name is still unset, do table lookup. */
21350 if (!c->x86_model_id[0]) {
21351 const char *p;
21352@@ -1078,10 +1085,12 @@ static __init int setup_disablecpuid(char *arg)
21353 }
21354 __setup("clearcpuid=", setup_disablecpuid);
21355
21356+DEFINE_PER_CPU(struct thread_info *, current_tinfo) = &init_task.tinfo;
21357+EXPORT_PER_CPU_SYMBOL(current_tinfo);
21358+
21359 #ifdef CONFIG_X86_64
21360-struct desc_ptr idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
21361-struct desc_ptr debug_idt_descr = { NR_VECTORS * 16 - 1,
21362- (unsigned long) debug_idt_table };
21363+struct desc_ptr idt_descr __read_only = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
21364+const struct desc_ptr debug_idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) debug_idt_table };
21365
21366 DEFINE_PER_CPU_FIRST(union irq_stack_union,
21367 irq_stack_union) __aligned(PAGE_SIZE) __visible;
21368@@ -1095,7 +1104,7 @@ DEFINE_PER_CPU(struct task_struct *, current_task) ____cacheline_aligned =
21369 EXPORT_PER_CPU_SYMBOL(current_task);
21370
21371 DEFINE_PER_CPU(unsigned long, kernel_stack) =
21372- (unsigned long)&init_thread_union - KERNEL_STACK_OFFSET + THREAD_SIZE;
21373+ (unsigned long)&init_thread_union - 16 + THREAD_SIZE;
21374 EXPORT_PER_CPU_SYMBOL(kernel_stack);
21375
21376 DEFINE_PER_CPU(char *, irq_stack_ptr) =
21377@@ -1245,7 +1254,7 @@ void cpu_init(void)
21378 load_ucode_ap();
21379
21380 cpu = stack_smp_processor_id();
21381- t = &per_cpu(init_tss, cpu);
21382+ t = init_tss + cpu;
21383 oist = &per_cpu(orig_ist, cpu);
21384
21385 #ifdef CONFIG_NUMA
21386@@ -1280,7 +1289,6 @@ void cpu_init(void)
21387 wrmsrl(MSR_KERNEL_GS_BASE, 0);
21388 barrier();
21389
21390- x86_configure_nx();
21391 enable_x2apic();
21392
21393 /*
21394@@ -1332,7 +1340,7 @@ void cpu_init(void)
21395 {
21396 int cpu = smp_processor_id();
21397 struct task_struct *curr = current;
21398- struct tss_struct *t = &per_cpu(init_tss, cpu);
21399+ struct tss_struct *t = init_tss + cpu;
21400 struct thread_struct *thread = &curr->thread;
21401
21402 show_ucode_info_early();
21403diff --git a/arch/x86/kernel/cpu/intel_cacheinfo.c b/arch/x86/kernel/cpu/intel_cacheinfo.c
21404index 0641113..06f5ba4 100644
21405--- a/arch/x86/kernel/cpu/intel_cacheinfo.c
21406+++ b/arch/x86/kernel/cpu/intel_cacheinfo.c
21407@@ -1014,6 +1014,22 @@ static struct attribute *default_attrs[] = {
21408 };
21409
21410 #ifdef CONFIG_AMD_NB
21411+static struct attribute *default_attrs_amd_nb[] = {
21412+ &type.attr,
21413+ &level.attr,
21414+ &coherency_line_size.attr,
21415+ &physical_line_partition.attr,
21416+ &ways_of_associativity.attr,
21417+ &number_of_sets.attr,
21418+ &size.attr,
21419+ &shared_cpu_map.attr,
21420+ &shared_cpu_list.attr,
21421+ NULL,
21422+ NULL,
21423+ NULL,
21424+ NULL
21425+};
21426+
21427 static struct attribute **amd_l3_attrs(void)
21428 {
21429 static struct attribute **attrs;
21430@@ -1024,18 +1040,7 @@ static struct attribute **amd_l3_attrs(void)
21431
21432 n = ARRAY_SIZE(default_attrs);
21433
21434- if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE))
21435- n += 2;
21436-
21437- if (amd_nb_has_feature(AMD_NB_L3_PARTITIONING))
21438- n += 1;
21439-
21440- attrs = kzalloc(n * sizeof (struct attribute *), GFP_KERNEL);
21441- if (attrs == NULL)
21442- return attrs = default_attrs;
21443-
21444- for (n = 0; default_attrs[n]; n++)
21445- attrs[n] = default_attrs[n];
21446+ attrs = default_attrs_amd_nb;
21447
21448 if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE)) {
21449 attrs[n++] = &cache_disable_0.attr;
21450@@ -1086,6 +1091,13 @@ static struct kobj_type ktype_cache = {
21451 .default_attrs = default_attrs,
21452 };
21453
21454+#ifdef CONFIG_AMD_NB
21455+static struct kobj_type ktype_cache_amd_nb = {
21456+ .sysfs_ops = &sysfs_ops,
21457+ .default_attrs = default_attrs_amd_nb,
21458+};
21459+#endif
21460+
21461 static struct kobj_type ktype_percpu_entry = {
21462 .sysfs_ops = &sysfs_ops,
21463 };
21464@@ -1151,20 +1163,26 @@ static int cache_add_dev(struct device *dev)
21465 return retval;
21466 }
21467
21468+#ifdef CONFIG_AMD_NB
21469+ amd_l3_attrs();
21470+#endif
21471+
21472 for (i = 0; i < num_cache_leaves; i++) {
21473+ struct kobj_type *ktype;
21474+
21475 this_object = INDEX_KOBJECT_PTR(cpu, i);
21476 this_object->cpu = cpu;
21477 this_object->index = i;
21478
21479 this_leaf = CPUID4_INFO_IDX(cpu, i);
21480
21481- ktype_cache.default_attrs = default_attrs;
21482+ ktype = &ktype_cache;
21483 #ifdef CONFIG_AMD_NB
21484 if (this_leaf->base.nb)
21485- ktype_cache.default_attrs = amd_l3_attrs();
21486+ ktype = &ktype_cache_amd_nb;
21487 #endif
21488 retval = kobject_init_and_add(&(this_object->kobj),
21489- &ktype_cache,
21490+ ktype,
21491 per_cpu(ici_cache_kobject, cpu),
21492 "index%1lu", i);
21493 if (unlikely(retval)) {
21494diff --git a/arch/x86/kernel/cpu/mcheck/mce.c b/arch/x86/kernel/cpu/mcheck/mce.c
21495index 4d5419b..95f11bb 100644
21496--- a/arch/x86/kernel/cpu/mcheck/mce.c
21497+++ b/arch/x86/kernel/cpu/mcheck/mce.c
21498@@ -45,6 +45,7 @@
21499 #include <asm/processor.h>
21500 #include <asm/mce.h>
21501 #include <asm/msr.h>
21502+#include <asm/local.h>
21503
21504 #include "mce-internal.h"
21505
21506@@ -258,7 +259,7 @@ static void print_mce(struct mce *m)
21507 !(m->mcgstatus & MCG_STATUS_EIPV) ? " !INEXACT!" : "",
21508 m->cs, m->ip);
21509
21510- if (m->cs == __KERNEL_CS)
21511+ if (m->cs == __KERNEL_CS || m->cs == __KERNEXEC_KERNEL_CS)
21512 print_symbol("{%s}", m->ip);
21513 pr_cont("\n");
21514 }
21515@@ -291,10 +292,10 @@ static void print_mce(struct mce *m)
21516
21517 #define PANIC_TIMEOUT 5 /* 5 seconds */
21518
21519-static atomic_t mce_paniced;
21520+static atomic_unchecked_t mce_paniced;
21521
21522 static int fake_panic;
21523-static atomic_t mce_fake_paniced;
21524+static atomic_unchecked_t mce_fake_paniced;
21525
21526 /* Panic in progress. Enable interrupts and wait for final IPI */
21527 static void wait_for_panic(void)
21528@@ -318,7 +319,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
21529 /*
21530 * Make sure only one CPU runs in machine check panic
21531 */
21532- if (atomic_inc_return(&mce_paniced) > 1)
21533+ if (atomic_inc_return_unchecked(&mce_paniced) > 1)
21534 wait_for_panic();
21535 barrier();
21536
21537@@ -326,7 +327,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
21538 console_verbose();
21539 } else {
21540 /* Don't log too much for fake panic */
21541- if (atomic_inc_return(&mce_fake_paniced) > 1)
21542+ if (atomic_inc_return_unchecked(&mce_fake_paniced) > 1)
21543 return;
21544 }
21545 /* First print corrected ones that are still unlogged */
21546@@ -365,7 +366,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
21547 if (!fake_panic) {
21548 if (panic_timeout == 0)
21549 panic_timeout = mca_cfg.panic_timeout;
21550- panic(msg);
21551+ panic("%s", msg);
21552 } else
21553 pr_emerg(HW_ERR "Fake kernel panic: %s\n", msg);
21554 }
21555@@ -695,7 +696,7 @@ static int mce_timed_out(u64 *t)
21556 * might have been modified by someone else.
21557 */
21558 rmb();
21559- if (atomic_read(&mce_paniced))
21560+ if (atomic_read_unchecked(&mce_paniced))
21561 wait_for_panic();
21562 if (!mca_cfg.monarch_timeout)
21563 goto out;
21564@@ -1666,7 +1667,7 @@ static void unexpected_machine_check(struct pt_regs *regs, long error_code)
21565 }
21566
21567 /* Call the installed machine check handler for this CPU setup. */
21568-void (*machine_check_vector)(struct pt_regs *, long error_code) =
21569+void (*machine_check_vector)(struct pt_regs *, long error_code) __read_only =
21570 unexpected_machine_check;
21571
21572 /*
21573@@ -1689,7 +1690,9 @@ void mcheck_cpu_init(struct cpuinfo_x86 *c)
21574 return;
21575 }
21576
21577+ pax_open_kernel();
21578 machine_check_vector = do_machine_check;
21579+ pax_close_kernel();
21580
21581 __mcheck_cpu_init_generic();
21582 __mcheck_cpu_init_vendor(c);
21583@@ -1703,7 +1706,7 @@ void mcheck_cpu_init(struct cpuinfo_x86 *c)
21584 */
21585
21586 static DEFINE_SPINLOCK(mce_chrdev_state_lock);
21587-static int mce_chrdev_open_count; /* #times opened */
21588+static local_t mce_chrdev_open_count; /* #times opened */
21589 static int mce_chrdev_open_exclu; /* already open exclusive? */
21590
21591 static int mce_chrdev_open(struct inode *inode, struct file *file)
21592@@ -1711,7 +1714,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
21593 spin_lock(&mce_chrdev_state_lock);
21594
21595 if (mce_chrdev_open_exclu ||
21596- (mce_chrdev_open_count && (file->f_flags & O_EXCL))) {
21597+ (local_read(&mce_chrdev_open_count) && (file->f_flags & O_EXCL))) {
21598 spin_unlock(&mce_chrdev_state_lock);
21599
21600 return -EBUSY;
21601@@ -1719,7 +1722,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
21602
21603 if (file->f_flags & O_EXCL)
21604 mce_chrdev_open_exclu = 1;
21605- mce_chrdev_open_count++;
21606+ local_inc(&mce_chrdev_open_count);
21607
21608 spin_unlock(&mce_chrdev_state_lock);
21609
21610@@ -1730,7 +1733,7 @@ static int mce_chrdev_release(struct inode *inode, struct file *file)
21611 {
21612 spin_lock(&mce_chrdev_state_lock);
21613
21614- mce_chrdev_open_count--;
21615+ local_dec(&mce_chrdev_open_count);
21616 mce_chrdev_open_exclu = 0;
21617
21618 spin_unlock(&mce_chrdev_state_lock);
21619@@ -2406,7 +2409,7 @@ static __init void mce_init_banks(void)
21620
21621 for (i = 0; i < mca_cfg.banks; i++) {
21622 struct mce_bank *b = &mce_banks[i];
21623- struct device_attribute *a = &b->attr;
21624+ device_attribute_no_const *a = &b->attr;
21625
21626 sysfs_attr_init(&a->attr);
21627 a->attr.name = b->attrname;
21628@@ -2474,7 +2477,7 @@ struct dentry *mce_get_debugfs_dir(void)
21629 static void mce_reset(void)
21630 {
21631 cpu_missing = 0;
21632- atomic_set(&mce_fake_paniced, 0);
21633+ atomic_set_unchecked(&mce_fake_paniced, 0);
21634 atomic_set(&mce_executing, 0);
21635 atomic_set(&mce_callin, 0);
21636 atomic_set(&global_nwo, 0);
21637diff --git a/arch/x86/kernel/cpu/mcheck/p5.c b/arch/x86/kernel/cpu/mcheck/p5.c
21638index a304298..49b6d06 100644
21639--- a/arch/x86/kernel/cpu/mcheck/p5.c
21640+++ b/arch/x86/kernel/cpu/mcheck/p5.c
21641@@ -10,6 +10,7 @@
21642 #include <asm/processor.h>
21643 #include <asm/mce.h>
21644 #include <asm/msr.h>
21645+#include <asm/pgtable.h>
21646
21647 /* By default disabled */
21648 int mce_p5_enabled __read_mostly;
21649@@ -48,7 +49,9 @@ void intel_p5_mcheck_init(struct cpuinfo_x86 *c)
21650 if (!cpu_has(c, X86_FEATURE_MCE))
21651 return;
21652
21653+ pax_open_kernel();
21654 machine_check_vector = pentium_machine_check;
21655+ pax_close_kernel();
21656 /* Make sure the vector pointer is visible before we enable MCEs: */
21657 wmb();
21658
21659diff --git a/arch/x86/kernel/cpu/mcheck/winchip.c b/arch/x86/kernel/cpu/mcheck/winchip.c
21660index 7dc5564..1273569 100644
21661--- a/arch/x86/kernel/cpu/mcheck/winchip.c
21662+++ b/arch/x86/kernel/cpu/mcheck/winchip.c
21663@@ -9,6 +9,7 @@
21664 #include <asm/processor.h>
21665 #include <asm/mce.h>
21666 #include <asm/msr.h>
21667+#include <asm/pgtable.h>
21668
21669 /* Machine check handler for WinChip C6: */
21670 static void winchip_machine_check(struct pt_regs *regs, long error_code)
21671@@ -22,7 +23,9 @@ void winchip_mcheck_init(struct cpuinfo_x86 *c)
21672 {
21673 u32 lo, hi;
21674
21675+ pax_open_kernel();
21676 machine_check_vector = winchip_machine_check;
21677+ pax_close_kernel();
21678 /* Make sure the vector pointer is visible before we enable MCEs: */
21679 wmb();
21680
21681diff --git a/arch/x86/kernel/cpu/microcode/core.c b/arch/x86/kernel/cpu/microcode/core.c
21682index 15c9876..0a43909 100644
21683--- a/arch/x86/kernel/cpu/microcode/core.c
21684+++ b/arch/x86/kernel/cpu/microcode/core.c
21685@@ -513,7 +513,7 @@ mc_cpu_callback(struct notifier_block *nb, unsigned long action, void *hcpu)
21686 return NOTIFY_OK;
21687 }
21688
21689-static struct notifier_block __refdata mc_cpu_notifier = {
21690+static struct notifier_block mc_cpu_notifier = {
21691 .notifier_call = mc_cpu_callback,
21692 };
21693
21694diff --git a/arch/x86/kernel/cpu/microcode/intel.c b/arch/x86/kernel/cpu/microcode/intel.c
21695index a276fa7..e66810f 100644
21696--- a/arch/x86/kernel/cpu/microcode/intel.c
21697+++ b/arch/x86/kernel/cpu/microcode/intel.c
21698@@ -293,13 +293,13 @@ static enum ucode_state request_microcode_fw(int cpu, struct device *device,
21699
21700 static int get_ucode_user(void *to, const void *from, size_t n)
21701 {
21702- return copy_from_user(to, from, n);
21703+ return copy_from_user(to, (const void __force_user *)from, n);
21704 }
21705
21706 static enum ucode_state
21707 request_microcode_user(int cpu, const void __user *buf, size_t size)
21708 {
21709- return generic_load_microcode(cpu, (void *)buf, size, &get_ucode_user);
21710+ return generic_load_microcode(cpu, (__force_kernel void *)buf, size, &get_ucode_user);
21711 }
21712
21713 static void microcode_fini_cpu(int cpu)
21714diff --git a/arch/x86/kernel/cpu/mtrr/main.c b/arch/x86/kernel/cpu/mtrr/main.c
21715index f961de9..8a9d332 100644
21716--- a/arch/x86/kernel/cpu/mtrr/main.c
21717+++ b/arch/x86/kernel/cpu/mtrr/main.c
21718@@ -66,7 +66,7 @@ static DEFINE_MUTEX(mtrr_mutex);
21719 u64 size_or_mask, size_and_mask;
21720 static bool mtrr_aps_delayed_init;
21721
21722-static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM];
21723+static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM] __read_only;
21724
21725 const struct mtrr_ops *mtrr_if;
21726
21727diff --git a/arch/x86/kernel/cpu/mtrr/mtrr.h b/arch/x86/kernel/cpu/mtrr/mtrr.h
21728index df5e41f..816c719 100644
21729--- a/arch/x86/kernel/cpu/mtrr/mtrr.h
21730+++ b/arch/x86/kernel/cpu/mtrr/mtrr.h
21731@@ -25,7 +25,7 @@ struct mtrr_ops {
21732 int (*validate_add_page)(unsigned long base, unsigned long size,
21733 unsigned int type);
21734 int (*have_wrcomb)(void);
21735-};
21736+} __do_const;
21737
21738 extern int generic_get_free_region(unsigned long base, unsigned long size,
21739 int replace_reg);
21740diff --git a/arch/x86/kernel/cpu/perf_event.c b/arch/x86/kernel/cpu/perf_event.c
21741index 79f9f84..38ace52 100644
21742--- a/arch/x86/kernel/cpu/perf_event.c
21743+++ b/arch/x86/kernel/cpu/perf_event.c
21744@@ -1351,7 +1351,7 @@ static void __init pmu_check_apic(void)
21745 pr_info("no hardware sampling interrupt available.\n");
21746 }
21747
21748-static struct attribute_group x86_pmu_format_group = {
21749+static attribute_group_no_const x86_pmu_format_group = {
21750 .name = "format",
21751 .attrs = NULL,
21752 };
21753@@ -1450,7 +1450,7 @@ static struct attribute *events_attr[] = {
21754 NULL,
21755 };
21756
21757-static struct attribute_group x86_pmu_events_group = {
21758+static attribute_group_no_const x86_pmu_events_group = {
21759 .name = "events",
21760 .attrs = events_attr,
21761 };
21762@@ -1971,7 +1971,7 @@ static unsigned long get_segment_base(unsigned int segment)
21763 if (idx > GDT_ENTRIES)
21764 return 0;
21765
21766- desc = __this_cpu_ptr(&gdt_page.gdt[0]);
21767+ desc = get_cpu_gdt_table(smp_processor_id());
21768 }
21769
21770 return get_desc_base(desc + idx);
21771@@ -2061,7 +2061,7 @@ perf_callchain_user(struct perf_callchain_entry *entry, struct pt_regs *regs)
21772 break;
21773
21774 perf_callchain_store(entry, frame.return_address);
21775- fp = frame.next_frame;
21776+ fp = (const void __force_user *)frame.next_frame;
21777 }
21778 }
21779
21780diff --git a/arch/x86/kernel/cpu/perf_event_amd_iommu.c b/arch/x86/kernel/cpu/perf_event_amd_iommu.c
21781index 639d128..e92d7e5 100644
21782--- a/arch/x86/kernel/cpu/perf_event_amd_iommu.c
21783+++ b/arch/x86/kernel/cpu/perf_event_amd_iommu.c
21784@@ -405,7 +405,7 @@ static void perf_iommu_del(struct perf_event *event, int flags)
21785 static __init int _init_events_attrs(struct perf_amd_iommu *perf_iommu)
21786 {
21787 struct attribute **attrs;
21788- struct attribute_group *attr_group;
21789+ attribute_group_no_const *attr_group;
21790 int i = 0, j;
21791
21792 while (amd_iommu_v2_event_descs[i].attr.attr.name)
21793diff --git a/arch/x86/kernel/cpu/perf_event_intel.c b/arch/x86/kernel/cpu/perf_event_intel.c
21794index aa333d9..f9db700 100644
21795--- a/arch/x86/kernel/cpu/perf_event_intel.c
21796+++ b/arch/x86/kernel/cpu/perf_event_intel.c
21797@@ -2309,10 +2309,10 @@ __init int intel_pmu_init(void)
21798 x86_pmu.num_counters_fixed = max((int)edx.split.num_counters_fixed, 3);
21799
21800 if (boot_cpu_has(X86_FEATURE_PDCM)) {
21801- u64 capabilities;
21802+ u64 capabilities = x86_pmu.intel_cap.capabilities;
21803
21804- rdmsrl(MSR_IA32_PERF_CAPABILITIES, capabilities);
21805- x86_pmu.intel_cap.capabilities = capabilities;
21806+ if (rdmsrl_safe(MSR_IA32_PERF_CAPABILITIES, &x86_pmu.intel_cap.capabilities))
21807+ x86_pmu.intel_cap.capabilities = capabilities;
21808 }
21809
21810 intel_ds_init();
21811diff --git a/arch/x86/kernel/cpu/perf_event_intel_rapl.c b/arch/x86/kernel/cpu/perf_event_intel_rapl.c
21812index 5ad35ad..e0a3960 100644
21813--- a/arch/x86/kernel/cpu/perf_event_intel_rapl.c
21814+++ b/arch/x86/kernel/cpu/perf_event_intel_rapl.c
21815@@ -425,7 +425,7 @@ static struct attribute *rapl_events_cln_attr[] = {
21816 NULL,
21817 };
21818
21819-static struct attribute_group rapl_pmu_events_group = {
21820+static attribute_group_no_const rapl_pmu_events_group __read_only = {
21821 .name = "events",
21822 .attrs = NULL, /* patched at runtime */
21823 };
21824diff --git a/arch/x86/kernel/cpu/perf_event_intel_uncore.c b/arch/x86/kernel/cpu/perf_event_intel_uncore.c
21825index 047f540..afdeba0 100644
21826--- a/arch/x86/kernel/cpu/perf_event_intel_uncore.c
21827+++ b/arch/x86/kernel/cpu/perf_event_intel_uncore.c
21828@@ -3326,7 +3326,7 @@ static void __init uncore_types_exit(struct intel_uncore_type **types)
21829 static int __init uncore_type_init(struct intel_uncore_type *type)
21830 {
21831 struct intel_uncore_pmu *pmus;
21832- struct attribute_group *attr_group;
21833+ attribute_group_no_const *attr_group;
21834 struct attribute **attrs;
21835 int i, j;
21836
21837diff --git a/arch/x86/kernel/cpu/perf_event_intel_uncore.h b/arch/x86/kernel/cpu/perf_event_intel_uncore.h
21838index a80ab71..4089da5 100644
21839--- a/arch/x86/kernel/cpu/perf_event_intel_uncore.h
21840+++ b/arch/x86/kernel/cpu/perf_event_intel_uncore.h
21841@@ -498,7 +498,7 @@ struct intel_uncore_box {
21842 struct uncore_event_desc {
21843 struct kobj_attribute attr;
21844 const char *config;
21845-};
21846+} __do_const;
21847
21848 #define INTEL_UNCORE_EVENT_DESC(_name, _config) \
21849 { \
21850diff --git a/arch/x86/kernel/cpuid.c b/arch/x86/kernel/cpuid.c
21851index 7d9481c..99c7e4b 100644
21852--- a/arch/x86/kernel/cpuid.c
21853+++ b/arch/x86/kernel/cpuid.c
21854@@ -170,7 +170,7 @@ static int cpuid_class_cpu_callback(struct notifier_block *nfb,
21855 return notifier_from_errno(err);
21856 }
21857
21858-static struct notifier_block __refdata cpuid_class_cpu_notifier =
21859+static struct notifier_block cpuid_class_cpu_notifier =
21860 {
21861 .notifier_call = cpuid_class_cpu_callback,
21862 };
21863diff --git a/arch/x86/kernel/crash.c b/arch/x86/kernel/crash.c
21864index a57902e..ebaae2a 100644
21865--- a/arch/x86/kernel/crash.c
21866+++ b/arch/x86/kernel/crash.c
21867@@ -57,10 +57,8 @@ static void kdump_nmi_callback(int cpu, struct pt_regs *regs)
21868 {
21869 #ifdef CONFIG_X86_32
21870 struct pt_regs fixed_regs;
21871-#endif
21872
21873-#ifdef CONFIG_X86_32
21874- if (!user_mode_vm(regs)) {
21875+ if (!user_mode(regs)) {
21876 crash_fixup_ss_esp(&fixed_regs, regs);
21877 regs = &fixed_regs;
21878 }
21879diff --git a/arch/x86/kernel/crash_dump_64.c b/arch/x86/kernel/crash_dump_64.c
21880index afa64ad..dce67dd 100644
21881--- a/arch/x86/kernel/crash_dump_64.c
21882+++ b/arch/x86/kernel/crash_dump_64.c
21883@@ -36,7 +36,7 @@ ssize_t copy_oldmem_page(unsigned long pfn, char *buf,
21884 return -ENOMEM;
21885
21886 if (userbuf) {
21887- if (copy_to_user(buf, vaddr + offset, csize)) {
21888+ if (copy_to_user((char __force_user *)buf, vaddr + offset, csize)) {
21889 iounmap(vaddr);
21890 return -EFAULT;
21891 }
21892diff --git a/arch/x86/kernel/doublefault.c b/arch/x86/kernel/doublefault.c
21893index f6dfd93..892ade4 100644
21894--- a/arch/x86/kernel/doublefault.c
21895+++ b/arch/x86/kernel/doublefault.c
21896@@ -12,7 +12,7 @@
21897
21898 #define DOUBLEFAULT_STACKSIZE (1024)
21899 static unsigned long doublefault_stack[DOUBLEFAULT_STACKSIZE];
21900-#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE)
21901+#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE-2)
21902
21903 #define ptr_ok(x) ((x) > PAGE_OFFSET && (x) < PAGE_OFFSET + MAXMEM)
21904
21905@@ -22,7 +22,7 @@ static void doublefault_fn(void)
21906 unsigned long gdt, tss;
21907
21908 native_store_gdt(&gdt_desc);
21909- gdt = gdt_desc.address;
21910+ gdt = (unsigned long)gdt_desc.address;
21911
21912 printk(KERN_EMERG "PANIC: double fault, gdt at %08lx [%d bytes]\n", gdt, gdt_desc.size);
21913
21914@@ -59,10 +59,10 @@ struct tss_struct doublefault_tss __cacheline_aligned = {
21915 /* 0x2 bit is always set */
21916 .flags = X86_EFLAGS_SF | 0x2,
21917 .sp = STACK_START,
21918- .es = __USER_DS,
21919+ .es = __KERNEL_DS,
21920 .cs = __KERNEL_CS,
21921 .ss = __KERNEL_DS,
21922- .ds = __USER_DS,
21923+ .ds = __KERNEL_DS,
21924 .fs = __KERNEL_PERCPU,
21925
21926 .__cr3 = __pa_nodebug(swapper_pg_dir),
21927diff --git a/arch/x86/kernel/dumpstack.c b/arch/x86/kernel/dumpstack.c
21928index d9c12d3..7858b62 100644
21929--- a/arch/x86/kernel/dumpstack.c
21930+++ b/arch/x86/kernel/dumpstack.c
21931@@ -2,6 +2,9 @@
21932 * Copyright (C) 1991, 1992 Linus Torvalds
21933 * Copyright (C) 2000, 2001, 2002 Andi Kleen, SuSE Labs
21934 */
21935+#ifdef CONFIG_GRKERNSEC_HIDESYM
21936+#define __INCLUDED_BY_HIDESYM 1
21937+#endif
21938 #include <linux/kallsyms.h>
21939 #include <linux/kprobes.h>
21940 #include <linux/uaccess.h>
21941@@ -40,16 +43,14 @@ void printk_address(unsigned long address)
21942 static void
21943 print_ftrace_graph_addr(unsigned long addr, void *data,
21944 const struct stacktrace_ops *ops,
21945- struct thread_info *tinfo, int *graph)
21946+ struct task_struct *task, int *graph)
21947 {
21948- struct task_struct *task;
21949 unsigned long ret_addr;
21950 int index;
21951
21952 if (addr != (unsigned long)return_to_handler)
21953 return;
21954
21955- task = tinfo->task;
21956 index = task->curr_ret_stack;
21957
21958 if (!task->ret_stack || index < *graph)
21959@@ -66,7 +67,7 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
21960 static inline void
21961 print_ftrace_graph_addr(unsigned long addr, void *data,
21962 const struct stacktrace_ops *ops,
21963- struct thread_info *tinfo, int *graph)
21964+ struct task_struct *task, int *graph)
21965 { }
21966 #endif
21967
21968@@ -77,10 +78,8 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
21969 * severe exception (double fault, nmi, stack fault, debug, mce) hardware stack
21970 */
21971
21972-static inline int valid_stack_ptr(struct thread_info *tinfo,
21973- void *p, unsigned int size, void *end)
21974+static inline int valid_stack_ptr(void *t, void *p, unsigned int size, void *end)
21975 {
21976- void *t = tinfo;
21977 if (end) {
21978 if (p < end && p >= (end-THREAD_SIZE))
21979 return 1;
21980@@ -91,14 +90,14 @@ static inline int valid_stack_ptr(struct thread_info *tinfo,
21981 }
21982
21983 unsigned long
21984-print_context_stack(struct thread_info *tinfo,
21985+print_context_stack(struct task_struct *task, void *stack_start,
21986 unsigned long *stack, unsigned long bp,
21987 const struct stacktrace_ops *ops, void *data,
21988 unsigned long *end, int *graph)
21989 {
21990 struct stack_frame *frame = (struct stack_frame *)bp;
21991
21992- while (valid_stack_ptr(tinfo, stack, sizeof(*stack), end)) {
21993+ while (valid_stack_ptr(stack_start, stack, sizeof(*stack), end)) {
21994 unsigned long addr;
21995
21996 addr = *stack;
21997@@ -110,7 +109,7 @@ print_context_stack(struct thread_info *tinfo,
21998 } else {
21999 ops->address(data, addr, 0);
22000 }
22001- print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
22002+ print_ftrace_graph_addr(addr, data, ops, task, graph);
22003 }
22004 stack++;
22005 }
22006@@ -119,7 +118,7 @@ print_context_stack(struct thread_info *tinfo,
22007 EXPORT_SYMBOL_GPL(print_context_stack);
22008
22009 unsigned long
22010-print_context_stack_bp(struct thread_info *tinfo,
22011+print_context_stack_bp(struct task_struct *task, void *stack_start,
22012 unsigned long *stack, unsigned long bp,
22013 const struct stacktrace_ops *ops, void *data,
22014 unsigned long *end, int *graph)
22015@@ -127,7 +126,7 @@ print_context_stack_bp(struct thread_info *tinfo,
22016 struct stack_frame *frame = (struct stack_frame *)bp;
22017 unsigned long *ret_addr = &frame->return_address;
22018
22019- while (valid_stack_ptr(tinfo, ret_addr, sizeof(*ret_addr), end)) {
22020+ while (valid_stack_ptr(stack_start, ret_addr, sizeof(*ret_addr), end)) {
22021 unsigned long addr = *ret_addr;
22022
22023 if (!__kernel_text_address(addr))
22024@@ -136,7 +135,7 @@ print_context_stack_bp(struct thread_info *tinfo,
22025 ops->address(data, addr, 1);
22026 frame = frame->next_frame;
22027 ret_addr = &frame->return_address;
22028- print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
22029+ print_ftrace_graph_addr(addr, data, ops, task, graph);
22030 }
22031
22032 return (unsigned long)frame;
22033@@ -155,7 +154,7 @@ static int print_trace_stack(void *data, char *name)
22034 static void print_trace_address(void *data, unsigned long addr, int reliable)
22035 {
22036 touch_nmi_watchdog();
22037- printk(data);
22038+ printk("%s", (char *)data);
22039 printk_stack_address(addr, reliable);
22040 }
22041
22042@@ -224,6 +223,8 @@ unsigned __kprobes long oops_begin(void)
22043 }
22044 EXPORT_SYMBOL_GPL(oops_begin);
22045
22046+extern void gr_handle_kernel_exploit(void);
22047+
22048 void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
22049 {
22050 if (regs && kexec_should_crash(current))
22051@@ -245,7 +246,10 @@ void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
22052 panic("Fatal exception in interrupt");
22053 if (panic_on_oops)
22054 panic("Fatal exception");
22055- do_exit(signr);
22056+
22057+ gr_handle_kernel_exploit();
22058+
22059+ do_group_exit(signr);
22060 }
22061
22062 int __kprobes __die(const char *str, struct pt_regs *regs, long err)
22063@@ -273,7 +277,7 @@ int __kprobes __die(const char *str, struct pt_regs *regs, long err)
22064 print_modules();
22065 show_regs(regs);
22066 #ifdef CONFIG_X86_32
22067- if (user_mode_vm(regs)) {
22068+ if (user_mode(regs)) {
22069 sp = regs->sp;
22070 ss = regs->ss & 0xffff;
22071 } else {
22072@@ -301,7 +305,7 @@ void die(const char *str, struct pt_regs *regs, long err)
22073 unsigned long flags = oops_begin();
22074 int sig = SIGSEGV;
22075
22076- if (!user_mode_vm(regs))
22077+ if (!user_mode(regs))
22078 report_bug(regs->ip, regs);
22079
22080 if (__die(str, regs, err))
22081diff --git a/arch/x86/kernel/dumpstack_32.c b/arch/x86/kernel/dumpstack_32.c
22082index f2a1770..10fa52d 100644
22083--- a/arch/x86/kernel/dumpstack_32.c
22084+++ b/arch/x86/kernel/dumpstack_32.c
22085@@ -38,15 +38,13 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
22086 bp = stack_frame(task, regs);
22087
22088 for (;;) {
22089- struct thread_info *context;
22090+ void *stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
22091
22092- context = (struct thread_info *)
22093- ((unsigned long)stack & (~(THREAD_SIZE - 1)));
22094- bp = ops->walk_stack(context, stack, bp, ops, data, NULL, &graph);
22095+ bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
22096
22097- stack = (unsigned long *)context->previous_esp;
22098- if (!stack)
22099+ if (stack_start == task_stack_page(task))
22100 break;
22101+ stack = *(unsigned long **)stack_start;
22102 if (ops->stack(data, "IRQ") < 0)
22103 break;
22104 touch_nmi_watchdog();
22105@@ -87,27 +85,28 @@ void show_regs(struct pt_regs *regs)
22106 int i;
22107
22108 show_regs_print_info(KERN_EMERG);
22109- __show_regs(regs, !user_mode_vm(regs));
22110+ __show_regs(regs, !user_mode(regs));
22111
22112 /*
22113 * When in-kernel, we also print out the stack and code at the
22114 * time of the fault..
22115 */
22116- if (!user_mode_vm(regs)) {
22117+ if (!user_mode(regs)) {
22118 unsigned int code_prologue = code_bytes * 43 / 64;
22119 unsigned int code_len = code_bytes;
22120 unsigned char c;
22121 u8 *ip;
22122+ unsigned long cs_base = get_desc_base(&get_cpu_gdt_table(0)[(0xffff & regs->cs) >> 3]);
22123
22124 pr_emerg("Stack:\n");
22125 show_stack_log_lvl(NULL, regs, &regs->sp, 0, KERN_EMERG);
22126
22127 pr_emerg("Code:");
22128
22129- ip = (u8 *)regs->ip - code_prologue;
22130+ ip = (u8 *)regs->ip - code_prologue + cs_base;
22131 if (ip < (u8 *)PAGE_OFFSET || probe_kernel_address(ip, c)) {
22132 /* try starting at IP */
22133- ip = (u8 *)regs->ip;
22134+ ip = (u8 *)regs->ip + cs_base;
22135 code_len = code_len - code_prologue + 1;
22136 }
22137 for (i = 0; i < code_len; i++, ip++) {
22138@@ -116,7 +115,7 @@ void show_regs(struct pt_regs *regs)
22139 pr_cont(" Bad EIP value.");
22140 break;
22141 }
22142- if (ip == (u8 *)regs->ip)
22143+ if (ip == (u8 *)regs->ip + cs_base)
22144 pr_cont(" <%02x>", c);
22145 else
22146 pr_cont(" %02x", c);
22147@@ -129,6 +128,7 @@ int is_valid_bugaddr(unsigned long ip)
22148 {
22149 unsigned short ud2;
22150
22151+ ip = ktla_ktva(ip);
22152 if (ip < PAGE_OFFSET)
22153 return 0;
22154 if (probe_kernel_address((unsigned short *)ip, ud2))
22155@@ -136,3 +136,15 @@ int is_valid_bugaddr(unsigned long ip)
22156
22157 return ud2 == 0x0b0f;
22158 }
22159+
22160+#if defined(CONFIG_PAX_MEMORY_STACKLEAK) || defined(CONFIG_PAX_USERCOPY)
22161+void pax_check_alloca(unsigned long size)
22162+{
22163+ unsigned long sp = (unsigned long)&sp, stack_left;
22164+
22165+ /* all kernel stacks are of the same size */
22166+ stack_left = sp & (THREAD_SIZE - 1);
22167+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
22168+}
22169+EXPORT_SYMBOL(pax_check_alloca);
22170+#endif
22171diff --git a/arch/x86/kernel/dumpstack_64.c b/arch/x86/kernel/dumpstack_64.c
22172index addb207..921706b 100644
22173--- a/arch/x86/kernel/dumpstack_64.c
22174+++ b/arch/x86/kernel/dumpstack_64.c
22175@@ -119,9 +119,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
22176 unsigned long *irq_stack_end =
22177 (unsigned long *)per_cpu(irq_stack_ptr, cpu);
22178 unsigned used = 0;
22179- struct thread_info *tinfo;
22180 int graph = 0;
22181 unsigned long dummy;
22182+ void *stack_start;
22183
22184 if (!task)
22185 task = current;
22186@@ -142,10 +142,10 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
22187 * current stack address. If the stacks consist of nested
22188 * exceptions
22189 */
22190- tinfo = task_thread_info(task);
22191 for (;;) {
22192 char *id;
22193 unsigned long *estack_end;
22194+
22195 estack_end = in_exception_stack(cpu, (unsigned long)stack,
22196 &used, &id);
22197
22198@@ -153,7 +153,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
22199 if (ops->stack(data, id) < 0)
22200 break;
22201
22202- bp = ops->walk_stack(tinfo, stack, bp, ops,
22203+ bp = ops->walk_stack(task, estack_end - EXCEPTION_STKSZ, stack, bp, ops,
22204 data, estack_end, &graph);
22205 ops->stack(data, "<EOE>");
22206 /*
22207@@ -161,6 +161,8 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
22208 * second-to-last pointer (index -2 to end) in the
22209 * exception stack:
22210 */
22211+ if ((u16)estack_end[-1] != __KERNEL_DS)
22212+ goto out;
22213 stack = (unsigned long *) estack_end[-2];
22214 continue;
22215 }
22216@@ -172,7 +174,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
22217 if (in_irq_stack(stack, irq_stack, irq_stack_end)) {
22218 if (ops->stack(data, "IRQ") < 0)
22219 break;
22220- bp = ops->walk_stack(tinfo, stack, bp,
22221+ bp = ops->walk_stack(task, irq_stack, stack, bp,
22222 ops, data, irq_stack_end, &graph);
22223 /*
22224 * We link to the next stack (which would be
22225@@ -191,7 +193,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
22226 /*
22227 * This handles the process stack:
22228 */
22229- bp = ops->walk_stack(tinfo, stack, bp, ops, data, NULL, &graph);
22230+ stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
22231+ bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
22232+out:
22233 put_cpu();
22234 }
22235 EXPORT_SYMBOL(dump_trace);
22236@@ -300,3 +304,50 @@ int is_valid_bugaddr(unsigned long ip)
22237
22238 return ud2 == 0x0b0f;
22239 }
22240+
22241+#if defined(CONFIG_PAX_MEMORY_STACKLEAK) || defined(CONFIG_PAX_USERCOPY)
22242+void pax_check_alloca(unsigned long size)
22243+{
22244+ unsigned long sp = (unsigned long)&sp, stack_start, stack_end;
22245+ unsigned cpu, used;
22246+ char *id;
22247+
22248+ /* check the process stack first */
22249+ stack_start = (unsigned long)task_stack_page(current);
22250+ stack_end = stack_start + THREAD_SIZE;
22251+ if (likely(stack_start <= sp && sp < stack_end)) {
22252+ unsigned long stack_left = sp & (THREAD_SIZE - 1);
22253+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
22254+ return;
22255+ }
22256+
22257+ cpu = get_cpu();
22258+
22259+ /* check the irq stacks */
22260+ stack_end = (unsigned long)per_cpu(irq_stack_ptr, cpu);
22261+ stack_start = stack_end - IRQ_STACK_SIZE;
22262+ if (stack_start <= sp && sp < stack_end) {
22263+ unsigned long stack_left = sp & (IRQ_STACK_SIZE - 1);
22264+ put_cpu();
22265+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
22266+ return;
22267+ }
22268+
22269+ /* check the exception stacks */
22270+ used = 0;
22271+ stack_end = (unsigned long)in_exception_stack(cpu, sp, &used, &id);
22272+ stack_start = stack_end - EXCEPTION_STKSZ;
22273+ if (stack_end && stack_start <= sp && sp < stack_end) {
22274+ unsigned long stack_left = sp & (EXCEPTION_STKSZ - 1);
22275+ put_cpu();
22276+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
22277+ return;
22278+ }
22279+
22280+ put_cpu();
22281+
22282+ /* unknown stack */
22283+ BUG();
22284+}
22285+EXPORT_SYMBOL(pax_check_alloca);
22286+#endif
22287diff --git a/arch/x86/kernel/e820.c b/arch/x86/kernel/e820.c
22288index 988c00a..4f673b6 100644
22289--- a/arch/x86/kernel/e820.c
22290+++ b/arch/x86/kernel/e820.c
22291@@ -803,8 +803,8 @@ unsigned long __init e820_end_of_low_ram_pfn(void)
22292
22293 static void early_panic(char *msg)
22294 {
22295- early_printk(msg);
22296- panic(msg);
22297+ early_printk("%s", msg);
22298+ panic("%s", msg);
22299 }
22300
22301 static int userdef __initdata;
22302diff --git a/arch/x86/kernel/early_printk.c b/arch/x86/kernel/early_printk.c
22303index 01d1c18..8073693 100644
22304--- a/arch/x86/kernel/early_printk.c
22305+++ b/arch/x86/kernel/early_printk.c
22306@@ -7,6 +7,7 @@
22307 #include <linux/pci_regs.h>
22308 #include <linux/pci_ids.h>
22309 #include <linux/errno.h>
22310+#include <linux/sched.h>
22311 #include <asm/io.h>
22312 #include <asm/processor.h>
22313 #include <asm/fcntl.h>
22314diff --git a/arch/x86/kernel/entry_32.S b/arch/x86/kernel/entry_32.S
22315index a2a4f46..6cab058 100644
22316--- a/arch/x86/kernel/entry_32.S
22317+++ b/arch/x86/kernel/entry_32.S
22318@@ -177,13 +177,153 @@
22319 /*CFI_REL_OFFSET gs, PT_GS*/
22320 .endm
22321 .macro SET_KERNEL_GS reg
22322+
22323+#ifdef CONFIG_CC_STACKPROTECTOR
22324 movl $(__KERNEL_STACK_CANARY), \reg
22325+#elif defined(CONFIG_PAX_MEMORY_UDEREF)
22326+ movl $(__USER_DS), \reg
22327+#else
22328+ xorl \reg, \reg
22329+#endif
22330+
22331 movl \reg, %gs
22332 .endm
22333
22334 #endif /* CONFIG_X86_32_LAZY_GS */
22335
22336-.macro SAVE_ALL
22337+.macro pax_enter_kernel
22338+#ifdef CONFIG_PAX_KERNEXEC
22339+ call pax_enter_kernel
22340+#endif
22341+.endm
22342+
22343+.macro pax_exit_kernel
22344+#ifdef CONFIG_PAX_KERNEXEC
22345+ call pax_exit_kernel
22346+#endif
22347+.endm
22348+
22349+#ifdef CONFIG_PAX_KERNEXEC
22350+ENTRY(pax_enter_kernel)
22351+#ifdef CONFIG_PARAVIRT
22352+ pushl %eax
22353+ pushl %ecx
22354+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0)
22355+ mov %eax, %esi
22356+#else
22357+ mov %cr0, %esi
22358+#endif
22359+ bts $16, %esi
22360+ jnc 1f
22361+ mov %cs, %esi
22362+ cmp $__KERNEL_CS, %esi
22363+ jz 3f
22364+ ljmp $__KERNEL_CS, $3f
22365+1: ljmp $__KERNEXEC_KERNEL_CS, $2f
22366+2:
22367+#ifdef CONFIG_PARAVIRT
22368+ mov %esi, %eax
22369+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
22370+#else
22371+ mov %esi, %cr0
22372+#endif
22373+3:
22374+#ifdef CONFIG_PARAVIRT
22375+ popl %ecx
22376+ popl %eax
22377+#endif
22378+ ret
22379+ENDPROC(pax_enter_kernel)
22380+
22381+ENTRY(pax_exit_kernel)
22382+#ifdef CONFIG_PARAVIRT
22383+ pushl %eax
22384+ pushl %ecx
22385+#endif
22386+ mov %cs, %esi
22387+ cmp $__KERNEXEC_KERNEL_CS, %esi
22388+ jnz 2f
22389+#ifdef CONFIG_PARAVIRT
22390+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0);
22391+ mov %eax, %esi
22392+#else
22393+ mov %cr0, %esi
22394+#endif
22395+ btr $16, %esi
22396+ ljmp $__KERNEL_CS, $1f
22397+1:
22398+#ifdef CONFIG_PARAVIRT
22399+ mov %esi, %eax
22400+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0);
22401+#else
22402+ mov %esi, %cr0
22403+#endif
22404+2:
22405+#ifdef CONFIG_PARAVIRT
22406+ popl %ecx
22407+ popl %eax
22408+#endif
22409+ ret
22410+ENDPROC(pax_exit_kernel)
22411+#endif
22412+
22413+ .macro pax_erase_kstack
22414+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
22415+ call pax_erase_kstack
22416+#endif
22417+ .endm
22418+
22419+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
22420+/*
22421+ * ebp: thread_info
22422+ */
22423+ENTRY(pax_erase_kstack)
22424+ pushl %edi
22425+ pushl %ecx
22426+ pushl %eax
22427+
22428+ mov TI_lowest_stack(%ebp), %edi
22429+ mov $-0xBEEF, %eax
22430+ std
22431+
22432+1: mov %edi, %ecx
22433+ and $THREAD_SIZE_asm - 1, %ecx
22434+ shr $2, %ecx
22435+ repne scasl
22436+ jecxz 2f
22437+
22438+ cmp $2*16, %ecx
22439+ jc 2f
22440+
22441+ mov $2*16, %ecx
22442+ repe scasl
22443+ jecxz 2f
22444+ jne 1b
22445+
22446+2: cld
22447+ mov %esp, %ecx
22448+ sub %edi, %ecx
22449+
22450+ cmp $THREAD_SIZE_asm, %ecx
22451+ jb 3f
22452+ ud2
22453+3:
22454+
22455+ shr $2, %ecx
22456+ rep stosl
22457+
22458+ mov TI_task_thread_sp0(%ebp), %edi
22459+ sub $128, %edi
22460+ mov %edi, TI_lowest_stack(%ebp)
22461+
22462+ popl %eax
22463+ popl %ecx
22464+ popl %edi
22465+ ret
22466+ENDPROC(pax_erase_kstack)
22467+#endif
22468+
22469+.macro __SAVE_ALL _DS
22470 cld
22471 PUSH_GS
22472 pushl_cfi %fs
22473@@ -206,7 +346,7 @@
22474 CFI_REL_OFFSET ecx, 0
22475 pushl_cfi %ebx
22476 CFI_REL_OFFSET ebx, 0
22477- movl $(__USER_DS), %edx
22478+ movl $\_DS, %edx
22479 movl %edx, %ds
22480 movl %edx, %es
22481 movl $(__KERNEL_PERCPU), %edx
22482@@ -214,6 +354,15 @@
22483 SET_KERNEL_GS %edx
22484 .endm
22485
22486+.macro SAVE_ALL
22487+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
22488+ __SAVE_ALL __KERNEL_DS
22489+ pax_enter_kernel
22490+#else
22491+ __SAVE_ALL __USER_DS
22492+#endif
22493+.endm
22494+
22495 .macro RESTORE_INT_REGS
22496 popl_cfi %ebx
22497 CFI_RESTORE ebx
22498@@ -297,7 +446,7 @@ ENTRY(ret_from_fork)
22499 popfl_cfi
22500 jmp syscall_exit
22501 CFI_ENDPROC
22502-END(ret_from_fork)
22503+ENDPROC(ret_from_fork)
22504
22505 ENTRY(ret_from_kernel_thread)
22506 CFI_STARTPROC
22507@@ -344,7 +493,15 @@ ret_from_intr:
22508 andl $SEGMENT_RPL_MASK, %eax
22509 #endif
22510 cmpl $USER_RPL, %eax
22511+
22512+#ifdef CONFIG_PAX_KERNEXEC
22513+ jae resume_userspace
22514+
22515+ pax_exit_kernel
22516+ jmp resume_kernel
22517+#else
22518 jb resume_kernel # not returning to v8086 or userspace
22519+#endif
22520
22521 ENTRY(resume_userspace)
22522 LOCKDEP_SYS_EXIT
22523@@ -356,8 +513,8 @@ ENTRY(resume_userspace)
22524 andl $_TIF_WORK_MASK, %ecx # is there any work to be done on
22525 # int/exception return?
22526 jne work_pending
22527- jmp restore_all
22528-END(ret_from_exception)
22529+ jmp restore_all_pax
22530+ENDPROC(ret_from_exception)
22531
22532 #ifdef CONFIG_PREEMPT
22533 ENTRY(resume_kernel)
22534@@ -369,7 +526,7 @@ need_resched:
22535 jz restore_all
22536 call preempt_schedule_irq
22537 jmp need_resched
22538-END(resume_kernel)
22539+ENDPROC(resume_kernel)
22540 #endif
22541 CFI_ENDPROC
22542 /*
22543@@ -403,30 +560,45 @@ sysenter_past_esp:
22544 /*CFI_REL_OFFSET cs, 0*/
22545 /*
22546 * Push current_thread_info()->sysenter_return to the stack.
22547- * A tiny bit of offset fixup is necessary - 4*4 means the 4 words
22548- * pushed above; +8 corresponds to copy_thread's esp0 setting.
22549 */
22550- pushl_cfi ((TI_sysenter_return)-THREAD_SIZE+8+4*4)(%esp)
22551+ pushl_cfi $0
22552 CFI_REL_OFFSET eip, 0
22553
22554 pushl_cfi %eax
22555 SAVE_ALL
22556+ GET_THREAD_INFO(%ebp)
22557+ movl TI_sysenter_return(%ebp),%ebp
22558+ movl %ebp,PT_EIP(%esp)
22559 ENABLE_INTERRUPTS(CLBR_NONE)
22560
22561 /*
22562 * Load the potential sixth argument from user stack.
22563 * Careful about security.
22564 */
22565+ movl PT_OLDESP(%esp),%ebp
22566+
22567+#ifdef CONFIG_PAX_MEMORY_UDEREF
22568+ mov PT_OLDSS(%esp),%ds
22569+1: movl %ds:(%ebp),%ebp
22570+ push %ss
22571+ pop %ds
22572+#else
22573 cmpl $__PAGE_OFFSET-3,%ebp
22574 jae syscall_fault
22575 ASM_STAC
22576 1: movl (%ebp),%ebp
22577 ASM_CLAC
22578+#endif
22579+
22580 movl %ebp,PT_EBP(%esp)
22581 _ASM_EXTABLE(1b,syscall_fault)
22582
22583 GET_THREAD_INFO(%ebp)
22584
22585+#ifdef CONFIG_PAX_RANDKSTACK
22586+ pax_erase_kstack
22587+#endif
22588+
22589 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
22590 jnz sysenter_audit
22591 sysenter_do_call:
22592@@ -441,12 +613,24 @@ sysenter_do_call:
22593 testl $_TIF_ALLWORK_MASK, %ecx
22594 jne sysexit_audit
22595 sysenter_exit:
22596+
22597+#ifdef CONFIG_PAX_RANDKSTACK
22598+ pushl_cfi %eax
22599+ movl %esp, %eax
22600+ call pax_randomize_kstack
22601+ popl_cfi %eax
22602+#endif
22603+
22604+ pax_erase_kstack
22605+
22606 /* if something modifies registers it must also disable sysexit */
22607 movl PT_EIP(%esp), %edx
22608 movl PT_OLDESP(%esp), %ecx
22609 xorl %ebp,%ebp
22610 TRACE_IRQS_ON
22611 1: mov PT_FS(%esp), %fs
22612+2: mov PT_DS(%esp), %ds
22613+3: mov PT_ES(%esp), %es
22614 PTGS_TO_GS
22615 ENABLE_INTERRUPTS_SYSEXIT
22616
22617@@ -463,6 +647,9 @@ sysenter_audit:
22618 movl %eax,%edx /* 2nd arg: syscall number */
22619 movl $AUDIT_ARCH_I386,%eax /* 1st arg: audit arch */
22620 call __audit_syscall_entry
22621+
22622+ pax_erase_kstack
22623+
22624 pushl_cfi %ebx
22625 movl PT_EAX(%esp),%eax /* reload syscall number */
22626 jmp sysenter_do_call
22627@@ -488,10 +675,16 @@ sysexit_audit:
22628
22629 CFI_ENDPROC
22630 .pushsection .fixup,"ax"
22631-2: movl $0,PT_FS(%esp)
22632+4: movl $0,PT_FS(%esp)
22633+ jmp 1b
22634+5: movl $0,PT_DS(%esp)
22635+ jmp 1b
22636+6: movl $0,PT_ES(%esp)
22637 jmp 1b
22638 .popsection
22639- _ASM_EXTABLE(1b,2b)
22640+ _ASM_EXTABLE(1b,4b)
22641+ _ASM_EXTABLE(2b,5b)
22642+ _ASM_EXTABLE(3b,6b)
22643 PTGS_TO_GS_EX
22644 ENDPROC(ia32_sysenter_target)
22645
22646@@ -506,6 +699,11 @@ ENTRY(system_call)
22647 pushl_cfi %eax # save orig_eax
22648 SAVE_ALL
22649 GET_THREAD_INFO(%ebp)
22650+
22651+#ifdef CONFIG_PAX_RANDKSTACK
22652+ pax_erase_kstack
22653+#endif
22654+
22655 # system call tracing in operation / emulation
22656 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
22657 jnz syscall_trace_entry
22658@@ -524,6 +722,15 @@ syscall_exit:
22659 testl $_TIF_ALLWORK_MASK, %ecx # current->work
22660 jne syscall_exit_work
22661
22662+restore_all_pax:
22663+
22664+#ifdef CONFIG_PAX_RANDKSTACK
22665+ movl %esp, %eax
22666+ call pax_randomize_kstack
22667+#endif
22668+
22669+ pax_erase_kstack
22670+
22671 restore_all:
22672 TRACE_IRQS_IRET
22673 restore_all_notrace:
22674@@ -580,14 +787,34 @@ ldt_ss:
22675 * compensating for the offset by changing to the ESPFIX segment with
22676 * a base address that matches for the difference.
22677 */
22678-#define GDT_ESPFIX_SS PER_CPU_VAR(gdt_page) + (GDT_ENTRY_ESPFIX_SS * 8)
22679+#define GDT_ESPFIX_SS (GDT_ENTRY_ESPFIX_SS * 8)(%ebx)
22680 mov %esp, %edx /* load kernel esp */
22681 mov PT_OLDESP(%esp), %eax /* load userspace esp */
22682 mov %dx, %ax /* eax: new kernel esp */
22683 sub %eax, %edx /* offset (low word is 0) */
22684+#ifdef CONFIG_SMP
22685+ movl PER_CPU_VAR(cpu_number), %ebx
22686+ shll $PAGE_SHIFT_asm, %ebx
22687+ addl $cpu_gdt_table, %ebx
22688+#else
22689+ movl $cpu_gdt_table, %ebx
22690+#endif
22691 shr $16, %edx
22692- mov %dl, GDT_ESPFIX_SS + 4 /* bits 16..23 */
22693- mov %dh, GDT_ESPFIX_SS + 7 /* bits 24..31 */
22694+
22695+#ifdef CONFIG_PAX_KERNEXEC
22696+ mov %cr0, %esi
22697+ btr $16, %esi
22698+ mov %esi, %cr0
22699+#endif
22700+
22701+ mov %dl, 4 + GDT_ESPFIX_SS /* bits 16..23 */
22702+ mov %dh, 7 + GDT_ESPFIX_SS /* bits 24..31 */
22703+
22704+#ifdef CONFIG_PAX_KERNEXEC
22705+ bts $16, %esi
22706+ mov %esi, %cr0
22707+#endif
22708+
22709 pushl_cfi $__ESPFIX_SS
22710 pushl_cfi %eax /* new kernel esp */
22711 /* Disable interrupts, but do not irqtrace this section: we
22712@@ -616,20 +843,18 @@ work_resched:
22713 movl TI_flags(%ebp), %ecx
22714 andl $_TIF_WORK_MASK, %ecx # is there any work to be done other
22715 # than syscall tracing?
22716- jz restore_all
22717+ jz restore_all_pax
22718 testb $_TIF_NEED_RESCHED, %cl
22719 jnz work_resched
22720
22721 work_notifysig: # deal with pending signals and
22722 # notify-resume requests
22723+ movl %esp, %eax
22724 #ifdef CONFIG_VM86
22725 testl $X86_EFLAGS_VM, PT_EFLAGS(%esp)
22726- movl %esp, %eax
22727 jne work_notifysig_v86 # returning to kernel-space or
22728 # vm86-space
22729 1:
22730-#else
22731- movl %esp, %eax
22732 #endif
22733 TRACE_IRQS_ON
22734 ENABLE_INTERRUPTS(CLBR_NONE)
22735@@ -650,7 +875,7 @@ work_notifysig_v86:
22736 movl %eax, %esp
22737 jmp 1b
22738 #endif
22739-END(work_pending)
22740+ENDPROC(work_pending)
22741
22742 # perform syscall exit tracing
22743 ALIGN
22744@@ -658,11 +883,14 @@ syscall_trace_entry:
22745 movl $-ENOSYS,PT_EAX(%esp)
22746 movl %esp, %eax
22747 call syscall_trace_enter
22748+
22749+ pax_erase_kstack
22750+
22751 /* What it returned is what we'll actually use. */
22752 cmpl $(NR_syscalls), %eax
22753 jnae syscall_call
22754 jmp syscall_exit
22755-END(syscall_trace_entry)
22756+ENDPROC(syscall_trace_entry)
22757
22758 # perform syscall exit tracing
22759 ALIGN
22760@@ -675,21 +903,25 @@ syscall_exit_work:
22761 movl %esp, %eax
22762 call syscall_trace_leave
22763 jmp resume_userspace
22764-END(syscall_exit_work)
22765+ENDPROC(syscall_exit_work)
22766 CFI_ENDPROC
22767
22768 RING0_INT_FRAME # can't unwind into user space anyway
22769 syscall_fault:
22770+#ifdef CONFIG_PAX_MEMORY_UDEREF
22771+ push %ss
22772+ pop %ds
22773+#endif
22774 ASM_CLAC
22775 GET_THREAD_INFO(%ebp)
22776 movl $-EFAULT,PT_EAX(%esp)
22777 jmp resume_userspace
22778-END(syscall_fault)
22779+ENDPROC(syscall_fault)
22780
22781 syscall_badsys:
22782 movl $-ENOSYS,PT_EAX(%esp)
22783 jmp resume_userspace
22784-END(syscall_badsys)
22785+ENDPROC(syscall_badsys)
22786 CFI_ENDPROC
22787 /*
22788 * End of kprobes section
22789@@ -705,8 +937,15 @@ END(syscall_badsys)
22790 * normal stack and adjusts ESP with the matching offset.
22791 */
22792 /* fixup the stack */
22793- mov GDT_ESPFIX_SS + 4, %al /* bits 16..23 */
22794- mov GDT_ESPFIX_SS + 7, %ah /* bits 24..31 */
22795+#ifdef CONFIG_SMP
22796+ movl PER_CPU_VAR(cpu_number), %ebx
22797+ shll $PAGE_SHIFT_asm, %ebx
22798+ addl $cpu_gdt_table, %ebx
22799+#else
22800+ movl $cpu_gdt_table, %ebx
22801+#endif
22802+ mov 4 + GDT_ESPFIX_SS, %al /* bits 16..23 */
22803+ mov 7 + GDT_ESPFIX_SS, %ah /* bits 24..31 */
22804 shl $16, %eax
22805 addl %esp, %eax /* the adjusted stack pointer */
22806 pushl_cfi $__KERNEL_DS
22807@@ -759,7 +998,7 @@ vector=vector+1
22808 .endr
22809 2: jmp common_interrupt
22810 .endr
22811-END(irq_entries_start)
22812+ENDPROC(irq_entries_start)
22813
22814 .previous
22815 END(interrupt)
22816@@ -820,7 +1059,7 @@ ENTRY(coprocessor_error)
22817 pushl_cfi $do_coprocessor_error
22818 jmp error_code
22819 CFI_ENDPROC
22820-END(coprocessor_error)
22821+ENDPROC(coprocessor_error)
22822
22823 ENTRY(simd_coprocessor_error)
22824 RING0_INT_FRAME
22825@@ -833,7 +1072,7 @@ ENTRY(simd_coprocessor_error)
22826 .section .altinstructions,"a"
22827 altinstruction_entry 661b, 663f, X86_FEATURE_XMM, 662b-661b, 664f-663f
22828 .previous
22829-.section .altinstr_replacement,"ax"
22830+.section .altinstr_replacement,"a"
22831 663: pushl $do_simd_coprocessor_error
22832 664:
22833 .previous
22834@@ -842,7 +1081,7 @@ ENTRY(simd_coprocessor_error)
22835 #endif
22836 jmp error_code
22837 CFI_ENDPROC
22838-END(simd_coprocessor_error)
22839+ENDPROC(simd_coprocessor_error)
22840
22841 ENTRY(device_not_available)
22842 RING0_INT_FRAME
22843@@ -851,18 +1090,18 @@ ENTRY(device_not_available)
22844 pushl_cfi $do_device_not_available
22845 jmp error_code
22846 CFI_ENDPROC
22847-END(device_not_available)
22848+ENDPROC(device_not_available)
22849
22850 #ifdef CONFIG_PARAVIRT
22851 ENTRY(native_iret)
22852 iret
22853 _ASM_EXTABLE(native_iret, iret_exc)
22854-END(native_iret)
22855+ENDPROC(native_iret)
22856
22857 ENTRY(native_irq_enable_sysexit)
22858 sti
22859 sysexit
22860-END(native_irq_enable_sysexit)
22861+ENDPROC(native_irq_enable_sysexit)
22862 #endif
22863
22864 ENTRY(overflow)
22865@@ -872,7 +1111,7 @@ ENTRY(overflow)
22866 pushl_cfi $do_overflow
22867 jmp error_code
22868 CFI_ENDPROC
22869-END(overflow)
22870+ENDPROC(overflow)
22871
22872 ENTRY(bounds)
22873 RING0_INT_FRAME
22874@@ -881,7 +1120,7 @@ ENTRY(bounds)
22875 pushl_cfi $do_bounds
22876 jmp error_code
22877 CFI_ENDPROC
22878-END(bounds)
22879+ENDPROC(bounds)
22880
22881 ENTRY(invalid_op)
22882 RING0_INT_FRAME
22883@@ -890,7 +1129,7 @@ ENTRY(invalid_op)
22884 pushl_cfi $do_invalid_op
22885 jmp error_code
22886 CFI_ENDPROC
22887-END(invalid_op)
22888+ENDPROC(invalid_op)
22889
22890 ENTRY(coprocessor_segment_overrun)
22891 RING0_INT_FRAME
22892@@ -899,7 +1138,7 @@ ENTRY(coprocessor_segment_overrun)
22893 pushl_cfi $do_coprocessor_segment_overrun
22894 jmp error_code
22895 CFI_ENDPROC
22896-END(coprocessor_segment_overrun)
22897+ENDPROC(coprocessor_segment_overrun)
22898
22899 ENTRY(invalid_TSS)
22900 RING0_EC_FRAME
22901@@ -907,7 +1146,7 @@ ENTRY(invalid_TSS)
22902 pushl_cfi $do_invalid_TSS
22903 jmp error_code
22904 CFI_ENDPROC
22905-END(invalid_TSS)
22906+ENDPROC(invalid_TSS)
22907
22908 ENTRY(segment_not_present)
22909 RING0_EC_FRAME
22910@@ -915,7 +1154,7 @@ ENTRY(segment_not_present)
22911 pushl_cfi $do_segment_not_present
22912 jmp error_code
22913 CFI_ENDPROC
22914-END(segment_not_present)
22915+ENDPROC(segment_not_present)
22916
22917 ENTRY(stack_segment)
22918 RING0_EC_FRAME
22919@@ -923,7 +1162,7 @@ ENTRY(stack_segment)
22920 pushl_cfi $do_stack_segment
22921 jmp error_code
22922 CFI_ENDPROC
22923-END(stack_segment)
22924+ENDPROC(stack_segment)
22925
22926 ENTRY(alignment_check)
22927 RING0_EC_FRAME
22928@@ -931,7 +1170,7 @@ ENTRY(alignment_check)
22929 pushl_cfi $do_alignment_check
22930 jmp error_code
22931 CFI_ENDPROC
22932-END(alignment_check)
22933+ENDPROC(alignment_check)
22934
22935 ENTRY(divide_error)
22936 RING0_INT_FRAME
22937@@ -940,7 +1179,7 @@ ENTRY(divide_error)
22938 pushl_cfi $do_divide_error
22939 jmp error_code
22940 CFI_ENDPROC
22941-END(divide_error)
22942+ENDPROC(divide_error)
22943
22944 #ifdef CONFIG_X86_MCE
22945 ENTRY(machine_check)
22946@@ -950,7 +1189,7 @@ ENTRY(machine_check)
22947 pushl_cfi machine_check_vector
22948 jmp error_code
22949 CFI_ENDPROC
22950-END(machine_check)
22951+ENDPROC(machine_check)
22952 #endif
22953
22954 ENTRY(spurious_interrupt_bug)
22955@@ -960,7 +1199,7 @@ ENTRY(spurious_interrupt_bug)
22956 pushl_cfi $do_spurious_interrupt_bug
22957 jmp error_code
22958 CFI_ENDPROC
22959-END(spurious_interrupt_bug)
22960+ENDPROC(spurious_interrupt_bug)
22961 /*
22962 * End of kprobes section
22963 */
22964@@ -1070,7 +1309,7 @@ BUILD_INTERRUPT3(hyperv_callback_vector, HYPERVISOR_CALLBACK_VECTOR,
22965
22966 ENTRY(mcount)
22967 ret
22968-END(mcount)
22969+ENDPROC(mcount)
22970
22971 ENTRY(ftrace_caller)
22972 cmpl $0, function_trace_stop
22973@@ -1103,7 +1342,7 @@ ftrace_graph_call:
22974 .globl ftrace_stub
22975 ftrace_stub:
22976 ret
22977-END(ftrace_caller)
22978+ENDPROC(ftrace_caller)
22979
22980 ENTRY(ftrace_regs_caller)
22981 pushf /* push flags before compare (in cs location) */
22982@@ -1207,7 +1446,7 @@ trace:
22983 popl %ecx
22984 popl %eax
22985 jmp ftrace_stub
22986-END(mcount)
22987+ENDPROC(mcount)
22988 #endif /* CONFIG_DYNAMIC_FTRACE */
22989 #endif /* CONFIG_FUNCTION_TRACER */
22990
22991@@ -1225,7 +1464,7 @@ ENTRY(ftrace_graph_caller)
22992 popl %ecx
22993 popl %eax
22994 ret
22995-END(ftrace_graph_caller)
22996+ENDPROC(ftrace_graph_caller)
22997
22998 .globl return_to_handler
22999 return_to_handler:
23000@@ -1291,15 +1530,18 @@ error_code:
23001 movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart
23002 REG_TO_PTGS %ecx
23003 SET_KERNEL_GS %ecx
23004- movl $(__USER_DS), %ecx
23005+ movl $(__KERNEL_DS), %ecx
23006 movl %ecx, %ds
23007 movl %ecx, %es
23008+
23009+ pax_enter_kernel
23010+
23011 TRACE_IRQS_OFF
23012 movl %esp,%eax # pt_regs pointer
23013 call *%edi
23014 jmp ret_from_exception
23015 CFI_ENDPROC
23016-END(page_fault)
23017+ENDPROC(page_fault)
23018
23019 /*
23020 * Debug traps and NMI can happen at the one SYSENTER instruction
23021@@ -1342,7 +1584,7 @@ debug_stack_correct:
23022 call do_debug
23023 jmp ret_from_exception
23024 CFI_ENDPROC
23025-END(debug)
23026+ENDPROC(debug)
23027
23028 /*
23029 * NMI is doubly nasty. It can happen _while_ we're handling
23030@@ -1380,6 +1622,9 @@ nmi_stack_correct:
23031 xorl %edx,%edx # zero error code
23032 movl %esp,%eax # pt_regs pointer
23033 call do_nmi
23034+
23035+ pax_exit_kernel
23036+
23037 jmp restore_all_notrace
23038 CFI_ENDPROC
23039
23040@@ -1416,12 +1661,15 @@ nmi_espfix_stack:
23041 FIXUP_ESPFIX_STACK # %eax == %esp
23042 xorl %edx,%edx # zero error code
23043 call do_nmi
23044+
23045+ pax_exit_kernel
23046+
23047 RESTORE_REGS
23048 lss 12+4(%esp), %esp # back to espfix stack
23049 CFI_ADJUST_CFA_OFFSET -24
23050 jmp irq_return
23051 CFI_ENDPROC
23052-END(nmi)
23053+ENDPROC(nmi)
23054
23055 ENTRY(int3)
23056 RING0_INT_FRAME
23057@@ -1434,14 +1682,14 @@ ENTRY(int3)
23058 call do_int3
23059 jmp ret_from_exception
23060 CFI_ENDPROC
23061-END(int3)
23062+ENDPROC(int3)
23063
23064 ENTRY(general_protection)
23065 RING0_EC_FRAME
23066 pushl_cfi $do_general_protection
23067 jmp error_code
23068 CFI_ENDPROC
23069-END(general_protection)
23070+ENDPROC(general_protection)
23071
23072 #ifdef CONFIG_KVM_GUEST
23073 ENTRY(async_page_fault)
23074@@ -1450,7 +1698,7 @@ ENTRY(async_page_fault)
23075 pushl_cfi $do_async_page_fault
23076 jmp error_code
23077 CFI_ENDPROC
23078-END(async_page_fault)
23079+ENDPROC(async_page_fault)
23080 #endif
23081
23082 /*
23083diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S
23084index 1e96c36..3ff710a 100644
23085--- a/arch/x86/kernel/entry_64.S
23086+++ b/arch/x86/kernel/entry_64.S
23087@@ -59,6 +59,8 @@
23088 #include <asm/context_tracking.h>
23089 #include <asm/smap.h>
23090 #include <linux/err.h>
23091+#include <asm/pgtable.h>
23092+#include <asm/alternative-asm.h>
23093
23094 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
23095 #include <linux/elf-em.h>
23096@@ -80,8 +82,9 @@
23097 #ifdef CONFIG_DYNAMIC_FTRACE
23098
23099 ENTRY(function_hook)
23100+ pax_force_retaddr
23101 retq
23102-END(function_hook)
23103+ENDPROC(function_hook)
23104
23105 /* skip is set if stack has been adjusted */
23106 .macro ftrace_caller_setup skip=0
23107@@ -122,8 +125,9 @@ GLOBAL(ftrace_graph_call)
23108 #endif
23109
23110 GLOBAL(ftrace_stub)
23111+ pax_force_retaddr
23112 retq
23113-END(ftrace_caller)
23114+ENDPROC(ftrace_caller)
23115
23116 ENTRY(ftrace_regs_caller)
23117 /* Save the current flags before compare (in SS location)*/
23118@@ -191,7 +195,7 @@ ftrace_restore_flags:
23119 popfq
23120 jmp ftrace_stub
23121
23122-END(ftrace_regs_caller)
23123+ENDPROC(ftrace_regs_caller)
23124
23125
23126 #else /* ! CONFIG_DYNAMIC_FTRACE */
23127@@ -212,6 +216,7 @@ ENTRY(function_hook)
23128 #endif
23129
23130 GLOBAL(ftrace_stub)
23131+ pax_force_retaddr
23132 retq
23133
23134 trace:
23135@@ -225,12 +230,13 @@ trace:
23136 #endif
23137 subq $MCOUNT_INSN_SIZE, %rdi
23138
23139+ pax_force_fptr ftrace_trace_function
23140 call *ftrace_trace_function
23141
23142 MCOUNT_RESTORE_FRAME
23143
23144 jmp ftrace_stub
23145-END(function_hook)
23146+ENDPROC(function_hook)
23147 #endif /* CONFIG_DYNAMIC_FTRACE */
23148 #endif /* CONFIG_FUNCTION_TRACER */
23149
23150@@ -252,8 +258,9 @@ ENTRY(ftrace_graph_caller)
23151
23152 MCOUNT_RESTORE_FRAME
23153
23154+ pax_force_retaddr
23155 retq
23156-END(ftrace_graph_caller)
23157+ENDPROC(ftrace_graph_caller)
23158
23159 GLOBAL(return_to_handler)
23160 subq $24, %rsp
23161@@ -269,7 +276,9 @@ GLOBAL(return_to_handler)
23162 movq 8(%rsp), %rdx
23163 movq (%rsp), %rax
23164 addq $24, %rsp
23165+ pax_force_fptr %rdi
23166 jmp *%rdi
23167+ENDPROC(return_to_handler)
23168 #endif
23169
23170
23171@@ -284,6 +293,430 @@ ENTRY(native_usergs_sysret64)
23172 ENDPROC(native_usergs_sysret64)
23173 #endif /* CONFIG_PARAVIRT */
23174
23175+ .macro ljmpq sel, off
23176+#if defined(CONFIG_MPSC) || defined(CONFIG_MCORE2) || defined (CONFIG_MATOM)
23177+ .byte 0x48; ljmp *1234f(%rip)
23178+ .pushsection .rodata
23179+ .align 16
23180+ 1234: .quad \off; .word \sel
23181+ .popsection
23182+#else
23183+ pushq $\sel
23184+ pushq $\off
23185+ lretq
23186+#endif
23187+ .endm
23188+
23189+ .macro pax_enter_kernel
23190+ pax_set_fptr_mask
23191+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
23192+ call pax_enter_kernel
23193+#endif
23194+ .endm
23195+
23196+ .macro pax_exit_kernel
23197+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
23198+ call pax_exit_kernel
23199+#endif
23200+
23201+ .endm
23202+
23203+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
23204+ENTRY(pax_enter_kernel)
23205+ pushq %rdi
23206+
23207+#ifdef CONFIG_PARAVIRT
23208+ PV_SAVE_REGS(CLBR_RDI)
23209+#endif
23210+
23211+#ifdef CONFIG_PAX_KERNEXEC
23212+ GET_CR0_INTO_RDI
23213+ bts $16,%rdi
23214+ jnc 3f
23215+ mov %cs,%edi
23216+ cmp $__KERNEL_CS,%edi
23217+ jnz 2f
23218+1:
23219+#endif
23220+
23221+#ifdef CONFIG_PAX_MEMORY_UDEREF
23222+ 661: jmp 111f
23223+ .pushsection .altinstr_replacement, "a"
23224+ 662: ASM_NOP2
23225+ .popsection
23226+ .pushsection .altinstructions, "a"
23227+ altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
23228+ .popsection
23229+ GET_CR3_INTO_RDI
23230+ cmp $0,%dil
23231+ jnz 112f
23232+ mov $__KERNEL_DS,%edi
23233+ mov %edi,%ss
23234+ jmp 111f
23235+112: cmp $1,%dil
23236+ jz 113f
23237+ ud2
23238+113: sub $4097,%rdi
23239+ bts $63,%rdi
23240+ SET_RDI_INTO_CR3
23241+ mov $__UDEREF_KERNEL_DS,%edi
23242+ mov %edi,%ss
23243+111:
23244+#endif
23245+
23246+#ifdef CONFIG_PARAVIRT
23247+ PV_RESTORE_REGS(CLBR_RDI)
23248+#endif
23249+
23250+ popq %rdi
23251+ pax_force_retaddr
23252+ retq
23253+
23254+#ifdef CONFIG_PAX_KERNEXEC
23255+2: ljmpq __KERNEL_CS,1b
23256+3: ljmpq __KERNEXEC_KERNEL_CS,4f
23257+4: SET_RDI_INTO_CR0
23258+ jmp 1b
23259+#endif
23260+ENDPROC(pax_enter_kernel)
23261+
23262+ENTRY(pax_exit_kernel)
23263+ pushq %rdi
23264+
23265+#ifdef CONFIG_PARAVIRT
23266+ PV_SAVE_REGS(CLBR_RDI)
23267+#endif
23268+
23269+#ifdef CONFIG_PAX_KERNEXEC
23270+ mov %cs,%rdi
23271+ cmp $__KERNEXEC_KERNEL_CS,%edi
23272+ jz 2f
23273+ GET_CR0_INTO_RDI
23274+ bts $16,%rdi
23275+ jnc 4f
23276+1:
23277+#endif
23278+
23279+#ifdef CONFIG_PAX_MEMORY_UDEREF
23280+ 661: jmp 111f
23281+ .pushsection .altinstr_replacement, "a"
23282+ 662: ASM_NOP2
23283+ .popsection
23284+ .pushsection .altinstructions, "a"
23285+ altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
23286+ .popsection
23287+ mov %ss,%edi
23288+ cmp $__UDEREF_KERNEL_DS,%edi
23289+ jnz 111f
23290+ GET_CR3_INTO_RDI
23291+ cmp $0,%dil
23292+ jz 112f
23293+ ud2
23294+112: add $4097,%rdi
23295+ bts $63,%rdi
23296+ SET_RDI_INTO_CR3
23297+ mov $__KERNEL_DS,%edi
23298+ mov %edi,%ss
23299+111:
23300+#endif
23301+
23302+#ifdef CONFIG_PARAVIRT
23303+ PV_RESTORE_REGS(CLBR_RDI);
23304+#endif
23305+
23306+ popq %rdi
23307+ pax_force_retaddr
23308+ retq
23309+
23310+#ifdef CONFIG_PAX_KERNEXEC
23311+2: GET_CR0_INTO_RDI
23312+ btr $16,%rdi
23313+ jnc 4f
23314+ ljmpq __KERNEL_CS,3f
23315+3: SET_RDI_INTO_CR0
23316+ jmp 1b
23317+4: ud2
23318+ jmp 4b
23319+#endif
23320+ENDPROC(pax_exit_kernel)
23321+#endif
23322+
23323+ .macro pax_enter_kernel_user
23324+ pax_set_fptr_mask
23325+#ifdef CONFIG_PAX_MEMORY_UDEREF
23326+ call pax_enter_kernel_user
23327+#endif
23328+ .endm
23329+
23330+ .macro pax_exit_kernel_user
23331+#ifdef CONFIG_PAX_MEMORY_UDEREF
23332+ call pax_exit_kernel_user
23333+#endif
23334+#ifdef CONFIG_PAX_RANDKSTACK
23335+ pushq %rax
23336+ pushq %r11
23337+ call pax_randomize_kstack
23338+ popq %r11
23339+ popq %rax
23340+#endif
23341+ .endm
23342+
23343+#ifdef CONFIG_PAX_MEMORY_UDEREF
23344+ENTRY(pax_enter_kernel_user)
23345+ pushq %rdi
23346+ pushq %rbx
23347+
23348+#ifdef CONFIG_PARAVIRT
23349+ PV_SAVE_REGS(CLBR_RDI)
23350+#endif
23351+
23352+ 661: jmp 111f
23353+ .pushsection .altinstr_replacement, "a"
23354+ 662: ASM_NOP2
23355+ .popsection
23356+ .pushsection .altinstructions, "a"
23357+ altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
23358+ .popsection
23359+ GET_CR3_INTO_RDI
23360+ cmp $1,%dil
23361+ jnz 4f
23362+ sub $4097,%rdi
23363+ bts $63,%rdi
23364+ SET_RDI_INTO_CR3
23365+ jmp 3f
23366+111:
23367+
23368+ GET_CR3_INTO_RDI
23369+ mov %rdi,%rbx
23370+ add $__START_KERNEL_map,%rbx
23371+ sub phys_base(%rip),%rbx
23372+
23373+#ifdef CONFIG_PARAVIRT
23374+ cmpl $0, pv_info+PARAVIRT_enabled
23375+ jz 1f
23376+ pushq %rdi
23377+ i = 0
23378+ .rept USER_PGD_PTRS
23379+ mov i*8(%rbx),%rsi
23380+ mov $0,%sil
23381+ lea i*8(%rbx),%rdi
23382+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
23383+ i = i + 1
23384+ .endr
23385+ popq %rdi
23386+ jmp 2f
23387+1:
23388+#endif
23389+
23390+ i = 0
23391+ .rept USER_PGD_PTRS
23392+ movb $0,i*8(%rbx)
23393+ i = i + 1
23394+ .endr
23395+
23396+2: SET_RDI_INTO_CR3
23397+
23398+#ifdef CONFIG_PAX_KERNEXEC
23399+ GET_CR0_INTO_RDI
23400+ bts $16,%rdi
23401+ SET_RDI_INTO_CR0
23402+#endif
23403+
23404+3:
23405+
23406+#ifdef CONFIG_PARAVIRT
23407+ PV_RESTORE_REGS(CLBR_RDI)
23408+#endif
23409+
23410+ popq %rbx
23411+ popq %rdi
23412+ pax_force_retaddr
23413+ retq
23414+4: ud2
23415+ENDPROC(pax_enter_kernel_user)
23416+
23417+ENTRY(pax_exit_kernel_user)
23418+ pushq %rdi
23419+ pushq %rbx
23420+
23421+#ifdef CONFIG_PARAVIRT
23422+ PV_SAVE_REGS(CLBR_RDI)
23423+#endif
23424+
23425+ GET_CR3_INTO_RDI
23426+ 661: jmp 1f
23427+ .pushsection .altinstr_replacement, "a"
23428+ 662: ASM_NOP2
23429+ .popsection
23430+ .pushsection .altinstructions, "a"
23431+ altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
23432+ .popsection
23433+ cmp $0,%dil
23434+ jnz 3f
23435+ add $4097,%rdi
23436+ bts $63,%rdi
23437+ SET_RDI_INTO_CR3
23438+ jmp 2f
23439+1:
23440+
23441+ mov %rdi,%rbx
23442+
23443+#ifdef CONFIG_PAX_KERNEXEC
23444+ GET_CR0_INTO_RDI
23445+ btr $16,%rdi
23446+ jnc 3f
23447+ SET_RDI_INTO_CR0
23448+#endif
23449+
23450+ add $__START_KERNEL_map,%rbx
23451+ sub phys_base(%rip),%rbx
23452+
23453+#ifdef CONFIG_PARAVIRT
23454+ cmpl $0, pv_info+PARAVIRT_enabled
23455+ jz 1f
23456+ i = 0
23457+ .rept USER_PGD_PTRS
23458+ mov i*8(%rbx),%rsi
23459+ mov $0x67,%sil
23460+ lea i*8(%rbx),%rdi
23461+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
23462+ i = i + 1
23463+ .endr
23464+ jmp 2f
23465+1:
23466+#endif
23467+
23468+ i = 0
23469+ .rept USER_PGD_PTRS
23470+ movb $0x67,i*8(%rbx)
23471+ i = i + 1
23472+ .endr
23473+2:
23474+
23475+#ifdef CONFIG_PARAVIRT
23476+ PV_RESTORE_REGS(CLBR_RDI)
23477+#endif
23478+
23479+ popq %rbx
23480+ popq %rdi
23481+ pax_force_retaddr
23482+ retq
23483+3: ud2
23484+ENDPROC(pax_exit_kernel_user)
23485+#endif
23486+
23487+ .macro pax_enter_kernel_nmi
23488+ pax_set_fptr_mask
23489+
23490+#ifdef CONFIG_PAX_KERNEXEC
23491+ GET_CR0_INTO_RDI
23492+ bts $16,%rdi
23493+ jc 110f
23494+ SET_RDI_INTO_CR0
23495+ or $2,%ebx
23496+110:
23497+#endif
23498+
23499+#ifdef CONFIG_PAX_MEMORY_UDEREF
23500+ 661: jmp 111f
23501+ .pushsection .altinstr_replacement, "a"
23502+ 662: ASM_NOP2
23503+ .popsection
23504+ .pushsection .altinstructions, "a"
23505+ altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
23506+ .popsection
23507+ GET_CR3_INTO_RDI
23508+ cmp $0,%dil
23509+ jz 111f
23510+ sub $4097,%rdi
23511+ or $4,%ebx
23512+ bts $63,%rdi
23513+ SET_RDI_INTO_CR3
23514+ mov $__UDEREF_KERNEL_DS,%edi
23515+ mov %edi,%ss
23516+111:
23517+#endif
23518+ .endm
23519+
23520+ .macro pax_exit_kernel_nmi
23521+#ifdef CONFIG_PAX_KERNEXEC
23522+ btr $1,%ebx
23523+ jnc 110f
23524+ GET_CR0_INTO_RDI
23525+ btr $16,%rdi
23526+ SET_RDI_INTO_CR0
23527+110:
23528+#endif
23529+
23530+#ifdef CONFIG_PAX_MEMORY_UDEREF
23531+ btr $2,%ebx
23532+ jnc 111f
23533+ GET_CR3_INTO_RDI
23534+ add $4097,%rdi
23535+ bts $63,%rdi
23536+ SET_RDI_INTO_CR3
23537+ mov $__KERNEL_DS,%edi
23538+ mov %edi,%ss
23539+111:
23540+#endif
23541+ .endm
23542+
23543+ .macro pax_erase_kstack
23544+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
23545+ call pax_erase_kstack
23546+#endif
23547+ .endm
23548+
23549+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
23550+ENTRY(pax_erase_kstack)
23551+ pushq %rdi
23552+ pushq %rcx
23553+ pushq %rax
23554+ pushq %r11
23555+
23556+ GET_THREAD_INFO(%r11)
23557+ mov TI_lowest_stack(%r11), %rdi
23558+ mov $-0xBEEF, %rax
23559+ std
23560+
23561+1: mov %edi, %ecx
23562+ and $THREAD_SIZE_asm - 1, %ecx
23563+ shr $3, %ecx
23564+ repne scasq
23565+ jecxz 2f
23566+
23567+ cmp $2*8, %ecx
23568+ jc 2f
23569+
23570+ mov $2*8, %ecx
23571+ repe scasq
23572+ jecxz 2f
23573+ jne 1b
23574+
23575+2: cld
23576+ mov %esp, %ecx
23577+ sub %edi, %ecx
23578+
23579+ cmp $THREAD_SIZE_asm, %rcx
23580+ jb 3f
23581+ ud2
23582+3:
23583+
23584+ shr $3, %ecx
23585+ rep stosq
23586+
23587+ mov TI_task_thread_sp0(%r11), %rdi
23588+ sub $256, %rdi
23589+ mov %rdi, TI_lowest_stack(%r11)
23590+
23591+ popq %r11
23592+ popq %rax
23593+ popq %rcx
23594+ popq %rdi
23595+ pax_force_retaddr
23596+ ret
23597+ENDPROC(pax_erase_kstack)
23598+#endif
23599
23600 .macro TRACE_IRQS_IRETQ offset=ARGOFFSET
23601 #ifdef CONFIG_TRACE_IRQFLAGS
23602@@ -320,7 +753,7 @@ ENDPROC(native_usergs_sysret64)
23603 .endm
23604
23605 .macro TRACE_IRQS_IRETQ_DEBUG offset=ARGOFFSET
23606- bt $9,EFLAGS-\offset(%rsp) /* interrupts off? */
23607+ bt $X86_EFLAGS_IF_BIT,EFLAGS-\offset(%rsp) /* interrupts off? */
23608 jnc 1f
23609 TRACE_IRQS_ON_DEBUG
23610 1:
23611@@ -358,27 +791,6 @@ ENDPROC(native_usergs_sysret64)
23612 movq \tmp,R11+\offset(%rsp)
23613 .endm
23614
23615- .macro FAKE_STACK_FRAME child_rip
23616- /* push in order ss, rsp, eflags, cs, rip */
23617- xorl %eax, %eax
23618- pushq_cfi $__KERNEL_DS /* ss */
23619- /*CFI_REL_OFFSET ss,0*/
23620- pushq_cfi %rax /* rsp */
23621- CFI_REL_OFFSET rsp,0
23622- pushq_cfi $(X86_EFLAGS_IF|X86_EFLAGS_FIXED) /* eflags - interrupts on */
23623- /*CFI_REL_OFFSET rflags,0*/
23624- pushq_cfi $__KERNEL_CS /* cs */
23625- /*CFI_REL_OFFSET cs,0*/
23626- pushq_cfi \child_rip /* rip */
23627- CFI_REL_OFFSET rip,0
23628- pushq_cfi %rax /* orig rax */
23629- .endm
23630-
23631- .macro UNFAKE_STACK_FRAME
23632- addq $8*6, %rsp
23633- CFI_ADJUST_CFA_OFFSET -(6*8)
23634- .endm
23635-
23636 /*
23637 * initial frame state for interrupts (and exceptions without error code)
23638 */
23639@@ -445,25 +857,26 @@ ENDPROC(native_usergs_sysret64)
23640 /* save partial stack frame */
23641 .macro SAVE_ARGS_IRQ
23642 cld
23643- /* start from rbp in pt_regs and jump over */
23644- movq_cfi rdi, (RDI-RBP)
23645- movq_cfi rsi, (RSI-RBP)
23646- movq_cfi rdx, (RDX-RBP)
23647- movq_cfi rcx, (RCX-RBP)
23648- movq_cfi rax, (RAX-RBP)
23649- movq_cfi r8, (R8-RBP)
23650- movq_cfi r9, (R9-RBP)
23651- movq_cfi r10, (R10-RBP)
23652- movq_cfi r11, (R11-RBP)
23653+ /* start from r15 in pt_regs and jump over */
23654+ movq_cfi rdi, RDI
23655+ movq_cfi rsi, RSI
23656+ movq_cfi rdx, RDX
23657+ movq_cfi rcx, RCX
23658+ movq_cfi rax, RAX
23659+ movq_cfi r8, R8
23660+ movq_cfi r9, R9
23661+ movq_cfi r10, R10
23662+ movq_cfi r11, R11
23663+ movq_cfi r12, R12
23664
23665 /* Save rbp so that we can unwind from get_irq_regs() */
23666- movq_cfi rbp, 0
23667+ movq_cfi rbp, RBP
23668
23669 /* Save previous stack value */
23670 movq %rsp, %rsi
23671
23672- leaq -RBP(%rsp),%rdi /* arg1 for handler */
23673- testl $3, CS-RBP(%rsi)
23674+ movq %rsp,%rdi /* arg1 for handler */
23675+ testb $3, CS(%rsi)
23676 je 1f
23677 SWAPGS
23678 /*
23679@@ -483,6 +896,18 @@ ENDPROC(native_usergs_sysret64)
23680 0x06 /* DW_OP_deref */, \
23681 0x08 /* DW_OP_const1u */, SS+8-RBP, \
23682 0x22 /* DW_OP_plus */
23683+
23684+#ifdef CONFIG_PAX_MEMORY_UDEREF
23685+ testb $3, CS(%rdi)
23686+ jnz 1f
23687+ pax_enter_kernel
23688+ jmp 2f
23689+1: pax_enter_kernel_user
23690+2:
23691+#else
23692+ pax_enter_kernel
23693+#endif
23694+
23695 /* We entered an interrupt context - irqs are off: */
23696 TRACE_IRQS_OFF
23697 .endm
23698@@ -514,9 +939,52 @@ ENTRY(save_paranoid)
23699 js 1f /* negative -> in kernel */
23700 SWAPGS
23701 xorl %ebx,%ebx
23702-1: ret
23703+1:
23704+#ifdef CONFIG_PAX_MEMORY_UDEREF
23705+ testb $3, CS+8(%rsp)
23706+ jnz 1f
23707+ pax_enter_kernel
23708+ jmp 2f
23709+1: pax_enter_kernel_user
23710+2:
23711+#else
23712+ pax_enter_kernel
23713+#endif
23714+ pax_force_retaddr
23715+ ret
23716 CFI_ENDPROC
23717-END(save_paranoid)
23718+ENDPROC(save_paranoid)
23719+
23720+ENTRY(save_paranoid_nmi)
23721+ XCPT_FRAME 1 RDI+8
23722+ cld
23723+ movq_cfi rdi, RDI+8
23724+ movq_cfi rsi, RSI+8
23725+ movq_cfi rdx, RDX+8
23726+ movq_cfi rcx, RCX+8
23727+ movq_cfi rax, RAX+8
23728+ movq_cfi r8, R8+8
23729+ movq_cfi r9, R9+8
23730+ movq_cfi r10, R10+8
23731+ movq_cfi r11, R11+8
23732+ movq_cfi rbx, RBX+8
23733+ movq_cfi rbp, RBP+8
23734+ movq_cfi r12, R12+8
23735+ movq_cfi r13, R13+8
23736+ movq_cfi r14, R14+8
23737+ movq_cfi r15, R15+8
23738+ movl $1,%ebx
23739+ movl $MSR_GS_BASE,%ecx
23740+ rdmsr
23741+ testl %edx,%edx
23742+ js 1f /* negative -> in kernel */
23743+ SWAPGS
23744+ xorl %ebx,%ebx
23745+1: pax_enter_kernel_nmi
23746+ pax_force_retaddr
23747+ ret
23748+ CFI_ENDPROC
23749+ENDPROC(save_paranoid_nmi)
23750 .popsection
23751
23752 /*
23753@@ -538,7 +1006,7 @@ ENTRY(ret_from_fork)
23754
23755 RESTORE_REST
23756
23757- testl $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
23758+ testb $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
23759 jz 1f
23760
23761 testl $_TIF_IA32, TI_flags(%rcx) # 32-bit compat task needs IRET
23762@@ -548,15 +1016,13 @@ ENTRY(ret_from_fork)
23763 jmp ret_from_sys_call # go to the SYSRET fastpath
23764
23765 1:
23766- subq $REST_SKIP, %rsp # leave space for volatiles
23767- CFI_ADJUST_CFA_OFFSET REST_SKIP
23768 movq %rbp, %rdi
23769 call *%rbx
23770 movl $0, RAX(%rsp)
23771 RESTORE_REST
23772 jmp int_ret_from_sys_call
23773 CFI_ENDPROC
23774-END(ret_from_fork)
23775+ENDPROC(ret_from_fork)
23776
23777 /*
23778 * System call entry. Up to 6 arguments in registers are supported.
23779@@ -593,7 +1059,7 @@ END(ret_from_fork)
23780 ENTRY(system_call)
23781 CFI_STARTPROC simple
23782 CFI_SIGNAL_FRAME
23783- CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
23784+ CFI_DEF_CFA rsp,0
23785 CFI_REGISTER rip,rcx
23786 /*CFI_REGISTER rflags,r11*/
23787 SWAPGS_UNSAFE_STACK
23788@@ -606,16 +1072,23 @@ GLOBAL(system_call_after_swapgs)
23789
23790 movq %rsp,PER_CPU_VAR(old_rsp)
23791 movq PER_CPU_VAR(kernel_stack),%rsp
23792+ SAVE_ARGS 8*6,0
23793+ pax_enter_kernel_user
23794+
23795+#ifdef CONFIG_PAX_RANDKSTACK
23796+ pax_erase_kstack
23797+#endif
23798+
23799 /*
23800 * No need to follow this irqs off/on section - it's straight
23801 * and short:
23802 */
23803 ENABLE_INTERRUPTS(CLBR_NONE)
23804- SAVE_ARGS 8,0
23805 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
23806 movq %rcx,RIP-ARGOFFSET(%rsp)
23807 CFI_REL_OFFSET rip,RIP-ARGOFFSET
23808- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
23809+ GET_THREAD_INFO(%rcx)
23810+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%rcx)
23811 jnz tracesys
23812 system_call_fastpath:
23813 #if __SYSCALL_MASK == ~0
23814@@ -639,10 +1112,13 @@ sysret_check:
23815 LOCKDEP_SYS_EXIT
23816 DISABLE_INTERRUPTS(CLBR_NONE)
23817 TRACE_IRQS_OFF
23818- movl TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET),%edx
23819+ GET_THREAD_INFO(%rcx)
23820+ movl TI_flags(%rcx),%edx
23821 andl %edi,%edx
23822 jnz sysret_careful
23823 CFI_REMEMBER_STATE
23824+ pax_exit_kernel_user
23825+ pax_erase_kstack
23826 /*
23827 * sysretq will re-enable interrupts:
23828 */
23829@@ -701,6 +1177,9 @@ auditsys:
23830 movq %rax,%rsi /* 2nd arg: syscall number */
23831 movl $AUDIT_ARCH_X86_64,%edi /* 1st arg: audit arch */
23832 call __audit_syscall_entry
23833+
23834+ pax_erase_kstack
23835+
23836 LOAD_ARGS 0 /* reload call-clobbered registers */
23837 jmp system_call_fastpath
23838
23839@@ -722,7 +1201,7 @@ sysret_audit:
23840 /* Do syscall tracing */
23841 tracesys:
23842 #ifdef CONFIG_AUDITSYSCALL
23843- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
23844+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%rcx)
23845 jz auditsys
23846 #endif
23847 SAVE_REST
23848@@ -730,12 +1209,15 @@ tracesys:
23849 FIXUP_TOP_OF_STACK %rdi
23850 movq %rsp,%rdi
23851 call syscall_trace_enter
23852+
23853+ pax_erase_kstack
23854+
23855 /*
23856 * Reload arg registers from stack in case ptrace changed them.
23857 * We don't reload %rax because syscall_trace_enter() returned
23858 * the value it wants us to use in the table lookup.
23859 */
23860- LOAD_ARGS ARGOFFSET, 1
23861+ LOAD_ARGS 1
23862 RESTORE_REST
23863 #if __SYSCALL_MASK == ~0
23864 cmpq $__NR_syscall_max,%rax
23865@@ -765,7 +1247,9 @@ GLOBAL(int_with_check)
23866 andl %edi,%edx
23867 jnz int_careful
23868 andl $~TS_COMPAT,TI_status(%rcx)
23869- jmp retint_swapgs
23870+ pax_exit_kernel_user
23871+ pax_erase_kstack
23872+ jmp retint_swapgs_pax
23873
23874 /* Either reschedule or signal or syscall exit tracking needed. */
23875 /* First do a reschedule test. */
23876@@ -811,7 +1295,7 @@ int_restore_rest:
23877 TRACE_IRQS_OFF
23878 jmp int_with_check
23879 CFI_ENDPROC
23880-END(system_call)
23881+ENDPROC(system_call)
23882
23883 .macro FORK_LIKE func
23884 ENTRY(stub_\func)
23885@@ -824,9 +1308,10 @@ ENTRY(stub_\func)
23886 DEFAULT_FRAME 0 8 /* offset 8: return address */
23887 call sys_\func
23888 RESTORE_TOP_OF_STACK %r11, 8
23889- ret $REST_SKIP /* pop extended registers */
23890+ pax_force_retaddr
23891+ ret
23892 CFI_ENDPROC
23893-END(stub_\func)
23894+ENDPROC(stub_\func)
23895 .endm
23896
23897 .macro FIXED_FRAME label,func
23898@@ -836,9 +1321,10 @@ ENTRY(\label)
23899 FIXUP_TOP_OF_STACK %r11, 8-ARGOFFSET
23900 call \func
23901 RESTORE_TOP_OF_STACK %r11, 8-ARGOFFSET
23902+ pax_force_retaddr
23903 ret
23904 CFI_ENDPROC
23905-END(\label)
23906+ENDPROC(\label)
23907 .endm
23908
23909 FORK_LIKE clone
23910@@ -846,19 +1332,6 @@ END(\label)
23911 FORK_LIKE vfork
23912 FIXED_FRAME stub_iopl, sys_iopl
23913
23914-ENTRY(ptregscall_common)
23915- DEFAULT_FRAME 1 8 /* offset 8: return address */
23916- RESTORE_TOP_OF_STACK %r11, 8
23917- movq_cfi_restore R15+8, r15
23918- movq_cfi_restore R14+8, r14
23919- movq_cfi_restore R13+8, r13
23920- movq_cfi_restore R12+8, r12
23921- movq_cfi_restore RBP+8, rbp
23922- movq_cfi_restore RBX+8, rbx
23923- ret $REST_SKIP /* pop extended registers */
23924- CFI_ENDPROC
23925-END(ptregscall_common)
23926-
23927 ENTRY(stub_execve)
23928 CFI_STARTPROC
23929 addq $8, %rsp
23930@@ -870,7 +1343,7 @@ ENTRY(stub_execve)
23931 RESTORE_REST
23932 jmp int_ret_from_sys_call
23933 CFI_ENDPROC
23934-END(stub_execve)
23935+ENDPROC(stub_execve)
23936
23937 /*
23938 * sigreturn is special because it needs to restore all registers on return.
23939@@ -887,7 +1360,7 @@ ENTRY(stub_rt_sigreturn)
23940 RESTORE_REST
23941 jmp int_ret_from_sys_call
23942 CFI_ENDPROC
23943-END(stub_rt_sigreturn)
23944+ENDPROC(stub_rt_sigreturn)
23945
23946 #ifdef CONFIG_X86_X32_ABI
23947 ENTRY(stub_x32_rt_sigreturn)
23948@@ -901,7 +1374,7 @@ ENTRY(stub_x32_rt_sigreturn)
23949 RESTORE_REST
23950 jmp int_ret_from_sys_call
23951 CFI_ENDPROC
23952-END(stub_x32_rt_sigreturn)
23953+ENDPROC(stub_x32_rt_sigreturn)
23954
23955 ENTRY(stub_x32_execve)
23956 CFI_STARTPROC
23957@@ -915,7 +1388,7 @@ ENTRY(stub_x32_execve)
23958 RESTORE_REST
23959 jmp int_ret_from_sys_call
23960 CFI_ENDPROC
23961-END(stub_x32_execve)
23962+ENDPROC(stub_x32_execve)
23963
23964 #endif
23965
23966@@ -952,7 +1425,7 @@ vector=vector+1
23967 2: jmp common_interrupt
23968 .endr
23969 CFI_ENDPROC
23970-END(irq_entries_start)
23971+ENDPROC(irq_entries_start)
23972
23973 .previous
23974 END(interrupt)
23975@@ -969,8 +1442,8 @@ END(interrupt)
23976 /* 0(%rsp): ~(interrupt number) */
23977 .macro interrupt func
23978 /* reserve pt_regs for scratch regs and rbp */
23979- subq $ORIG_RAX-RBP, %rsp
23980- CFI_ADJUST_CFA_OFFSET ORIG_RAX-RBP
23981+ subq $ORIG_RAX, %rsp
23982+ CFI_ADJUST_CFA_OFFSET ORIG_RAX
23983 SAVE_ARGS_IRQ
23984 call \func
23985 .endm
23986@@ -997,14 +1470,14 @@ ret_from_intr:
23987
23988 /* Restore saved previous stack */
23989 popq %rsi
23990- CFI_DEF_CFA rsi,SS+8-RBP /* reg/off reset after def_cfa_expr */
23991- leaq ARGOFFSET-RBP(%rsi), %rsp
23992+ CFI_DEF_CFA rsi,SS+8 /* reg/off reset after def_cfa_expr */
23993+ movq %rsi, %rsp
23994 CFI_DEF_CFA_REGISTER rsp
23995- CFI_ADJUST_CFA_OFFSET RBP-ARGOFFSET
23996+ CFI_ADJUST_CFA_OFFSET -ARGOFFSET
23997
23998 exit_intr:
23999 GET_THREAD_INFO(%rcx)
24000- testl $3,CS-ARGOFFSET(%rsp)
24001+ testb $3,CS-ARGOFFSET(%rsp)
24002 je retint_kernel
24003
24004 /* Interrupt came from user space */
24005@@ -1026,12 +1499,16 @@ retint_swapgs: /* return to user-space */
24006 * The iretq could re-enable interrupts:
24007 */
24008 DISABLE_INTERRUPTS(CLBR_ANY)
24009+ pax_exit_kernel_user
24010+retint_swapgs_pax:
24011 TRACE_IRQS_IRETQ
24012 SWAPGS
24013 jmp restore_args
24014
24015 retint_restore_args: /* return to kernel space */
24016 DISABLE_INTERRUPTS(CLBR_ANY)
24017+ pax_exit_kernel
24018+ pax_force_retaddr (RIP-ARGOFFSET)
24019 /*
24020 * The iretq could re-enable interrupts:
24021 */
24022@@ -1112,7 +1589,7 @@ ENTRY(retint_kernel)
24023 #endif
24024
24025 CFI_ENDPROC
24026-END(common_interrupt)
24027+ENDPROC(common_interrupt)
24028 /*
24029 * End of kprobes section
24030 */
24031@@ -1130,7 +1607,7 @@ ENTRY(\sym)
24032 interrupt \do_sym
24033 jmp ret_from_intr
24034 CFI_ENDPROC
24035-END(\sym)
24036+ENDPROC(\sym)
24037 .endm
24038
24039 #ifdef CONFIG_TRACING
24040@@ -1218,7 +1695,7 @@ ENTRY(\sym)
24041 call \do_sym
24042 jmp error_exit /* %ebx: no swapgs flag */
24043 CFI_ENDPROC
24044-END(\sym)
24045+ENDPROC(\sym)
24046 .endm
24047
24048 .macro paranoidzeroentry sym do_sym
24049@@ -1236,10 +1713,10 @@ ENTRY(\sym)
24050 call \do_sym
24051 jmp paranoid_exit /* %ebx: no swapgs flag */
24052 CFI_ENDPROC
24053-END(\sym)
24054+ENDPROC(\sym)
24055 .endm
24056
24057-#define INIT_TSS_IST(x) PER_CPU_VAR(init_tss) + (TSS_ist + ((x) - 1) * 8)
24058+#define INIT_TSS_IST(x) (TSS_ist + ((x) - 1) * 8)(%r13)
24059 .macro paranoidzeroentry_ist sym do_sym ist
24060 ENTRY(\sym)
24061 INTR_FRAME
24062@@ -1252,12 +1729,18 @@ ENTRY(\sym)
24063 TRACE_IRQS_OFF_DEBUG
24064 movq %rsp,%rdi /* pt_regs pointer */
24065 xorl %esi,%esi /* no error code */
24066+#ifdef CONFIG_SMP
24067+ imul $TSS_size, PER_CPU_VAR(cpu_number), %r13d
24068+ lea init_tss(%r13), %r13
24069+#else
24070+ lea init_tss(%rip), %r13
24071+#endif
24072 subq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
24073 call \do_sym
24074 addq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
24075 jmp paranoid_exit /* %ebx: no swapgs flag */
24076 CFI_ENDPROC
24077-END(\sym)
24078+ENDPROC(\sym)
24079 .endm
24080
24081 .macro errorentry sym do_sym
24082@@ -1275,7 +1758,7 @@ ENTRY(\sym)
24083 call \do_sym
24084 jmp error_exit /* %ebx: no swapgs flag */
24085 CFI_ENDPROC
24086-END(\sym)
24087+ENDPROC(\sym)
24088 .endm
24089
24090 #ifdef CONFIG_TRACING
24091@@ -1306,7 +1789,7 @@ ENTRY(\sym)
24092 call \do_sym
24093 jmp paranoid_exit /* %ebx: no swapgs flag */
24094 CFI_ENDPROC
24095-END(\sym)
24096+ENDPROC(\sym)
24097 .endm
24098
24099 zeroentry divide_error do_divide_error
24100@@ -1336,9 +1819,10 @@ gs_change:
24101 2: mfence /* workaround */
24102 SWAPGS
24103 popfq_cfi
24104+ pax_force_retaddr
24105 ret
24106 CFI_ENDPROC
24107-END(native_load_gs_index)
24108+ENDPROC(native_load_gs_index)
24109
24110 _ASM_EXTABLE(gs_change,bad_gs)
24111 .section .fixup,"ax"
24112@@ -1366,9 +1850,10 @@ ENTRY(do_softirq_own_stack)
24113 CFI_DEF_CFA_REGISTER rsp
24114 CFI_ADJUST_CFA_OFFSET -8
24115 decl PER_CPU_VAR(irq_count)
24116+ pax_force_retaddr
24117 ret
24118 CFI_ENDPROC
24119-END(do_softirq_own_stack)
24120+ENDPROC(do_softirq_own_stack)
24121
24122 #ifdef CONFIG_XEN
24123 zeroentry xen_hypervisor_callback xen_do_hypervisor_callback
24124@@ -1406,7 +1891,7 @@ ENTRY(xen_do_hypervisor_callback) # do_hypervisor_callback(struct *pt_regs)
24125 decl PER_CPU_VAR(irq_count)
24126 jmp error_exit
24127 CFI_ENDPROC
24128-END(xen_do_hypervisor_callback)
24129+ENDPROC(xen_do_hypervisor_callback)
24130
24131 /*
24132 * Hypervisor uses this for application faults while it executes.
24133@@ -1465,7 +1950,7 @@ ENTRY(xen_failsafe_callback)
24134 SAVE_ALL
24135 jmp error_exit
24136 CFI_ENDPROC
24137-END(xen_failsafe_callback)
24138+ENDPROC(xen_failsafe_callback)
24139
24140 apicinterrupt3 HYPERVISOR_CALLBACK_VECTOR \
24141 xen_hvm_callback_vector xen_evtchn_do_upcall
24142@@ -1517,18 +2002,33 @@ ENTRY(paranoid_exit)
24143 DEFAULT_FRAME
24144 DISABLE_INTERRUPTS(CLBR_NONE)
24145 TRACE_IRQS_OFF_DEBUG
24146- testl %ebx,%ebx /* swapgs needed? */
24147+ testl $1,%ebx /* swapgs needed? */
24148 jnz paranoid_restore
24149- testl $3,CS(%rsp)
24150+ testb $3,CS(%rsp)
24151 jnz paranoid_userspace
24152+#ifdef CONFIG_PAX_MEMORY_UDEREF
24153+ pax_exit_kernel
24154+ TRACE_IRQS_IRETQ 0
24155+ SWAPGS_UNSAFE_STACK
24156+ RESTORE_ALL 8
24157+ pax_force_retaddr_bts
24158+ jmp irq_return
24159+#endif
24160 paranoid_swapgs:
24161+#ifdef CONFIG_PAX_MEMORY_UDEREF
24162+ pax_exit_kernel_user
24163+#else
24164+ pax_exit_kernel
24165+#endif
24166 TRACE_IRQS_IRETQ 0
24167 SWAPGS_UNSAFE_STACK
24168 RESTORE_ALL 8
24169 jmp irq_return
24170 paranoid_restore:
24171+ pax_exit_kernel
24172 TRACE_IRQS_IRETQ_DEBUG 0
24173 RESTORE_ALL 8
24174+ pax_force_retaddr_bts
24175 jmp irq_return
24176 paranoid_userspace:
24177 GET_THREAD_INFO(%rcx)
24178@@ -1557,7 +2057,7 @@ paranoid_schedule:
24179 TRACE_IRQS_OFF
24180 jmp paranoid_userspace
24181 CFI_ENDPROC
24182-END(paranoid_exit)
24183+ENDPROC(paranoid_exit)
24184
24185 /*
24186 * Exception entry point. This expects an error code/orig_rax on the stack.
24187@@ -1584,12 +2084,23 @@ ENTRY(error_entry)
24188 movq_cfi r14, R14+8
24189 movq_cfi r15, R15+8
24190 xorl %ebx,%ebx
24191- testl $3,CS+8(%rsp)
24192+ testb $3,CS+8(%rsp)
24193 je error_kernelspace
24194 error_swapgs:
24195 SWAPGS
24196 error_sti:
24197+#ifdef CONFIG_PAX_MEMORY_UDEREF
24198+ testb $3, CS+8(%rsp)
24199+ jnz 1f
24200+ pax_enter_kernel
24201+ jmp 2f
24202+1: pax_enter_kernel_user
24203+2:
24204+#else
24205+ pax_enter_kernel
24206+#endif
24207 TRACE_IRQS_OFF
24208+ pax_force_retaddr
24209 ret
24210
24211 /*
24212@@ -1616,7 +2127,7 @@ bstep_iret:
24213 movq %rcx,RIP+8(%rsp)
24214 jmp error_swapgs
24215 CFI_ENDPROC
24216-END(error_entry)
24217+ENDPROC(error_entry)
24218
24219
24220 /* ebx: no swapgs flag (1: don't need swapgs, 0: need it) */
24221@@ -1627,7 +2138,7 @@ ENTRY(error_exit)
24222 DISABLE_INTERRUPTS(CLBR_NONE)
24223 TRACE_IRQS_OFF
24224 GET_THREAD_INFO(%rcx)
24225- testl %eax,%eax
24226+ testl $1,%eax
24227 jne retint_kernel
24228 LOCKDEP_SYS_EXIT_IRQ
24229 movl TI_flags(%rcx),%edx
24230@@ -1636,7 +2147,7 @@ ENTRY(error_exit)
24231 jnz retint_careful
24232 jmp retint_swapgs
24233 CFI_ENDPROC
24234-END(error_exit)
24235+ENDPROC(error_exit)
24236
24237 /*
24238 * Test if a given stack is an NMI stack or not.
24239@@ -1694,9 +2205,11 @@ ENTRY(nmi)
24240 * If %cs was not the kernel segment, then the NMI triggered in user
24241 * space, which means it is definitely not nested.
24242 */
24243+ cmpl $__KERNEXEC_KERNEL_CS, 16(%rsp)
24244+ je 1f
24245 cmpl $__KERNEL_CS, 16(%rsp)
24246 jne first_nmi
24247-
24248+1:
24249 /*
24250 * Check the special variable on the stack to see if NMIs are
24251 * executing.
24252@@ -1730,8 +2243,7 @@ nested_nmi:
24253
24254 1:
24255 /* Set up the interrupted NMIs stack to jump to repeat_nmi */
24256- leaq -1*8(%rsp), %rdx
24257- movq %rdx, %rsp
24258+ subq $8, %rsp
24259 CFI_ADJUST_CFA_OFFSET 1*8
24260 leaq -10*8(%rsp), %rdx
24261 pushq_cfi $__KERNEL_DS
24262@@ -1749,6 +2261,7 @@ nested_nmi_out:
24263 CFI_RESTORE rdx
24264
24265 /* No need to check faults here */
24266+# pax_force_retaddr_bts
24267 INTERRUPT_RETURN
24268
24269 CFI_RESTORE_STATE
24270@@ -1845,13 +2358,13 @@ end_repeat_nmi:
24271 subq $ORIG_RAX-R15, %rsp
24272 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
24273 /*
24274- * Use save_paranoid to handle SWAPGS, but no need to use paranoid_exit
24275+ * Use save_paranoid_nmi to handle SWAPGS, but no need to use paranoid_exit
24276 * as we should not be calling schedule in NMI context.
24277 * Even with normal interrupts enabled. An NMI should not be
24278 * setting NEED_RESCHED or anything that normal interrupts and
24279 * exceptions might do.
24280 */
24281- call save_paranoid
24282+ call save_paranoid_nmi
24283 DEFAULT_FRAME 0
24284
24285 /*
24286@@ -1861,9 +2374,9 @@ end_repeat_nmi:
24287 * NMI itself takes a page fault, the page fault that was preempted
24288 * will read the information from the NMI page fault and not the
24289 * origin fault. Save it off and restore it if it changes.
24290- * Use the r12 callee-saved register.
24291+ * Use the r13 callee-saved register.
24292 */
24293- movq %cr2, %r12
24294+ movq %cr2, %r13
24295
24296 /* paranoidentry do_nmi, 0; without TRACE_IRQS_OFF */
24297 movq %rsp,%rdi
24298@@ -1872,31 +2385,36 @@ end_repeat_nmi:
24299
24300 /* Did the NMI take a page fault? Restore cr2 if it did */
24301 movq %cr2, %rcx
24302- cmpq %rcx, %r12
24303+ cmpq %rcx, %r13
24304 je 1f
24305- movq %r12, %cr2
24306+ movq %r13, %cr2
24307 1:
24308
24309- testl %ebx,%ebx /* swapgs needed? */
24310+ testl $1,%ebx /* swapgs needed? */
24311 jnz nmi_restore
24312 nmi_swapgs:
24313 SWAPGS_UNSAFE_STACK
24314 nmi_restore:
24315+ pax_exit_kernel_nmi
24316 /* Pop the extra iret frame at once */
24317 RESTORE_ALL 6*8
24318+ testb $3, 8(%rsp)
24319+ jnz 1f
24320+ pax_force_retaddr_bts
24321+1:
24322
24323 /* Clear the NMI executing stack variable */
24324 movq $0, 5*8(%rsp)
24325 jmp irq_return
24326 CFI_ENDPROC
24327-END(nmi)
24328+ENDPROC(nmi)
24329
24330 ENTRY(ignore_sysret)
24331 CFI_STARTPROC
24332 mov $-ENOSYS,%eax
24333 sysret
24334 CFI_ENDPROC
24335-END(ignore_sysret)
24336+ENDPROC(ignore_sysret)
24337
24338 /*
24339 * End of kprobes section
24340diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c
24341index 1ffc32d..e52c745 100644
24342--- a/arch/x86/kernel/ftrace.c
24343+++ b/arch/x86/kernel/ftrace.c
24344@@ -104,6 +104,8 @@ ftrace_modify_code_direct(unsigned long ip, unsigned const char *old_code,
24345 {
24346 unsigned char replaced[MCOUNT_INSN_SIZE];
24347
24348+ ip = ktla_ktva(ip);
24349+
24350 /*
24351 * Note: Due to modules and __init, code can
24352 * disappear and change, we need to protect against faulting
24353@@ -229,7 +231,7 @@ static int update_ftrace_func(unsigned long ip, void *new)
24354 unsigned char old[MCOUNT_INSN_SIZE];
24355 int ret;
24356
24357- memcpy(old, (void *)ip, MCOUNT_INSN_SIZE);
24358+ memcpy(old, (void *)ktla_ktva(ip), MCOUNT_INSN_SIZE);
24359
24360 ftrace_update_func = ip;
24361 /* Make sure the breakpoints see the ftrace_update_func update */
24362@@ -306,7 +308,7 @@ static int ftrace_write(unsigned long ip, const char *val, int size)
24363 * kernel identity mapping to modify code.
24364 */
24365 if (within(ip, (unsigned long)_text, (unsigned long)_etext))
24366- ip = (unsigned long)__va(__pa_symbol(ip));
24367+ ip = (unsigned long)__va(__pa_symbol(ktla_ktva(ip)));
24368
24369 return probe_kernel_write((void *)ip, val, size);
24370 }
24371@@ -316,7 +318,7 @@ static int add_break(unsigned long ip, const char *old)
24372 unsigned char replaced[MCOUNT_INSN_SIZE];
24373 unsigned char brk = BREAKPOINT_INSTRUCTION;
24374
24375- if (probe_kernel_read(replaced, (void *)ip, MCOUNT_INSN_SIZE))
24376+ if (probe_kernel_read(replaced, (void *)ktla_ktva(ip), MCOUNT_INSN_SIZE))
24377 return -EFAULT;
24378
24379 /* Make sure it is what we expect it to be */
24380@@ -664,7 +666,7 @@ ftrace_modify_code(unsigned long ip, unsigned const char *old_code,
24381 return ret;
24382
24383 fail_update:
24384- probe_kernel_write((void *)ip, &old_code[0], 1);
24385+ probe_kernel_write((void *)ktla_ktva(ip), &old_code[0], 1);
24386 goto out;
24387 }
24388
24389diff --git a/arch/x86/kernel/head64.c b/arch/x86/kernel/head64.c
24390index 85126cc..1bbce17 100644
24391--- a/arch/x86/kernel/head64.c
24392+++ b/arch/x86/kernel/head64.c
24393@@ -67,12 +67,12 @@ again:
24394 pgd = *pgd_p;
24395
24396 /*
24397- * The use of __START_KERNEL_map rather than __PAGE_OFFSET here is
24398- * critical -- __PAGE_OFFSET would point us back into the dynamic
24399+ * The use of __early_va rather than __va here is critical:
24400+ * __va would point us back into the dynamic
24401 * range and we might end up looping forever...
24402 */
24403 if (pgd)
24404- pud_p = (pudval_t *)((pgd & PTE_PFN_MASK) + __START_KERNEL_map - phys_base);
24405+ pud_p = (pudval_t *)(__early_va(pgd & PTE_PFN_MASK));
24406 else {
24407 if (next_early_pgt >= EARLY_DYNAMIC_PAGE_TABLES) {
24408 reset_early_page_tables();
24409@@ -82,13 +82,13 @@ again:
24410 pud_p = (pudval_t *)early_dynamic_pgts[next_early_pgt++];
24411 for (i = 0; i < PTRS_PER_PUD; i++)
24412 pud_p[i] = 0;
24413- *pgd_p = (pgdval_t)pud_p - __START_KERNEL_map + phys_base + _KERNPG_TABLE;
24414+ *pgd_p = (pgdval_t)__pa(pud_p) + _KERNPG_TABLE;
24415 }
24416 pud_p += pud_index(address);
24417 pud = *pud_p;
24418
24419 if (pud)
24420- pmd_p = (pmdval_t *)((pud & PTE_PFN_MASK) + __START_KERNEL_map - phys_base);
24421+ pmd_p = (pmdval_t *)(__early_va(pud & PTE_PFN_MASK));
24422 else {
24423 if (next_early_pgt >= EARLY_DYNAMIC_PAGE_TABLES) {
24424 reset_early_page_tables();
24425@@ -98,7 +98,7 @@ again:
24426 pmd_p = (pmdval_t *)early_dynamic_pgts[next_early_pgt++];
24427 for (i = 0; i < PTRS_PER_PMD; i++)
24428 pmd_p[i] = 0;
24429- *pud_p = (pudval_t)pmd_p - __START_KERNEL_map + phys_base + _KERNPG_TABLE;
24430+ *pud_p = (pudval_t)__pa(pmd_p) + _KERNPG_TABLE;
24431 }
24432 pmd = (physaddr & PMD_MASK) + early_pmd_flags;
24433 pmd_p[pmd_index(address)] = pmd;
24434@@ -175,7 +175,6 @@ asmlinkage void __init x86_64_start_kernel(char * real_mode_data)
24435 if (console_loglevel == 10)
24436 early_printk("Kernel alive\n");
24437
24438- clear_page(init_level4_pgt);
24439 /* set init_level4_pgt kernel high mapping*/
24440 init_level4_pgt[511] = early_level4_pgt[511];
24441
24442diff --git a/arch/x86/kernel/head_32.S b/arch/x86/kernel/head_32.S
24443index f36bd42..56ee1534 100644
24444--- a/arch/x86/kernel/head_32.S
24445+++ b/arch/x86/kernel/head_32.S
24446@@ -26,6 +26,12 @@
24447 /* Physical address */
24448 #define pa(X) ((X) - __PAGE_OFFSET)
24449
24450+#ifdef CONFIG_PAX_KERNEXEC
24451+#define ta(X) (X)
24452+#else
24453+#define ta(X) ((X) - __PAGE_OFFSET)
24454+#endif
24455+
24456 /*
24457 * References to members of the new_cpu_data structure.
24458 */
24459@@ -55,11 +61,7 @@
24460 * and small than max_low_pfn, otherwise will waste some page table entries
24461 */
24462
24463-#if PTRS_PER_PMD > 1
24464-#define PAGE_TABLE_SIZE(pages) (((pages) / PTRS_PER_PMD) + PTRS_PER_PGD)
24465-#else
24466-#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PGD)
24467-#endif
24468+#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PTE)
24469
24470 /* Number of possible pages in the lowmem region */
24471 LOWMEM_PAGES = (((1<<32) - __PAGE_OFFSET) >> PAGE_SHIFT)
24472@@ -78,6 +80,12 @@ INIT_MAP_SIZE = PAGE_TABLE_SIZE(KERNEL_PAGES) * PAGE_SIZE
24473 RESERVE_BRK(pagetables, INIT_MAP_SIZE)
24474
24475 /*
24476+ * Real beginning of normal "text" segment
24477+ */
24478+ENTRY(stext)
24479+ENTRY(_stext)
24480+
24481+/*
24482 * 32-bit kernel entrypoint; only used by the boot CPU. On entry,
24483 * %esi points to the real-mode code as a 32-bit pointer.
24484 * CS and DS must be 4 GB flat segments, but we don't depend on
24485@@ -85,6 +93,13 @@ RESERVE_BRK(pagetables, INIT_MAP_SIZE)
24486 * can.
24487 */
24488 __HEAD
24489+
24490+#ifdef CONFIG_PAX_KERNEXEC
24491+ jmp startup_32
24492+/* PaX: fill first page in .text with int3 to catch NULL derefs in kernel mode */
24493+.fill PAGE_SIZE-5,1,0xcc
24494+#endif
24495+
24496 ENTRY(startup_32)
24497 movl pa(stack_start),%ecx
24498
24499@@ -106,6 +121,59 @@ ENTRY(startup_32)
24500 2:
24501 leal -__PAGE_OFFSET(%ecx),%esp
24502
24503+#ifdef CONFIG_SMP
24504+ movl $pa(cpu_gdt_table),%edi
24505+ movl $__per_cpu_load,%eax
24506+ movw %ax,GDT_ENTRY_PERCPU * 8 + 2(%edi)
24507+ rorl $16,%eax
24508+ movb %al,GDT_ENTRY_PERCPU * 8 + 4(%edi)
24509+ movb %ah,GDT_ENTRY_PERCPU * 8 + 7(%edi)
24510+ movl $__per_cpu_end - 1,%eax
24511+ subl $__per_cpu_start,%eax
24512+ movw %ax,GDT_ENTRY_PERCPU * 8 + 0(%edi)
24513+#endif
24514+
24515+#ifdef CONFIG_PAX_MEMORY_UDEREF
24516+ movl $NR_CPUS,%ecx
24517+ movl $pa(cpu_gdt_table),%edi
24518+1:
24519+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c09700),GDT_ENTRY_KERNEL_DS * 8 + 4(%edi)
24520+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0fb00),GDT_ENTRY_DEFAULT_USER_CS * 8 + 4(%edi)
24521+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0f300),GDT_ENTRY_DEFAULT_USER_DS * 8 + 4(%edi)
24522+ addl $PAGE_SIZE_asm,%edi
24523+ loop 1b
24524+#endif
24525+
24526+#ifdef CONFIG_PAX_KERNEXEC
24527+ movl $pa(boot_gdt),%edi
24528+ movl $__LOAD_PHYSICAL_ADDR,%eax
24529+ movw %ax,GDT_ENTRY_BOOT_CS * 8 + 2(%edi)
24530+ rorl $16,%eax
24531+ movb %al,GDT_ENTRY_BOOT_CS * 8 + 4(%edi)
24532+ movb %ah,GDT_ENTRY_BOOT_CS * 8 + 7(%edi)
24533+ rorl $16,%eax
24534+
24535+ ljmp $(__BOOT_CS),$1f
24536+1:
24537+
24538+ movl $NR_CPUS,%ecx
24539+ movl $pa(cpu_gdt_table),%edi
24540+ addl $__PAGE_OFFSET,%eax
24541+1:
24542+ movb $0xc0,GDT_ENTRY_KERNEL_CS * 8 + 6(%edi)
24543+ movb $0xc0,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 6(%edi)
24544+ movw %ax,GDT_ENTRY_KERNEL_CS * 8 + 2(%edi)
24545+ movw %ax,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 2(%edi)
24546+ rorl $16,%eax
24547+ movb %al,GDT_ENTRY_KERNEL_CS * 8 + 4(%edi)
24548+ movb %al,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 4(%edi)
24549+ movb %ah,GDT_ENTRY_KERNEL_CS * 8 + 7(%edi)
24550+ movb %ah,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 7(%edi)
24551+ rorl $16,%eax
24552+ addl $PAGE_SIZE_asm,%edi
24553+ loop 1b
24554+#endif
24555+
24556 /*
24557 * Clear BSS first so that there are no surprises...
24558 */
24559@@ -201,8 +269,11 @@ ENTRY(startup_32)
24560 movl %eax, pa(max_pfn_mapped)
24561
24562 /* Do early initialization of the fixmap area */
24563- movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
24564- movl %eax,pa(initial_pg_pmd+0x1000*KPMDS-8)
24565+#ifdef CONFIG_COMPAT_VDSO
24566+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_pg_pmd+0x1000*KPMDS-8)
24567+#else
24568+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_pg_pmd+0x1000*KPMDS-8)
24569+#endif
24570 #else /* Not PAE */
24571
24572 page_pde_offset = (__PAGE_OFFSET >> 20);
24573@@ -232,8 +303,11 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
24574 movl %eax, pa(max_pfn_mapped)
24575
24576 /* Do early initialization of the fixmap area */
24577- movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
24578- movl %eax,pa(initial_page_table+0xffc)
24579+#ifdef CONFIG_COMPAT_VDSO
24580+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_page_table+0xffc)
24581+#else
24582+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_page_table+0xffc)
24583+#endif
24584 #endif
24585
24586 #ifdef CONFIG_PARAVIRT
24587@@ -247,9 +321,7 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
24588 cmpl $num_subarch_entries, %eax
24589 jae bad_subarch
24590
24591- movl pa(subarch_entries)(,%eax,4), %eax
24592- subl $__PAGE_OFFSET, %eax
24593- jmp *%eax
24594+ jmp *pa(subarch_entries)(,%eax,4)
24595
24596 bad_subarch:
24597 WEAK(lguest_entry)
24598@@ -261,10 +333,10 @@ WEAK(xen_entry)
24599 __INITDATA
24600
24601 subarch_entries:
24602- .long default_entry /* normal x86/PC */
24603- .long lguest_entry /* lguest hypervisor */
24604- .long xen_entry /* Xen hypervisor */
24605- .long default_entry /* Moorestown MID */
24606+ .long ta(default_entry) /* normal x86/PC */
24607+ .long ta(lguest_entry) /* lguest hypervisor */
24608+ .long ta(xen_entry) /* Xen hypervisor */
24609+ .long ta(default_entry) /* Moorestown MID */
24610 num_subarch_entries = (. - subarch_entries) / 4
24611 .previous
24612 #else
24613@@ -354,6 +426,7 @@ default_entry:
24614 movl pa(mmu_cr4_features),%eax
24615 movl %eax,%cr4
24616
24617+#ifdef CONFIG_X86_PAE
24618 testb $X86_CR4_PAE, %al # check if PAE is enabled
24619 jz enable_paging
24620
24621@@ -382,6 +455,9 @@ default_entry:
24622 /* Make changes effective */
24623 wrmsr
24624
24625+ btsl $_PAGE_BIT_NX-32,pa(__supported_pte_mask+4)
24626+#endif
24627+
24628 enable_paging:
24629
24630 /*
24631@@ -449,14 +525,20 @@ is486:
24632 1: movl $(__KERNEL_DS),%eax # reload all the segment registers
24633 movl %eax,%ss # after changing gdt.
24634
24635- movl $(__USER_DS),%eax # DS/ES contains default USER segment
24636+# movl $(__KERNEL_DS),%eax # DS/ES contains default KERNEL segment
24637 movl %eax,%ds
24638 movl %eax,%es
24639
24640 movl $(__KERNEL_PERCPU), %eax
24641 movl %eax,%fs # set this cpu's percpu
24642
24643+#ifdef CONFIG_CC_STACKPROTECTOR
24644 movl $(__KERNEL_STACK_CANARY),%eax
24645+#elif defined(CONFIG_PAX_MEMORY_UDEREF)
24646+ movl $(__USER_DS),%eax
24647+#else
24648+ xorl %eax,%eax
24649+#endif
24650 movl %eax,%gs
24651
24652 xorl %eax,%eax # Clear LDT
24653@@ -512,8 +594,11 @@ setup_once:
24654 * relocation. Manually set base address in stack canary
24655 * segment descriptor.
24656 */
24657- movl $gdt_page,%eax
24658+ movl $cpu_gdt_table,%eax
24659 movl $stack_canary,%ecx
24660+#ifdef CONFIG_SMP
24661+ addl $__per_cpu_load,%ecx
24662+#endif
24663 movw %cx, 8 * GDT_ENTRY_STACK_CANARY + 2(%eax)
24664 shrl $16, %ecx
24665 movb %cl, 8 * GDT_ENTRY_STACK_CANARY + 4(%eax)
24666@@ -548,7 +633,7 @@ ENTRY(early_idt_handler)
24667 cmpl $2,(%esp) # X86_TRAP_NMI
24668 je is_nmi # Ignore NMI
24669
24670- cmpl $2,%ss:early_recursion_flag
24671+ cmpl $1,%ss:early_recursion_flag
24672 je hlt_loop
24673 incl %ss:early_recursion_flag
24674
24675@@ -586,8 +671,8 @@ ENTRY(early_idt_handler)
24676 pushl (20+6*4)(%esp) /* trapno */
24677 pushl $fault_msg
24678 call printk
24679-#endif
24680 call dump_stack
24681+#endif
24682 hlt_loop:
24683 hlt
24684 jmp hlt_loop
24685@@ -607,8 +692,11 @@ ENDPROC(early_idt_handler)
24686 /* This is the default interrupt "handler" :-) */
24687 ALIGN
24688 ignore_int:
24689- cld
24690 #ifdef CONFIG_PRINTK
24691+ cmpl $2,%ss:early_recursion_flag
24692+ je hlt_loop
24693+ incl %ss:early_recursion_flag
24694+ cld
24695 pushl %eax
24696 pushl %ecx
24697 pushl %edx
24698@@ -617,9 +705,6 @@ ignore_int:
24699 movl $(__KERNEL_DS),%eax
24700 movl %eax,%ds
24701 movl %eax,%es
24702- cmpl $2,early_recursion_flag
24703- je hlt_loop
24704- incl early_recursion_flag
24705 pushl 16(%esp)
24706 pushl 24(%esp)
24707 pushl 32(%esp)
24708@@ -653,29 +738,34 @@ ENTRY(setup_once_ref)
24709 /*
24710 * BSS section
24711 */
24712-__PAGE_ALIGNED_BSS
24713- .align PAGE_SIZE
24714 #ifdef CONFIG_X86_PAE
24715+.section .initial_pg_pmd,"a",@progbits
24716 initial_pg_pmd:
24717 .fill 1024*KPMDS,4,0
24718 #else
24719+.section .initial_page_table,"a",@progbits
24720 ENTRY(initial_page_table)
24721 .fill 1024,4,0
24722 #endif
24723+.section .initial_pg_fixmap,"a",@progbits
24724 initial_pg_fixmap:
24725 .fill 1024,4,0
24726+.section .empty_zero_page,"a",@progbits
24727 ENTRY(empty_zero_page)
24728 .fill 4096,1,0
24729+.section .swapper_pg_dir,"a",@progbits
24730 ENTRY(swapper_pg_dir)
24731+#ifdef CONFIG_X86_PAE
24732+ .fill 4,8,0
24733+#else
24734 .fill 1024,4,0
24735+#endif
24736
24737 /*
24738 * This starts the data section.
24739 */
24740 #ifdef CONFIG_X86_PAE
24741-__PAGE_ALIGNED_DATA
24742- /* Page-aligned for the benefit of paravirt? */
24743- .align PAGE_SIZE
24744+.section .initial_page_table,"a",@progbits
24745 ENTRY(initial_page_table)
24746 .long pa(initial_pg_pmd+PGD_IDENT_ATTR),0 /* low identity map */
24747 # if KPMDS == 3
24748@@ -694,12 +784,20 @@ ENTRY(initial_page_table)
24749 # error "Kernel PMDs should be 1, 2 or 3"
24750 # endif
24751 .align PAGE_SIZE /* needs to be page-sized too */
24752+
24753+#ifdef CONFIG_PAX_PER_CPU_PGD
24754+ENTRY(cpu_pgd)
24755+ .rept 2*NR_CPUS
24756+ .fill 4,8,0
24757+ .endr
24758+#endif
24759+
24760 #endif
24761
24762 .data
24763 .balign 4
24764 ENTRY(stack_start)
24765- .long init_thread_union+THREAD_SIZE
24766+ .long init_thread_union+THREAD_SIZE-8
24767
24768 __INITRODATA
24769 int_msg:
24770@@ -727,7 +825,7 @@ fault_msg:
24771 * segment size, and 32-bit linear address value:
24772 */
24773
24774- .data
24775+.section .rodata,"a",@progbits
24776 .globl boot_gdt_descr
24777 .globl idt_descr
24778
24779@@ -736,7 +834,7 @@ fault_msg:
24780 .word 0 # 32 bit align gdt_desc.address
24781 boot_gdt_descr:
24782 .word __BOOT_DS+7
24783- .long boot_gdt - __PAGE_OFFSET
24784+ .long pa(boot_gdt)
24785
24786 .word 0 # 32-bit align idt_desc.address
24787 idt_descr:
24788@@ -747,7 +845,7 @@ idt_descr:
24789 .word 0 # 32 bit align gdt_desc.address
24790 ENTRY(early_gdt_descr)
24791 .word GDT_ENTRIES*8-1
24792- .long gdt_page /* Overwritten for secondary CPUs */
24793+ .long cpu_gdt_table /* Overwritten for secondary CPUs */
24794
24795 /*
24796 * The boot_gdt must mirror the equivalent in setup.S and is
24797@@ -756,5 +854,65 @@ ENTRY(early_gdt_descr)
24798 .align L1_CACHE_BYTES
24799 ENTRY(boot_gdt)
24800 .fill GDT_ENTRY_BOOT_CS,8,0
24801- .quad 0x00cf9a000000ffff /* kernel 4GB code at 0x00000000 */
24802- .quad 0x00cf92000000ffff /* kernel 4GB data at 0x00000000 */
24803+ .quad 0x00cf9b000000ffff /* kernel 4GB code at 0x00000000 */
24804+ .quad 0x00cf93000000ffff /* kernel 4GB data at 0x00000000 */
24805+
24806+ .align PAGE_SIZE_asm
24807+ENTRY(cpu_gdt_table)
24808+ .rept NR_CPUS
24809+ .quad 0x0000000000000000 /* NULL descriptor */
24810+ .quad 0x0000000000000000 /* 0x0b reserved */
24811+ .quad 0x0000000000000000 /* 0x13 reserved */
24812+ .quad 0x0000000000000000 /* 0x1b reserved */
24813+
24814+#ifdef CONFIG_PAX_KERNEXEC
24815+ .quad 0x00cf9b000000ffff /* 0x20 alternate kernel 4GB code at 0x00000000 */
24816+#else
24817+ .quad 0x0000000000000000 /* 0x20 unused */
24818+#endif
24819+
24820+ .quad 0x0000000000000000 /* 0x28 unused */
24821+ .quad 0x0000000000000000 /* 0x33 TLS entry 1 */
24822+ .quad 0x0000000000000000 /* 0x3b TLS entry 2 */
24823+ .quad 0x0000000000000000 /* 0x43 TLS entry 3 */
24824+ .quad 0x0000000000000000 /* 0x4b reserved */
24825+ .quad 0x0000000000000000 /* 0x53 reserved */
24826+ .quad 0x0000000000000000 /* 0x5b reserved */
24827+
24828+ .quad 0x00cf9b000000ffff /* 0x60 kernel 4GB code at 0x00000000 */
24829+ .quad 0x00cf93000000ffff /* 0x68 kernel 4GB data at 0x00000000 */
24830+ .quad 0x00cffb000000ffff /* 0x73 user 4GB code at 0x00000000 */
24831+ .quad 0x00cff3000000ffff /* 0x7b user 4GB data at 0x00000000 */
24832+
24833+ .quad 0x0000000000000000 /* 0x80 TSS descriptor */
24834+ .quad 0x0000000000000000 /* 0x88 LDT descriptor */
24835+
24836+ /*
24837+ * Segments used for calling PnP BIOS have byte granularity.
24838+ * The code segments and data segments have fixed 64k limits,
24839+ * the transfer segment sizes are set at run time.
24840+ */
24841+ .quad 0x00409b000000ffff /* 0x90 32-bit code */
24842+ .quad 0x00009b000000ffff /* 0x98 16-bit code */
24843+ .quad 0x000093000000ffff /* 0xa0 16-bit data */
24844+ .quad 0x0000930000000000 /* 0xa8 16-bit data */
24845+ .quad 0x0000930000000000 /* 0xb0 16-bit data */
24846+
24847+ /*
24848+ * The APM segments have byte granularity and their bases
24849+ * are set at run time. All have 64k limits.
24850+ */
24851+ .quad 0x00409b000000ffff /* 0xb8 APM CS code */
24852+ .quad 0x00009b000000ffff /* 0xc0 APM CS 16 code (16 bit) */
24853+ .quad 0x004093000000ffff /* 0xc8 APM DS data */
24854+
24855+ .quad 0x00c0930000000000 /* 0xd0 - ESPFIX SS */
24856+ .quad 0x0040930000000000 /* 0xd8 - PERCPU */
24857+ .quad 0x0040910000000017 /* 0xe0 - STACK_CANARY */
24858+ .quad 0x0000000000000000 /* 0xe8 - PCIBIOS_CS */
24859+ .quad 0x0000000000000000 /* 0xf0 - PCIBIOS_DS */
24860+ .quad 0x0000000000000000 /* 0xf8 - GDT entry 31: double-fault TSS */
24861+
24862+ /* Be sure this is zeroed to avoid false validations in Xen */
24863+ .fill PAGE_SIZE_asm - GDT_SIZE,1,0
24864+ .endr
24865diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S
24866index a468c0a..c7dec74 100644
24867--- a/arch/x86/kernel/head_64.S
24868+++ b/arch/x86/kernel/head_64.S
24869@@ -20,6 +20,8 @@
24870 #include <asm/processor-flags.h>
24871 #include <asm/percpu.h>
24872 #include <asm/nops.h>
24873+#include <asm/cpufeature.h>
24874+#include <asm/alternative-asm.h>
24875
24876 #ifdef CONFIG_PARAVIRT
24877 #include <asm/asm-offsets.h>
24878@@ -41,6 +43,12 @@ L4_PAGE_OFFSET = pgd_index(__PAGE_OFFSET)
24879 L3_PAGE_OFFSET = pud_index(__PAGE_OFFSET)
24880 L4_START_KERNEL = pgd_index(__START_KERNEL_map)
24881 L3_START_KERNEL = pud_index(__START_KERNEL_map)
24882+L4_VMALLOC_START = pgd_index(VMALLOC_START)
24883+L3_VMALLOC_START = pud_index(VMALLOC_START)
24884+L4_VMALLOC_END = pgd_index(VMALLOC_END)
24885+L3_VMALLOC_END = pud_index(VMALLOC_END)
24886+L4_VMEMMAP_START = pgd_index(VMEMMAP_START)
24887+L3_VMEMMAP_START = pud_index(VMEMMAP_START)
24888
24889 .text
24890 __HEAD
24891@@ -89,11 +97,24 @@ startup_64:
24892 * Fixup the physical addresses in the page table
24893 */
24894 addq %rbp, early_level4_pgt + (L4_START_KERNEL*8)(%rip)
24895+ addq %rbp, init_level4_pgt + (L4_PAGE_OFFSET*8)(%rip)
24896+ addq %rbp, init_level4_pgt + (L4_VMALLOC_START*8)(%rip)
24897+ addq %rbp, init_level4_pgt + (L4_VMALLOC_END*8)(%rip)
24898+ addq %rbp, init_level4_pgt + (L4_VMEMMAP_START*8)(%rip)
24899+ addq %rbp, init_level4_pgt + (L4_START_KERNEL*8)(%rip)
24900
24901- addq %rbp, level3_kernel_pgt + (510*8)(%rip)
24902- addq %rbp, level3_kernel_pgt + (511*8)(%rip)
24903+ addq %rbp, level3_ident_pgt + (0*8)(%rip)
24904+#ifndef CONFIG_XEN
24905+ addq %rbp, level3_ident_pgt + (1*8)(%rip)
24906+#endif
24907+
24908+ addq %rbp, level3_vmemmap_pgt + (L3_VMEMMAP_START*8)(%rip)
24909+
24910+ addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8)(%rip)
24911+ addq %rbp, level3_kernel_pgt + ((L3_START_KERNEL+1)*8)(%rip)
24912
24913 addq %rbp, level2_fixmap_pgt + (506*8)(%rip)
24914+ addq %rbp, level2_fixmap_pgt + (507*8)(%rip)
24915
24916 /*
24917 * Set up the identity mapping for the switchover. These
24918@@ -177,8 +198,8 @@ ENTRY(secondary_startup_64)
24919 movq $(init_level4_pgt - __START_KERNEL_map), %rax
24920 1:
24921
24922- /* Enable PAE mode and PGE */
24923- movl $(X86_CR4_PAE | X86_CR4_PGE), %ecx
24924+ /* Enable PAE mode and PSE/PGE */
24925+ movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %ecx
24926 movq %rcx, %cr4
24927
24928 /* Setup early boot stage 4 level pagetables. */
24929@@ -199,10 +220,19 @@ ENTRY(secondary_startup_64)
24930 movl $MSR_EFER, %ecx
24931 rdmsr
24932 btsl $_EFER_SCE, %eax /* Enable System Call */
24933- btl $20,%edi /* No Execute supported? */
24934+ btl $(X86_FEATURE_NX & 31),%edi /* No Execute supported? */
24935 jnc 1f
24936 btsl $_EFER_NX, %eax
24937 btsq $_PAGE_BIT_NX,early_pmd_flags(%rip)
24938+#ifndef CONFIG_EFI
24939+ btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_PAGE_OFFSET(%rip)
24940+#endif
24941+ btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_VMALLOC_START(%rip)
24942+ btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_VMALLOC_END(%rip)
24943+ btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_VMEMMAP_START(%rip)
24944+ btsq $_PAGE_BIT_NX, level2_fixmap_pgt + 8*506(%rip)
24945+ btsq $_PAGE_BIT_NX, level2_fixmap_pgt + 8*507(%rip)
24946+ btsq $_PAGE_BIT_NX, __supported_pte_mask(%rip)
24947 1: wrmsr /* Make changes effective */
24948
24949 /* Setup cr0 */
24950@@ -282,6 +312,7 @@ ENTRY(secondary_startup_64)
24951 * REX.W + FF /5 JMP m16:64 Jump far, absolute indirect,
24952 * address given in m16:64.
24953 */
24954+ pax_set_fptr_mask
24955 movq initial_code(%rip),%rax
24956 pushq $0 # fake return address to stop unwinder
24957 pushq $__KERNEL_CS # set correct cs
24958@@ -313,7 +344,7 @@ ENDPROC(start_cpu0)
24959 .quad INIT_PER_CPU_VAR(irq_stack_union)
24960
24961 GLOBAL(stack_start)
24962- .quad init_thread_union+THREAD_SIZE-8
24963+ .quad init_thread_union+THREAD_SIZE-16
24964 .word 0
24965 __FINITDATA
24966
24967@@ -391,7 +422,7 @@ ENTRY(early_idt_handler)
24968 call dump_stack
24969 #ifdef CONFIG_KALLSYMS
24970 leaq early_idt_ripmsg(%rip),%rdi
24971- movq 40(%rsp),%rsi # %rip again
24972+ movq 88(%rsp),%rsi # %rip again
24973 call __print_symbol
24974 #endif
24975 #endif /* EARLY_PRINTK */
24976@@ -420,6 +451,7 @@ ENDPROC(early_idt_handler)
24977 early_recursion_flag:
24978 .long 0
24979
24980+ .section .rodata,"a",@progbits
24981 #ifdef CONFIG_EARLY_PRINTK
24982 early_idt_msg:
24983 .asciz "PANIC: early exception %02lx rip %lx:%lx error %lx cr2 %lx\n"
24984@@ -447,29 +479,52 @@ NEXT_PAGE(early_level4_pgt)
24985 NEXT_PAGE(early_dynamic_pgts)
24986 .fill 512*EARLY_DYNAMIC_PAGE_TABLES,8,0
24987
24988- .data
24989+ .section .rodata,"a",@progbits
24990
24991-#ifndef CONFIG_XEN
24992 NEXT_PAGE(init_level4_pgt)
24993- .fill 512,8,0
24994-#else
24995-NEXT_PAGE(init_level4_pgt)
24996- .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
24997 .org init_level4_pgt + L4_PAGE_OFFSET*8, 0
24998 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
24999+ .org init_level4_pgt + L4_VMALLOC_START*8, 0
25000+ .quad level3_vmalloc_start_pgt - __START_KERNEL_map + _KERNPG_TABLE
25001+ .org init_level4_pgt + L4_VMALLOC_END*8, 0
25002+ .quad level3_vmalloc_end_pgt - __START_KERNEL_map + _KERNPG_TABLE
25003+ .org init_level4_pgt + L4_VMEMMAP_START*8, 0
25004+ .quad level3_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
25005 .org init_level4_pgt + L4_START_KERNEL*8, 0
25006 /* (2^48-(2*1024*1024*1024))/(2^39) = 511 */
25007 .quad level3_kernel_pgt - __START_KERNEL_map + _PAGE_TABLE
25008
25009+#ifdef CONFIG_PAX_PER_CPU_PGD
25010+NEXT_PAGE(cpu_pgd)
25011+ .rept 2*NR_CPUS
25012+ .fill 512,8,0
25013+ .endr
25014+#endif
25015+
25016 NEXT_PAGE(level3_ident_pgt)
25017 .quad level2_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
25018+#ifdef CONFIG_XEN
25019 .fill 511, 8, 0
25020+#else
25021+ .quad level2_ident_pgt + PAGE_SIZE - __START_KERNEL_map + _KERNPG_TABLE
25022+ .fill 510,8,0
25023+#endif
25024+
25025+NEXT_PAGE(level3_vmalloc_start_pgt)
25026+ .fill 512,8,0
25027+
25028+NEXT_PAGE(level3_vmalloc_end_pgt)
25029+ .fill 512,8,0
25030+
25031+NEXT_PAGE(level3_vmemmap_pgt)
25032+ .fill L3_VMEMMAP_START,8,0
25033+ .quad level2_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
25034+
25035 NEXT_PAGE(level2_ident_pgt)
25036- /* Since I easily can, map the first 1G.
25037+ /* Since I easily can, map the first 2G.
25038 * Don't set NX because code runs from these pages.
25039 */
25040- PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, PTRS_PER_PMD)
25041-#endif
25042+ PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, 2*PTRS_PER_PMD)
25043
25044 NEXT_PAGE(level3_kernel_pgt)
25045 .fill L3_START_KERNEL,8,0
25046@@ -477,6 +532,9 @@ NEXT_PAGE(level3_kernel_pgt)
25047 .quad level2_kernel_pgt - __START_KERNEL_map + _KERNPG_TABLE
25048 .quad level2_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
25049
25050+NEXT_PAGE(level2_vmemmap_pgt)
25051+ .fill 512,8,0
25052+
25053 NEXT_PAGE(level2_kernel_pgt)
25054 /*
25055 * 512 MB kernel mapping. We spend a full page on this pagetable
25056@@ -494,28 +552,64 @@ NEXT_PAGE(level2_kernel_pgt)
25057 NEXT_PAGE(level2_fixmap_pgt)
25058 .fill 506,8,0
25059 .quad level1_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
25060- /* 8MB reserved for vsyscalls + a 2MB hole = 4 + 1 entries */
25061- .fill 5,8,0
25062+ .quad level1_vsyscall_pgt - __START_KERNEL_map + _PAGE_TABLE
25063+ /* 6MB reserved for vsyscalls + a 2MB hole = 3 + 1 entries */
25064+ .fill 4,8,0
25065
25066 NEXT_PAGE(level1_fixmap_pgt)
25067 .fill 512,8,0
25068
25069+NEXT_PAGE(level1_vsyscall_pgt)
25070+ .fill 512,8,0
25071+
25072 #undef PMDS
25073
25074- .data
25075+ .align PAGE_SIZE
25076+ENTRY(cpu_gdt_table)
25077+ .rept NR_CPUS
25078+ .quad 0x0000000000000000 /* NULL descriptor */
25079+ .quad 0x00cf9b000000ffff /* __KERNEL32_CS */
25080+ .quad 0x00af9b000000ffff /* __KERNEL_CS */
25081+ .quad 0x00cf93000000ffff /* __KERNEL_DS */
25082+ .quad 0x00cffb000000ffff /* __USER32_CS */
25083+ .quad 0x00cff3000000ffff /* __USER_DS, __USER32_DS */
25084+ .quad 0x00affb000000ffff /* __USER_CS */
25085+
25086+#ifdef CONFIG_PAX_KERNEXEC
25087+ .quad 0x00af9b000000ffff /* __KERNEXEC_KERNEL_CS */
25088+#else
25089+ .quad 0x0 /* unused */
25090+#endif
25091+
25092+ .quad 0,0 /* TSS */
25093+ .quad 0,0 /* LDT */
25094+ .quad 0,0,0 /* three TLS descriptors */
25095+ .quad 0x0000f40000000000 /* node/CPU stored in limit */
25096+ /* asm/segment.h:GDT_ENTRIES must match this */
25097+
25098+#ifdef CONFIG_PAX_MEMORY_UDEREF
25099+ .quad 0x00cf93000000ffff /* __UDEREF_KERNEL_DS */
25100+#else
25101+ .quad 0x0 /* unused */
25102+#endif
25103+
25104+ /* zero the remaining page */
25105+ .fill PAGE_SIZE / 8 - GDT_ENTRIES,8,0
25106+ .endr
25107+
25108 .align 16
25109 .globl early_gdt_descr
25110 early_gdt_descr:
25111 .word GDT_ENTRIES*8-1
25112 early_gdt_descr_base:
25113- .quad INIT_PER_CPU_VAR(gdt_page)
25114+ .quad cpu_gdt_table
25115
25116 ENTRY(phys_base)
25117 /* This must match the first entry in level2_kernel_pgt */
25118 .quad 0x0000000000000000
25119
25120 #include "../../x86/xen/xen-head.S"
25121-
25122- __PAGE_ALIGNED_BSS
25123+
25124+ .section .rodata,"a",@progbits
25125 NEXT_PAGE(empty_zero_page)
25126 .skip PAGE_SIZE
25127diff --git a/arch/x86/kernel/i386_ksyms_32.c b/arch/x86/kernel/i386_ksyms_32.c
25128index 05fd74f..c3548b1 100644
25129--- a/arch/x86/kernel/i386_ksyms_32.c
25130+++ b/arch/x86/kernel/i386_ksyms_32.c
25131@@ -20,8 +20,12 @@ extern void cmpxchg8b_emu(void);
25132 EXPORT_SYMBOL(cmpxchg8b_emu);
25133 #endif
25134
25135+EXPORT_SYMBOL_GPL(cpu_gdt_table);
25136+
25137 /* Networking helper routines. */
25138 EXPORT_SYMBOL(csum_partial_copy_generic);
25139+EXPORT_SYMBOL(csum_partial_copy_generic_to_user);
25140+EXPORT_SYMBOL(csum_partial_copy_generic_from_user);
25141
25142 EXPORT_SYMBOL(__get_user_1);
25143 EXPORT_SYMBOL(__get_user_2);
25144@@ -44,3 +48,11 @@ EXPORT_SYMBOL(___preempt_schedule);
25145 EXPORT_SYMBOL(___preempt_schedule_context);
25146 #endif
25147 #endif
25148+
25149+#ifdef CONFIG_PAX_KERNEXEC
25150+EXPORT_SYMBOL(__LOAD_PHYSICAL_ADDR);
25151+#endif
25152+
25153+#ifdef CONFIG_PAX_PER_CPU_PGD
25154+EXPORT_SYMBOL(cpu_pgd);
25155+#endif
25156diff --git a/arch/x86/kernel/i387.c b/arch/x86/kernel/i387.c
25157index d5dd808..b6432cf 100644
25158--- a/arch/x86/kernel/i387.c
25159+++ b/arch/x86/kernel/i387.c
25160@@ -51,7 +51,7 @@ static inline bool interrupted_kernel_fpu_idle(void)
25161 static inline bool interrupted_user_mode(void)
25162 {
25163 struct pt_regs *regs = get_irq_regs();
25164- return regs && user_mode_vm(regs);
25165+ return regs && user_mode(regs);
25166 }
25167
25168 /*
25169diff --git a/arch/x86/kernel/i8259.c b/arch/x86/kernel/i8259.c
25170index 2e977b5..5f2c273 100644
25171--- a/arch/x86/kernel/i8259.c
25172+++ b/arch/x86/kernel/i8259.c
25173@@ -110,7 +110,7 @@ static int i8259A_irq_pending(unsigned int irq)
25174 static void make_8259A_irq(unsigned int irq)
25175 {
25176 disable_irq_nosync(irq);
25177- io_apic_irqs &= ~(1<<irq);
25178+ io_apic_irqs &= ~(1UL<<irq);
25179 irq_set_chip_and_handler_name(irq, &i8259A_chip, handle_level_irq,
25180 i8259A_chip.name);
25181 enable_irq(irq);
25182@@ -209,7 +209,7 @@ spurious_8259A_irq:
25183 "spurious 8259A interrupt: IRQ%d.\n", irq);
25184 spurious_irq_mask |= irqmask;
25185 }
25186- atomic_inc(&irq_err_count);
25187+ atomic_inc_unchecked(&irq_err_count);
25188 /*
25189 * Theoretically we do not have to handle this IRQ,
25190 * but in Linux this does not cause problems and is
25191@@ -332,14 +332,16 @@ static void init_8259A(int auto_eoi)
25192 /* (slave's support for AEOI in flat mode is to be investigated) */
25193 outb_pic(SLAVE_ICW4_DEFAULT, PIC_SLAVE_IMR);
25194
25195+ pax_open_kernel();
25196 if (auto_eoi)
25197 /*
25198 * In AEOI mode we just have to mask the interrupt
25199 * when acking.
25200 */
25201- i8259A_chip.irq_mask_ack = disable_8259A_irq;
25202+ *(void **)&i8259A_chip.irq_mask_ack = disable_8259A_irq;
25203 else
25204- i8259A_chip.irq_mask_ack = mask_and_ack_8259A;
25205+ *(void **)&i8259A_chip.irq_mask_ack = mask_and_ack_8259A;
25206+ pax_close_kernel();
25207
25208 udelay(100); /* wait for 8259A to initialize */
25209
25210diff --git a/arch/x86/kernel/io_delay.c b/arch/x86/kernel/io_delay.c
25211index a979b5b..1d6db75 100644
25212--- a/arch/x86/kernel/io_delay.c
25213+++ b/arch/x86/kernel/io_delay.c
25214@@ -58,7 +58,7 @@ static int __init dmi_io_delay_0xed_port(const struct dmi_system_id *id)
25215 * Quirk table for systems that misbehave (lock up, etc.) if port
25216 * 0x80 is used:
25217 */
25218-static struct dmi_system_id __initdata io_delay_0xed_port_dmi_table[] = {
25219+static const struct dmi_system_id __initconst io_delay_0xed_port_dmi_table[] = {
25220 {
25221 .callback = dmi_io_delay_0xed_port,
25222 .ident = "Compaq Presario V6000",
25223diff --git a/arch/x86/kernel/ioport.c b/arch/x86/kernel/ioport.c
25224index 4ddaf66..49d5c18 100644
25225--- a/arch/x86/kernel/ioport.c
25226+++ b/arch/x86/kernel/ioport.c
25227@@ -6,6 +6,7 @@
25228 #include <linux/sched.h>
25229 #include <linux/kernel.h>
25230 #include <linux/capability.h>
25231+#include <linux/security.h>
25232 #include <linux/errno.h>
25233 #include <linux/types.h>
25234 #include <linux/ioport.h>
25235@@ -30,6 +31,12 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
25236 return -EINVAL;
25237 if (turn_on && !capable(CAP_SYS_RAWIO))
25238 return -EPERM;
25239+#ifdef CONFIG_GRKERNSEC_IO
25240+ if (turn_on && grsec_disable_privio) {
25241+ gr_handle_ioperm();
25242+ return -ENODEV;
25243+ }
25244+#endif
25245
25246 /*
25247 * If it's the first ioperm() call in this thread's lifetime, set the
25248@@ -54,7 +61,7 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
25249 * because the ->io_bitmap_max value must match the bitmap
25250 * contents:
25251 */
25252- tss = &per_cpu(init_tss, get_cpu());
25253+ tss = init_tss + get_cpu();
25254
25255 if (turn_on)
25256 bitmap_clear(t->io_bitmap_ptr, from, num);
25257@@ -105,6 +112,12 @@ SYSCALL_DEFINE1(iopl, unsigned int, level)
25258 if (level > old) {
25259 if (!capable(CAP_SYS_RAWIO))
25260 return -EPERM;
25261+#ifdef CONFIG_GRKERNSEC_IO
25262+ if (grsec_disable_privio) {
25263+ gr_handle_iopl();
25264+ return -ENODEV;
25265+ }
25266+#endif
25267 }
25268 regs->flags = (regs->flags & ~X86_EFLAGS_IOPL) | (level << 12);
25269 t->iopl = level << 12;
25270diff --git a/arch/x86/kernel/irq.c b/arch/x86/kernel/irq.c
25271index d99f31d..1c0f466 100644
25272--- a/arch/x86/kernel/irq.c
25273+++ b/arch/x86/kernel/irq.c
25274@@ -21,7 +21,7 @@
25275 #define CREATE_TRACE_POINTS
25276 #include <asm/trace/irq_vectors.h>
25277
25278-atomic_t irq_err_count;
25279+atomic_unchecked_t irq_err_count;
25280
25281 /* Function pointer for generic interrupt vector handling */
25282 void (*x86_platform_ipi_callback)(void) = NULL;
25283@@ -125,9 +125,9 @@ int arch_show_interrupts(struct seq_file *p, int prec)
25284 seq_printf(p, "%10u ", per_cpu(mce_poll_count, j));
25285 seq_printf(p, " Machine check polls\n");
25286 #endif
25287- seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
25288+ seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
25289 #if defined(CONFIG_X86_IO_APIC)
25290- seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read(&irq_mis_count));
25291+ seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read_unchecked(&irq_mis_count));
25292 #endif
25293 return 0;
25294 }
25295@@ -167,7 +167,7 @@ u64 arch_irq_stat_cpu(unsigned int cpu)
25296
25297 u64 arch_irq_stat(void)
25298 {
25299- u64 sum = atomic_read(&irq_err_count);
25300+ u64 sum = atomic_read_unchecked(&irq_err_count);
25301 return sum;
25302 }
25303
25304diff --git a/arch/x86/kernel/irq_32.c b/arch/x86/kernel/irq_32.c
25305index d7fcbed..96e715a 100644
25306--- a/arch/x86/kernel/irq_32.c
25307+++ b/arch/x86/kernel/irq_32.c
25308@@ -29,6 +29,8 @@ EXPORT_PER_CPU_SYMBOL(irq_regs);
25309
25310 #ifdef CONFIG_DEBUG_STACKOVERFLOW
25311
25312+extern void gr_handle_kernel_exploit(void);
25313+
25314 int sysctl_panic_on_stackoverflow __read_mostly;
25315
25316 /* Debugging check for stack overflow: is there less than 1KB free? */
25317@@ -39,13 +41,14 @@ static int check_stack_overflow(void)
25318 __asm__ __volatile__("andl %%esp,%0" :
25319 "=r" (sp) : "0" (THREAD_SIZE - 1));
25320
25321- return sp < (sizeof(struct thread_info) + STACK_WARN);
25322+ return sp < STACK_WARN;
25323 }
25324
25325 static void print_stack_overflow(void)
25326 {
25327 printk(KERN_WARNING "low stack detected by irq handler\n");
25328 dump_stack();
25329+ gr_handle_kernel_exploit();
25330 if (sysctl_panic_on_stackoverflow)
25331 panic("low stack detected by irq handler - check messages\n");
25332 }
25333@@ -59,8 +62,8 @@ static inline void print_stack_overflow(void) { }
25334 * per-CPU IRQ handling contexts (thread information and stack)
25335 */
25336 union irq_ctx {
25337- struct thread_info tinfo;
25338- u32 stack[THREAD_SIZE/sizeof(u32)];
25339+ unsigned long previous_esp;
25340+ u32 stack[THREAD_SIZE/sizeof(u32)];
25341 } __attribute__((aligned(THREAD_SIZE)));
25342
25343 static DEFINE_PER_CPU(union irq_ctx *, hardirq_ctx);
25344@@ -80,10 +83,9 @@ static void call_on_stack(void *func, void *stack)
25345 static inline int
25346 execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
25347 {
25348- union irq_ctx *curctx, *irqctx;
25349+ union irq_ctx *irqctx;
25350 u32 *isp, arg1, arg2;
25351
25352- curctx = (union irq_ctx *) current_thread_info();
25353 irqctx = __this_cpu_read(hardirq_ctx);
25354
25355 /*
25356@@ -92,13 +94,16 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
25357 * handler) we can't do that and just have to keep using the
25358 * current stack (which is the irq stack already after all)
25359 */
25360- if (unlikely(curctx == irqctx))
25361+ if (unlikely((void *)current_stack_pointer - (void *)irqctx < THREAD_SIZE))
25362 return 0;
25363
25364 /* build the stack frame on the IRQ stack */
25365- isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
25366- irqctx->tinfo.task = curctx->tinfo.task;
25367- irqctx->tinfo.previous_esp = current_stack_pointer;
25368+ isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
25369+ irqctx->previous_esp = current_stack_pointer;
25370+
25371+#ifdef CONFIG_PAX_MEMORY_UDEREF
25372+ __set_fs(MAKE_MM_SEG(0));
25373+#endif
25374
25375 if (unlikely(overflow))
25376 call_on_stack(print_stack_overflow, isp);
25377@@ -110,6 +115,11 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
25378 : "0" (irq), "1" (desc), "2" (isp),
25379 "D" (desc->handle_irq)
25380 : "memory", "cc", "ecx");
25381+
25382+#ifdef CONFIG_PAX_MEMORY_UDEREF
25383+ __set_fs(current_thread_info()->addr_limit);
25384+#endif
25385+
25386 return 1;
25387 }
25388
25389@@ -118,48 +128,34 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
25390 */
25391 void irq_ctx_init(int cpu)
25392 {
25393- union irq_ctx *irqctx;
25394-
25395 if (per_cpu(hardirq_ctx, cpu))
25396 return;
25397
25398- irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
25399- THREADINFO_GFP,
25400- THREAD_SIZE_ORDER));
25401- memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
25402- irqctx->tinfo.cpu = cpu;
25403- irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
25404-
25405- per_cpu(hardirq_ctx, cpu) = irqctx;
25406-
25407- irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
25408- THREADINFO_GFP,
25409- THREAD_SIZE_ORDER));
25410- memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
25411- irqctx->tinfo.cpu = cpu;
25412- irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
25413-
25414- per_cpu(softirq_ctx, cpu) = irqctx;
25415-
25416- printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
25417- cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
25418+ per_cpu(hardirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
25419+ per_cpu(softirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
25420 }
25421
25422 void do_softirq_own_stack(void)
25423 {
25424- struct thread_info *curctx;
25425 union irq_ctx *irqctx;
25426 u32 *isp;
25427
25428- curctx = current_thread_info();
25429 irqctx = __this_cpu_read(softirq_ctx);
25430- irqctx->tinfo.task = curctx->task;
25431- irqctx->tinfo.previous_esp = current_stack_pointer;
25432+ irqctx->previous_esp = current_stack_pointer;
25433
25434 /* build the stack frame on the softirq stack */
25435- isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
25436+ isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
25437+
25438+#ifdef CONFIG_PAX_MEMORY_UDEREF
25439+ __set_fs(MAKE_MM_SEG(0));
25440+#endif
25441
25442 call_on_stack(__do_softirq, isp);
25443+
25444+#ifdef CONFIG_PAX_MEMORY_UDEREF
25445+ __set_fs(current_thread_info()->addr_limit);
25446+#endif
25447+
25448 }
25449
25450 bool handle_irq(unsigned irq, struct pt_regs *regs)
25451@@ -173,7 +169,7 @@ bool handle_irq(unsigned irq, struct pt_regs *regs)
25452 if (unlikely(!desc))
25453 return false;
25454
25455- if (user_mode_vm(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
25456+ if (user_mode(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
25457 if (unlikely(overflow))
25458 print_stack_overflow();
25459 desc->handle_irq(irq, desc);
25460diff --git a/arch/x86/kernel/irq_64.c b/arch/x86/kernel/irq_64.c
25461index 4d1c746..55a22d6 100644
25462--- a/arch/x86/kernel/irq_64.c
25463+++ b/arch/x86/kernel/irq_64.c
25464@@ -26,6 +26,8 @@ EXPORT_PER_CPU_SYMBOL(irq_stat);
25465 DEFINE_PER_CPU(struct pt_regs *, irq_regs);
25466 EXPORT_PER_CPU_SYMBOL(irq_regs);
25467
25468+extern void gr_handle_kernel_exploit(void);
25469+
25470 int sysctl_panic_on_stackoverflow;
25471
25472 /*
25473@@ -44,7 +46,7 @@ static inline void stack_overflow_check(struct pt_regs *regs)
25474 u64 estack_top, estack_bottom;
25475 u64 curbase = (u64)task_stack_page(current);
25476
25477- if (user_mode_vm(regs))
25478+ if (user_mode(regs))
25479 return;
25480
25481 if (regs->sp >= curbase + sizeof(struct thread_info) +
25482@@ -69,6 +71,8 @@ static inline void stack_overflow_check(struct pt_regs *regs)
25483 irq_stack_top, irq_stack_bottom,
25484 estack_top, estack_bottom);
25485
25486+ gr_handle_kernel_exploit();
25487+
25488 if (sysctl_panic_on_stackoverflow)
25489 panic("low stack detected by irq handler - check messages\n");
25490 #endif
25491diff --git a/arch/x86/kernel/jump_label.c b/arch/x86/kernel/jump_label.c
25492index 26d5a55..a01160a 100644
25493--- a/arch/x86/kernel/jump_label.c
25494+++ b/arch/x86/kernel/jump_label.c
25495@@ -51,7 +51,7 @@ static void __jump_label_transform(struct jump_entry *entry,
25496 * Jump label is enabled for the first time.
25497 * So we expect a default_nop...
25498 */
25499- if (unlikely(memcmp((void *)entry->code, default_nop, 5)
25500+ if (unlikely(memcmp((void *)ktla_ktva(entry->code), default_nop, 5)
25501 != 0))
25502 bug_at((void *)entry->code, __LINE__);
25503 } else {
25504@@ -59,7 +59,7 @@ static void __jump_label_transform(struct jump_entry *entry,
25505 * ...otherwise expect an ideal_nop. Otherwise
25506 * something went horribly wrong.
25507 */
25508- if (unlikely(memcmp((void *)entry->code, ideal_nop, 5)
25509+ if (unlikely(memcmp((void *)ktla_ktva(entry->code), ideal_nop, 5)
25510 != 0))
25511 bug_at((void *)entry->code, __LINE__);
25512 }
25513@@ -75,13 +75,13 @@ static void __jump_label_transform(struct jump_entry *entry,
25514 * are converting the default nop to the ideal nop.
25515 */
25516 if (init) {
25517- if (unlikely(memcmp((void *)entry->code, default_nop, 5) != 0))
25518+ if (unlikely(memcmp((void *)ktla_ktva(entry->code), default_nop, 5) != 0))
25519 bug_at((void *)entry->code, __LINE__);
25520 } else {
25521 code.jump = 0xe9;
25522 code.offset = entry->target -
25523 (entry->code + JUMP_LABEL_NOP_SIZE);
25524- if (unlikely(memcmp((void *)entry->code, &code, 5) != 0))
25525+ if (unlikely(memcmp((void *)ktla_ktva(entry->code), &code, 5) != 0))
25526 bug_at((void *)entry->code, __LINE__);
25527 }
25528 memcpy(&code, ideal_nops[NOP_ATOMIC5], JUMP_LABEL_NOP_SIZE);
25529diff --git a/arch/x86/kernel/kgdb.c b/arch/x86/kernel/kgdb.c
25530index 7ec1d5f..5a7d130 100644
25531--- a/arch/x86/kernel/kgdb.c
25532+++ b/arch/x86/kernel/kgdb.c
25533@@ -126,11 +126,11 @@ char *dbg_get_reg(int regno, void *mem, struct pt_regs *regs)
25534 #ifdef CONFIG_X86_32
25535 switch (regno) {
25536 case GDB_SS:
25537- if (!user_mode_vm(regs))
25538+ if (!user_mode(regs))
25539 *(unsigned long *)mem = __KERNEL_DS;
25540 break;
25541 case GDB_SP:
25542- if (!user_mode_vm(regs))
25543+ if (!user_mode(regs))
25544 *(unsigned long *)mem = kernel_stack_pointer(regs);
25545 break;
25546 case GDB_GS:
25547@@ -228,7 +228,10 @@ static void kgdb_correct_hw_break(void)
25548 bp->attr.bp_addr = breakinfo[breakno].addr;
25549 bp->attr.bp_len = breakinfo[breakno].len;
25550 bp->attr.bp_type = breakinfo[breakno].type;
25551- info->address = breakinfo[breakno].addr;
25552+ if (breakinfo[breakno].type == X86_BREAKPOINT_EXECUTE)
25553+ info->address = ktla_ktva(breakinfo[breakno].addr);
25554+ else
25555+ info->address = breakinfo[breakno].addr;
25556 info->len = breakinfo[breakno].len;
25557 info->type = breakinfo[breakno].type;
25558 val = arch_install_hw_breakpoint(bp);
25559@@ -475,12 +478,12 @@ int kgdb_arch_handle_exception(int e_vector, int signo, int err_code,
25560 case 'k':
25561 /* clear the trace bit */
25562 linux_regs->flags &= ~X86_EFLAGS_TF;
25563- atomic_set(&kgdb_cpu_doing_single_step, -1);
25564+ atomic_set_unchecked(&kgdb_cpu_doing_single_step, -1);
25565
25566 /* set the trace bit if we're stepping */
25567 if (remcomInBuffer[0] == 's') {
25568 linux_regs->flags |= X86_EFLAGS_TF;
25569- atomic_set(&kgdb_cpu_doing_single_step,
25570+ atomic_set_unchecked(&kgdb_cpu_doing_single_step,
25571 raw_smp_processor_id());
25572 }
25573
25574@@ -545,7 +548,7 @@ static int __kgdb_notify(struct die_args *args, unsigned long cmd)
25575
25576 switch (cmd) {
25577 case DIE_DEBUG:
25578- if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
25579+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
25580 if (user_mode(regs))
25581 return single_step_cont(regs, args);
25582 break;
25583@@ -750,11 +753,11 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
25584 #endif /* CONFIG_DEBUG_RODATA */
25585
25586 bpt->type = BP_BREAKPOINT;
25587- err = probe_kernel_read(bpt->saved_instr, (char *)bpt->bpt_addr,
25588+ err = probe_kernel_read(bpt->saved_instr, ktla_ktva((char *)bpt->bpt_addr),
25589 BREAK_INSTR_SIZE);
25590 if (err)
25591 return err;
25592- err = probe_kernel_write((char *)bpt->bpt_addr,
25593+ err = probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
25594 arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE);
25595 #ifdef CONFIG_DEBUG_RODATA
25596 if (!err)
25597@@ -767,7 +770,7 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
25598 return -EBUSY;
25599 text_poke((void *)bpt->bpt_addr, arch_kgdb_ops.gdb_bpt_instr,
25600 BREAK_INSTR_SIZE);
25601- err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
25602+ err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
25603 if (err)
25604 return err;
25605 if (memcmp(opc, arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE))
25606@@ -792,13 +795,13 @@ int kgdb_arch_remove_breakpoint(struct kgdb_bkpt *bpt)
25607 if (mutex_is_locked(&text_mutex))
25608 goto knl_write;
25609 text_poke((void *)bpt->bpt_addr, bpt->saved_instr, BREAK_INSTR_SIZE);
25610- err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
25611+ err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
25612 if (err || memcmp(opc, bpt->saved_instr, BREAK_INSTR_SIZE))
25613 goto knl_write;
25614 return err;
25615 knl_write:
25616 #endif /* CONFIG_DEBUG_RODATA */
25617- return probe_kernel_write((char *)bpt->bpt_addr,
25618+ return probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
25619 (char *)bpt->saved_instr, BREAK_INSTR_SIZE);
25620 }
25621
25622diff --git a/arch/x86/kernel/kprobes/core.c b/arch/x86/kernel/kprobes/core.c
25623index 79a3f96..6ba030a 100644
25624--- a/arch/x86/kernel/kprobes/core.c
25625+++ b/arch/x86/kernel/kprobes/core.c
25626@@ -119,9 +119,12 @@ static void __kprobes __synthesize_relative_insn(void *from, void *to, u8 op)
25627 s32 raddr;
25628 } __packed *insn;
25629
25630- insn = (struct __arch_relative_insn *)from;
25631+ insn = (struct __arch_relative_insn *)ktla_ktva(from);
25632+
25633+ pax_open_kernel();
25634 insn->raddr = (s32)((long)(to) - ((long)(from) + 5));
25635 insn->op = op;
25636+ pax_close_kernel();
25637 }
25638
25639 /* Insert a jump instruction at address 'from', which jumps to address 'to'.*/
25640@@ -164,7 +167,7 @@ int __kprobes can_boost(kprobe_opcode_t *opcodes)
25641 kprobe_opcode_t opcode;
25642 kprobe_opcode_t *orig_opcodes = opcodes;
25643
25644- if (search_exception_tables((unsigned long)opcodes))
25645+ if (search_exception_tables(ktva_ktla((unsigned long)opcodes)))
25646 return 0; /* Page fault may occur on this address. */
25647
25648 retry:
25649@@ -238,9 +241,9 @@ __recover_probed_insn(kprobe_opcode_t *buf, unsigned long addr)
25650 * for the first byte, we can recover the original instruction
25651 * from it and kp->opcode.
25652 */
25653- memcpy(buf, kp->addr, MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
25654+ memcpy(buf, ktla_ktva(kp->addr), MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
25655 buf[0] = kp->opcode;
25656- return (unsigned long)buf;
25657+ return ktva_ktla((unsigned long)buf);
25658 }
25659
25660 /*
25661@@ -332,7 +335,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
25662 /* Another subsystem puts a breakpoint, failed to recover */
25663 if (insn.opcode.bytes[0] == BREAKPOINT_INSTRUCTION)
25664 return 0;
25665+ pax_open_kernel();
25666 memcpy(dest, insn.kaddr, insn.length);
25667+ pax_close_kernel();
25668
25669 #ifdef CONFIG_X86_64
25670 if (insn_rip_relative(&insn)) {
25671@@ -359,7 +364,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
25672 return 0;
25673 }
25674 disp = (u8 *) dest + insn_offset_displacement(&insn);
25675+ pax_open_kernel();
25676 *(s32 *) disp = (s32) newdisp;
25677+ pax_close_kernel();
25678 }
25679 #endif
25680 return insn.length;
25681@@ -498,7 +505,7 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
25682 * nor set current_kprobe, because it doesn't use single
25683 * stepping.
25684 */
25685- regs->ip = (unsigned long)p->ainsn.insn;
25686+ regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
25687 preempt_enable_no_resched();
25688 return;
25689 }
25690@@ -515,9 +522,9 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
25691 regs->flags &= ~X86_EFLAGS_IF;
25692 /* single step inline if the instruction is an int3 */
25693 if (p->opcode == BREAKPOINT_INSTRUCTION)
25694- regs->ip = (unsigned long)p->addr;
25695+ regs->ip = ktla_ktva((unsigned long)p->addr);
25696 else
25697- regs->ip = (unsigned long)p->ainsn.insn;
25698+ regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
25699 }
25700
25701 /*
25702@@ -596,7 +603,7 @@ static int __kprobes kprobe_handler(struct pt_regs *regs)
25703 setup_singlestep(p, regs, kcb, 0);
25704 return 1;
25705 }
25706- } else if (*addr != BREAKPOINT_INSTRUCTION) {
25707+ } else if (*(kprobe_opcode_t *)ktla_ktva((unsigned long)addr) != BREAKPOINT_INSTRUCTION) {
25708 /*
25709 * The breakpoint instruction was removed right
25710 * after we hit it. Another cpu has removed
25711@@ -642,6 +649,9 @@ static void __used __kprobes kretprobe_trampoline_holder(void)
25712 " movq %rax, 152(%rsp)\n"
25713 RESTORE_REGS_STRING
25714 " popfq\n"
25715+#ifdef KERNEXEC_PLUGIN
25716+ " btsq $63,(%rsp)\n"
25717+#endif
25718 #else
25719 " pushf\n"
25720 SAVE_REGS_STRING
25721@@ -779,7 +789,7 @@ static void __kprobes
25722 resume_execution(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *kcb)
25723 {
25724 unsigned long *tos = stack_addr(regs);
25725- unsigned long copy_ip = (unsigned long)p->ainsn.insn;
25726+ unsigned long copy_ip = ktva_ktla((unsigned long)p->ainsn.insn);
25727 unsigned long orig_ip = (unsigned long)p->addr;
25728 kprobe_opcode_t *insn = p->ainsn.insn;
25729
25730@@ -961,7 +971,7 @@ kprobe_exceptions_notify(struct notifier_block *self, unsigned long val, void *d
25731 struct die_args *args = data;
25732 int ret = NOTIFY_DONE;
25733
25734- if (args->regs && user_mode_vm(args->regs))
25735+ if (args->regs && user_mode(args->regs))
25736 return ret;
25737
25738 switch (val) {
25739diff --git a/arch/x86/kernel/kprobes/opt.c b/arch/x86/kernel/kprobes/opt.c
25740index 898160b..758cde8 100644
25741--- a/arch/x86/kernel/kprobes/opt.c
25742+++ b/arch/x86/kernel/kprobes/opt.c
25743@@ -79,6 +79,7 @@ found:
25744 /* Insert a move instruction which sets a pointer to eax/rdi (1st arg). */
25745 static void __kprobes synthesize_set_arg1(kprobe_opcode_t *addr, unsigned long val)
25746 {
25747+ pax_open_kernel();
25748 #ifdef CONFIG_X86_64
25749 *addr++ = 0x48;
25750 *addr++ = 0xbf;
25751@@ -86,6 +87,7 @@ static void __kprobes synthesize_set_arg1(kprobe_opcode_t *addr, unsigned long v
25752 *addr++ = 0xb8;
25753 #endif
25754 *(unsigned long *)addr = val;
25755+ pax_close_kernel();
25756 }
25757
25758 asm (
25759@@ -335,7 +337,7 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
25760 * Verify if the address gap is in 2GB range, because this uses
25761 * a relative jump.
25762 */
25763- rel = (long)op->optinsn.insn - (long)op->kp.addr + RELATIVEJUMP_SIZE;
25764+ rel = (long)op->optinsn.insn - ktla_ktva((long)op->kp.addr) + RELATIVEJUMP_SIZE;
25765 if (abs(rel) > 0x7fffffff)
25766 return -ERANGE;
25767
25768@@ -350,16 +352,18 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
25769 op->optinsn.size = ret;
25770
25771 /* Copy arch-dep-instance from template */
25772- memcpy(buf, &optprobe_template_entry, TMPL_END_IDX);
25773+ pax_open_kernel();
25774+ memcpy(buf, ktla_ktva(&optprobe_template_entry), TMPL_END_IDX);
25775+ pax_close_kernel();
25776
25777 /* Set probe information */
25778 synthesize_set_arg1(buf + TMPL_MOVE_IDX, (unsigned long)op);
25779
25780 /* Set probe function call */
25781- synthesize_relcall(buf + TMPL_CALL_IDX, optimized_callback);
25782+ synthesize_relcall(ktva_ktla(buf) + TMPL_CALL_IDX, optimized_callback);
25783
25784 /* Set returning jmp instruction at the tail of out-of-line buffer */
25785- synthesize_reljump(buf + TMPL_END_IDX + op->optinsn.size,
25786+ synthesize_reljump(ktva_ktla(buf) + TMPL_END_IDX + op->optinsn.size,
25787 (u8 *)op->kp.addr + op->optinsn.size);
25788
25789 flush_icache_range((unsigned long) buf,
25790@@ -384,7 +388,7 @@ void __kprobes arch_optimize_kprobes(struct list_head *oplist)
25791 WARN_ON(kprobe_disabled(&op->kp));
25792
25793 /* Backup instructions which will be replaced by jump address */
25794- memcpy(op->optinsn.copied_insn, op->kp.addr + INT3_SIZE,
25795+ memcpy(op->optinsn.copied_insn, ktla_ktva(op->kp.addr) + INT3_SIZE,
25796 RELATIVE_ADDR_SIZE);
25797
25798 insn_buf[0] = RELATIVEJUMP_OPCODE;
25799@@ -433,7 +437,7 @@ setup_detour_execution(struct kprobe *p, struct pt_regs *regs, int reenter)
25800 /* This kprobe is really able to run optimized path. */
25801 op = container_of(p, struct optimized_kprobe, kp);
25802 /* Detour through copied instructions */
25803- regs->ip = (unsigned long)op->optinsn.insn + TMPL_END_IDX;
25804+ regs->ip = ktva_ktla((unsigned long)op->optinsn.insn) + TMPL_END_IDX;
25805 if (!reenter)
25806 reset_current_kprobe();
25807 preempt_enable_no_resched();
25808diff --git a/arch/x86/kernel/ksysfs.c b/arch/x86/kernel/ksysfs.c
25809index c2bedae..25e7ab6 100644
25810--- a/arch/x86/kernel/ksysfs.c
25811+++ b/arch/x86/kernel/ksysfs.c
25812@@ -184,7 +184,7 @@ out:
25813
25814 static struct kobj_attribute type_attr = __ATTR_RO(type);
25815
25816-static struct bin_attribute data_attr = {
25817+static bin_attribute_no_const data_attr __read_only = {
25818 .attr = {
25819 .name = "data",
25820 .mode = S_IRUGO,
25821diff --git a/arch/x86/kernel/ldt.c b/arch/x86/kernel/ldt.c
25822index af1d14a..37b8776 100644
25823--- a/arch/x86/kernel/ldt.c
25824+++ b/arch/x86/kernel/ldt.c
25825@@ -66,13 +66,13 @@ static int alloc_ldt(mm_context_t *pc, int mincount, int reload)
25826 if (reload) {
25827 #ifdef CONFIG_SMP
25828 preempt_disable();
25829- load_LDT(pc);
25830+ load_LDT_nolock(pc);
25831 if (!cpumask_equal(mm_cpumask(current->mm),
25832 cpumask_of(smp_processor_id())))
25833 smp_call_function(flush_ldt, current->mm, 1);
25834 preempt_enable();
25835 #else
25836- load_LDT(pc);
25837+ load_LDT_nolock(pc);
25838 #endif
25839 }
25840 if (oldsize) {
25841@@ -94,7 +94,7 @@ static inline int copy_ldt(mm_context_t *new, mm_context_t *old)
25842 return err;
25843
25844 for (i = 0; i < old->size; i++)
25845- write_ldt_entry(new->ldt, i, old->ldt + i * LDT_ENTRY_SIZE);
25846+ write_ldt_entry(new->ldt, i, old->ldt + i);
25847 return 0;
25848 }
25849
25850@@ -115,6 +115,24 @@ int init_new_context(struct task_struct *tsk, struct mm_struct *mm)
25851 retval = copy_ldt(&mm->context, &old_mm->context);
25852 mutex_unlock(&old_mm->context.lock);
25853 }
25854+
25855+ if (tsk == current) {
25856+ mm->context.vdso = 0;
25857+
25858+#ifdef CONFIG_X86_32
25859+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
25860+ mm->context.user_cs_base = 0UL;
25861+ mm->context.user_cs_limit = ~0UL;
25862+
25863+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
25864+ cpus_clear(mm->context.cpu_user_cs_mask);
25865+#endif
25866+
25867+#endif
25868+#endif
25869+
25870+ }
25871+
25872 return retval;
25873 }
25874
25875@@ -229,6 +247,13 @@ static int write_ldt(void __user *ptr, unsigned long bytecount, int oldmode)
25876 }
25877 }
25878
25879+#ifdef CONFIG_PAX_SEGMEXEC
25880+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (ldt_info.contents & MODIFY_LDT_CONTENTS_CODE)) {
25881+ error = -EINVAL;
25882+ goto out_unlock;
25883+ }
25884+#endif
25885+
25886 /*
25887 * On x86-64 we do not support 16-bit segments due to
25888 * IRET leaking the high bits of the kernel stack address.
25889diff --git a/arch/x86/kernel/machine_kexec_32.c b/arch/x86/kernel/machine_kexec_32.c
25890index 1667b1d..16492c5 100644
25891--- a/arch/x86/kernel/machine_kexec_32.c
25892+++ b/arch/x86/kernel/machine_kexec_32.c
25893@@ -25,7 +25,7 @@
25894 #include <asm/cacheflush.h>
25895 #include <asm/debugreg.h>
25896
25897-static void set_idt(void *newidt, __u16 limit)
25898+static void set_idt(struct desc_struct *newidt, __u16 limit)
25899 {
25900 struct desc_ptr curidt;
25901
25902@@ -37,7 +37,7 @@ static void set_idt(void *newidt, __u16 limit)
25903 }
25904
25905
25906-static void set_gdt(void *newgdt, __u16 limit)
25907+static void set_gdt(struct desc_struct *newgdt, __u16 limit)
25908 {
25909 struct desc_ptr curgdt;
25910
25911@@ -215,7 +215,7 @@ void machine_kexec(struct kimage *image)
25912 }
25913
25914 control_page = page_address(image->control_code_page);
25915- memcpy(control_page, relocate_kernel, KEXEC_CONTROL_CODE_MAX_SIZE);
25916+ memcpy(control_page, (void *)ktla_ktva((unsigned long)relocate_kernel), KEXEC_CONTROL_CODE_MAX_SIZE);
25917
25918 relocate_kernel_ptr = control_page;
25919 page_list[PA_CONTROL_PAGE] = __pa(control_page);
25920diff --git a/arch/x86/kernel/module.c b/arch/x86/kernel/module.c
25921index 18be189..4a9fe40 100644
25922--- a/arch/x86/kernel/module.c
25923+++ b/arch/x86/kernel/module.c
25924@@ -43,15 +43,60 @@ do { \
25925 } while (0)
25926 #endif
25927
25928-void *module_alloc(unsigned long size)
25929+static inline void *__module_alloc(unsigned long size, pgprot_t prot)
25930 {
25931- if (PAGE_ALIGN(size) > MODULES_LEN)
25932+ if (!size || PAGE_ALIGN(size) > MODULES_LEN)
25933 return NULL;
25934 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
25935- GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
25936+ GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, prot,
25937 NUMA_NO_NODE, __builtin_return_address(0));
25938 }
25939
25940+void *module_alloc(unsigned long size)
25941+{
25942+
25943+#ifdef CONFIG_PAX_KERNEXEC
25944+ return __module_alloc(size, PAGE_KERNEL);
25945+#else
25946+ return __module_alloc(size, PAGE_KERNEL_EXEC);
25947+#endif
25948+
25949+}
25950+
25951+#ifdef CONFIG_PAX_KERNEXEC
25952+#ifdef CONFIG_X86_32
25953+void *module_alloc_exec(unsigned long size)
25954+{
25955+ struct vm_struct *area;
25956+
25957+ if (size == 0)
25958+ return NULL;
25959+
25960+ area = __get_vm_area(size, VM_ALLOC, (unsigned long)&MODULES_EXEC_VADDR, (unsigned long)&MODULES_EXEC_END);
25961+ return area ? area->addr : NULL;
25962+}
25963+EXPORT_SYMBOL(module_alloc_exec);
25964+
25965+void module_free_exec(struct module *mod, void *module_region)
25966+{
25967+ vunmap(module_region);
25968+}
25969+EXPORT_SYMBOL(module_free_exec);
25970+#else
25971+void module_free_exec(struct module *mod, void *module_region)
25972+{
25973+ module_free(mod, module_region);
25974+}
25975+EXPORT_SYMBOL(module_free_exec);
25976+
25977+void *module_alloc_exec(unsigned long size)
25978+{
25979+ return __module_alloc(size, PAGE_KERNEL_RX);
25980+}
25981+EXPORT_SYMBOL(module_alloc_exec);
25982+#endif
25983+#endif
25984+
25985 #ifdef CONFIG_X86_32
25986 int apply_relocate(Elf32_Shdr *sechdrs,
25987 const char *strtab,
25988@@ -62,14 +107,16 @@ int apply_relocate(Elf32_Shdr *sechdrs,
25989 unsigned int i;
25990 Elf32_Rel *rel = (void *)sechdrs[relsec].sh_addr;
25991 Elf32_Sym *sym;
25992- uint32_t *location;
25993+ uint32_t *plocation, location;
25994
25995 DEBUGP("Applying relocate section %u to %u\n",
25996 relsec, sechdrs[relsec].sh_info);
25997 for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
25998 /* This is where to make the change */
25999- location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr
26000- + rel[i].r_offset;
26001+ plocation = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr + rel[i].r_offset;
26002+ location = (uint32_t)plocation;
26003+ if (sechdrs[sechdrs[relsec].sh_info].sh_flags & SHF_EXECINSTR)
26004+ plocation = ktla_ktva((void *)plocation);
26005 /* This is the symbol it is referring to. Note that all
26006 undefined symbols have been resolved. */
26007 sym = (Elf32_Sym *)sechdrs[symindex].sh_addr
26008@@ -78,11 +125,15 @@ int apply_relocate(Elf32_Shdr *sechdrs,
26009 switch (ELF32_R_TYPE(rel[i].r_info)) {
26010 case R_386_32:
26011 /* We add the value into the location given */
26012- *location += sym->st_value;
26013+ pax_open_kernel();
26014+ *plocation += sym->st_value;
26015+ pax_close_kernel();
26016 break;
26017 case R_386_PC32:
26018 /* Add the value, subtract its position */
26019- *location += sym->st_value - (uint32_t)location;
26020+ pax_open_kernel();
26021+ *plocation += sym->st_value - location;
26022+ pax_close_kernel();
26023 break;
26024 default:
26025 pr_err("%s: Unknown relocation: %u\n",
26026@@ -127,21 +178,30 @@ int apply_relocate_add(Elf64_Shdr *sechdrs,
26027 case R_X86_64_NONE:
26028 break;
26029 case R_X86_64_64:
26030+ pax_open_kernel();
26031 *(u64 *)loc = val;
26032+ pax_close_kernel();
26033 break;
26034 case R_X86_64_32:
26035+ pax_open_kernel();
26036 *(u32 *)loc = val;
26037+ pax_close_kernel();
26038 if (val != *(u32 *)loc)
26039 goto overflow;
26040 break;
26041 case R_X86_64_32S:
26042+ pax_open_kernel();
26043 *(s32 *)loc = val;
26044+ pax_close_kernel();
26045 if ((s64)val != *(s32 *)loc)
26046 goto overflow;
26047 break;
26048 case R_X86_64_PC32:
26049 val -= (u64)loc;
26050+ pax_open_kernel();
26051 *(u32 *)loc = val;
26052+ pax_close_kernel();
26053+
26054 #if 0
26055 if ((s64)val != *(s32 *)loc)
26056 goto overflow;
26057diff --git a/arch/x86/kernel/msr.c b/arch/x86/kernel/msr.c
26058index 05266b5..3432443 100644
26059--- a/arch/x86/kernel/msr.c
26060+++ b/arch/x86/kernel/msr.c
26061@@ -37,6 +37,7 @@
26062 #include <linux/notifier.h>
26063 #include <linux/uaccess.h>
26064 #include <linux/gfp.h>
26065+#include <linux/grsecurity.h>
26066
26067 #include <asm/processor.h>
26068 #include <asm/msr.h>
26069@@ -103,6 +104,11 @@ static ssize_t msr_write(struct file *file, const char __user *buf,
26070 int err = 0;
26071 ssize_t bytes = 0;
26072
26073+#ifdef CONFIG_GRKERNSEC_KMEM
26074+ gr_handle_msr_write();
26075+ return -EPERM;
26076+#endif
26077+
26078 if (count % 8)
26079 return -EINVAL; /* Invalid chunk size */
26080
26081@@ -150,6 +156,10 @@ static long msr_ioctl(struct file *file, unsigned int ioc, unsigned long arg)
26082 err = -EBADF;
26083 break;
26084 }
26085+#ifdef CONFIG_GRKERNSEC_KMEM
26086+ gr_handle_msr_write();
26087+ return -EPERM;
26088+#endif
26089 if (copy_from_user(&regs, uregs, sizeof regs)) {
26090 err = -EFAULT;
26091 break;
26092@@ -233,7 +243,7 @@ static int msr_class_cpu_callback(struct notifier_block *nfb,
26093 return notifier_from_errno(err);
26094 }
26095
26096-static struct notifier_block __refdata msr_class_cpu_notifier = {
26097+static struct notifier_block msr_class_cpu_notifier = {
26098 .notifier_call = msr_class_cpu_callback,
26099 };
26100
26101diff --git a/arch/x86/kernel/nmi.c b/arch/x86/kernel/nmi.c
26102index 6fcb49c..5b3f4ff 100644
26103--- a/arch/x86/kernel/nmi.c
26104+++ b/arch/x86/kernel/nmi.c
26105@@ -138,7 +138,7 @@ static int __kprobes nmi_handle(unsigned int type, struct pt_regs *regs, bool b2
26106 return handled;
26107 }
26108
26109-int __register_nmi_handler(unsigned int type, struct nmiaction *action)
26110+int __register_nmi_handler(unsigned int type, const struct nmiaction *action)
26111 {
26112 struct nmi_desc *desc = nmi_to_desc(type);
26113 unsigned long flags;
26114@@ -162,9 +162,9 @@ int __register_nmi_handler(unsigned int type, struct nmiaction *action)
26115 * event confuses some handlers (kdump uses this flag)
26116 */
26117 if (action->flags & NMI_FLAG_FIRST)
26118- list_add_rcu(&action->list, &desc->head);
26119+ pax_list_add_rcu((struct list_head *)&action->list, &desc->head);
26120 else
26121- list_add_tail_rcu(&action->list, &desc->head);
26122+ pax_list_add_tail_rcu((struct list_head *)&action->list, &desc->head);
26123
26124 spin_unlock_irqrestore(&desc->lock, flags);
26125 return 0;
26126@@ -187,7 +187,7 @@ void unregister_nmi_handler(unsigned int type, const char *name)
26127 if (!strcmp(n->name, name)) {
26128 WARN(in_nmi(),
26129 "Trying to free NMI (%s) from NMI context!\n", n->name);
26130- list_del_rcu(&n->list);
26131+ pax_list_del_rcu((struct list_head *)&n->list);
26132 break;
26133 }
26134 }
26135@@ -512,6 +512,17 @@ static inline void nmi_nesting_postprocess(void)
26136 dotraplinkage notrace __kprobes void
26137 do_nmi(struct pt_regs *regs, long error_code)
26138 {
26139+
26140+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
26141+ if (!user_mode(regs)) {
26142+ unsigned long cs = regs->cs & 0xFFFF;
26143+ unsigned long ip = ktva_ktla(regs->ip);
26144+
26145+ if ((cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS) && ip <= (unsigned long)_etext)
26146+ regs->ip = ip;
26147+ }
26148+#endif
26149+
26150 nmi_nesting_preprocess(regs);
26151
26152 nmi_enter();
26153diff --git a/arch/x86/kernel/nmi_selftest.c b/arch/x86/kernel/nmi_selftest.c
26154index 6d9582e..f746287 100644
26155--- a/arch/x86/kernel/nmi_selftest.c
26156+++ b/arch/x86/kernel/nmi_selftest.c
26157@@ -43,7 +43,7 @@ static void __init init_nmi_testsuite(void)
26158 {
26159 /* trap all the unknown NMIs we may generate */
26160 register_nmi_handler(NMI_UNKNOWN, nmi_unk_cb, 0, "nmi_selftest_unk",
26161- __initdata);
26162+ __initconst);
26163 }
26164
26165 static void __init cleanup_nmi_testsuite(void)
26166@@ -66,7 +66,7 @@ static void __init test_nmi_ipi(struct cpumask *mask)
26167 unsigned long timeout;
26168
26169 if (register_nmi_handler(NMI_LOCAL, test_nmi_ipi_callback,
26170- NMI_FLAG_FIRST, "nmi_selftest", __initdata)) {
26171+ NMI_FLAG_FIRST, "nmi_selftest", __initconst)) {
26172 nmi_fail = FAILURE;
26173 return;
26174 }
26175diff --git a/arch/x86/kernel/paravirt-spinlocks.c b/arch/x86/kernel/paravirt-spinlocks.c
26176index bbb6c73..24a58ef 100644
26177--- a/arch/x86/kernel/paravirt-spinlocks.c
26178+++ b/arch/x86/kernel/paravirt-spinlocks.c
26179@@ -8,7 +8,7 @@
26180
26181 #include <asm/paravirt.h>
26182
26183-struct pv_lock_ops pv_lock_ops = {
26184+struct pv_lock_ops pv_lock_ops __read_only = {
26185 #ifdef CONFIG_SMP
26186 .lock_spinning = __PV_IS_CALLEE_SAVE(paravirt_nop),
26187 .unlock_kick = paravirt_nop,
26188diff --git a/arch/x86/kernel/paravirt.c b/arch/x86/kernel/paravirt.c
26189index 1b10af8..45bfbec 100644
26190--- a/arch/x86/kernel/paravirt.c
26191+++ b/arch/x86/kernel/paravirt.c
26192@@ -55,6 +55,9 @@ u64 _paravirt_ident_64(u64 x)
26193 {
26194 return x;
26195 }
26196+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
26197+PV_CALLEE_SAVE_REGS_THUNK(_paravirt_ident_64);
26198+#endif
26199
26200 void __init default_banner(void)
26201 {
26202@@ -141,16 +144,20 @@ unsigned paravirt_patch_default(u8 type, u16 clobbers, void *insnbuf,
26203
26204 if (opfunc == NULL)
26205 /* If there's no function, patch it with a ud2a (BUG) */
26206- ret = paravirt_patch_insns(insnbuf, len, ud2a, ud2a+sizeof(ud2a));
26207- else if (opfunc == _paravirt_nop)
26208+ ret = paravirt_patch_insns(insnbuf, len, ktva_ktla(ud2a), ud2a+sizeof(ud2a));
26209+ else if (opfunc == (void *)_paravirt_nop)
26210 /* If the operation is a nop, then nop the callsite */
26211 ret = paravirt_patch_nop();
26212
26213 /* identity functions just return their single argument */
26214- else if (opfunc == _paravirt_ident_32)
26215+ else if (opfunc == (void *)_paravirt_ident_32)
26216 ret = paravirt_patch_ident_32(insnbuf, len);
26217- else if (opfunc == _paravirt_ident_64)
26218+ else if (opfunc == (void *)_paravirt_ident_64)
26219 ret = paravirt_patch_ident_64(insnbuf, len);
26220+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
26221+ else if (opfunc == (void *)__raw_callee_save__paravirt_ident_64)
26222+ ret = paravirt_patch_ident_64(insnbuf, len);
26223+#endif
26224
26225 else if (type == PARAVIRT_PATCH(pv_cpu_ops.iret) ||
26226 type == PARAVIRT_PATCH(pv_cpu_ops.irq_enable_sysexit) ||
26227@@ -175,7 +182,7 @@ unsigned paravirt_patch_insns(void *insnbuf, unsigned len,
26228 if (insn_len > len || start == NULL)
26229 insn_len = len;
26230 else
26231- memcpy(insnbuf, start, insn_len);
26232+ memcpy(insnbuf, ktla_ktva(start), insn_len);
26233
26234 return insn_len;
26235 }
26236@@ -299,7 +306,7 @@ enum paravirt_lazy_mode paravirt_get_lazy_mode(void)
26237 return this_cpu_read(paravirt_lazy_mode);
26238 }
26239
26240-struct pv_info pv_info = {
26241+struct pv_info pv_info __read_only = {
26242 .name = "bare hardware",
26243 .paravirt_enabled = 0,
26244 .kernel_rpl = 0,
26245@@ -310,16 +317,16 @@ struct pv_info pv_info = {
26246 #endif
26247 };
26248
26249-struct pv_init_ops pv_init_ops = {
26250+struct pv_init_ops pv_init_ops __read_only = {
26251 .patch = native_patch,
26252 };
26253
26254-struct pv_time_ops pv_time_ops = {
26255+struct pv_time_ops pv_time_ops __read_only = {
26256 .sched_clock = native_sched_clock,
26257 .steal_clock = native_steal_clock,
26258 };
26259
26260-__visible struct pv_irq_ops pv_irq_ops = {
26261+__visible struct pv_irq_ops pv_irq_ops __read_only = {
26262 .save_fl = __PV_IS_CALLEE_SAVE(native_save_fl),
26263 .restore_fl = __PV_IS_CALLEE_SAVE(native_restore_fl),
26264 .irq_disable = __PV_IS_CALLEE_SAVE(native_irq_disable),
26265@@ -331,7 +338,7 @@ __visible struct pv_irq_ops pv_irq_ops = {
26266 #endif
26267 };
26268
26269-__visible struct pv_cpu_ops pv_cpu_ops = {
26270+__visible struct pv_cpu_ops pv_cpu_ops __read_only = {
26271 .cpuid = native_cpuid,
26272 .get_debugreg = native_get_debugreg,
26273 .set_debugreg = native_set_debugreg,
26274@@ -389,21 +396,26 @@ __visible struct pv_cpu_ops pv_cpu_ops = {
26275 .end_context_switch = paravirt_nop,
26276 };
26277
26278-struct pv_apic_ops pv_apic_ops = {
26279+struct pv_apic_ops pv_apic_ops __read_only= {
26280 #ifdef CONFIG_X86_LOCAL_APIC
26281 .startup_ipi_hook = paravirt_nop,
26282 #endif
26283 };
26284
26285-#if defined(CONFIG_X86_32) && !defined(CONFIG_X86_PAE)
26286+#ifdef CONFIG_X86_32
26287+#ifdef CONFIG_X86_PAE
26288+/* 64-bit pagetable entries */
26289+#define PTE_IDENT PV_CALLEE_SAVE(_paravirt_ident_64)
26290+#else
26291 /* 32-bit pagetable entries */
26292 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_32)
26293+#endif
26294 #else
26295 /* 64-bit pagetable entries */
26296 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_64)
26297 #endif
26298
26299-struct pv_mmu_ops pv_mmu_ops = {
26300+struct pv_mmu_ops pv_mmu_ops __read_only = {
26301
26302 .read_cr2 = native_read_cr2,
26303 .write_cr2 = native_write_cr2,
26304@@ -453,6 +465,7 @@ struct pv_mmu_ops pv_mmu_ops = {
26305 .make_pud = PTE_IDENT,
26306
26307 .set_pgd = native_set_pgd,
26308+ .set_pgd_batched = native_set_pgd_batched,
26309 #endif
26310 #endif /* PAGETABLE_LEVELS >= 3 */
26311
26312@@ -473,6 +486,12 @@ struct pv_mmu_ops pv_mmu_ops = {
26313 },
26314
26315 .set_fixmap = native_set_fixmap,
26316+
26317+#ifdef CONFIG_PAX_KERNEXEC
26318+ .pax_open_kernel = native_pax_open_kernel,
26319+ .pax_close_kernel = native_pax_close_kernel,
26320+#endif
26321+
26322 };
26323
26324 EXPORT_SYMBOL_GPL(pv_time_ops);
26325diff --git a/arch/x86/kernel/pci-calgary_64.c b/arch/x86/kernel/pci-calgary_64.c
26326index 299d493..2ccb0ee 100644
26327--- a/arch/x86/kernel/pci-calgary_64.c
26328+++ b/arch/x86/kernel/pci-calgary_64.c
26329@@ -1339,7 +1339,7 @@ static void __init get_tce_space_from_tar(void)
26330 tce_space = be64_to_cpu(readq(target));
26331 tce_space = tce_space & TAR_SW_BITS;
26332
26333- tce_space = tce_space & (~specified_table_size);
26334+ tce_space = tce_space & (~(unsigned long)specified_table_size);
26335 info->tce_space = (u64 *)__va(tce_space);
26336 }
26337 }
26338diff --git a/arch/x86/kernel/pci-iommu_table.c b/arch/x86/kernel/pci-iommu_table.c
26339index 35ccf75..7a15747 100644
26340--- a/arch/x86/kernel/pci-iommu_table.c
26341+++ b/arch/x86/kernel/pci-iommu_table.c
26342@@ -2,7 +2,7 @@
26343 #include <asm/iommu_table.h>
26344 #include <linux/string.h>
26345 #include <linux/kallsyms.h>
26346-
26347+#include <linux/sched.h>
26348
26349 #define DEBUG 1
26350
26351diff --git a/arch/x86/kernel/pci-swiotlb.c b/arch/x86/kernel/pci-swiotlb.c
26352index 6c483ba..d10ce2f 100644
26353--- a/arch/x86/kernel/pci-swiotlb.c
26354+++ b/arch/x86/kernel/pci-swiotlb.c
26355@@ -32,7 +32,7 @@ static void x86_swiotlb_free_coherent(struct device *dev, size_t size,
26356 void *vaddr, dma_addr_t dma_addr,
26357 struct dma_attrs *attrs)
26358 {
26359- swiotlb_free_coherent(dev, size, vaddr, dma_addr);
26360+ swiotlb_free_coherent(dev, size, vaddr, dma_addr, attrs);
26361 }
26362
26363 static struct dma_map_ops swiotlb_dma_ops = {
26364diff --git a/arch/x86/kernel/preempt.S b/arch/x86/kernel/preempt.S
26365index ca7f0d5..8996469 100644
26366--- a/arch/x86/kernel/preempt.S
26367+++ b/arch/x86/kernel/preempt.S
26368@@ -3,12 +3,14 @@
26369 #include <asm/dwarf2.h>
26370 #include <asm/asm.h>
26371 #include <asm/calling.h>
26372+#include <asm/alternative-asm.h>
26373
26374 ENTRY(___preempt_schedule)
26375 CFI_STARTPROC
26376 SAVE_ALL
26377 call preempt_schedule
26378 RESTORE_ALL
26379+ pax_force_retaddr
26380 ret
26381 CFI_ENDPROC
26382
26383@@ -19,6 +21,7 @@ ENTRY(___preempt_schedule_context)
26384 SAVE_ALL
26385 call preempt_schedule_context
26386 RESTORE_ALL
26387+ pax_force_retaddr
26388 ret
26389 CFI_ENDPROC
26390
26391diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c
26392index 3fb8d95..254dc51 100644
26393--- a/arch/x86/kernel/process.c
26394+++ b/arch/x86/kernel/process.c
26395@@ -36,7 +36,8 @@
26396 * section. Since TSS's are completely CPU-local, we want them
26397 * on exact cacheline boundaries, to eliminate cacheline ping-pong.
26398 */
26399-__visible DEFINE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss) = INIT_TSS;
26400+struct tss_struct init_tss[NR_CPUS] __visible ____cacheline_internodealigned_in_smp = { [0 ... NR_CPUS-1] = INIT_TSS };
26401+EXPORT_SYMBOL(init_tss);
26402
26403 #ifdef CONFIG_X86_64
26404 static DEFINE_PER_CPU(unsigned char, is_idle);
26405@@ -92,7 +93,7 @@ void arch_task_cache_init(void)
26406 task_xstate_cachep =
26407 kmem_cache_create("task_xstate", xstate_size,
26408 __alignof__(union thread_xstate),
26409- SLAB_PANIC | SLAB_NOTRACK, NULL);
26410+ SLAB_PANIC | SLAB_NOTRACK | SLAB_USERCOPY, NULL);
26411 }
26412
26413 /*
26414@@ -105,7 +106,7 @@ void exit_thread(void)
26415 unsigned long *bp = t->io_bitmap_ptr;
26416
26417 if (bp) {
26418- struct tss_struct *tss = &per_cpu(init_tss, get_cpu());
26419+ struct tss_struct *tss = init_tss + get_cpu();
26420
26421 t->io_bitmap_ptr = NULL;
26422 clear_thread_flag(TIF_IO_BITMAP);
26423@@ -125,6 +126,9 @@ void flush_thread(void)
26424 {
26425 struct task_struct *tsk = current;
26426
26427+#if defined(CONFIG_X86_32) && !defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_PAX_MEMORY_UDEREF)
26428+ loadsegment(gs, 0);
26429+#endif
26430 flush_ptrace_hw_breakpoint(tsk);
26431 memset(tsk->thread.tls_array, 0, sizeof(tsk->thread.tls_array));
26432 drop_init_fpu(tsk);
26433@@ -271,7 +275,7 @@ static void __exit_idle(void)
26434 void exit_idle(void)
26435 {
26436 /* idle loop has pid 0 */
26437- if (current->pid)
26438+ if (task_pid_nr(current))
26439 return;
26440 __exit_idle();
26441 }
26442@@ -327,7 +331,7 @@ bool xen_set_default_idle(void)
26443 return ret;
26444 }
26445 #endif
26446-void stop_this_cpu(void *dummy)
26447+__noreturn void stop_this_cpu(void *dummy)
26448 {
26449 local_irq_disable();
26450 /*
26451@@ -456,16 +460,37 @@ static int __init idle_setup(char *str)
26452 }
26453 early_param("idle", idle_setup);
26454
26455-unsigned long arch_align_stack(unsigned long sp)
26456+#ifdef CONFIG_PAX_RANDKSTACK
26457+void pax_randomize_kstack(struct pt_regs *regs)
26458 {
26459- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
26460- sp -= get_random_int() % 8192;
26461- return sp & ~0xf;
26462-}
26463+ struct thread_struct *thread = &current->thread;
26464+ unsigned long time;
26465
26466-unsigned long arch_randomize_brk(struct mm_struct *mm)
26467-{
26468- unsigned long range_end = mm->brk + 0x02000000;
26469- return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
26470-}
26471+ if (!randomize_va_space)
26472+ return;
26473+
26474+ if (v8086_mode(regs))
26475+ return;
26476
26477+ rdtscl(time);
26478+
26479+ /* P4 seems to return a 0 LSB, ignore it */
26480+#ifdef CONFIG_MPENTIUM4
26481+ time &= 0x3EUL;
26482+ time <<= 2;
26483+#elif defined(CONFIG_X86_64)
26484+ time &= 0xFUL;
26485+ time <<= 4;
26486+#else
26487+ time &= 0x1FUL;
26488+ time <<= 3;
26489+#endif
26490+
26491+ thread->sp0 ^= time;
26492+ load_sp0(init_tss + smp_processor_id(), thread);
26493+
26494+#ifdef CONFIG_X86_64
26495+ this_cpu_write(kernel_stack, thread->sp0);
26496+#endif
26497+}
26498+#endif
26499diff --git a/arch/x86/kernel/process_32.c b/arch/x86/kernel/process_32.c
26500index 0de43e9..056b840 100644
26501--- a/arch/x86/kernel/process_32.c
26502+++ b/arch/x86/kernel/process_32.c
26503@@ -64,6 +64,7 @@ asmlinkage void ret_from_kernel_thread(void) __asm__("ret_from_kernel_thread");
26504 unsigned long thread_saved_pc(struct task_struct *tsk)
26505 {
26506 return ((unsigned long *)tsk->thread.sp)[3];
26507+//XXX return tsk->thread.eip;
26508 }
26509
26510 void __show_regs(struct pt_regs *regs, int all)
26511@@ -73,19 +74,18 @@ void __show_regs(struct pt_regs *regs, int all)
26512 unsigned long sp;
26513 unsigned short ss, gs;
26514
26515- if (user_mode_vm(regs)) {
26516+ if (user_mode(regs)) {
26517 sp = regs->sp;
26518 ss = regs->ss & 0xffff;
26519- gs = get_user_gs(regs);
26520 } else {
26521 sp = kernel_stack_pointer(regs);
26522 savesegment(ss, ss);
26523- savesegment(gs, gs);
26524 }
26525+ gs = get_user_gs(regs);
26526
26527 printk(KERN_DEFAULT "EIP: %04x:[<%08lx>] EFLAGS: %08lx CPU: %d\n",
26528 (u16)regs->cs, regs->ip, regs->flags,
26529- smp_processor_id());
26530+ raw_smp_processor_id());
26531 print_symbol("EIP is at %s\n", regs->ip);
26532
26533 printk(KERN_DEFAULT "EAX: %08lx EBX: %08lx ECX: %08lx EDX: %08lx\n",
26534@@ -132,20 +132,21 @@ void release_thread(struct task_struct *dead_task)
26535 int copy_thread(unsigned long clone_flags, unsigned long sp,
26536 unsigned long arg, struct task_struct *p)
26537 {
26538- struct pt_regs *childregs = task_pt_regs(p);
26539+ struct pt_regs *childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 8;
26540 struct task_struct *tsk;
26541 int err;
26542
26543 p->thread.sp = (unsigned long) childregs;
26544 p->thread.sp0 = (unsigned long) (childregs+1);
26545+ p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
26546
26547 if (unlikely(p->flags & PF_KTHREAD)) {
26548 /* kernel thread */
26549 memset(childregs, 0, sizeof(struct pt_regs));
26550 p->thread.ip = (unsigned long) ret_from_kernel_thread;
26551- task_user_gs(p) = __KERNEL_STACK_CANARY;
26552- childregs->ds = __USER_DS;
26553- childregs->es = __USER_DS;
26554+ savesegment(gs, childregs->gs);
26555+ childregs->ds = __KERNEL_DS;
26556+ childregs->es = __KERNEL_DS;
26557 childregs->fs = __KERNEL_PERCPU;
26558 childregs->bx = sp; /* function */
26559 childregs->bp = arg;
26560@@ -252,7 +253,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26561 struct thread_struct *prev = &prev_p->thread,
26562 *next = &next_p->thread;
26563 int cpu = smp_processor_id();
26564- struct tss_struct *tss = &per_cpu(init_tss, cpu);
26565+ struct tss_struct *tss = init_tss + cpu;
26566 fpu_switch_t fpu;
26567
26568 /* never put a printk in __switch_to... printk() calls wake_up*() indirectly */
26569@@ -276,6 +277,10 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26570 */
26571 lazy_save_gs(prev->gs);
26572
26573+#ifdef CONFIG_PAX_MEMORY_UDEREF
26574+ __set_fs(task_thread_info(next_p)->addr_limit);
26575+#endif
26576+
26577 /*
26578 * Load the per-thread Thread-Local Storage descriptor.
26579 */
26580@@ -314,6 +319,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26581 */
26582 arch_end_context_switch(next_p);
26583
26584+ this_cpu_write(current_task, next_p);
26585+ this_cpu_write(current_tinfo, &next_p->tinfo);
26586+
26587 /*
26588 * Restore %gs if needed (which is common)
26589 */
26590@@ -322,8 +330,6 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26591
26592 switch_fpu_finish(next_p, fpu);
26593
26594- this_cpu_write(current_task, next_p);
26595-
26596 return prev_p;
26597 }
26598
26599@@ -353,4 +359,3 @@ unsigned long get_wchan(struct task_struct *p)
26600 } while (count++ < 16);
26601 return 0;
26602 }
26603-
26604diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c
26605index 9c0280f..5bbb1c0 100644
26606--- a/arch/x86/kernel/process_64.c
26607+++ b/arch/x86/kernel/process_64.c
26608@@ -158,10 +158,11 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
26609 struct pt_regs *childregs;
26610 struct task_struct *me = current;
26611
26612- p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE;
26613+ p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE - 16;
26614 childregs = task_pt_regs(p);
26615 p->thread.sp = (unsigned long) childregs;
26616 p->thread.usersp = me->thread.usersp;
26617+ p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
26618 set_tsk_thread_flag(p, TIF_FORK);
26619 p->thread.fpu_counter = 0;
26620 p->thread.io_bitmap_ptr = NULL;
26621@@ -172,6 +173,8 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
26622 p->thread.fs = p->thread.fsindex ? 0 : me->thread.fs;
26623 savesegment(es, p->thread.es);
26624 savesegment(ds, p->thread.ds);
26625+ savesegment(ss, p->thread.ss);
26626+ BUG_ON(p->thread.ss == __UDEREF_KERNEL_DS);
26627 memset(p->thread.ptrace_bps, 0, sizeof(p->thread.ptrace_bps));
26628
26629 if (unlikely(p->flags & PF_KTHREAD)) {
26630@@ -280,7 +283,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26631 struct thread_struct *prev = &prev_p->thread;
26632 struct thread_struct *next = &next_p->thread;
26633 int cpu = smp_processor_id();
26634- struct tss_struct *tss = &per_cpu(init_tss, cpu);
26635+ struct tss_struct *tss = init_tss + cpu;
26636 unsigned fsindex, gsindex;
26637 fpu_switch_t fpu;
26638
26639@@ -303,6 +306,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26640 if (unlikely(next->ds | prev->ds))
26641 loadsegment(ds, next->ds);
26642
26643+ savesegment(ss, prev->ss);
26644+ if (unlikely(next->ss != prev->ss))
26645+ loadsegment(ss, next->ss);
26646
26647 /* We must save %fs and %gs before load_TLS() because
26648 * %fs and %gs may be cleared by load_TLS().
26649@@ -362,6 +368,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26650 prev->usersp = this_cpu_read(old_rsp);
26651 this_cpu_write(old_rsp, next->usersp);
26652 this_cpu_write(current_task, next_p);
26653+ this_cpu_write(current_tinfo, &next_p->tinfo);
26654
26655 /*
26656 * If it were not for PREEMPT_ACTIVE we could guarantee that the
26657@@ -371,9 +378,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26658 task_thread_info(prev_p)->saved_preempt_count = this_cpu_read(__preempt_count);
26659 this_cpu_write(__preempt_count, task_thread_info(next_p)->saved_preempt_count);
26660
26661- this_cpu_write(kernel_stack,
26662- (unsigned long)task_stack_page(next_p) +
26663- THREAD_SIZE - KERNEL_STACK_OFFSET);
26664+ this_cpu_write(kernel_stack, next->sp0);
26665
26666 /*
26667 * Now maybe reload the debug registers and handle I/O bitmaps
26668@@ -442,12 +447,11 @@ unsigned long get_wchan(struct task_struct *p)
26669 if (!p || p == current || p->state == TASK_RUNNING)
26670 return 0;
26671 stack = (unsigned long)task_stack_page(p);
26672- if (p->thread.sp < stack || p->thread.sp >= stack+THREAD_SIZE)
26673+ if (p->thread.sp < stack || p->thread.sp > stack+THREAD_SIZE-16-sizeof(u64))
26674 return 0;
26675 fp = *(u64 *)(p->thread.sp);
26676 do {
26677- if (fp < (unsigned long)stack ||
26678- fp >= (unsigned long)stack+THREAD_SIZE)
26679+ if (fp < stack || fp > stack+THREAD_SIZE-16-sizeof(u64))
26680 return 0;
26681 ip = *(u64 *)(fp+8);
26682 if (!in_sched_functions(ip))
26683diff --git a/arch/x86/kernel/ptrace.c b/arch/x86/kernel/ptrace.c
26684index 7461f50..1334029 100644
26685--- a/arch/x86/kernel/ptrace.c
26686+++ b/arch/x86/kernel/ptrace.c
26687@@ -184,14 +184,13 @@ unsigned long kernel_stack_pointer(struct pt_regs *regs)
26688 {
26689 unsigned long context = (unsigned long)regs & ~(THREAD_SIZE - 1);
26690 unsigned long sp = (unsigned long)&regs->sp;
26691- struct thread_info *tinfo;
26692
26693- if (context == (sp & ~(THREAD_SIZE - 1)))
26694+ if (context == ((sp + 8) & ~(THREAD_SIZE - 1)))
26695 return sp;
26696
26697- tinfo = (struct thread_info *)context;
26698- if (tinfo->previous_esp)
26699- return tinfo->previous_esp;
26700+ sp = *(unsigned long *)context;
26701+ if (sp)
26702+ return sp;
26703
26704 return (unsigned long)regs;
26705 }
26706@@ -588,7 +587,7 @@ static void ptrace_triggered(struct perf_event *bp,
26707 static unsigned long ptrace_get_dr7(struct perf_event *bp[])
26708 {
26709 int i;
26710- int dr7 = 0;
26711+ unsigned long dr7 = 0;
26712 struct arch_hw_breakpoint *info;
26713
26714 for (i = 0; i < HBP_NUM; i++) {
26715@@ -822,7 +821,7 @@ long arch_ptrace(struct task_struct *child, long request,
26716 unsigned long addr, unsigned long data)
26717 {
26718 int ret;
26719- unsigned long __user *datap = (unsigned long __user *)data;
26720+ unsigned long __user *datap = (__force unsigned long __user *)data;
26721
26722 switch (request) {
26723 /* read the word at location addr in the USER area. */
26724@@ -907,14 +906,14 @@ long arch_ptrace(struct task_struct *child, long request,
26725 if ((int) addr < 0)
26726 return -EIO;
26727 ret = do_get_thread_area(child, addr,
26728- (struct user_desc __user *)data);
26729+ (__force struct user_desc __user *) data);
26730 break;
26731
26732 case PTRACE_SET_THREAD_AREA:
26733 if ((int) addr < 0)
26734 return -EIO;
26735 ret = do_set_thread_area(child, addr,
26736- (struct user_desc __user *)data, 0);
26737+ (__force struct user_desc __user *) data, 0);
26738 break;
26739 #endif
26740
26741@@ -1292,7 +1291,7 @@ long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
26742
26743 #ifdef CONFIG_X86_64
26744
26745-static struct user_regset x86_64_regsets[] __read_mostly = {
26746+static user_regset_no_const x86_64_regsets[] __read_only = {
26747 [REGSET_GENERAL] = {
26748 .core_note_type = NT_PRSTATUS,
26749 .n = sizeof(struct user_regs_struct) / sizeof(long),
26750@@ -1333,7 +1332,7 @@ static const struct user_regset_view user_x86_64_view = {
26751 #endif /* CONFIG_X86_64 */
26752
26753 #if defined CONFIG_X86_32 || defined CONFIG_IA32_EMULATION
26754-static struct user_regset x86_32_regsets[] __read_mostly = {
26755+static user_regset_no_const x86_32_regsets[] __read_only = {
26756 [REGSET_GENERAL] = {
26757 .core_note_type = NT_PRSTATUS,
26758 .n = sizeof(struct user_regs_struct32) / sizeof(u32),
26759@@ -1386,7 +1385,7 @@ static const struct user_regset_view user_x86_32_view = {
26760 */
26761 u64 xstate_fx_sw_bytes[USER_XSTATE_FX_SW_WORDS];
26762
26763-void update_regset_xstate_info(unsigned int size, u64 xstate_mask)
26764+void __init update_regset_xstate_info(unsigned int size, u64 xstate_mask)
26765 {
26766 #ifdef CONFIG_X86_64
26767 x86_64_regsets[REGSET_XSTATE].n = size / sizeof(u64);
26768@@ -1421,7 +1420,7 @@ static void fill_sigtrap_info(struct task_struct *tsk,
26769 memset(info, 0, sizeof(*info));
26770 info->si_signo = SIGTRAP;
26771 info->si_code = si_code;
26772- info->si_addr = user_mode_vm(regs) ? (void __user *)regs->ip : NULL;
26773+ info->si_addr = user_mode(regs) ? (__force void __user *)regs->ip : NULL;
26774 }
26775
26776 void user_single_step_siginfo(struct task_struct *tsk,
26777@@ -1450,6 +1449,10 @@ void send_sigtrap(struct task_struct *tsk, struct pt_regs *regs,
26778 # define IS_IA32 0
26779 #endif
26780
26781+#ifdef CONFIG_GRKERNSEC_SETXID
26782+extern void gr_delayed_cred_worker(void);
26783+#endif
26784+
26785 /*
26786 * We must return the syscall number to actually look up in the table.
26787 * This can be -1L to skip running any syscall at all.
26788@@ -1460,6 +1463,11 @@ long syscall_trace_enter(struct pt_regs *regs)
26789
26790 user_exit();
26791
26792+#ifdef CONFIG_GRKERNSEC_SETXID
26793+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
26794+ gr_delayed_cred_worker();
26795+#endif
26796+
26797 /*
26798 * If we stepped into a sysenter/syscall insn, it trapped in
26799 * kernel mode; do_debug() cleared TF and set TIF_SINGLESTEP.
26800@@ -1515,6 +1523,11 @@ void syscall_trace_leave(struct pt_regs *regs)
26801 */
26802 user_exit();
26803
26804+#ifdef CONFIG_GRKERNSEC_SETXID
26805+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
26806+ gr_delayed_cred_worker();
26807+#endif
26808+
26809 audit_syscall_exit(regs);
26810
26811 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
26812diff --git a/arch/x86/kernel/pvclock.c b/arch/x86/kernel/pvclock.c
26813index 2f355d2..e75ed0a 100644
26814--- a/arch/x86/kernel/pvclock.c
26815+++ b/arch/x86/kernel/pvclock.c
26816@@ -51,11 +51,11 @@ void pvclock_touch_watchdogs(void)
26817 reset_hung_task_detector();
26818 }
26819
26820-static atomic64_t last_value = ATOMIC64_INIT(0);
26821+static atomic64_unchecked_t last_value = ATOMIC64_INIT(0);
26822
26823 void pvclock_resume(void)
26824 {
26825- atomic64_set(&last_value, 0);
26826+ atomic64_set_unchecked(&last_value, 0);
26827 }
26828
26829 u8 pvclock_read_flags(struct pvclock_vcpu_time_info *src)
26830@@ -105,11 +105,11 @@ cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
26831 * updating at the same time, and one of them could be slightly behind,
26832 * making the assumption that last_value always go forward fail to hold.
26833 */
26834- last = atomic64_read(&last_value);
26835+ last = atomic64_read_unchecked(&last_value);
26836 do {
26837 if (ret < last)
26838 return last;
26839- last = atomic64_cmpxchg(&last_value, last, ret);
26840+ last = atomic64_cmpxchg_unchecked(&last_value, last, ret);
26841 } while (unlikely(last != ret));
26842
26843 return ret;
26844diff --git a/arch/x86/kernel/reboot.c b/arch/x86/kernel/reboot.c
26845index c752cb4..866c432 100644
26846--- a/arch/x86/kernel/reboot.c
26847+++ b/arch/x86/kernel/reboot.c
26848@@ -68,6 +68,11 @@ static int __init set_bios_reboot(const struct dmi_system_id *d)
26849
26850 void __noreturn machine_real_restart(unsigned int type)
26851 {
26852+
26853+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
26854+ struct desc_struct *gdt;
26855+#endif
26856+
26857 local_irq_disable();
26858
26859 /*
26860@@ -95,7 +100,29 @@ void __noreturn machine_real_restart(unsigned int type)
26861
26862 /* Jump to the identity-mapped low memory code */
26863 #ifdef CONFIG_X86_32
26864- asm volatile("jmpl *%0" : :
26865+
26866+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
26867+ gdt = get_cpu_gdt_table(smp_processor_id());
26868+ pax_open_kernel();
26869+#ifdef CONFIG_PAX_MEMORY_UDEREF
26870+ gdt[GDT_ENTRY_KERNEL_DS].type = 3;
26871+ gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
26872+ loadsegment(ds, __KERNEL_DS);
26873+ loadsegment(es, __KERNEL_DS);
26874+ loadsegment(ss, __KERNEL_DS);
26875+#endif
26876+#ifdef CONFIG_PAX_KERNEXEC
26877+ gdt[GDT_ENTRY_KERNEL_CS].base0 = 0;
26878+ gdt[GDT_ENTRY_KERNEL_CS].base1 = 0;
26879+ gdt[GDT_ENTRY_KERNEL_CS].base2 = 0;
26880+ gdt[GDT_ENTRY_KERNEL_CS].limit0 = 0xffff;
26881+ gdt[GDT_ENTRY_KERNEL_CS].limit = 0xf;
26882+ gdt[GDT_ENTRY_KERNEL_CS].g = 1;
26883+#endif
26884+ pax_close_kernel();
26885+#endif
26886+
26887+ asm volatile("ljmpl *%0" : :
26888 "rm" (real_mode_header->machine_real_restart_asm),
26889 "a" (type));
26890 #else
26891@@ -470,7 +497,7 @@ void __attribute__((weak)) mach_reboot_fixups(void)
26892 * try to force a triple fault and then cycle between hitting the keyboard
26893 * controller and doing that
26894 */
26895-static void native_machine_emergency_restart(void)
26896+static void __noreturn native_machine_emergency_restart(void)
26897 {
26898 int i;
26899 int attempt = 0;
26900@@ -593,13 +620,13 @@ void native_machine_shutdown(void)
26901 #endif
26902 }
26903
26904-static void __machine_emergency_restart(int emergency)
26905+static void __noreturn __machine_emergency_restart(int emergency)
26906 {
26907 reboot_emergency = emergency;
26908 machine_ops.emergency_restart();
26909 }
26910
26911-static void native_machine_restart(char *__unused)
26912+static void __noreturn native_machine_restart(char *__unused)
26913 {
26914 pr_notice("machine restart\n");
26915
26916@@ -608,7 +635,7 @@ static void native_machine_restart(char *__unused)
26917 __machine_emergency_restart(0);
26918 }
26919
26920-static void native_machine_halt(void)
26921+static void __noreturn native_machine_halt(void)
26922 {
26923 /* Stop other cpus and apics */
26924 machine_shutdown();
26925@@ -618,7 +645,7 @@ static void native_machine_halt(void)
26926 stop_this_cpu(NULL);
26927 }
26928
26929-static void native_machine_power_off(void)
26930+static void __noreturn native_machine_power_off(void)
26931 {
26932 if (pm_power_off) {
26933 if (!reboot_force)
26934@@ -627,9 +654,10 @@ static void native_machine_power_off(void)
26935 }
26936 /* A fallback in case there is no PM info available */
26937 tboot_shutdown(TB_SHUTDOWN_HALT);
26938+ unreachable();
26939 }
26940
26941-struct machine_ops machine_ops = {
26942+struct machine_ops machine_ops __read_only = {
26943 .power_off = native_machine_power_off,
26944 .shutdown = native_machine_shutdown,
26945 .emergency_restart = native_machine_emergency_restart,
26946diff --git a/arch/x86/kernel/reboot_fixups_32.c b/arch/x86/kernel/reboot_fixups_32.c
26947index c8e41e9..64049ef 100644
26948--- a/arch/x86/kernel/reboot_fixups_32.c
26949+++ b/arch/x86/kernel/reboot_fixups_32.c
26950@@ -57,7 +57,7 @@ struct device_fixup {
26951 unsigned int vendor;
26952 unsigned int device;
26953 void (*reboot_fixup)(struct pci_dev *);
26954-};
26955+} __do_const;
26956
26957 /*
26958 * PCI ids solely used for fixups_table go here
26959diff --git a/arch/x86/kernel/relocate_kernel_64.S b/arch/x86/kernel/relocate_kernel_64.S
26960index 3fd2c69..a444264 100644
26961--- a/arch/x86/kernel/relocate_kernel_64.S
26962+++ b/arch/x86/kernel/relocate_kernel_64.S
26963@@ -96,8 +96,7 @@ relocate_kernel:
26964
26965 /* jump to identity mapped page */
26966 addq $(identity_mapped - relocate_kernel), %r8
26967- pushq %r8
26968- ret
26969+ jmp *%r8
26970
26971 identity_mapped:
26972 /* set return address to 0 if not preserving context */
26973diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
26974index ce72964..be8aea7 100644
26975--- a/arch/x86/kernel/setup.c
26976+++ b/arch/x86/kernel/setup.c
26977@@ -110,6 +110,7 @@
26978 #include <asm/mce.h>
26979 #include <asm/alternative.h>
26980 #include <asm/prom.h>
26981+#include <asm/boot.h>
26982
26983 /*
26984 * max_low_pfn_mapped: highest direct mapped pfn under 4GB
26985@@ -205,12 +206,50 @@ EXPORT_SYMBOL(boot_cpu_data);
26986 #endif
26987
26988
26989-#if !defined(CONFIG_X86_PAE) || defined(CONFIG_X86_64)
26990-__visible unsigned long mmu_cr4_features;
26991+#ifdef CONFIG_X86_64
26992+__visible unsigned long mmu_cr4_features __read_only = X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE;
26993+#elif defined(CONFIG_X86_PAE)
26994+__visible unsigned long mmu_cr4_features __read_only = X86_CR4_PAE;
26995 #else
26996-__visible unsigned long mmu_cr4_features = X86_CR4_PAE;
26997+__visible unsigned long mmu_cr4_features __read_only;
26998 #endif
26999
27000+void set_in_cr4(unsigned long mask)
27001+{
27002+ unsigned long cr4 = read_cr4();
27003+
27004+ if ((cr4 & mask) == mask && cr4 == mmu_cr4_features)
27005+ return;
27006+
27007+ pax_open_kernel();
27008+ mmu_cr4_features |= mask;
27009+ pax_close_kernel();
27010+
27011+ if (trampoline_cr4_features)
27012+ *trampoline_cr4_features = mmu_cr4_features;
27013+ cr4 |= mask;
27014+ write_cr4(cr4);
27015+}
27016+EXPORT_SYMBOL(set_in_cr4);
27017+
27018+void clear_in_cr4(unsigned long mask)
27019+{
27020+ unsigned long cr4 = read_cr4();
27021+
27022+ if (!(cr4 & mask) && cr4 == mmu_cr4_features)
27023+ return;
27024+
27025+ pax_open_kernel();
27026+ mmu_cr4_features &= ~mask;
27027+ pax_close_kernel();
27028+
27029+ if (trampoline_cr4_features)
27030+ *trampoline_cr4_features = mmu_cr4_features;
27031+ cr4 &= ~mask;
27032+ write_cr4(cr4);
27033+}
27034+EXPORT_SYMBOL(clear_in_cr4);
27035+
27036 /* Boot loader ID and version as integers, for the benefit of proc_dointvec */
27037 int bootloader_type, bootloader_version;
27038
27039@@ -772,7 +811,7 @@ static void __init trim_bios_range(void)
27040 * area (640->1Mb) as ram even though it is not.
27041 * take them out.
27042 */
27043- e820_remove_range(BIOS_BEGIN, BIOS_END - BIOS_BEGIN, E820_RAM, 1);
27044+ e820_remove_range(ISA_START_ADDRESS, ISA_END_ADDRESS - ISA_START_ADDRESS, E820_RAM, 1);
27045
27046 sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
27047 }
27048@@ -780,7 +819,7 @@ static void __init trim_bios_range(void)
27049 /* called before trim_bios_range() to spare extra sanitize */
27050 static void __init e820_add_kernel_range(void)
27051 {
27052- u64 start = __pa_symbol(_text);
27053+ u64 start = __pa_symbol(ktla_ktva(_text));
27054 u64 size = __pa_symbol(_end) - start;
27055
27056 /*
27057@@ -856,8 +895,12 @@ dump_kernel_offset(struct notifier_block *self, unsigned long v, void *p)
27058
27059 void __init setup_arch(char **cmdline_p)
27060 {
27061+#ifdef CONFIG_X86_32
27062+ memblock_reserve(LOAD_PHYSICAL_ADDR, __pa_symbol(__bss_stop) - LOAD_PHYSICAL_ADDR);
27063+#else
27064 memblock_reserve(__pa_symbol(_text),
27065 (unsigned long)__bss_stop - (unsigned long)_text);
27066+#endif
27067
27068 early_reserve_initrd();
27069
27070@@ -947,14 +990,14 @@ void __init setup_arch(char **cmdline_p)
27071
27072 if (!boot_params.hdr.root_flags)
27073 root_mountflags &= ~MS_RDONLY;
27074- init_mm.start_code = (unsigned long) _text;
27075- init_mm.end_code = (unsigned long) _etext;
27076+ init_mm.start_code = ktla_ktva((unsigned long) _text);
27077+ init_mm.end_code = ktla_ktva((unsigned long) _etext);
27078 init_mm.end_data = (unsigned long) _edata;
27079 init_mm.brk = _brk_end;
27080
27081- code_resource.start = __pa_symbol(_text);
27082- code_resource.end = __pa_symbol(_etext)-1;
27083- data_resource.start = __pa_symbol(_etext);
27084+ code_resource.start = __pa_symbol(ktla_ktva(_text));
27085+ code_resource.end = __pa_symbol(ktla_ktva(_etext))-1;
27086+ data_resource.start = __pa_symbol(_sdata);
27087 data_resource.end = __pa_symbol(_edata)-1;
27088 bss_resource.start = __pa_symbol(__bss_start);
27089 bss_resource.end = __pa_symbol(__bss_stop)-1;
27090diff --git a/arch/x86/kernel/setup_percpu.c b/arch/x86/kernel/setup_percpu.c
27091index 5cdff03..80fa283 100644
27092--- a/arch/x86/kernel/setup_percpu.c
27093+++ b/arch/x86/kernel/setup_percpu.c
27094@@ -21,19 +21,17 @@
27095 #include <asm/cpu.h>
27096 #include <asm/stackprotector.h>
27097
27098-DEFINE_PER_CPU_READ_MOSTLY(int, cpu_number);
27099+#ifdef CONFIG_SMP
27100+DEFINE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
27101 EXPORT_PER_CPU_SYMBOL(cpu_number);
27102+#endif
27103
27104-#ifdef CONFIG_X86_64
27105 #define BOOT_PERCPU_OFFSET ((unsigned long)__per_cpu_load)
27106-#else
27107-#define BOOT_PERCPU_OFFSET 0
27108-#endif
27109
27110 DEFINE_PER_CPU(unsigned long, this_cpu_off) = BOOT_PERCPU_OFFSET;
27111 EXPORT_PER_CPU_SYMBOL(this_cpu_off);
27112
27113-unsigned long __per_cpu_offset[NR_CPUS] __read_mostly = {
27114+unsigned long __per_cpu_offset[NR_CPUS] __read_only = {
27115 [0 ... NR_CPUS-1] = BOOT_PERCPU_OFFSET,
27116 };
27117 EXPORT_SYMBOL(__per_cpu_offset);
27118@@ -66,7 +64,7 @@ static bool __init pcpu_need_numa(void)
27119 {
27120 #ifdef CONFIG_NEED_MULTIPLE_NODES
27121 pg_data_t *last = NULL;
27122- unsigned int cpu;
27123+ int cpu;
27124
27125 for_each_possible_cpu(cpu) {
27126 int node = early_cpu_to_node(cpu);
27127@@ -155,10 +153,10 @@ static inline void setup_percpu_segment(int cpu)
27128 {
27129 #ifdef CONFIG_X86_32
27130 struct desc_struct gdt;
27131+ unsigned long base = per_cpu_offset(cpu);
27132
27133- pack_descriptor(&gdt, per_cpu_offset(cpu), 0xFFFFF,
27134- 0x2 | DESCTYPE_S, 0x8);
27135- gdt.s = 1;
27136+ pack_descriptor(&gdt, base, (VMALLOC_END - base - 1) >> PAGE_SHIFT,
27137+ 0x83 | DESCTYPE_S, 0xC);
27138 write_gdt_entry(get_cpu_gdt_table(cpu),
27139 GDT_ENTRY_PERCPU, &gdt, DESCTYPE_S);
27140 #endif
27141@@ -219,6 +217,11 @@ void __init setup_per_cpu_areas(void)
27142 /* alrighty, percpu areas up and running */
27143 delta = (unsigned long)pcpu_base_addr - (unsigned long)__per_cpu_start;
27144 for_each_possible_cpu(cpu) {
27145+#ifdef CONFIG_CC_STACKPROTECTOR
27146+#ifdef CONFIG_X86_32
27147+ unsigned long canary = per_cpu(stack_canary.canary, cpu);
27148+#endif
27149+#endif
27150 per_cpu_offset(cpu) = delta + pcpu_unit_offsets[cpu];
27151 per_cpu(this_cpu_off, cpu) = per_cpu_offset(cpu);
27152 per_cpu(cpu_number, cpu) = cpu;
27153@@ -259,6 +262,12 @@ void __init setup_per_cpu_areas(void)
27154 */
27155 set_cpu_numa_node(cpu, early_cpu_to_node(cpu));
27156 #endif
27157+#ifdef CONFIG_CC_STACKPROTECTOR
27158+#ifdef CONFIG_X86_32
27159+ if (!cpu)
27160+ per_cpu(stack_canary.canary, cpu) = canary;
27161+#endif
27162+#endif
27163 /*
27164 * Up to this point, the boot CPU has been using .init.data
27165 * area. Reload any changed state for the boot CPU.
27166diff --git a/arch/x86/kernel/signal.c b/arch/x86/kernel/signal.c
27167index 9e5de68..16c53cb 100644
27168--- a/arch/x86/kernel/signal.c
27169+++ b/arch/x86/kernel/signal.c
27170@@ -190,7 +190,7 @@ static unsigned long align_sigframe(unsigned long sp)
27171 * Align the stack pointer according to the i386 ABI,
27172 * i.e. so that on function entry ((sp + 4) & 15) == 0.
27173 */
27174- sp = ((sp + 4) & -16ul) - 4;
27175+ sp = ((sp - 12) & -16ul) - 4;
27176 #else /* !CONFIG_X86_32 */
27177 sp = round_down(sp, 16) - 8;
27178 #endif
27179@@ -298,9 +298,9 @@ __setup_frame(int sig, struct ksignal *ksig, sigset_t *set,
27180 }
27181
27182 if (current->mm->context.vdso)
27183- restorer = VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
27184+ restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
27185 else
27186- restorer = &frame->retcode;
27187+ restorer = (void __user *)&frame->retcode;
27188 if (ksig->ka.sa.sa_flags & SA_RESTORER)
27189 restorer = ksig->ka.sa.sa_restorer;
27190
27191@@ -314,7 +314,7 @@ __setup_frame(int sig, struct ksignal *ksig, sigset_t *set,
27192 * reasons and because gdb uses it as a signature to notice
27193 * signal handler stack frames.
27194 */
27195- err |= __put_user(*((u64 *)&retcode), (u64 *)frame->retcode);
27196+ err |= __put_user(*((u64 *)&retcode), (u64 __user *)frame->retcode);
27197
27198 if (err)
27199 return -EFAULT;
27200@@ -361,7 +361,10 @@ static int __setup_rt_frame(int sig, struct ksignal *ksig,
27201 save_altstack_ex(&frame->uc.uc_stack, regs->sp);
27202
27203 /* Set up to return from userspace. */
27204- restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
27205+ if (current->mm->context.vdso)
27206+ restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
27207+ else
27208+ restorer = (void __user *)&frame->retcode;
27209 if (ksig->ka.sa.sa_flags & SA_RESTORER)
27210 restorer = ksig->ka.sa.sa_restorer;
27211 put_user_ex(restorer, &frame->pretcode);
27212@@ -373,7 +376,7 @@ static int __setup_rt_frame(int sig, struct ksignal *ksig,
27213 * reasons and because gdb uses it as a signature to notice
27214 * signal handler stack frames.
27215 */
27216- put_user_ex(*((u64 *)&rt_retcode), (u64 *)frame->retcode);
27217+ put_user_ex(*((u64 *)&rt_retcode), (u64 __user *)frame->retcode);
27218 } put_user_catch(err);
27219
27220 err |= copy_siginfo_to_user(&frame->info, &ksig->info);
27221@@ -609,7 +612,12 @@ setup_rt_frame(struct ksignal *ksig, struct pt_regs *regs)
27222 {
27223 int usig = signr_convert(ksig->sig);
27224 sigset_t *set = sigmask_to_save();
27225- compat_sigset_t *cset = (compat_sigset_t *) set;
27226+ sigset_t sigcopy;
27227+ compat_sigset_t *cset;
27228+
27229+ sigcopy = *set;
27230+
27231+ cset = (compat_sigset_t *) &sigcopy;
27232
27233 /* Set up the stack frame */
27234 if (is_ia32_frame()) {
27235@@ -620,7 +628,7 @@ setup_rt_frame(struct ksignal *ksig, struct pt_regs *regs)
27236 } else if (is_x32_frame()) {
27237 return x32_setup_rt_frame(ksig, cset, regs);
27238 } else {
27239- return __setup_rt_frame(ksig->sig, ksig, set, regs);
27240+ return __setup_rt_frame(ksig->sig, ksig, &sigcopy, regs);
27241 }
27242 }
27243
27244diff --git a/arch/x86/kernel/smp.c b/arch/x86/kernel/smp.c
27245index 7c3a5a6..f0a8961 100644
27246--- a/arch/x86/kernel/smp.c
27247+++ b/arch/x86/kernel/smp.c
27248@@ -341,7 +341,7 @@ static int __init nonmi_ipi_setup(char *str)
27249
27250 __setup("nonmi_ipi", nonmi_ipi_setup);
27251
27252-struct smp_ops smp_ops = {
27253+struct smp_ops smp_ops __read_only = {
27254 .smp_prepare_boot_cpu = native_smp_prepare_boot_cpu,
27255 .smp_prepare_cpus = native_smp_prepare_cpus,
27256 .smp_cpus_done = native_smp_cpus_done,
27257diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
27258index a32da80..30c97f1 100644
27259--- a/arch/x86/kernel/smpboot.c
27260+++ b/arch/x86/kernel/smpboot.c
27261@@ -229,14 +229,18 @@ static void notrace start_secondary(void *unused)
27262
27263 enable_start_cpu0 = 0;
27264
27265-#ifdef CONFIG_X86_32
27266- /* switch away from the initial page table */
27267- load_cr3(swapper_pg_dir);
27268- __flush_tlb_all();
27269-#endif
27270-
27271 /* otherwise gcc will move up smp_processor_id before the cpu_init */
27272 barrier();
27273+
27274+ /* switch away from the initial page table */
27275+#ifdef CONFIG_PAX_PER_CPU_PGD
27276+ load_cr3(get_cpu_pgd(smp_processor_id(), kernel));
27277+ __flush_tlb_all();
27278+#elif defined(CONFIG_X86_32)
27279+ load_cr3(swapper_pg_dir);
27280+ __flush_tlb_all();
27281+#endif
27282+
27283 /*
27284 * Check TSC synchronization with the BP:
27285 */
27286@@ -749,8 +753,9 @@ static int do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
27287 alternatives_enable_smp();
27288
27289 idle->thread.sp = (unsigned long) (((struct pt_regs *)
27290- (THREAD_SIZE + task_stack_page(idle))) - 1);
27291+ (THREAD_SIZE - 16 + task_stack_page(idle))) - 1);
27292 per_cpu(current_task, cpu) = idle;
27293+ per_cpu(current_tinfo, cpu) = &idle->tinfo;
27294
27295 #ifdef CONFIG_X86_32
27296 /* Stack for startup_32 can be just as for start_secondary onwards */
27297@@ -758,11 +763,13 @@ static int do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
27298 #else
27299 clear_tsk_thread_flag(idle, TIF_FORK);
27300 initial_gs = per_cpu_offset(cpu);
27301- per_cpu(kernel_stack, cpu) =
27302- (unsigned long)task_stack_page(idle) -
27303- KERNEL_STACK_OFFSET + THREAD_SIZE;
27304+ per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
27305 #endif
27306+
27307+ pax_open_kernel();
27308 early_gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
27309+ pax_close_kernel();
27310+
27311 initial_code = (unsigned long)start_secondary;
27312 stack_start = idle->thread.sp;
27313
27314@@ -911,6 +918,15 @@ int native_cpu_up(unsigned int cpu, struct task_struct *tidle)
27315 /* the FPU context is blank, nobody can own it */
27316 __cpu_disable_lazy_restore(cpu);
27317
27318+#ifdef CONFIG_PAX_PER_CPU_PGD
27319+ clone_pgd_range(get_cpu_pgd(cpu, kernel) + KERNEL_PGD_BOUNDARY,
27320+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
27321+ KERNEL_PGD_PTRS);
27322+ clone_pgd_range(get_cpu_pgd(cpu, user) + KERNEL_PGD_BOUNDARY,
27323+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
27324+ KERNEL_PGD_PTRS);
27325+#endif
27326+
27327 err = do_boot_cpu(apicid, cpu, tidle);
27328 if (err) {
27329 pr_debug("do_boot_cpu failed %d\n", err);
27330diff --git a/arch/x86/kernel/step.c b/arch/x86/kernel/step.c
27331index 9b4d51d..5d28b58 100644
27332--- a/arch/x86/kernel/step.c
27333+++ b/arch/x86/kernel/step.c
27334@@ -27,10 +27,10 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
27335 struct desc_struct *desc;
27336 unsigned long base;
27337
27338- seg &= ~7UL;
27339+ seg >>= 3;
27340
27341 mutex_lock(&child->mm->context.lock);
27342- if (unlikely((seg >> 3) >= child->mm->context.size))
27343+ if (unlikely(seg >= child->mm->context.size))
27344 addr = -1L; /* bogus selector, access would fault */
27345 else {
27346 desc = child->mm->context.ldt + seg;
27347@@ -42,7 +42,8 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
27348 addr += base;
27349 }
27350 mutex_unlock(&child->mm->context.lock);
27351- }
27352+ } else if (seg == __KERNEL_CS || seg == __KERNEXEC_KERNEL_CS)
27353+ addr = ktla_ktva(addr);
27354
27355 return addr;
27356 }
27357@@ -53,6 +54,9 @@ static int is_setting_trap_flag(struct task_struct *child, struct pt_regs *regs)
27358 unsigned char opcode[15];
27359 unsigned long addr = convert_ip_to_linear(child, regs);
27360
27361+ if (addr == -EINVAL)
27362+ return 0;
27363+
27364 copied = access_process_vm(child, addr, opcode, sizeof(opcode), 0);
27365 for (i = 0; i < copied; i++) {
27366 switch (opcode[i]) {
27367diff --git a/arch/x86/kernel/sys_i386_32.c b/arch/x86/kernel/sys_i386_32.c
27368new file mode 100644
27369index 0000000..5877189
27370--- /dev/null
27371+++ b/arch/x86/kernel/sys_i386_32.c
27372@@ -0,0 +1,189 @@
27373+/*
27374+ * This file contains various random system calls that
27375+ * have a non-standard calling sequence on the Linux/i386
27376+ * platform.
27377+ */
27378+
27379+#include <linux/errno.h>
27380+#include <linux/sched.h>
27381+#include <linux/mm.h>
27382+#include <linux/fs.h>
27383+#include <linux/smp.h>
27384+#include <linux/sem.h>
27385+#include <linux/msg.h>
27386+#include <linux/shm.h>
27387+#include <linux/stat.h>
27388+#include <linux/syscalls.h>
27389+#include <linux/mman.h>
27390+#include <linux/file.h>
27391+#include <linux/utsname.h>
27392+#include <linux/ipc.h>
27393+#include <linux/elf.h>
27394+
27395+#include <linux/uaccess.h>
27396+#include <linux/unistd.h>
27397+
27398+#include <asm/syscalls.h>
27399+
27400+int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags)
27401+{
27402+ unsigned long pax_task_size = TASK_SIZE;
27403+
27404+#ifdef CONFIG_PAX_SEGMEXEC
27405+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
27406+ pax_task_size = SEGMEXEC_TASK_SIZE;
27407+#endif
27408+
27409+ if (flags & MAP_FIXED)
27410+ if (len > pax_task_size || addr > pax_task_size - len)
27411+ return -EINVAL;
27412+
27413+ return 0;
27414+}
27415+
27416+/*
27417+ * Align a virtual address to avoid aliasing in the I$ on AMD F15h.
27418+ */
27419+static unsigned long get_align_mask(void)
27420+{
27421+ if (va_align.flags < 0 || !(va_align.flags & ALIGN_VA_32))
27422+ return 0;
27423+
27424+ if (!(current->flags & PF_RANDOMIZE))
27425+ return 0;
27426+
27427+ return va_align.mask;
27428+}
27429+
27430+unsigned long
27431+arch_get_unmapped_area(struct file *filp, unsigned long addr,
27432+ unsigned long len, unsigned long pgoff, unsigned long flags)
27433+{
27434+ struct mm_struct *mm = current->mm;
27435+ struct vm_area_struct *vma;
27436+ unsigned long pax_task_size = TASK_SIZE;
27437+ struct vm_unmapped_area_info info;
27438+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
27439+
27440+#ifdef CONFIG_PAX_SEGMEXEC
27441+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
27442+ pax_task_size = SEGMEXEC_TASK_SIZE;
27443+#endif
27444+
27445+ pax_task_size -= PAGE_SIZE;
27446+
27447+ if (len > pax_task_size)
27448+ return -ENOMEM;
27449+
27450+ if (flags & MAP_FIXED)
27451+ return addr;
27452+
27453+#ifdef CONFIG_PAX_RANDMMAP
27454+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
27455+#endif
27456+
27457+ if (addr) {
27458+ addr = PAGE_ALIGN(addr);
27459+ if (pax_task_size - len >= addr) {
27460+ vma = find_vma(mm, addr);
27461+ if (check_heap_stack_gap(vma, addr, len, offset))
27462+ return addr;
27463+ }
27464+ }
27465+
27466+ info.flags = 0;
27467+ info.length = len;
27468+ info.align_mask = filp ? get_align_mask() : 0;
27469+ info.align_offset = pgoff << PAGE_SHIFT;
27470+ info.threadstack_offset = offset;
27471+
27472+#ifdef CONFIG_PAX_PAGEEXEC
27473+ if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE)) {
27474+ info.low_limit = 0x00110000UL;
27475+ info.high_limit = mm->start_code;
27476+
27477+#ifdef CONFIG_PAX_RANDMMAP
27478+ if (mm->pax_flags & MF_PAX_RANDMMAP)
27479+ info.low_limit += mm->delta_mmap & 0x03FFF000UL;
27480+#endif
27481+
27482+ if (info.low_limit < info.high_limit) {
27483+ addr = vm_unmapped_area(&info);
27484+ if (!IS_ERR_VALUE(addr))
27485+ return addr;
27486+ }
27487+ } else
27488+#endif
27489+
27490+ info.low_limit = mm->mmap_base;
27491+ info.high_limit = pax_task_size;
27492+
27493+ return vm_unmapped_area(&info);
27494+}
27495+
27496+unsigned long
27497+arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
27498+ const unsigned long len, const unsigned long pgoff,
27499+ const unsigned long flags)
27500+{
27501+ struct vm_area_struct *vma;
27502+ struct mm_struct *mm = current->mm;
27503+ unsigned long addr = addr0, pax_task_size = TASK_SIZE;
27504+ struct vm_unmapped_area_info info;
27505+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
27506+
27507+#ifdef CONFIG_PAX_SEGMEXEC
27508+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
27509+ pax_task_size = SEGMEXEC_TASK_SIZE;
27510+#endif
27511+
27512+ pax_task_size -= PAGE_SIZE;
27513+
27514+ /* requested length too big for entire address space */
27515+ if (len > pax_task_size)
27516+ return -ENOMEM;
27517+
27518+ if (flags & MAP_FIXED)
27519+ return addr;
27520+
27521+#ifdef CONFIG_PAX_PAGEEXEC
27522+ if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE))
27523+ goto bottomup;
27524+#endif
27525+
27526+#ifdef CONFIG_PAX_RANDMMAP
27527+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
27528+#endif
27529+
27530+ /* requesting a specific address */
27531+ if (addr) {
27532+ addr = PAGE_ALIGN(addr);
27533+ if (pax_task_size - len >= addr) {
27534+ vma = find_vma(mm, addr);
27535+ if (check_heap_stack_gap(vma, addr, len, offset))
27536+ return addr;
27537+ }
27538+ }
27539+
27540+ info.flags = VM_UNMAPPED_AREA_TOPDOWN;
27541+ info.length = len;
27542+ info.low_limit = PAGE_SIZE;
27543+ info.high_limit = mm->mmap_base;
27544+ info.align_mask = filp ? get_align_mask() : 0;
27545+ info.align_offset = pgoff << PAGE_SHIFT;
27546+ info.threadstack_offset = offset;
27547+
27548+ addr = vm_unmapped_area(&info);
27549+ if (!(addr & ~PAGE_MASK))
27550+ return addr;
27551+ VM_BUG_ON(addr != -ENOMEM);
27552+
27553+bottomup:
27554+ /*
27555+ * A failed mmap() very likely causes application failure,
27556+ * so fall back to the bottom-up function here. This scenario
27557+ * can happen with large stack limits and large mmap()
27558+ * allocations.
27559+ */
27560+ return arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
27561+}
27562diff --git a/arch/x86/kernel/sys_x86_64.c b/arch/x86/kernel/sys_x86_64.c
27563index 30277e2..5664a29 100644
27564--- a/arch/x86/kernel/sys_x86_64.c
27565+++ b/arch/x86/kernel/sys_x86_64.c
27566@@ -81,8 +81,8 @@ out:
27567 return error;
27568 }
27569
27570-static void find_start_end(unsigned long flags, unsigned long *begin,
27571- unsigned long *end)
27572+static void find_start_end(struct mm_struct *mm, unsigned long flags,
27573+ unsigned long *begin, unsigned long *end)
27574 {
27575 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT)) {
27576 unsigned long new_begin;
27577@@ -101,7 +101,7 @@ static void find_start_end(unsigned long flags, unsigned long *begin,
27578 *begin = new_begin;
27579 }
27580 } else {
27581- *begin = current->mm->mmap_legacy_base;
27582+ *begin = mm->mmap_legacy_base;
27583 *end = TASK_SIZE;
27584 }
27585 }
27586@@ -114,20 +114,24 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
27587 struct vm_area_struct *vma;
27588 struct vm_unmapped_area_info info;
27589 unsigned long begin, end;
27590+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
27591
27592 if (flags & MAP_FIXED)
27593 return addr;
27594
27595- find_start_end(flags, &begin, &end);
27596+ find_start_end(mm, flags, &begin, &end);
27597
27598 if (len > end)
27599 return -ENOMEM;
27600
27601+#ifdef CONFIG_PAX_RANDMMAP
27602+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
27603+#endif
27604+
27605 if (addr) {
27606 addr = PAGE_ALIGN(addr);
27607 vma = find_vma(mm, addr);
27608- if (end - len >= addr &&
27609- (!vma || addr + len <= vma->vm_start))
27610+ if (end - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
27611 return addr;
27612 }
27613
27614@@ -137,6 +141,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
27615 info.high_limit = end;
27616 info.align_mask = filp ? get_align_mask() : 0;
27617 info.align_offset = pgoff << PAGE_SHIFT;
27618+ info.threadstack_offset = offset;
27619 return vm_unmapped_area(&info);
27620 }
27621
27622@@ -149,6 +154,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
27623 struct mm_struct *mm = current->mm;
27624 unsigned long addr = addr0;
27625 struct vm_unmapped_area_info info;
27626+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
27627
27628 /* requested length too big for entire address space */
27629 if (len > TASK_SIZE)
27630@@ -161,12 +167,15 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
27631 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT))
27632 goto bottomup;
27633
27634+#ifdef CONFIG_PAX_RANDMMAP
27635+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
27636+#endif
27637+
27638 /* requesting a specific address */
27639 if (addr) {
27640 addr = PAGE_ALIGN(addr);
27641 vma = find_vma(mm, addr);
27642- if (TASK_SIZE - len >= addr &&
27643- (!vma || addr + len <= vma->vm_start))
27644+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
27645 return addr;
27646 }
27647
27648@@ -176,6 +185,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
27649 info.high_limit = mm->mmap_base;
27650 info.align_mask = filp ? get_align_mask() : 0;
27651 info.align_offset = pgoff << PAGE_SHIFT;
27652+ info.threadstack_offset = offset;
27653 addr = vm_unmapped_area(&info);
27654 if (!(addr & ~PAGE_MASK))
27655 return addr;
27656diff --git a/arch/x86/kernel/tboot.c b/arch/x86/kernel/tboot.c
27657index 91a4496..bb87552 100644
27658--- a/arch/x86/kernel/tboot.c
27659+++ b/arch/x86/kernel/tboot.c
27660@@ -221,7 +221,7 @@ static int tboot_setup_sleep(void)
27661
27662 void tboot_shutdown(u32 shutdown_type)
27663 {
27664- void (*shutdown)(void);
27665+ void (* __noreturn shutdown)(void);
27666
27667 if (!tboot_enabled())
27668 return;
27669@@ -243,7 +243,7 @@ void tboot_shutdown(u32 shutdown_type)
27670
27671 switch_to_tboot_pt();
27672
27673- shutdown = (void(*)(void))(unsigned long)tboot->shutdown_entry;
27674+ shutdown = (void *)(unsigned long)tboot->shutdown_entry;
27675 shutdown();
27676
27677 /* should not reach here */
27678@@ -310,7 +310,7 @@ static int tboot_extended_sleep(u8 sleep_state, u32 val_a, u32 val_b)
27679 return -ENODEV;
27680 }
27681
27682-static atomic_t ap_wfs_count;
27683+static atomic_unchecked_t ap_wfs_count;
27684
27685 static int tboot_wait_for_aps(int num_aps)
27686 {
27687@@ -334,9 +334,9 @@ static int tboot_cpu_callback(struct notifier_block *nfb, unsigned long action,
27688 {
27689 switch (action) {
27690 case CPU_DYING:
27691- atomic_inc(&ap_wfs_count);
27692+ atomic_inc_unchecked(&ap_wfs_count);
27693 if (num_online_cpus() == 1)
27694- if (tboot_wait_for_aps(atomic_read(&ap_wfs_count)))
27695+ if (tboot_wait_for_aps(atomic_read_unchecked(&ap_wfs_count)))
27696 return NOTIFY_BAD;
27697 break;
27698 }
27699@@ -422,7 +422,7 @@ static __init int tboot_late_init(void)
27700
27701 tboot_create_trampoline();
27702
27703- atomic_set(&ap_wfs_count, 0);
27704+ atomic_set_unchecked(&ap_wfs_count, 0);
27705 register_hotcpu_notifier(&tboot_cpu_notifier);
27706
27707 #ifdef CONFIG_DEBUG_FS
27708diff --git a/arch/x86/kernel/time.c b/arch/x86/kernel/time.c
27709index 24d3c91..d06b473 100644
27710--- a/arch/x86/kernel/time.c
27711+++ b/arch/x86/kernel/time.c
27712@@ -30,9 +30,9 @@ unsigned long profile_pc(struct pt_regs *regs)
27713 {
27714 unsigned long pc = instruction_pointer(regs);
27715
27716- if (!user_mode_vm(regs) && in_lock_functions(pc)) {
27717+ if (!user_mode(regs) && in_lock_functions(pc)) {
27718 #ifdef CONFIG_FRAME_POINTER
27719- return *(unsigned long *)(regs->bp + sizeof(long));
27720+ return ktla_ktva(*(unsigned long *)(regs->bp + sizeof(long)));
27721 #else
27722 unsigned long *sp =
27723 (unsigned long *)kernel_stack_pointer(regs);
27724@@ -41,11 +41,17 @@ unsigned long profile_pc(struct pt_regs *regs)
27725 * or above a saved flags. Eflags has bits 22-31 zero,
27726 * kernel addresses don't.
27727 */
27728+
27729+#ifdef CONFIG_PAX_KERNEXEC
27730+ return ktla_ktva(sp[0]);
27731+#else
27732 if (sp[0] >> 22)
27733 return sp[0];
27734 if (sp[1] >> 22)
27735 return sp[1];
27736 #endif
27737+
27738+#endif
27739 }
27740 return pc;
27741 }
27742diff --git a/arch/x86/kernel/tls.c b/arch/x86/kernel/tls.c
27743index f7fec09..9991981 100644
27744--- a/arch/x86/kernel/tls.c
27745+++ b/arch/x86/kernel/tls.c
27746@@ -84,6 +84,11 @@ int do_set_thread_area(struct task_struct *p, int idx,
27747 if (idx < GDT_ENTRY_TLS_MIN || idx > GDT_ENTRY_TLS_MAX)
27748 return -EINVAL;
27749
27750+#ifdef CONFIG_PAX_SEGMEXEC
27751+ if ((p->mm->pax_flags & MF_PAX_SEGMEXEC) && (info.contents & MODIFY_LDT_CONTENTS_CODE))
27752+ return -EINVAL;
27753+#endif
27754+
27755 set_tls_desc(p, idx, &info, 1);
27756
27757 return 0;
27758@@ -200,7 +205,7 @@ int regset_tls_set(struct task_struct *target, const struct user_regset *regset,
27759
27760 if (kbuf)
27761 info = kbuf;
27762- else if (__copy_from_user(infobuf, ubuf, count))
27763+ else if (count > sizeof infobuf || __copy_from_user(infobuf, ubuf, count))
27764 return -EFAULT;
27765 else
27766 info = infobuf;
27767diff --git a/arch/x86/kernel/tracepoint.c b/arch/x86/kernel/tracepoint.c
27768index 1c113db..287b42e 100644
27769--- a/arch/x86/kernel/tracepoint.c
27770+++ b/arch/x86/kernel/tracepoint.c
27771@@ -9,11 +9,11 @@
27772 #include <linux/atomic.h>
27773
27774 atomic_t trace_idt_ctr = ATOMIC_INIT(0);
27775-struct desc_ptr trace_idt_descr = { NR_VECTORS * 16 - 1,
27776+const struct desc_ptr trace_idt_descr = { NR_VECTORS * 16 - 1,
27777 (unsigned long) trace_idt_table };
27778
27779 /* No need to be aligned, but done to keep all IDTs defined the same way. */
27780-gate_desc trace_idt_table[NR_VECTORS] __page_aligned_bss;
27781+gate_desc trace_idt_table[NR_VECTORS] __page_aligned_rodata;
27782
27783 static int trace_irq_vector_refcount;
27784 static DEFINE_MUTEX(irq_vector_mutex);
27785diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
27786index 57409f6..e2c17e1 100644
27787--- a/arch/x86/kernel/traps.c
27788+++ b/arch/x86/kernel/traps.c
27789@@ -66,7 +66,7 @@
27790 #include <asm/proto.h>
27791
27792 /* No need to be aligned, but done to keep all IDTs defined the same way. */
27793-gate_desc debug_idt_table[NR_VECTORS] __page_aligned_bss;
27794+gate_desc debug_idt_table[NR_VECTORS] __page_aligned_rodata;
27795 #else
27796 #include <asm/processor-flags.h>
27797 #include <asm/setup.h>
27798@@ -75,7 +75,7 @@ asmlinkage int system_call(void);
27799 #endif
27800
27801 /* Must be page-aligned because the real IDT is used in a fixmap. */
27802-gate_desc idt_table[NR_VECTORS] __page_aligned_bss;
27803+gate_desc idt_table[NR_VECTORS] __page_aligned_rodata;
27804
27805 DECLARE_BITMAP(used_vectors, NR_VECTORS);
27806 EXPORT_SYMBOL_GPL(used_vectors);
27807@@ -107,11 +107,11 @@ static inline void preempt_conditional_cli(struct pt_regs *regs)
27808 }
27809
27810 static int __kprobes
27811-do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
27812+do_trap_no_signal(struct task_struct *tsk, int trapnr, const char *str,
27813 struct pt_regs *regs, long error_code)
27814 {
27815 #ifdef CONFIG_X86_32
27816- if (regs->flags & X86_VM_MASK) {
27817+ if (v8086_mode(regs)) {
27818 /*
27819 * Traps 0, 1, 3, 4, and 5 should be forwarded to vm86.
27820 * On nmi (interrupt 2), do_trap should not be called.
27821@@ -124,12 +124,24 @@ do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
27822 return -1;
27823 }
27824 #endif
27825- if (!user_mode(regs)) {
27826+ if (!user_mode_novm(regs)) {
27827 if (!fixup_exception(regs)) {
27828 tsk->thread.error_code = error_code;
27829 tsk->thread.trap_nr = trapnr;
27830+
27831+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
27832+ if (trapnr == X86_TRAP_SS && ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS))
27833+ str = "PAX: suspicious stack segment fault";
27834+#endif
27835+
27836 die(str, regs, error_code);
27837 }
27838+
27839+#ifdef CONFIG_PAX_REFCOUNT
27840+ if (trapnr == X86_TRAP_OF)
27841+ pax_report_refcount_overflow(regs);
27842+#endif
27843+
27844 return 0;
27845 }
27846
27847@@ -137,7 +149,7 @@ do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
27848 }
27849
27850 static void __kprobes
27851-do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
27852+do_trap(int trapnr, int signr, const char *str, struct pt_regs *regs,
27853 long error_code, siginfo_t *info)
27854 {
27855 struct task_struct *tsk = current;
27856@@ -161,7 +173,7 @@ do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
27857 if (show_unhandled_signals && unhandled_signal(tsk, signr) &&
27858 printk_ratelimit()) {
27859 pr_info("%s[%d] trap %s ip:%lx sp:%lx error:%lx",
27860- tsk->comm, tsk->pid, str,
27861+ tsk->comm, task_pid_nr(tsk), str,
27862 regs->ip, regs->sp, error_code);
27863 print_vma_addr(" in ", regs->ip);
27864 pr_cont("\n");
27865@@ -273,7 +285,7 @@ do_general_protection(struct pt_regs *regs, long error_code)
27866 conditional_sti(regs);
27867
27868 #ifdef CONFIG_X86_32
27869- if (regs->flags & X86_VM_MASK) {
27870+ if (v8086_mode(regs)) {
27871 local_irq_enable();
27872 handle_vm86_fault((struct kernel_vm86_regs *) regs, error_code);
27873 goto exit;
27874@@ -281,18 +293,42 @@ do_general_protection(struct pt_regs *regs, long error_code)
27875 #endif
27876
27877 tsk = current;
27878- if (!user_mode(regs)) {
27879+ if (!user_mode_novm(regs)) {
27880 if (fixup_exception(regs))
27881 goto exit;
27882
27883 tsk->thread.error_code = error_code;
27884 tsk->thread.trap_nr = X86_TRAP_GP;
27885 if (notify_die(DIE_GPF, "general protection fault", regs, error_code,
27886- X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP)
27887+ X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP) {
27888+
27889+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
27890+ if ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS)
27891+ die("PAX: suspicious general protection fault", regs, error_code);
27892+ else
27893+#endif
27894+
27895 die("general protection fault", regs, error_code);
27896+ }
27897 goto exit;
27898 }
27899
27900+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
27901+ if (!(__supported_pte_mask & _PAGE_NX) && tsk->mm && (tsk->mm->pax_flags & MF_PAX_PAGEEXEC)) {
27902+ struct mm_struct *mm = tsk->mm;
27903+ unsigned long limit;
27904+
27905+ down_write(&mm->mmap_sem);
27906+ limit = mm->context.user_cs_limit;
27907+ if (limit < TASK_SIZE) {
27908+ track_exec_limit(mm, limit, TASK_SIZE, VM_EXEC);
27909+ up_write(&mm->mmap_sem);
27910+ return;
27911+ }
27912+ up_write(&mm->mmap_sem);
27913+ }
27914+#endif
27915+
27916 tsk->thread.error_code = error_code;
27917 tsk->thread.trap_nr = X86_TRAP_GP;
27918
27919@@ -453,7 +489,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
27920 /* It's safe to allow irq's after DR6 has been saved */
27921 preempt_conditional_sti(regs);
27922
27923- if (regs->flags & X86_VM_MASK) {
27924+ if (v8086_mode(regs)) {
27925 handle_vm86_trap((struct kernel_vm86_regs *) regs, error_code,
27926 X86_TRAP_DB);
27927 preempt_conditional_cli(regs);
27928@@ -468,7 +504,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
27929 * We already checked v86 mode above, so we can check for kernel mode
27930 * by just checking the CPL of CS.
27931 */
27932- if ((dr6 & DR_STEP) && !user_mode(regs)) {
27933+ if ((dr6 & DR_STEP) && !user_mode_novm(regs)) {
27934 tsk->thread.debugreg6 &= ~DR_STEP;
27935 set_tsk_thread_flag(tsk, TIF_SINGLESTEP);
27936 regs->flags &= ~X86_EFLAGS_TF;
27937@@ -500,7 +536,7 @@ void math_error(struct pt_regs *regs, int error_code, int trapnr)
27938 return;
27939 conditional_sti(regs);
27940
27941- if (!user_mode_vm(regs))
27942+ if (!user_mode(regs))
27943 {
27944 if (!fixup_exception(regs)) {
27945 task->thread.error_code = error_code;
27946diff --git a/arch/x86/kernel/tsc.c b/arch/x86/kernel/tsc.c
27947index cfbe99f..a6e8fa7 100644
27948--- a/arch/x86/kernel/tsc.c
27949+++ b/arch/x86/kernel/tsc.c
27950@@ -150,7 +150,7 @@ static void cyc2ns_write_end(int cpu, struct cyc2ns_data *data)
27951 */
27952 smp_wmb();
27953
27954- ACCESS_ONCE(c2n->head) = data;
27955+ ACCESS_ONCE_RW(c2n->head) = data;
27956 }
27957
27958 /*
27959diff --git a/arch/x86/kernel/uprobes.c b/arch/x86/kernel/uprobes.c
27960index 2ed8459..7cf329f 100644
27961--- a/arch/x86/kernel/uprobes.c
27962+++ b/arch/x86/kernel/uprobes.c
27963@@ -629,7 +629,7 @@ int arch_uprobe_exception_notify(struct notifier_block *self, unsigned long val,
27964 int ret = NOTIFY_DONE;
27965
27966 /* We are only interested in userspace traps */
27967- if (regs && !user_mode_vm(regs))
27968+ if (regs && !user_mode(regs))
27969 return NOTIFY_DONE;
27970
27971 switch (val) {
27972@@ -719,7 +719,7 @@ arch_uretprobe_hijack_return_addr(unsigned long trampoline_vaddr, struct pt_regs
27973
27974 if (ncopied != rasize) {
27975 pr_err("uprobe: return address clobbered: pid=%d, %%sp=%#lx, "
27976- "%%ip=%#lx\n", current->pid, regs->sp, regs->ip);
27977+ "%%ip=%#lx\n", task_pid_nr(current), regs->sp, regs->ip);
27978
27979 force_sig_info(SIGSEGV, SEND_SIG_FORCED, current);
27980 }
27981diff --git a/arch/x86/kernel/verify_cpu.S b/arch/x86/kernel/verify_cpu.S
27982index b9242ba..50c5edd 100644
27983--- a/arch/x86/kernel/verify_cpu.S
27984+++ b/arch/x86/kernel/verify_cpu.S
27985@@ -20,6 +20,7 @@
27986 * arch/x86/boot/compressed/head_64.S: Boot cpu verification
27987 * arch/x86/kernel/trampoline_64.S: secondary processor verification
27988 * arch/x86/kernel/head_32.S: processor startup
27989+ * arch/x86/kernel/acpi/realmode/wakeup.S: 32bit processor resume
27990 *
27991 * verify_cpu, returns the status of longmode and SSE in register %eax.
27992 * 0: Success 1: Failure
27993diff --git a/arch/x86/kernel/vm86_32.c b/arch/x86/kernel/vm86_32.c
27994index e8edcf5..27f9344 100644
27995--- a/arch/x86/kernel/vm86_32.c
27996+++ b/arch/x86/kernel/vm86_32.c
27997@@ -44,6 +44,7 @@
27998 #include <linux/ptrace.h>
27999 #include <linux/audit.h>
28000 #include <linux/stddef.h>
28001+#include <linux/grsecurity.h>
28002
28003 #include <asm/uaccess.h>
28004 #include <asm/io.h>
28005@@ -150,7 +151,7 @@ struct pt_regs *save_v86_state(struct kernel_vm86_regs *regs)
28006 do_exit(SIGSEGV);
28007 }
28008
28009- tss = &per_cpu(init_tss, get_cpu());
28010+ tss = init_tss + get_cpu();
28011 current->thread.sp0 = current->thread.saved_sp0;
28012 current->thread.sysenter_cs = __KERNEL_CS;
28013 load_sp0(tss, &current->thread);
28014@@ -214,6 +215,14 @@ SYSCALL_DEFINE1(vm86old, struct vm86_struct __user *, v86)
28015
28016 if (tsk->thread.saved_sp0)
28017 return -EPERM;
28018+
28019+#ifdef CONFIG_GRKERNSEC_VM86
28020+ if (!capable(CAP_SYS_RAWIO)) {
28021+ gr_handle_vm86();
28022+ return -EPERM;
28023+ }
28024+#endif
28025+
28026 tmp = copy_vm86_regs_from_user(&info.regs, &v86->regs,
28027 offsetof(struct kernel_vm86_struct, vm86plus) -
28028 sizeof(info.regs));
28029@@ -238,6 +247,13 @@ SYSCALL_DEFINE2(vm86, unsigned long, cmd, unsigned long, arg)
28030 int tmp;
28031 struct vm86plus_struct __user *v86;
28032
28033+#ifdef CONFIG_GRKERNSEC_VM86
28034+ if (!capable(CAP_SYS_RAWIO)) {
28035+ gr_handle_vm86();
28036+ return -EPERM;
28037+ }
28038+#endif
28039+
28040 tsk = current;
28041 switch (cmd) {
28042 case VM86_REQUEST_IRQ:
28043@@ -318,7 +334,7 @@ static void do_sys_vm86(struct kernel_vm86_struct *info, struct task_struct *tsk
28044 tsk->thread.saved_fs = info->regs32->fs;
28045 tsk->thread.saved_gs = get_user_gs(info->regs32);
28046
28047- tss = &per_cpu(init_tss, get_cpu());
28048+ tss = init_tss + get_cpu();
28049 tsk->thread.sp0 = (unsigned long) &info->VM86_TSS_ESP0;
28050 if (cpu_has_sep)
28051 tsk->thread.sysenter_cs = 0;
28052@@ -525,7 +541,7 @@ static void do_int(struct kernel_vm86_regs *regs, int i,
28053 goto cannot_handle;
28054 if (i == 0x21 && is_revectored(AH(regs), &KVM86->int21_revectored))
28055 goto cannot_handle;
28056- intr_ptr = (unsigned long __user *) (i << 2);
28057+ intr_ptr = (__force unsigned long __user *) (i << 2);
28058 if (get_user(segoffs, intr_ptr))
28059 goto cannot_handle;
28060 if ((segoffs >> 16) == BIOSSEG)
28061diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
28062index da6b35a..977e9cf 100644
28063--- a/arch/x86/kernel/vmlinux.lds.S
28064+++ b/arch/x86/kernel/vmlinux.lds.S
28065@@ -26,6 +26,13 @@
28066 #include <asm/page_types.h>
28067 #include <asm/cache.h>
28068 #include <asm/boot.h>
28069+#include <asm/segment.h>
28070+
28071+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
28072+#define __KERNEL_TEXT_OFFSET (LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR)
28073+#else
28074+#define __KERNEL_TEXT_OFFSET 0
28075+#endif
28076
28077 #undef i386 /* in case the preprocessor is a 32bit one */
28078
28079@@ -69,30 +76,43 @@ jiffies_64 = jiffies;
28080
28081 PHDRS {
28082 text PT_LOAD FLAGS(5); /* R_E */
28083+#ifdef CONFIG_X86_32
28084+ module PT_LOAD FLAGS(5); /* R_E */
28085+#endif
28086+#ifdef CONFIG_XEN
28087+ rodata PT_LOAD FLAGS(5); /* R_E */
28088+#else
28089+ rodata PT_LOAD FLAGS(4); /* R__ */
28090+#endif
28091 data PT_LOAD FLAGS(6); /* RW_ */
28092-#ifdef CONFIG_X86_64
28093+ init.begin PT_LOAD FLAGS(6); /* RW_ */
28094 #ifdef CONFIG_SMP
28095 percpu PT_LOAD FLAGS(6); /* RW_ */
28096 #endif
28097+ text.init PT_LOAD FLAGS(5); /* R_E */
28098+ text.exit PT_LOAD FLAGS(5); /* R_E */
28099 init PT_LOAD FLAGS(7); /* RWE */
28100-#endif
28101 note PT_NOTE FLAGS(0); /* ___ */
28102 }
28103
28104 SECTIONS
28105 {
28106 #ifdef CONFIG_X86_32
28107- . = LOAD_OFFSET + LOAD_PHYSICAL_ADDR;
28108- phys_startup_32 = startup_32 - LOAD_OFFSET;
28109+ . = LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR;
28110 #else
28111- . = __START_KERNEL;
28112- phys_startup_64 = startup_64 - LOAD_OFFSET;
28113+ . = __START_KERNEL;
28114 #endif
28115
28116 /* Text and read-only data */
28117- .text : AT(ADDR(.text) - LOAD_OFFSET) {
28118- _text = .;
28119+ .text (. - __KERNEL_TEXT_OFFSET): AT(ADDR(.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
28120 /* bootstrapping code */
28121+#ifdef CONFIG_X86_32
28122+ phys_startup_32 = startup_32 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
28123+#else
28124+ phys_startup_64 = startup_64 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
28125+#endif
28126+ __LOAD_PHYSICAL_ADDR = . - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
28127+ _text = .;
28128 HEAD_TEXT
28129 . = ALIGN(8);
28130 _stext = .;
28131@@ -104,13 +124,47 @@ SECTIONS
28132 IRQENTRY_TEXT
28133 *(.fixup)
28134 *(.gnu.warning)
28135- /* End of text section */
28136- _etext = .;
28137 } :text = 0x9090
28138
28139- NOTES :text :note
28140+ . += __KERNEL_TEXT_OFFSET;
28141
28142- EXCEPTION_TABLE(16) :text = 0x9090
28143+#ifdef CONFIG_X86_32
28144+ . = ALIGN(PAGE_SIZE);
28145+ .module.text : AT(ADDR(.module.text) - LOAD_OFFSET) {
28146+
28147+#ifdef CONFIG_PAX_KERNEXEC
28148+ MODULES_EXEC_VADDR = .;
28149+ BYTE(0)
28150+ . += (CONFIG_PAX_KERNEXEC_MODULE_TEXT * 1024 * 1024);
28151+ . = ALIGN(HPAGE_SIZE) - 1;
28152+ MODULES_EXEC_END = .;
28153+#endif
28154+
28155+ } :module
28156+#endif
28157+
28158+ .text.end : AT(ADDR(.text.end) - LOAD_OFFSET) {
28159+ /* End of text section */
28160+ BYTE(0)
28161+ _etext = . - __KERNEL_TEXT_OFFSET;
28162+ }
28163+
28164+#ifdef CONFIG_X86_32
28165+ . = ALIGN(PAGE_SIZE);
28166+ .rodata.page_aligned : AT(ADDR(.rodata.page_aligned) - LOAD_OFFSET) {
28167+ . = ALIGN(PAGE_SIZE);
28168+ *(.empty_zero_page)
28169+ *(.initial_pg_fixmap)
28170+ *(.initial_pg_pmd)
28171+ *(.initial_page_table)
28172+ *(.swapper_pg_dir)
28173+ } :rodata
28174+#endif
28175+
28176+ . = ALIGN(PAGE_SIZE);
28177+ NOTES :rodata :note
28178+
28179+ EXCEPTION_TABLE(16) :rodata
28180
28181 #if defined(CONFIG_DEBUG_RODATA)
28182 /* .text should occupy whole number of pages */
28183@@ -122,16 +176,20 @@ SECTIONS
28184
28185 /* Data */
28186 .data : AT(ADDR(.data) - LOAD_OFFSET) {
28187+
28188+#ifdef CONFIG_PAX_KERNEXEC
28189+ . = ALIGN(HPAGE_SIZE);
28190+#else
28191+ . = ALIGN(PAGE_SIZE);
28192+#endif
28193+
28194 /* Start of data section */
28195 _sdata = .;
28196
28197 /* init_task */
28198 INIT_TASK_DATA(THREAD_SIZE)
28199
28200-#ifdef CONFIG_X86_32
28201- /* 32 bit has nosave before _edata */
28202 NOSAVE_DATA
28203-#endif
28204
28205 PAGE_ALIGNED_DATA(PAGE_SIZE)
28206
28207@@ -172,12 +230,19 @@ SECTIONS
28208 #endif /* CONFIG_X86_64 */
28209
28210 /* Init code and data - will be freed after init */
28211- . = ALIGN(PAGE_SIZE);
28212 .init.begin : AT(ADDR(.init.begin) - LOAD_OFFSET) {
28213+ BYTE(0)
28214+
28215+#ifdef CONFIG_PAX_KERNEXEC
28216+ . = ALIGN(HPAGE_SIZE);
28217+#else
28218+ . = ALIGN(PAGE_SIZE);
28219+#endif
28220+
28221 __init_begin = .; /* paired with __init_end */
28222- }
28223+ } :init.begin
28224
28225-#if defined(CONFIG_X86_64) && defined(CONFIG_SMP)
28226+#ifdef CONFIG_SMP
28227 /*
28228 * percpu offsets are zero-based on SMP. PERCPU_VADDR() changes the
28229 * output PHDR, so the next output section - .init.text - should
28230@@ -186,12 +251,27 @@ SECTIONS
28231 PERCPU_VADDR(INTERNODE_CACHE_BYTES, 0, :percpu)
28232 #endif
28233
28234- INIT_TEXT_SECTION(PAGE_SIZE)
28235-#ifdef CONFIG_X86_64
28236- :init
28237-#endif
28238+ . = ALIGN(PAGE_SIZE);
28239+ init_begin = .;
28240+ .init.text (. - __KERNEL_TEXT_OFFSET): AT(init_begin - LOAD_OFFSET) {
28241+ VMLINUX_SYMBOL(_sinittext) = .;
28242+ INIT_TEXT
28243+ VMLINUX_SYMBOL(_einittext) = .;
28244+ . = ALIGN(PAGE_SIZE);
28245+ } :text.init
28246
28247- INIT_DATA_SECTION(16)
28248+ /*
28249+ * .exit.text is discard at runtime, not link time, to deal with
28250+ * references from .altinstructions and .eh_frame
28251+ */
28252+ .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
28253+ EXIT_TEXT
28254+ . = ALIGN(16);
28255+ } :text.exit
28256+ . = init_begin + SIZEOF(.init.text) + SIZEOF(.exit.text);
28257+
28258+ . = ALIGN(PAGE_SIZE);
28259+ INIT_DATA_SECTION(16) :init
28260
28261 .x86_cpu_dev.init : AT(ADDR(.x86_cpu_dev.init) - LOAD_OFFSET) {
28262 __x86_cpu_dev_start = .;
28263@@ -262,19 +342,12 @@ SECTIONS
28264 }
28265
28266 . = ALIGN(8);
28267- /*
28268- * .exit.text is discard at runtime, not link time, to deal with
28269- * references from .altinstructions and .eh_frame
28270- */
28271- .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET) {
28272- EXIT_TEXT
28273- }
28274
28275 .exit.data : AT(ADDR(.exit.data) - LOAD_OFFSET) {
28276 EXIT_DATA
28277 }
28278
28279-#if !defined(CONFIG_X86_64) || !defined(CONFIG_SMP)
28280+#ifndef CONFIG_SMP
28281 PERCPU_SECTION(INTERNODE_CACHE_BYTES)
28282 #endif
28283
28284@@ -293,16 +366,10 @@ SECTIONS
28285 .smp_locks : AT(ADDR(.smp_locks) - LOAD_OFFSET) {
28286 __smp_locks = .;
28287 *(.smp_locks)
28288- . = ALIGN(PAGE_SIZE);
28289 __smp_locks_end = .;
28290+ . = ALIGN(PAGE_SIZE);
28291 }
28292
28293-#ifdef CONFIG_X86_64
28294- .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) {
28295- NOSAVE_DATA
28296- }
28297-#endif
28298-
28299 /* BSS */
28300 . = ALIGN(PAGE_SIZE);
28301 .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
28302@@ -318,6 +385,7 @@ SECTIONS
28303 __brk_base = .;
28304 . += 64 * 1024; /* 64k alignment slop space */
28305 *(.brk_reservation) /* areas brk users have reserved */
28306+ . = ALIGN(HPAGE_SIZE);
28307 __brk_limit = .;
28308 }
28309
28310@@ -344,13 +412,12 @@ SECTIONS
28311 * for the boot processor.
28312 */
28313 #define INIT_PER_CPU(x) init_per_cpu__##x = x + __per_cpu_load
28314-INIT_PER_CPU(gdt_page);
28315 INIT_PER_CPU(irq_stack_union);
28316
28317 /*
28318 * Build-time check on the image size:
28319 */
28320-. = ASSERT((_end - _text <= KERNEL_IMAGE_SIZE),
28321+. = ASSERT((_end - _text - __KERNEL_TEXT_OFFSET <= KERNEL_IMAGE_SIZE),
28322 "kernel image bigger than KERNEL_IMAGE_SIZE");
28323
28324 #ifdef CONFIG_SMP
28325diff --git a/arch/x86/kernel/vsyscall_64.c b/arch/x86/kernel/vsyscall_64.c
28326index 1f96f93..6f29be7 100644
28327--- a/arch/x86/kernel/vsyscall_64.c
28328+++ b/arch/x86/kernel/vsyscall_64.c
28329@@ -56,15 +56,13 @@
28330 DEFINE_VVAR(int, vgetcpu_mode);
28331 DEFINE_VVAR(struct vsyscall_gtod_data, vsyscall_gtod_data);
28332
28333-static enum { EMULATE, NATIVE, NONE } vsyscall_mode = EMULATE;
28334+static enum { EMULATE, NONE } vsyscall_mode = EMULATE;
28335
28336 static int __init vsyscall_setup(char *str)
28337 {
28338 if (str) {
28339 if (!strcmp("emulate", str))
28340 vsyscall_mode = EMULATE;
28341- else if (!strcmp("native", str))
28342- vsyscall_mode = NATIVE;
28343 else if (!strcmp("none", str))
28344 vsyscall_mode = NONE;
28345 else
28346@@ -101,7 +99,7 @@ void update_vsyscall(struct timekeeper *tk)
28347 vdata->monotonic_time_sec = tk->xtime_sec
28348 + tk->wall_to_monotonic.tv_sec;
28349 vdata->monotonic_time_snsec = tk->xtime_nsec
28350- + (tk->wall_to_monotonic.tv_nsec
28351+ + ((u64)tk->wall_to_monotonic.tv_nsec
28352 << tk->shift);
28353 while (vdata->monotonic_time_snsec >=
28354 (((u64)NSEC_PER_SEC) << tk->shift)) {
28355@@ -323,8 +321,7 @@ do_ret:
28356 return true;
28357
28358 sigsegv:
28359- force_sig(SIGSEGV, current);
28360- return true;
28361+ do_group_exit(SIGKILL);
28362 }
28363
28364 /*
28365@@ -377,10 +374,7 @@ void __init map_vsyscall(void)
28366 extern char __vvar_page;
28367 unsigned long physaddr_vvar_page = __pa_symbol(&__vvar_page);
28368
28369- __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall,
28370- vsyscall_mode == NATIVE
28371- ? PAGE_KERNEL_VSYSCALL
28372- : PAGE_KERNEL_VVAR);
28373+ __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall, PAGE_KERNEL_VVAR);
28374 BUILD_BUG_ON((unsigned long)__fix_to_virt(VSYSCALL_FIRST_PAGE) !=
28375 (unsigned long)VSYSCALL_START);
28376
28377diff --git a/arch/x86/kernel/x8664_ksyms_64.c b/arch/x86/kernel/x8664_ksyms_64.c
28378index 04068192..4d75aa6 100644
28379--- a/arch/x86/kernel/x8664_ksyms_64.c
28380+++ b/arch/x86/kernel/x8664_ksyms_64.c
28381@@ -34,8 +34,6 @@ EXPORT_SYMBOL(copy_user_generic_string);
28382 EXPORT_SYMBOL(copy_user_generic_unrolled);
28383 EXPORT_SYMBOL(copy_user_enhanced_fast_string);
28384 EXPORT_SYMBOL(__copy_user_nocache);
28385-EXPORT_SYMBOL(_copy_from_user);
28386-EXPORT_SYMBOL(_copy_to_user);
28387
28388 EXPORT_SYMBOL(copy_page);
28389 EXPORT_SYMBOL(clear_page);
28390@@ -73,3 +71,7 @@ EXPORT_SYMBOL(___preempt_schedule);
28391 EXPORT_SYMBOL(___preempt_schedule_context);
28392 #endif
28393 #endif
28394+
28395+#ifdef CONFIG_PAX_PER_CPU_PGD
28396+EXPORT_SYMBOL(cpu_pgd);
28397+#endif
28398diff --git a/arch/x86/kernel/x86_init.c b/arch/x86/kernel/x86_init.c
28399index e48b674..a451dd9 100644
28400--- a/arch/x86/kernel/x86_init.c
28401+++ b/arch/x86/kernel/x86_init.c
28402@@ -93,7 +93,7 @@ struct x86_cpuinit_ops x86_cpuinit = {
28403 static void default_nmi_init(void) { };
28404 static int default_i8042_detect(void) { return 1; };
28405
28406-struct x86_platform_ops x86_platform = {
28407+struct x86_platform_ops x86_platform __read_only = {
28408 .calibrate_tsc = native_calibrate_tsc,
28409 .get_wallclock = mach_get_cmos_time,
28410 .set_wallclock = mach_set_rtc_mmss,
28411@@ -109,7 +109,7 @@ struct x86_platform_ops x86_platform = {
28412 EXPORT_SYMBOL_GPL(x86_platform);
28413
28414 #if defined(CONFIG_PCI_MSI)
28415-struct x86_msi_ops x86_msi = {
28416+struct x86_msi_ops x86_msi __read_only = {
28417 .setup_msi_irqs = native_setup_msi_irqs,
28418 .compose_msi_msg = native_compose_msi_msg,
28419 .teardown_msi_irq = native_teardown_msi_irq,
28420@@ -150,7 +150,7 @@ u32 arch_msix_mask_irq(struct msi_desc *desc, u32 flag)
28421 }
28422 #endif
28423
28424-struct x86_io_apic_ops x86_io_apic_ops = {
28425+struct x86_io_apic_ops x86_io_apic_ops __read_only = {
28426 .init = native_io_apic_init_mappings,
28427 .read = native_io_apic_read,
28428 .write = native_io_apic_write,
28429diff --git a/arch/x86/kernel/xsave.c b/arch/x86/kernel/xsave.c
28430index a4b451c..8dfe1ad 100644
28431--- a/arch/x86/kernel/xsave.c
28432+++ b/arch/x86/kernel/xsave.c
28433@@ -164,18 +164,18 @@ static inline int save_xstate_epilog(void __user *buf, int ia32_frame)
28434
28435 /* Setup the bytes not touched by the [f]xsave and reserved for SW. */
28436 sw_bytes = ia32_frame ? &fx_sw_reserved_ia32 : &fx_sw_reserved;
28437- err = __copy_to_user(&x->i387.sw_reserved, sw_bytes, sizeof(*sw_bytes));
28438+ err = __copy_to_user(x->i387.sw_reserved, sw_bytes, sizeof(*sw_bytes));
28439
28440 if (!use_xsave())
28441 return err;
28442
28443- err |= __put_user(FP_XSTATE_MAGIC2, (__u32 *)(buf + xstate_size));
28444+ err |= __put_user(FP_XSTATE_MAGIC2, (__u32 __user *)(buf + xstate_size));
28445
28446 /*
28447 * Read the xstate_bv which we copied (directly from the cpu or
28448 * from the state in task struct) to the user buffers.
28449 */
28450- err |= __get_user(xstate_bv, (__u32 *)&x->xsave_hdr.xstate_bv);
28451+ err |= __get_user(xstate_bv, (__u32 __user *)&x->xsave_hdr.xstate_bv);
28452
28453 /*
28454 * For legacy compatible, we always set FP/SSE bits in the bit
28455@@ -190,7 +190,7 @@ static inline int save_xstate_epilog(void __user *buf, int ia32_frame)
28456 */
28457 xstate_bv |= XSTATE_FPSSE;
28458
28459- err |= __put_user(xstate_bv, (__u32 *)&x->xsave_hdr.xstate_bv);
28460+ err |= __put_user(xstate_bv, (__u32 __user *)&x->xsave_hdr.xstate_bv);
28461
28462 return err;
28463 }
28464@@ -199,6 +199,7 @@ static inline int save_user_xstate(struct xsave_struct __user *buf)
28465 {
28466 int err;
28467
28468+ buf = (struct xsave_struct __user *)____m(buf);
28469 if (use_xsave())
28470 err = xsave_user(buf);
28471 else if (use_fxsr())
28472@@ -311,6 +312,7 @@ sanitize_restored_xstate(struct task_struct *tsk,
28473 */
28474 static inline int restore_user_xstate(void __user *buf, u64 xbv, int fx_only)
28475 {
28476+ buf = (void __user *)____m(buf);
28477 if (use_xsave()) {
28478 if ((unsigned long)buf % 64 || fx_only) {
28479 u64 init_bv = pcntxt_mask & ~XSTATE_FPSSE;
28480diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
28481index c697625..a032162 100644
28482--- a/arch/x86/kvm/cpuid.c
28483+++ b/arch/x86/kvm/cpuid.c
28484@@ -156,15 +156,20 @@ int kvm_vcpu_ioctl_set_cpuid2(struct kvm_vcpu *vcpu,
28485 struct kvm_cpuid2 *cpuid,
28486 struct kvm_cpuid_entry2 __user *entries)
28487 {
28488- int r;
28489+ int r, i;
28490
28491 r = -E2BIG;
28492 if (cpuid->nent > KVM_MAX_CPUID_ENTRIES)
28493 goto out;
28494 r = -EFAULT;
28495- if (copy_from_user(&vcpu->arch.cpuid_entries, entries,
28496- cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
28497+ if (!access_ok(VERIFY_READ, entries, cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
28498 goto out;
28499+ for (i = 0; i < cpuid->nent; ++i) {
28500+ struct kvm_cpuid_entry2 cpuid_entry;
28501+ if (__copy_from_user(&cpuid_entry, entries + i, sizeof(cpuid_entry)))
28502+ goto out;
28503+ vcpu->arch.cpuid_entries[i] = cpuid_entry;
28504+ }
28505 vcpu->arch.cpuid_nent = cpuid->nent;
28506 kvm_apic_set_version(vcpu);
28507 kvm_x86_ops->cpuid_update(vcpu);
28508@@ -179,15 +184,19 @@ int kvm_vcpu_ioctl_get_cpuid2(struct kvm_vcpu *vcpu,
28509 struct kvm_cpuid2 *cpuid,
28510 struct kvm_cpuid_entry2 __user *entries)
28511 {
28512- int r;
28513+ int r, i;
28514
28515 r = -E2BIG;
28516 if (cpuid->nent < vcpu->arch.cpuid_nent)
28517 goto out;
28518 r = -EFAULT;
28519- if (copy_to_user(entries, &vcpu->arch.cpuid_entries,
28520- vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
28521+ if (!access_ok(VERIFY_WRITE, entries, vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
28522 goto out;
28523+ for (i = 0; i < vcpu->arch.cpuid_nent; ++i) {
28524+ struct kvm_cpuid_entry2 cpuid_entry = vcpu->arch.cpuid_entries[i];
28525+ if (__copy_to_user(entries + i, &cpuid_entry, sizeof(cpuid_entry)))
28526+ goto out;
28527+ }
28528 return 0;
28529
28530 out:
28531diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
28532index 9736529..ab4f54c 100644
28533--- a/arch/x86/kvm/lapic.c
28534+++ b/arch/x86/kvm/lapic.c
28535@@ -55,7 +55,7 @@
28536 #define APIC_BUS_CYCLE_NS 1
28537
28538 /* #define apic_debug(fmt,arg...) printk(KERN_WARNING fmt,##arg) */
28539-#define apic_debug(fmt, arg...)
28540+#define apic_debug(fmt, arg...) do {} while (0)
28541
28542 #define APIC_LVT_NUM 6
28543 /* 14 is the version for Xeon and Pentium 8.4.8*/
28544diff --git a/arch/x86/kvm/paging_tmpl.h b/arch/x86/kvm/paging_tmpl.h
28545index cba218a..1cc1bed 100644
28546--- a/arch/x86/kvm/paging_tmpl.h
28547+++ b/arch/x86/kvm/paging_tmpl.h
28548@@ -331,7 +331,7 @@ retry_walk:
28549 if (unlikely(kvm_is_error_hva(host_addr)))
28550 goto error;
28551
28552- ptep_user = (pt_element_t __user *)((void *)host_addr + offset);
28553+ ptep_user = (pt_element_t __force_user *)((void *)host_addr + offset);
28554 if (unlikely(__copy_from_user(&pte, ptep_user, sizeof(pte))))
28555 goto error;
28556 walker->ptep_user[walker->level - 1] = ptep_user;
28557diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
28558index 2de1bc0..22251ee 100644
28559--- a/arch/x86/kvm/svm.c
28560+++ b/arch/x86/kvm/svm.c
28561@@ -3508,7 +3508,11 @@ static void reload_tss(struct kvm_vcpu *vcpu)
28562 int cpu = raw_smp_processor_id();
28563
28564 struct svm_cpu_data *sd = per_cpu(svm_data, cpu);
28565+
28566+ pax_open_kernel();
28567 sd->tss_desc->type = 9; /* available 32/64-bit TSS */
28568+ pax_close_kernel();
28569+
28570 load_TR_desc();
28571 }
28572
28573@@ -3911,6 +3915,10 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu)
28574 #endif
28575 #endif
28576
28577+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
28578+ __set_fs(current_thread_info()->addr_limit);
28579+#endif
28580+
28581 reload_tss(vcpu);
28582
28583 local_irq_disable();
28584diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
28585index 3927528..fc19971 100644
28586--- a/arch/x86/kvm/vmx.c
28587+++ b/arch/x86/kvm/vmx.c
28588@@ -1320,12 +1320,12 @@ static void vmcs_write64(unsigned long field, u64 value)
28589 #endif
28590 }
28591
28592-static void vmcs_clear_bits(unsigned long field, u32 mask)
28593+static void vmcs_clear_bits(unsigned long field, unsigned long mask)
28594 {
28595 vmcs_writel(field, vmcs_readl(field) & ~mask);
28596 }
28597
28598-static void vmcs_set_bits(unsigned long field, u32 mask)
28599+static void vmcs_set_bits(unsigned long field, unsigned long mask)
28600 {
28601 vmcs_writel(field, vmcs_readl(field) | mask);
28602 }
28603@@ -1585,7 +1585,11 @@ static void reload_tss(void)
28604 struct desc_struct *descs;
28605
28606 descs = (void *)gdt->address;
28607+
28608+ pax_open_kernel();
28609 descs[GDT_ENTRY_TSS].type = 9; /* available TSS */
28610+ pax_close_kernel();
28611+
28612 load_TR_desc();
28613 }
28614
28615@@ -1809,6 +1813,10 @@ static void vmx_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
28616 vmcs_writel(HOST_TR_BASE, kvm_read_tr_base()); /* 22.2.4 */
28617 vmcs_writel(HOST_GDTR_BASE, gdt->address); /* 22.2.4 */
28618
28619+#ifdef CONFIG_PAX_PER_CPU_PGD
28620+ vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
28621+#endif
28622+
28623 rdmsrl(MSR_IA32_SYSENTER_ESP, sysenter_esp);
28624 vmcs_writel(HOST_IA32_SYSENTER_ESP, sysenter_esp); /* 22.2.3 */
28625 vmx->loaded_vmcs->cpu = cpu;
28626@@ -2098,7 +2106,7 @@ static void setup_msrs(struct vcpu_vmx *vmx)
28627 * reads and returns guest's timestamp counter "register"
28628 * guest_tsc = host_tsc + tsc_offset -- 21.3
28629 */
28630-static u64 guest_read_tsc(void)
28631+static u64 __intentional_overflow(-1) guest_read_tsc(void)
28632 {
28633 u64 host_tsc, tsc_offset;
28634
28635@@ -3024,8 +3032,11 @@ static __init int hardware_setup(void)
28636 if (!cpu_has_vmx_flexpriority())
28637 flexpriority_enabled = 0;
28638
28639- if (!cpu_has_vmx_tpr_shadow())
28640- kvm_x86_ops->update_cr8_intercept = NULL;
28641+ if (!cpu_has_vmx_tpr_shadow()) {
28642+ pax_open_kernel();
28643+ *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
28644+ pax_close_kernel();
28645+ }
28646
28647 if (enable_ept && !cpu_has_vmx_ept_2m_page())
28648 kvm_disable_largepages();
28649@@ -3036,13 +3047,15 @@ static __init int hardware_setup(void)
28650 if (!cpu_has_vmx_apicv())
28651 enable_apicv = 0;
28652
28653+ pax_open_kernel();
28654 if (enable_apicv)
28655- kvm_x86_ops->update_cr8_intercept = NULL;
28656+ *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
28657 else {
28658- kvm_x86_ops->hwapic_irr_update = NULL;
28659- kvm_x86_ops->deliver_posted_interrupt = NULL;
28660- kvm_x86_ops->sync_pir_to_irr = vmx_sync_pir_to_irr_dummy;
28661+ *(void **)&kvm_x86_ops->hwapic_irr_update = NULL;
28662+ *(void **)&kvm_x86_ops->deliver_posted_interrupt = NULL;
28663+ *(void **)&kvm_x86_ops->sync_pir_to_irr = vmx_sync_pir_to_irr_dummy;
28664 }
28665+ pax_close_kernel();
28666
28667 if (nested)
28668 nested_vmx_setup_ctls_msrs();
28669@@ -4165,7 +4178,10 @@ static void vmx_set_constant_host_state(struct vcpu_vmx *vmx)
28670
28671 vmcs_writel(HOST_CR0, read_cr0() & ~X86_CR0_TS); /* 22.2.3 */
28672 vmcs_writel(HOST_CR4, read_cr4()); /* 22.2.3, 22.2.5 */
28673+
28674+#ifndef CONFIG_PAX_PER_CPU_PGD
28675 vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
28676+#endif
28677
28678 vmcs_write16(HOST_CS_SELECTOR, __KERNEL_CS); /* 22.2.4 */
28679 #ifdef CONFIG_X86_64
28680@@ -4187,7 +4203,7 @@ static void vmx_set_constant_host_state(struct vcpu_vmx *vmx)
28681 vmcs_writel(HOST_IDTR_BASE, dt.address); /* 22.2.4 */
28682 vmx->host_idt_base = dt.address;
28683
28684- vmcs_writel(HOST_RIP, vmx_return); /* 22.2.5 */
28685+ vmcs_writel(HOST_RIP, ktla_ktva(vmx_return)); /* 22.2.5 */
28686
28687 rdmsr(MSR_IA32_SYSENTER_CS, low32, high32);
28688 vmcs_write32(HOST_IA32_SYSENTER_CS, low32);
28689@@ -7265,6 +7281,12 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
28690 "jmp 2f \n\t"
28691 "1: " __ex(ASM_VMX_VMRESUME) "\n\t"
28692 "2: "
28693+
28694+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
28695+ "ljmp %[cs],$3f\n\t"
28696+ "3: "
28697+#endif
28698+
28699 /* Save guest registers, load host registers, keep flags */
28700 "mov %0, %c[wordsize](%%" _ASM_SP ") \n\t"
28701 "pop %0 \n\t"
28702@@ -7317,6 +7339,11 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
28703 #endif
28704 [cr2]"i"(offsetof(struct vcpu_vmx, vcpu.arch.cr2)),
28705 [wordsize]"i"(sizeof(ulong))
28706+
28707+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
28708+ ,[cs]"i"(__KERNEL_CS)
28709+#endif
28710+
28711 : "cc", "memory"
28712 #ifdef CONFIG_X86_64
28713 , "rax", "rbx", "rdi", "rsi"
28714@@ -7330,7 +7357,7 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
28715 if (debugctlmsr)
28716 update_debugctlmsr(debugctlmsr);
28717
28718-#ifndef CONFIG_X86_64
28719+#ifdef CONFIG_X86_32
28720 /*
28721 * The sysexit path does not restore ds/es, so we must set them to
28722 * a reasonable value ourselves.
28723@@ -7339,8 +7366,18 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
28724 * may be executed in interrupt context, which saves and restore segments
28725 * around it, nullifying its effect.
28726 */
28727- loadsegment(ds, __USER_DS);
28728- loadsegment(es, __USER_DS);
28729+ loadsegment(ds, __KERNEL_DS);
28730+ loadsegment(es, __KERNEL_DS);
28731+ loadsegment(ss, __KERNEL_DS);
28732+
28733+#ifdef CONFIG_PAX_KERNEXEC
28734+ loadsegment(fs, __KERNEL_PERCPU);
28735+#endif
28736+
28737+#ifdef CONFIG_PAX_MEMORY_UDEREF
28738+ __set_fs(current_thread_info()->addr_limit);
28739+#endif
28740+
28741 #endif
28742
28743 vcpu->arch.regs_avail = ~((1 << VCPU_REGS_RIP) | (1 << VCPU_REGS_RSP)
28744diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
28745index 2b85784..ad70e19 100644
28746--- a/arch/x86/kvm/x86.c
28747+++ b/arch/x86/kvm/x86.c
28748@@ -1777,8 +1777,8 @@ static int xen_hvm_config(struct kvm_vcpu *vcpu, u64 data)
28749 {
28750 struct kvm *kvm = vcpu->kvm;
28751 int lm = is_long_mode(vcpu);
28752- u8 *blob_addr = lm ? (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_64
28753- : (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
28754+ u8 __user *blob_addr = lm ? (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_64
28755+ : (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
28756 u8 blob_size = lm ? kvm->arch.xen_hvm_config.blob_size_64
28757 : kvm->arch.xen_hvm_config.blob_size_32;
28758 u32 page_num = data & ~PAGE_MASK;
28759@@ -2689,6 +2689,8 @@ long kvm_arch_dev_ioctl(struct file *filp,
28760 if (n < msr_list.nmsrs)
28761 goto out;
28762 r = -EFAULT;
28763+ if (num_msrs_to_save > ARRAY_SIZE(msrs_to_save))
28764+ goto out;
28765 if (copy_to_user(user_msr_list->indices, &msrs_to_save,
28766 num_msrs_to_save * sizeof(u32)))
28767 goto out;
28768@@ -5503,7 +5505,7 @@ static struct notifier_block pvclock_gtod_notifier = {
28769 };
28770 #endif
28771
28772-int kvm_arch_init(void *opaque)
28773+int kvm_arch_init(const void *opaque)
28774 {
28775 int r;
28776 struct kvm_x86_ops *ops = opaque;
28777diff --git a/arch/x86/lguest/boot.c b/arch/x86/lguest/boot.c
28778index ad1fb5f..fe30b66 100644
28779--- a/arch/x86/lguest/boot.c
28780+++ b/arch/x86/lguest/boot.c
28781@@ -1206,9 +1206,10 @@ static __init int early_put_chars(u32 vtermno, const char *buf, int count)
28782 * Rebooting also tells the Host we're finished, but the RESTART flag tells the
28783 * Launcher to reboot us.
28784 */
28785-static void lguest_restart(char *reason)
28786+static __noreturn void lguest_restart(char *reason)
28787 {
28788 hcall(LHCALL_SHUTDOWN, __pa(reason), LGUEST_SHUTDOWN_RESTART, 0, 0);
28789+ BUG();
28790 }
28791
28792 /*G:050
28793diff --git a/arch/x86/lib/atomic64_386_32.S b/arch/x86/lib/atomic64_386_32.S
28794index 00933d5..3a64af9 100644
28795--- a/arch/x86/lib/atomic64_386_32.S
28796+++ b/arch/x86/lib/atomic64_386_32.S
28797@@ -48,6 +48,10 @@ BEGIN(read)
28798 movl (v), %eax
28799 movl 4(v), %edx
28800 RET_ENDP
28801+BEGIN(read_unchecked)
28802+ movl (v), %eax
28803+ movl 4(v), %edx
28804+RET_ENDP
28805 #undef v
28806
28807 #define v %esi
28808@@ -55,6 +59,10 @@ BEGIN(set)
28809 movl %ebx, (v)
28810 movl %ecx, 4(v)
28811 RET_ENDP
28812+BEGIN(set_unchecked)
28813+ movl %ebx, (v)
28814+ movl %ecx, 4(v)
28815+RET_ENDP
28816 #undef v
28817
28818 #define v %esi
28819@@ -70,6 +78,20 @@ RET_ENDP
28820 BEGIN(add)
28821 addl %eax, (v)
28822 adcl %edx, 4(v)
28823+
28824+#ifdef CONFIG_PAX_REFCOUNT
28825+ jno 0f
28826+ subl %eax, (v)
28827+ sbbl %edx, 4(v)
28828+ int $4
28829+0:
28830+ _ASM_EXTABLE(0b, 0b)
28831+#endif
28832+
28833+RET_ENDP
28834+BEGIN(add_unchecked)
28835+ addl %eax, (v)
28836+ adcl %edx, 4(v)
28837 RET_ENDP
28838 #undef v
28839
28840@@ -77,6 +99,24 @@ RET_ENDP
28841 BEGIN(add_return)
28842 addl (v), %eax
28843 adcl 4(v), %edx
28844+
28845+#ifdef CONFIG_PAX_REFCOUNT
28846+ into
28847+1234:
28848+ _ASM_EXTABLE(1234b, 2f)
28849+#endif
28850+
28851+ movl %eax, (v)
28852+ movl %edx, 4(v)
28853+
28854+#ifdef CONFIG_PAX_REFCOUNT
28855+2:
28856+#endif
28857+
28858+RET_ENDP
28859+BEGIN(add_return_unchecked)
28860+ addl (v), %eax
28861+ adcl 4(v), %edx
28862 movl %eax, (v)
28863 movl %edx, 4(v)
28864 RET_ENDP
28865@@ -86,6 +126,20 @@ RET_ENDP
28866 BEGIN(sub)
28867 subl %eax, (v)
28868 sbbl %edx, 4(v)
28869+
28870+#ifdef CONFIG_PAX_REFCOUNT
28871+ jno 0f
28872+ addl %eax, (v)
28873+ adcl %edx, 4(v)
28874+ int $4
28875+0:
28876+ _ASM_EXTABLE(0b, 0b)
28877+#endif
28878+
28879+RET_ENDP
28880+BEGIN(sub_unchecked)
28881+ subl %eax, (v)
28882+ sbbl %edx, 4(v)
28883 RET_ENDP
28884 #undef v
28885
28886@@ -96,6 +150,27 @@ BEGIN(sub_return)
28887 sbbl $0, %edx
28888 addl (v), %eax
28889 adcl 4(v), %edx
28890+
28891+#ifdef CONFIG_PAX_REFCOUNT
28892+ into
28893+1234:
28894+ _ASM_EXTABLE(1234b, 2f)
28895+#endif
28896+
28897+ movl %eax, (v)
28898+ movl %edx, 4(v)
28899+
28900+#ifdef CONFIG_PAX_REFCOUNT
28901+2:
28902+#endif
28903+
28904+RET_ENDP
28905+BEGIN(sub_return_unchecked)
28906+ negl %edx
28907+ negl %eax
28908+ sbbl $0, %edx
28909+ addl (v), %eax
28910+ adcl 4(v), %edx
28911 movl %eax, (v)
28912 movl %edx, 4(v)
28913 RET_ENDP
28914@@ -105,6 +180,20 @@ RET_ENDP
28915 BEGIN(inc)
28916 addl $1, (v)
28917 adcl $0, 4(v)
28918+
28919+#ifdef CONFIG_PAX_REFCOUNT
28920+ jno 0f
28921+ subl $1, (v)
28922+ sbbl $0, 4(v)
28923+ int $4
28924+0:
28925+ _ASM_EXTABLE(0b, 0b)
28926+#endif
28927+
28928+RET_ENDP
28929+BEGIN(inc_unchecked)
28930+ addl $1, (v)
28931+ adcl $0, 4(v)
28932 RET_ENDP
28933 #undef v
28934
28935@@ -114,6 +203,26 @@ BEGIN(inc_return)
28936 movl 4(v), %edx
28937 addl $1, %eax
28938 adcl $0, %edx
28939+
28940+#ifdef CONFIG_PAX_REFCOUNT
28941+ into
28942+1234:
28943+ _ASM_EXTABLE(1234b, 2f)
28944+#endif
28945+
28946+ movl %eax, (v)
28947+ movl %edx, 4(v)
28948+
28949+#ifdef CONFIG_PAX_REFCOUNT
28950+2:
28951+#endif
28952+
28953+RET_ENDP
28954+BEGIN(inc_return_unchecked)
28955+ movl (v), %eax
28956+ movl 4(v), %edx
28957+ addl $1, %eax
28958+ adcl $0, %edx
28959 movl %eax, (v)
28960 movl %edx, 4(v)
28961 RET_ENDP
28962@@ -123,6 +232,20 @@ RET_ENDP
28963 BEGIN(dec)
28964 subl $1, (v)
28965 sbbl $0, 4(v)
28966+
28967+#ifdef CONFIG_PAX_REFCOUNT
28968+ jno 0f
28969+ addl $1, (v)
28970+ adcl $0, 4(v)
28971+ int $4
28972+0:
28973+ _ASM_EXTABLE(0b, 0b)
28974+#endif
28975+
28976+RET_ENDP
28977+BEGIN(dec_unchecked)
28978+ subl $1, (v)
28979+ sbbl $0, 4(v)
28980 RET_ENDP
28981 #undef v
28982
28983@@ -132,6 +255,26 @@ BEGIN(dec_return)
28984 movl 4(v), %edx
28985 subl $1, %eax
28986 sbbl $0, %edx
28987+
28988+#ifdef CONFIG_PAX_REFCOUNT
28989+ into
28990+1234:
28991+ _ASM_EXTABLE(1234b, 2f)
28992+#endif
28993+
28994+ movl %eax, (v)
28995+ movl %edx, 4(v)
28996+
28997+#ifdef CONFIG_PAX_REFCOUNT
28998+2:
28999+#endif
29000+
29001+RET_ENDP
29002+BEGIN(dec_return_unchecked)
29003+ movl (v), %eax
29004+ movl 4(v), %edx
29005+ subl $1, %eax
29006+ sbbl $0, %edx
29007 movl %eax, (v)
29008 movl %edx, 4(v)
29009 RET_ENDP
29010@@ -143,6 +286,13 @@ BEGIN(add_unless)
29011 adcl %edx, %edi
29012 addl (v), %eax
29013 adcl 4(v), %edx
29014+
29015+#ifdef CONFIG_PAX_REFCOUNT
29016+ into
29017+1234:
29018+ _ASM_EXTABLE(1234b, 2f)
29019+#endif
29020+
29021 cmpl %eax, %ecx
29022 je 3f
29023 1:
29024@@ -168,6 +318,13 @@ BEGIN(inc_not_zero)
29025 1:
29026 addl $1, %eax
29027 adcl $0, %edx
29028+
29029+#ifdef CONFIG_PAX_REFCOUNT
29030+ into
29031+1234:
29032+ _ASM_EXTABLE(1234b, 2f)
29033+#endif
29034+
29035 movl %eax, (v)
29036 movl %edx, 4(v)
29037 movl $1, %eax
29038@@ -186,6 +343,13 @@ BEGIN(dec_if_positive)
29039 movl 4(v), %edx
29040 subl $1, %eax
29041 sbbl $0, %edx
29042+
29043+#ifdef CONFIG_PAX_REFCOUNT
29044+ into
29045+1234:
29046+ _ASM_EXTABLE(1234b, 1f)
29047+#endif
29048+
29049 js 1f
29050 movl %eax, (v)
29051 movl %edx, 4(v)
29052diff --git a/arch/x86/lib/atomic64_cx8_32.S b/arch/x86/lib/atomic64_cx8_32.S
29053index f5cc9eb..51fa319 100644
29054--- a/arch/x86/lib/atomic64_cx8_32.S
29055+++ b/arch/x86/lib/atomic64_cx8_32.S
29056@@ -35,10 +35,20 @@ ENTRY(atomic64_read_cx8)
29057 CFI_STARTPROC
29058
29059 read64 %ecx
29060+ pax_force_retaddr
29061 ret
29062 CFI_ENDPROC
29063 ENDPROC(atomic64_read_cx8)
29064
29065+ENTRY(atomic64_read_unchecked_cx8)
29066+ CFI_STARTPROC
29067+
29068+ read64 %ecx
29069+ pax_force_retaddr
29070+ ret
29071+ CFI_ENDPROC
29072+ENDPROC(atomic64_read_unchecked_cx8)
29073+
29074 ENTRY(atomic64_set_cx8)
29075 CFI_STARTPROC
29076
29077@@ -48,10 +58,25 @@ ENTRY(atomic64_set_cx8)
29078 cmpxchg8b (%esi)
29079 jne 1b
29080
29081+ pax_force_retaddr
29082 ret
29083 CFI_ENDPROC
29084 ENDPROC(atomic64_set_cx8)
29085
29086+ENTRY(atomic64_set_unchecked_cx8)
29087+ CFI_STARTPROC
29088+
29089+1:
29090+/* we don't need LOCK_PREFIX since aligned 64-bit writes
29091+ * are atomic on 586 and newer */
29092+ cmpxchg8b (%esi)
29093+ jne 1b
29094+
29095+ pax_force_retaddr
29096+ ret
29097+ CFI_ENDPROC
29098+ENDPROC(atomic64_set_unchecked_cx8)
29099+
29100 ENTRY(atomic64_xchg_cx8)
29101 CFI_STARTPROC
29102
29103@@ -60,12 +85,13 @@ ENTRY(atomic64_xchg_cx8)
29104 cmpxchg8b (%esi)
29105 jne 1b
29106
29107+ pax_force_retaddr
29108 ret
29109 CFI_ENDPROC
29110 ENDPROC(atomic64_xchg_cx8)
29111
29112-.macro addsub_return func ins insc
29113-ENTRY(atomic64_\func\()_return_cx8)
29114+.macro addsub_return func ins insc unchecked=""
29115+ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
29116 CFI_STARTPROC
29117 SAVE ebp
29118 SAVE ebx
29119@@ -82,27 +108,44 @@ ENTRY(atomic64_\func\()_return_cx8)
29120 movl %edx, %ecx
29121 \ins\()l %esi, %ebx
29122 \insc\()l %edi, %ecx
29123+
29124+.ifb \unchecked
29125+#ifdef CONFIG_PAX_REFCOUNT
29126+ into
29127+2:
29128+ _ASM_EXTABLE(2b, 3f)
29129+#endif
29130+.endif
29131+
29132 LOCK_PREFIX
29133 cmpxchg8b (%ebp)
29134 jne 1b
29135-
29136-10:
29137 movl %ebx, %eax
29138 movl %ecx, %edx
29139+
29140+.ifb \unchecked
29141+#ifdef CONFIG_PAX_REFCOUNT
29142+3:
29143+#endif
29144+.endif
29145+
29146 RESTORE edi
29147 RESTORE esi
29148 RESTORE ebx
29149 RESTORE ebp
29150+ pax_force_retaddr
29151 ret
29152 CFI_ENDPROC
29153-ENDPROC(atomic64_\func\()_return_cx8)
29154+ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
29155 .endm
29156
29157 addsub_return add add adc
29158 addsub_return sub sub sbb
29159+addsub_return add add adc _unchecked
29160+addsub_return sub sub sbb _unchecked
29161
29162-.macro incdec_return func ins insc
29163-ENTRY(atomic64_\func\()_return_cx8)
29164+.macro incdec_return func ins insc unchecked=""
29165+ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
29166 CFI_STARTPROC
29167 SAVE ebx
29168
29169@@ -112,21 +155,39 @@ ENTRY(atomic64_\func\()_return_cx8)
29170 movl %edx, %ecx
29171 \ins\()l $1, %ebx
29172 \insc\()l $0, %ecx
29173+
29174+.ifb \unchecked
29175+#ifdef CONFIG_PAX_REFCOUNT
29176+ into
29177+2:
29178+ _ASM_EXTABLE(2b, 3f)
29179+#endif
29180+.endif
29181+
29182 LOCK_PREFIX
29183 cmpxchg8b (%esi)
29184 jne 1b
29185
29186-10:
29187 movl %ebx, %eax
29188 movl %ecx, %edx
29189+
29190+.ifb \unchecked
29191+#ifdef CONFIG_PAX_REFCOUNT
29192+3:
29193+#endif
29194+.endif
29195+
29196 RESTORE ebx
29197+ pax_force_retaddr
29198 ret
29199 CFI_ENDPROC
29200-ENDPROC(atomic64_\func\()_return_cx8)
29201+ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
29202 .endm
29203
29204 incdec_return inc add adc
29205 incdec_return dec sub sbb
29206+incdec_return inc add adc _unchecked
29207+incdec_return dec sub sbb _unchecked
29208
29209 ENTRY(atomic64_dec_if_positive_cx8)
29210 CFI_STARTPROC
29211@@ -138,6 +199,13 @@ ENTRY(atomic64_dec_if_positive_cx8)
29212 movl %edx, %ecx
29213 subl $1, %ebx
29214 sbb $0, %ecx
29215+
29216+#ifdef CONFIG_PAX_REFCOUNT
29217+ into
29218+1234:
29219+ _ASM_EXTABLE(1234b, 2f)
29220+#endif
29221+
29222 js 2f
29223 LOCK_PREFIX
29224 cmpxchg8b (%esi)
29225@@ -147,6 +215,7 @@ ENTRY(atomic64_dec_if_positive_cx8)
29226 movl %ebx, %eax
29227 movl %ecx, %edx
29228 RESTORE ebx
29229+ pax_force_retaddr
29230 ret
29231 CFI_ENDPROC
29232 ENDPROC(atomic64_dec_if_positive_cx8)
29233@@ -171,6 +240,13 @@ ENTRY(atomic64_add_unless_cx8)
29234 movl %edx, %ecx
29235 addl %ebp, %ebx
29236 adcl %edi, %ecx
29237+
29238+#ifdef CONFIG_PAX_REFCOUNT
29239+ into
29240+1234:
29241+ _ASM_EXTABLE(1234b, 3f)
29242+#endif
29243+
29244 LOCK_PREFIX
29245 cmpxchg8b (%esi)
29246 jne 1b
29247@@ -181,6 +257,7 @@ ENTRY(atomic64_add_unless_cx8)
29248 CFI_ADJUST_CFA_OFFSET -8
29249 RESTORE ebx
29250 RESTORE ebp
29251+ pax_force_retaddr
29252 ret
29253 4:
29254 cmpl %edx, 4(%esp)
29255@@ -203,6 +280,13 @@ ENTRY(atomic64_inc_not_zero_cx8)
29256 xorl %ecx, %ecx
29257 addl $1, %ebx
29258 adcl %edx, %ecx
29259+
29260+#ifdef CONFIG_PAX_REFCOUNT
29261+ into
29262+1234:
29263+ _ASM_EXTABLE(1234b, 3f)
29264+#endif
29265+
29266 LOCK_PREFIX
29267 cmpxchg8b (%esi)
29268 jne 1b
29269@@ -210,6 +294,7 @@ ENTRY(atomic64_inc_not_zero_cx8)
29270 movl $1, %eax
29271 3:
29272 RESTORE ebx
29273+ pax_force_retaddr
29274 ret
29275 CFI_ENDPROC
29276 ENDPROC(atomic64_inc_not_zero_cx8)
29277diff --git a/arch/x86/lib/checksum_32.S b/arch/x86/lib/checksum_32.S
29278index e78b8ee..7e173a8 100644
29279--- a/arch/x86/lib/checksum_32.S
29280+++ b/arch/x86/lib/checksum_32.S
29281@@ -29,7 +29,8 @@
29282 #include <asm/dwarf2.h>
29283 #include <asm/errno.h>
29284 #include <asm/asm.h>
29285-
29286+#include <asm/segment.h>
29287+
29288 /*
29289 * computes a partial checksum, e.g. for TCP/UDP fragments
29290 */
29291@@ -293,9 +294,24 @@ unsigned int csum_partial_copy_generic (const char *src, char *dst,
29292
29293 #define ARGBASE 16
29294 #define FP 12
29295-
29296-ENTRY(csum_partial_copy_generic)
29297+
29298+ENTRY(csum_partial_copy_generic_to_user)
29299 CFI_STARTPROC
29300+
29301+#ifdef CONFIG_PAX_MEMORY_UDEREF
29302+ pushl_cfi %gs
29303+ popl_cfi %es
29304+ jmp csum_partial_copy_generic
29305+#endif
29306+
29307+ENTRY(csum_partial_copy_generic_from_user)
29308+
29309+#ifdef CONFIG_PAX_MEMORY_UDEREF
29310+ pushl_cfi %gs
29311+ popl_cfi %ds
29312+#endif
29313+
29314+ENTRY(csum_partial_copy_generic)
29315 subl $4,%esp
29316 CFI_ADJUST_CFA_OFFSET 4
29317 pushl_cfi %edi
29318@@ -317,7 +333,7 @@ ENTRY(csum_partial_copy_generic)
29319 jmp 4f
29320 SRC(1: movw (%esi), %bx )
29321 addl $2, %esi
29322-DST( movw %bx, (%edi) )
29323+DST( movw %bx, %es:(%edi) )
29324 addl $2, %edi
29325 addw %bx, %ax
29326 adcl $0, %eax
29327@@ -329,30 +345,30 @@ DST( movw %bx, (%edi) )
29328 SRC(1: movl (%esi), %ebx )
29329 SRC( movl 4(%esi), %edx )
29330 adcl %ebx, %eax
29331-DST( movl %ebx, (%edi) )
29332+DST( movl %ebx, %es:(%edi) )
29333 adcl %edx, %eax
29334-DST( movl %edx, 4(%edi) )
29335+DST( movl %edx, %es:4(%edi) )
29336
29337 SRC( movl 8(%esi), %ebx )
29338 SRC( movl 12(%esi), %edx )
29339 adcl %ebx, %eax
29340-DST( movl %ebx, 8(%edi) )
29341+DST( movl %ebx, %es:8(%edi) )
29342 adcl %edx, %eax
29343-DST( movl %edx, 12(%edi) )
29344+DST( movl %edx, %es:12(%edi) )
29345
29346 SRC( movl 16(%esi), %ebx )
29347 SRC( movl 20(%esi), %edx )
29348 adcl %ebx, %eax
29349-DST( movl %ebx, 16(%edi) )
29350+DST( movl %ebx, %es:16(%edi) )
29351 adcl %edx, %eax
29352-DST( movl %edx, 20(%edi) )
29353+DST( movl %edx, %es:20(%edi) )
29354
29355 SRC( movl 24(%esi), %ebx )
29356 SRC( movl 28(%esi), %edx )
29357 adcl %ebx, %eax
29358-DST( movl %ebx, 24(%edi) )
29359+DST( movl %ebx, %es:24(%edi) )
29360 adcl %edx, %eax
29361-DST( movl %edx, 28(%edi) )
29362+DST( movl %edx, %es:28(%edi) )
29363
29364 lea 32(%esi), %esi
29365 lea 32(%edi), %edi
29366@@ -366,7 +382,7 @@ DST( movl %edx, 28(%edi) )
29367 shrl $2, %edx # This clears CF
29368 SRC(3: movl (%esi), %ebx )
29369 adcl %ebx, %eax
29370-DST( movl %ebx, (%edi) )
29371+DST( movl %ebx, %es:(%edi) )
29372 lea 4(%esi), %esi
29373 lea 4(%edi), %edi
29374 dec %edx
29375@@ -378,12 +394,12 @@ DST( movl %ebx, (%edi) )
29376 jb 5f
29377 SRC( movw (%esi), %cx )
29378 leal 2(%esi), %esi
29379-DST( movw %cx, (%edi) )
29380+DST( movw %cx, %es:(%edi) )
29381 leal 2(%edi), %edi
29382 je 6f
29383 shll $16,%ecx
29384 SRC(5: movb (%esi), %cl )
29385-DST( movb %cl, (%edi) )
29386+DST( movb %cl, %es:(%edi) )
29387 6: addl %ecx, %eax
29388 adcl $0, %eax
29389 7:
29390@@ -394,7 +410,7 @@ DST( movb %cl, (%edi) )
29391
29392 6001:
29393 movl ARGBASE+20(%esp), %ebx # src_err_ptr
29394- movl $-EFAULT, (%ebx)
29395+ movl $-EFAULT, %ss:(%ebx)
29396
29397 # zero the complete destination - computing the rest
29398 # is too much work
29399@@ -407,11 +423,15 @@ DST( movb %cl, (%edi) )
29400
29401 6002:
29402 movl ARGBASE+24(%esp), %ebx # dst_err_ptr
29403- movl $-EFAULT,(%ebx)
29404+ movl $-EFAULT,%ss:(%ebx)
29405 jmp 5000b
29406
29407 .previous
29408
29409+ pushl_cfi %ss
29410+ popl_cfi %ds
29411+ pushl_cfi %ss
29412+ popl_cfi %es
29413 popl_cfi %ebx
29414 CFI_RESTORE ebx
29415 popl_cfi %esi
29416@@ -421,26 +441,43 @@ DST( movb %cl, (%edi) )
29417 popl_cfi %ecx # equivalent to addl $4,%esp
29418 ret
29419 CFI_ENDPROC
29420-ENDPROC(csum_partial_copy_generic)
29421+ENDPROC(csum_partial_copy_generic_to_user)
29422
29423 #else
29424
29425 /* Version for PentiumII/PPro */
29426
29427 #define ROUND1(x) \
29428+ nop; nop; nop; \
29429 SRC(movl x(%esi), %ebx ) ; \
29430 addl %ebx, %eax ; \
29431- DST(movl %ebx, x(%edi) ) ;
29432+ DST(movl %ebx, %es:x(%edi)) ;
29433
29434 #define ROUND(x) \
29435+ nop; nop; nop; \
29436 SRC(movl x(%esi), %ebx ) ; \
29437 adcl %ebx, %eax ; \
29438- DST(movl %ebx, x(%edi) ) ;
29439+ DST(movl %ebx, %es:x(%edi)) ;
29440
29441 #define ARGBASE 12
29442-
29443-ENTRY(csum_partial_copy_generic)
29444+
29445+ENTRY(csum_partial_copy_generic_to_user)
29446 CFI_STARTPROC
29447+
29448+#ifdef CONFIG_PAX_MEMORY_UDEREF
29449+ pushl_cfi %gs
29450+ popl_cfi %es
29451+ jmp csum_partial_copy_generic
29452+#endif
29453+
29454+ENTRY(csum_partial_copy_generic_from_user)
29455+
29456+#ifdef CONFIG_PAX_MEMORY_UDEREF
29457+ pushl_cfi %gs
29458+ popl_cfi %ds
29459+#endif
29460+
29461+ENTRY(csum_partial_copy_generic)
29462 pushl_cfi %ebx
29463 CFI_REL_OFFSET ebx, 0
29464 pushl_cfi %edi
29465@@ -461,7 +498,7 @@ ENTRY(csum_partial_copy_generic)
29466 subl %ebx, %edi
29467 lea -1(%esi),%edx
29468 andl $-32,%edx
29469- lea 3f(%ebx,%ebx), %ebx
29470+ lea 3f(%ebx,%ebx,2), %ebx
29471 testl %esi, %esi
29472 jmp *%ebx
29473 1: addl $64,%esi
29474@@ -482,19 +519,19 @@ ENTRY(csum_partial_copy_generic)
29475 jb 5f
29476 SRC( movw (%esi), %dx )
29477 leal 2(%esi), %esi
29478-DST( movw %dx, (%edi) )
29479+DST( movw %dx, %es:(%edi) )
29480 leal 2(%edi), %edi
29481 je 6f
29482 shll $16,%edx
29483 5:
29484 SRC( movb (%esi), %dl )
29485-DST( movb %dl, (%edi) )
29486+DST( movb %dl, %es:(%edi) )
29487 6: addl %edx, %eax
29488 adcl $0, %eax
29489 7:
29490 .section .fixup, "ax"
29491 6001: movl ARGBASE+20(%esp), %ebx # src_err_ptr
29492- movl $-EFAULT, (%ebx)
29493+ movl $-EFAULT, %ss:(%ebx)
29494 # zero the complete destination (computing the rest is too much work)
29495 movl ARGBASE+8(%esp),%edi # dst
29496 movl ARGBASE+12(%esp),%ecx # len
29497@@ -502,10 +539,17 @@ DST( movb %dl, (%edi) )
29498 rep; stosb
29499 jmp 7b
29500 6002: movl ARGBASE+24(%esp), %ebx # dst_err_ptr
29501- movl $-EFAULT, (%ebx)
29502+ movl $-EFAULT, %ss:(%ebx)
29503 jmp 7b
29504 .previous
29505
29506+#ifdef CONFIG_PAX_MEMORY_UDEREF
29507+ pushl_cfi %ss
29508+ popl_cfi %ds
29509+ pushl_cfi %ss
29510+ popl_cfi %es
29511+#endif
29512+
29513 popl_cfi %esi
29514 CFI_RESTORE esi
29515 popl_cfi %edi
29516@@ -514,7 +558,7 @@ DST( movb %dl, (%edi) )
29517 CFI_RESTORE ebx
29518 ret
29519 CFI_ENDPROC
29520-ENDPROC(csum_partial_copy_generic)
29521+ENDPROC(csum_partial_copy_generic_to_user)
29522
29523 #undef ROUND
29524 #undef ROUND1
29525diff --git a/arch/x86/lib/clear_page_64.S b/arch/x86/lib/clear_page_64.S
29526index f2145cf..cea889d 100644
29527--- a/arch/x86/lib/clear_page_64.S
29528+++ b/arch/x86/lib/clear_page_64.S
29529@@ -11,6 +11,7 @@ ENTRY(clear_page_c)
29530 movl $4096/8,%ecx
29531 xorl %eax,%eax
29532 rep stosq
29533+ pax_force_retaddr
29534 ret
29535 CFI_ENDPROC
29536 ENDPROC(clear_page_c)
29537@@ -20,6 +21,7 @@ ENTRY(clear_page_c_e)
29538 movl $4096,%ecx
29539 xorl %eax,%eax
29540 rep stosb
29541+ pax_force_retaddr
29542 ret
29543 CFI_ENDPROC
29544 ENDPROC(clear_page_c_e)
29545@@ -43,6 +45,7 @@ ENTRY(clear_page)
29546 leaq 64(%rdi),%rdi
29547 jnz .Lloop
29548 nop
29549+ pax_force_retaddr
29550 ret
29551 CFI_ENDPROC
29552 .Lclear_page_end:
29553@@ -58,7 +61,7 @@ ENDPROC(clear_page)
29554
29555 #include <asm/cpufeature.h>
29556
29557- .section .altinstr_replacement,"ax"
29558+ .section .altinstr_replacement,"a"
29559 1: .byte 0xeb /* jmp <disp8> */
29560 .byte (clear_page_c - clear_page) - (2f - 1b) /* offset */
29561 2: .byte 0xeb /* jmp <disp8> */
29562diff --git a/arch/x86/lib/cmpxchg16b_emu.S b/arch/x86/lib/cmpxchg16b_emu.S
29563index 1e572c5..2a162cd 100644
29564--- a/arch/x86/lib/cmpxchg16b_emu.S
29565+++ b/arch/x86/lib/cmpxchg16b_emu.S
29566@@ -53,11 +53,13 @@ this_cpu_cmpxchg16b_emu:
29567
29568 popf
29569 mov $1, %al
29570+ pax_force_retaddr
29571 ret
29572
29573 not_same:
29574 popf
29575 xor %al,%al
29576+ pax_force_retaddr
29577 ret
29578
29579 CFI_ENDPROC
29580diff --git a/arch/x86/lib/copy_page_64.S b/arch/x86/lib/copy_page_64.S
29581index 176cca6..e0d658e 100644
29582--- a/arch/x86/lib/copy_page_64.S
29583+++ b/arch/x86/lib/copy_page_64.S
29584@@ -9,6 +9,7 @@ copy_page_rep:
29585 CFI_STARTPROC
29586 movl $4096/8, %ecx
29587 rep movsq
29588+ pax_force_retaddr
29589 ret
29590 CFI_ENDPROC
29591 ENDPROC(copy_page_rep)
29592@@ -24,8 +25,8 @@ ENTRY(copy_page)
29593 CFI_ADJUST_CFA_OFFSET 2*8
29594 movq %rbx, (%rsp)
29595 CFI_REL_OFFSET rbx, 0
29596- movq %r12, 1*8(%rsp)
29597- CFI_REL_OFFSET r12, 1*8
29598+ movq %r13, 1*8(%rsp)
29599+ CFI_REL_OFFSET r13, 1*8
29600
29601 movl $(4096/64)-5, %ecx
29602 .p2align 4
29603@@ -38,7 +39,7 @@ ENTRY(copy_page)
29604 movq 0x8*4(%rsi), %r9
29605 movq 0x8*5(%rsi), %r10
29606 movq 0x8*6(%rsi), %r11
29607- movq 0x8*7(%rsi), %r12
29608+ movq 0x8*7(%rsi), %r13
29609
29610 prefetcht0 5*64(%rsi)
29611
29612@@ -49,7 +50,7 @@ ENTRY(copy_page)
29613 movq %r9, 0x8*4(%rdi)
29614 movq %r10, 0x8*5(%rdi)
29615 movq %r11, 0x8*6(%rdi)
29616- movq %r12, 0x8*7(%rdi)
29617+ movq %r13, 0x8*7(%rdi)
29618
29619 leaq 64 (%rsi), %rsi
29620 leaq 64 (%rdi), %rdi
29621@@ -68,7 +69,7 @@ ENTRY(copy_page)
29622 movq 0x8*4(%rsi), %r9
29623 movq 0x8*5(%rsi), %r10
29624 movq 0x8*6(%rsi), %r11
29625- movq 0x8*7(%rsi), %r12
29626+ movq 0x8*7(%rsi), %r13
29627
29628 movq %rax, 0x8*0(%rdi)
29629 movq %rbx, 0x8*1(%rdi)
29630@@ -77,7 +78,7 @@ ENTRY(copy_page)
29631 movq %r9, 0x8*4(%rdi)
29632 movq %r10, 0x8*5(%rdi)
29633 movq %r11, 0x8*6(%rdi)
29634- movq %r12, 0x8*7(%rdi)
29635+ movq %r13, 0x8*7(%rdi)
29636
29637 leaq 64(%rdi), %rdi
29638 leaq 64(%rsi), %rsi
29639@@ -85,10 +86,11 @@ ENTRY(copy_page)
29640
29641 movq (%rsp), %rbx
29642 CFI_RESTORE rbx
29643- movq 1*8(%rsp), %r12
29644- CFI_RESTORE r12
29645+ movq 1*8(%rsp), %r13
29646+ CFI_RESTORE r13
29647 addq $2*8, %rsp
29648 CFI_ADJUST_CFA_OFFSET -2*8
29649+ pax_force_retaddr
29650 ret
29651 .Lcopy_page_end:
29652 CFI_ENDPROC
29653@@ -99,7 +101,7 @@ ENDPROC(copy_page)
29654
29655 #include <asm/cpufeature.h>
29656
29657- .section .altinstr_replacement,"ax"
29658+ .section .altinstr_replacement,"a"
29659 1: .byte 0xeb /* jmp <disp8> */
29660 .byte (copy_page_rep - copy_page) - (2f - 1b) /* offset */
29661 2:
29662diff --git a/arch/x86/lib/copy_user_64.S b/arch/x86/lib/copy_user_64.S
29663index dee945d..a84067b 100644
29664--- a/arch/x86/lib/copy_user_64.S
29665+++ b/arch/x86/lib/copy_user_64.S
29666@@ -18,31 +18,7 @@
29667 #include <asm/alternative-asm.h>
29668 #include <asm/asm.h>
29669 #include <asm/smap.h>
29670-
29671-/*
29672- * By placing feature2 after feature1 in altinstructions section, we logically
29673- * implement:
29674- * If CPU has feature2, jmp to alt2 is used
29675- * else if CPU has feature1, jmp to alt1 is used
29676- * else jmp to orig is used.
29677- */
29678- .macro ALTERNATIVE_JUMP feature1,feature2,orig,alt1,alt2
29679-0:
29680- .byte 0xe9 /* 32bit jump */
29681- .long \orig-1f /* by default jump to orig */
29682-1:
29683- .section .altinstr_replacement,"ax"
29684-2: .byte 0xe9 /* near jump with 32bit immediate */
29685- .long \alt1-1b /* offset */ /* or alternatively to alt1 */
29686-3: .byte 0xe9 /* near jump with 32bit immediate */
29687- .long \alt2-1b /* offset */ /* or alternatively to alt2 */
29688- .previous
29689-
29690- .section .altinstructions,"a"
29691- altinstruction_entry 0b,2b,\feature1,5,5
29692- altinstruction_entry 0b,3b,\feature2,5,5
29693- .previous
29694- .endm
29695+#include <asm/pgtable.h>
29696
29697 .macro ALIGN_DESTINATION
29698 #ifdef FIX_ALIGNMENT
29699@@ -70,52 +46,6 @@
29700 #endif
29701 .endm
29702
29703-/* Standard copy_to_user with segment limit checking */
29704-ENTRY(_copy_to_user)
29705- CFI_STARTPROC
29706- GET_THREAD_INFO(%rax)
29707- movq %rdi,%rcx
29708- addq %rdx,%rcx
29709- jc bad_to_user
29710- cmpq TI_addr_limit(%rax),%rcx
29711- ja bad_to_user
29712- ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
29713- copy_user_generic_unrolled,copy_user_generic_string, \
29714- copy_user_enhanced_fast_string
29715- CFI_ENDPROC
29716-ENDPROC(_copy_to_user)
29717-
29718-/* Standard copy_from_user with segment limit checking */
29719-ENTRY(_copy_from_user)
29720- CFI_STARTPROC
29721- GET_THREAD_INFO(%rax)
29722- movq %rsi,%rcx
29723- addq %rdx,%rcx
29724- jc bad_from_user
29725- cmpq TI_addr_limit(%rax),%rcx
29726- ja bad_from_user
29727- ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
29728- copy_user_generic_unrolled,copy_user_generic_string, \
29729- copy_user_enhanced_fast_string
29730- CFI_ENDPROC
29731-ENDPROC(_copy_from_user)
29732-
29733- .section .fixup,"ax"
29734- /* must zero dest */
29735-ENTRY(bad_from_user)
29736-bad_from_user:
29737- CFI_STARTPROC
29738- movl %edx,%ecx
29739- xorl %eax,%eax
29740- rep
29741- stosb
29742-bad_to_user:
29743- movl %edx,%eax
29744- ret
29745- CFI_ENDPROC
29746-ENDPROC(bad_from_user)
29747- .previous
29748-
29749 /*
29750 * copy_user_generic_unrolled - memory copy with exception handling.
29751 * This version is for CPUs like P4 that don't have efficient micro
29752@@ -131,6 +61,7 @@ ENDPROC(bad_from_user)
29753 */
29754 ENTRY(copy_user_generic_unrolled)
29755 CFI_STARTPROC
29756+ ASM_PAX_OPEN_USERLAND
29757 ASM_STAC
29758 cmpl $8,%edx
29759 jb 20f /* less then 8 bytes, go to byte copy loop */
29760@@ -180,6 +111,8 @@ ENTRY(copy_user_generic_unrolled)
29761 jnz 21b
29762 23: xor %eax,%eax
29763 ASM_CLAC
29764+ ASM_PAX_CLOSE_USERLAND
29765+ pax_force_retaddr
29766 ret
29767
29768 .section .fixup,"ax"
29769@@ -235,6 +168,7 @@ ENDPROC(copy_user_generic_unrolled)
29770 */
29771 ENTRY(copy_user_generic_string)
29772 CFI_STARTPROC
29773+ ASM_PAX_OPEN_USERLAND
29774 ASM_STAC
29775 cmpl $8,%edx
29776 jb 2f /* less than 8 bytes, go to byte copy loop */
29777@@ -249,6 +183,8 @@ ENTRY(copy_user_generic_string)
29778 movsb
29779 xorl %eax,%eax
29780 ASM_CLAC
29781+ ASM_PAX_CLOSE_USERLAND
29782+ pax_force_retaddr
29783 ret
29784
29785 .section .fixup,"ax"
29786@@ -276,12 +212,15 @@ ENDPROC(copy_user_generic_string)
29787 */
29788 ENTRY(copy_user_enhanced_fast_string)
29789 CFI_STARTPROC
29790+ ASM_PAX_OPEN_USERLAND
29791 ASM_STAC
29792 movl %edx,%ecx
29793 1: rep
29794 movsb
29795 xorl %eax,%eax
29796 ASM_CLAC
29797+ ASM_PAX_CLOSE_USERLAND
29798+ pax_force_retaddr
29799 ret
29800
29801 .section .fixup,"ax"
29802diff --git a/arch/x86/lib/copy_user_nocache_64.S b/arch/x86/lib/copy_user_nocache_64.S
29803index 6a4f43c..c70fb52 100644
29804--- a/arch/x86/lib/copy_user_nocache_64.S
29805+++ b/arch/x86/lib/copy_user_nocache_64.S
29806@@ -8,6 +8,7 @@
29807
29808 #include <linux/linkage.h>
29809 #include <asm/dwarf2.h>
29810+#include <asm/alternative-asm.h>
29811
29812 #define FIX_ALIGNMENT 1
29813
29814@@ -16,6 +17,7 @@
29815 #include <asm/thread_info.h>
29816 #include <asm/asm.h>
29817 #include <asm/smap.h>
29818+#include <asm/pgtable.h>
29819
29820 .macro ALIGN_DESTINATION
29821 #ifdef FIX_ALIGNMENT
29822@@ -49,6 +51,16 @@
29823 */
29824 ENTRY(__copy_user_nocache)
29825 CFI_STARTPROC
29826+
29827+#ifdef CONFIG_PAX_MEMORY_UDEREF
29828+ mov pax_user_shadow_base,%rcx
29829+ cmp %rcx,%rsi
29830+ jae 1f
29831+ add %rcx,%rsi
29832+1:
29833+#endif
29834+
29835+ ASM_PAX_OPEN_USERLAND
29836 ASM_STAC
29837 cmpl $8,%edx
29838 jb 20f /* less then 8 bytes, go to byte copy loop */
29839@@ -98,7 +110,9 @@ ENTRY(__copy_user_nocache)
29840 jnz 21b
29841 23: xorl %eax,%eax
29842 ASM_CLAC
29843+ ASM_PAX_CLOSE_USERLAND
29844 sfence
29845+ pax_force_retaddr
29846 ret
29847
29848 .section .fixup,"ax"
29849diff --git a/arch/x86/lib/csum-copy_64.S b/arch/x86/lib/csum-copy_64.S
29850index 2419d5f..fe52d0e 100644
29851--- a/arch/x86/lib/csum-copy_64.S
29852+++ b/arch/x86/lib/csum-copy_64.S
29853@@ -9,6 +9,7 @@
29854 #include <asm/dwarf2.h>
29855 #include <asm/errno.h>
29856 #include <asm/asm.h>
29857+#include <asm/alternative-asm.h>
29858
29859 /*
29860 * Checksum copy with exception handling.
29861@@ -56,8 +57,8 @@ ENTRY(csum_partial_copy_generic)
29862 CFI_ADJUST_CFA_OFFSET 7*8
29863 movq %rbx, 2*8(%rsp)
29864 CFI_REL_OFFSET rbx, 2*8
29865- movq %r12, 3*8(%rsp)
29866- CFI_REL_OFFSET r12, 3*8
29867+ movq %r15, 3*8(%rsp)
29868+ CFI_REL_OFFSET r15, 3*8
29869 movq %r14, 4*8(%rsp)
29870 CFI_REL_OFFSET r14, 4*8
29871 movq %r13, 5*8(%rsp)
29872@@ -72,16 +73,16 @@ ENTRY(csum_partial_copy_generic)
29873 movl %edx, %ecx
29874
29875 xorl %r9d, %r9d
29876- movq %rcx, %r12
29877+ movq %rcx, %r15
29878
29879- shrq $6, %r12
29880+ shrq $6, %r15
29881 jz .Lhandle_tail /* < 64 */
29882
29883 clc
29884
29885 /* main loop. clear in 64 byte blocks */
29886 /* r9: zero, r8: temp2, rbx: temp1, rax: sum, rcx: saved length */
29887- /* r11: temp3, rdx: temp4, r12 loopcnt */
29888+ /* r11: temp3, rdx: temp4, r15 loopcnt */
29889 /* r10: temp5, rbp: temp6, r14 temp7, r13 temp8 */
29890 .p2align 4
29891 .Lloop:
29892@@ -115,7 +116,7 @@ ENTRY(csum_partial_copy_generic)
29893 adcq %r14, %rax
29894 adcq %r13, %rax
29895
29896- decl %r12d
29897+ decl %r15d
29898
29899 dest
29900 movq %rbx, (%rsi)
29901@@ -210,8 +211,8 @@ ENTRY(csum_partial_copy_generic)
29902 .Lende:
29903 movq 2*8(%rsp), %rbx
29904 CFI_RESTORE rbx
29905- movq 3*8(%rsp), %r12
29906- CFI_RESTORE r12
29907+ movq 3*8(%rsp), %r15
29908+ CFI_RESTORE r15
29909 movq 4*8(%rsp), %r14
29910 CFI_RESTORE r14
29911 movq 5*8(%rsp), %r13
29912@@ -220,6 +221,7 @@ ENTRY(csum_partial_copy_generic)
29913 CFI_RESTORE rbp
29914 addq $7*8, %rsp
29915 CFI_ADJUST_CFA_OFFSET -7*8
29916+ pax_force_retaddr
29917 ret
29918 CFI_RESTORE_STATE
29919
29920diff --git a/arch/x86/lib/csum-wrappers_64.c b/arch/x86/lib/csum-wrappers_64.c
29921index 7609e0e..b449b98 100644
29922--- a/arch/x86/lib/csum-wrappers_64.c
29923+++ b/arch/x86/lib/csum-wrappers_64.c
29924@@ -53,10 +53,12 @@ csum_partial_copy_from_user(const void __user *src, void *dst,
29925 len -= 2;
29926 }
29927 }
29928+ pax_open_userland();
29929 stac();
29930- isum = csum_partial_copy_generic((__force const void *)src,
29931+ isum = csum_partial_copy_generic((const void __force_kernel *)____m(src),
29932 dst, len, isum, errp, NULL);
29933 clac();
29934+ pax_close_userland();
29935 if (unlikely(*errp))
29936 goto out_err;
29937
29938@@ -110,10 +112,12 @@ csum_partial_copy_to_user(const void *src, void __user *dst,
29939 }
29940
29941 *errp = 0;
29942+ pax_open_userland();
29943 stac();
29944- ret = csum_partial_copy_generic(src, (void __force *)dst,
29945+ ret = csum_partial_copy_generic(src, (void __force_kernel *)____m(dst),
29946 len, isum, NULL, errp);
29947 clac();
29948+ pax_close_userland();
29949 return ret;
29950 }
29951 EXPORT_SYMBOL(csum_partial_copy_to_user);
29952diff --git a/arch/x86/lib/getuser.S b/arch/x86/lib/getuser.S
29953index a451235..1daa956 100644
29954--- a/arch/x86/lib/getuser.S
29955+++ b/arch/x86/lib/getuser.S
29956@@ -33,17 +33,40 @@
29957 #include <asm/thread_info.h>
29958 #include <asm/asm.h>
29959 #include <asm/smap.h>
29960+#include <asm/segment.h>
29961+#include <asm/pgtable.h>
29962+#include <asm/alternative-asm.h>
29963+
29964+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
29965+#define __copyuser_seg gs;
29966+#else
29967+#define __copyuser_seg
29968+#endif
29969
29970 .text
29971 ENTRY(__get_user_1)
29972 CFI_STARTPROC
29973+
29974+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
29975 GET_THREAD_INFO(%_ASM_DX)
29976 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
29977 jae bad_get_user
29978 ASM_STAC
29979-1: movzbl (%_ASM_AX),%edx
29980+
29981+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
29982+ mov pax_user_shadow_base,%_ASM_DX
29983+ cmp %_ASM_DX,%_ASM_AX
29984+ jae 1234f
29985+ add %_ASM_DX,%_ASM_AX
29986+1234:
29987+#endif
29988+
29989+#endif
29990+
29991+1: __copyuser_seg movzbl (%_ASM_AX),%edx
29992 xor %eax,%eax
29993 ASM_CLAC
29994+ pax_force_retaddr
29995 ret
29996 CFI_ENDPROC
29997 ENDPROC(__get_user_1)
29998@@ -51,14 +74,28 @@ ENDPROC(__get_user_1)
29999 ENTRY(__get_user_2)
30000 CFI_STARTPROC
30001 add $1,%_ASM_AX
30002+
30003+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30004 jc bad_get_user
30005 GET_THREAD_INFO(%_ASM_DX)
30006 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
30007 jae bad_get_user
30008 ASM_STAC
30009-2: movzwl -1(%_ASM_AX),%edx
30010+
30011+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30012+ mov pax_user_shadow_base,%_ASM_DX
30013+ cmp %_ASM_DX,%_ASM_AX
30014+ jae 1234f
30015+ add %_ASM_DX,%_ASM_AX
30016+1234:
30017+#endif
30018+
30019+#endif
30020+
30021+2: __copyuser_seg movzwl -1(%_ASM_AX),%edx
30022 xor %eax,%eax
30023 ASM_CLAC
30024+ pax_force_retaddr
30025 ret
30026 CFI_ENDPROC
30027 ENDPROC(__get_user_2)
30028@@ -66,14 +103,28 @@ ENDPROC(__get_user_2)
30029 ENTRY(__get_user_4)
30030 CFI_STARTPROC
30031 add $3,%_ASM_AX
30032+
30033+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30034 jc bad_get_user
30035 GET_THREAD_INFO(%_ASM_DX)
30036 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
30037 jae bad_get_user
30038 ASM_STAC
30039-3: movl -3(%_ASM_AX),%edx
30040+
30041+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30042+ mov pax_user_shadow_base,%_ASM_DX
30043+ cmp %_ASM_DX,%_ASM_AX
30044+ jae 1234f
30045+ add %_ASM_DX,%_ASM_AX
30046+1234:
30047+#endif
30048+
30049+#endif
30050+
30051+3: __copyuser_seg movl -3(%_ASM_AX),%edx
30052 xor %eax,%eax
30053 ASM_CLAC
30054+ pax_force_retaddr
30055 ret
30056 CFI_ENDPROC
30057 ENDPROC(__get_user_4)
30058@@ -86,10 +137,20 @@ ENTRY(__get_user_8)
30059 GET_THREAD_INFO(%_ASM_DX)
30060 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
30061 jae bad_get_user
30062+
30063+#ifdef CONFIG_PAX_MEMORY_UDEREF
30064+ mov pax_user_shadow_base,%_ASM_DX
30065+ cmp %_ASM_DX,%_ASM_AX
30066+ jae 1234f
30067+ add %_ASM_DX,%_ASM_AX
30068+1234:
30069+#endif
30070+
30071 ASM_STAC
30072 4: movq -7(%_ASM_AX),%rdx
30073 xor %eax,%eax
30074 ASM_CLAC
30075+ pax_force_retaddr
30076 ret
30077 #else
30078 add $7,%_ASM_AX
30079@@ -98,10 +159,11 @@ ENTRY(__get_user_8)
30080 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
30081 jae bad_get_user_8
30082 ASM_STAC
30083-4: movl -7(%_ASM_AX),%edx
30084-5: movl -3(%_ASM_AX),%ecx
30085+4: __copyuser_seg movl -7(%_ASM_AX),%edx
30086+5: __copyuser_seg movl -3(%_ASM_AX),%ecx
30087 xor %eax,%eax
30088 ASM_CLAC
30089+ pax_force_retaddr
30090 ret
30091 #endif
30092 CFI_ENDPROC
30093@@ -113,6 +175,7 @@ bad_get_user:
30094 xor %edx,%edx
30095 mov $(-EFAULT),%_ASM_AX
30096 ASM_CLAC
30097+ pax_force_retaddr
30098 ret
30099 CFI_ENDPROC
30100 END(bad_get_user)
30101@@ -124,6 +187,7 @@ bad_get_user_8:
30102 xor %ecx,%ecx
30103 mov $(-EFAULT),%_ASM_AX
30104 ASM_CLAC
30105+ pax_force_retaddr
30106 ret
30107 CFI_ENDPROC
30108 END(bad_get_user_8)
30109diff --git a/arch/x86/lib/insn.c b/arch/x86/lib/insn.c
30110index 54fcffe..7be149e 100644
30111--- a/arch/x86/lib/insn.c
30112+++ b/arch/x86/lib/insn.c
30113@@ -20,8 +20,10 @@
30114
30115 #ifdef __KERNEL__
30116 #include <linux/string.h>
30117+#include <asm/pgtable_types.h>
30118 #else
30119 #include <string.h>
30120+#define ktla_ktva(addr) addr
30121 #endif
30122 #include <asm/inat.h>
30123 #include <asm/insn.h>
30124@@ -53,8 +55,8 @@
30125 void insn_init(struct insn *insn, const void *kaddr, int x86_64)
30126 {
30127 memset(insn, 0, sizeof(*insn));
30128- insn->kaddr = kaddr;
30129- insn->next_byte = kaddr;
30130+ insn->kaddr = ktla_ktva(kaddr);
30131+ insn->next_byte = ktla_ktva(kaddr);
30132 insn->x86_64 = x86_64 ? 1 : 0;
30133 insn->opnd_bytes = 4;
30134 if (x86_64)
30135diff --git a/arch/x86/lib/iomap_copy_64.S b/arch/x86/lib/iomap_copy_64.S
30136index 05a95e7..326f2fa 100644
30137--- a/arch/x86/lib/iomap_copy_64.S
30138+++ b/arch/x86/lib/iomap_copy_64.S
30139@@ -17,6 +17,7 @@
30140
30141 #include <linux/linkage.h>
30142 #include <asm/dwarf2.h>
30143+#include <asm/alternative-asm.h>
30144
30145 /*
30146 * override generic version in lib/iomap_copy.c
30147@@ -25,6 +26,7 @@ ENTRY(__iowrite32_copy)
30148 CFI_STARTPROC
30149 movl %edx,%ecx
30150 rep movsd
30151+ pax_force_retaddr
30152 ret
30153 CFI_ENDPROC
30154 ENDPROC(__iowrite32_copy)
30155diff --git a/arch/x86/lib/memcpy_64.S b/arch/x86/lib/memcpy_64.S
30156index 56313a3..0db417e 100644
30157--- a/arch/x86/lib/memcpy_64.S
30158+++ b/arch/x86/lib/memcpy_64.S
30159@@ -24,7 +24,7 @@
30160 * This gets patched over the unrolled variant (below) via the
30161 * alternative instructions framework:
30162 */
30163- .section .altinstr_replacement, "ax", @progbits
30164+ .section .altinstr_replacement, "a", @progbits
30165 .Lmemcpy_c:
30166 movq %rdi, %rax
30167 movq %rdx, %rcx
30168@@ -33,6 +33,7 @@
30169 rep movsq
30170 movl %edx, %ecx
30171 rep movsb
30172+ pax_force_retaddr
30173 ret
30174 .Lmemcpy_e:
30175 .previous
30176@@ -44,11 +45,12 @@
30177 * This gets patched over the unrolled variant (below) via the
30178 * alternative instructions framework:
30179 */
30180- .section .altinstr_replacement, "ax", @progbits
30181+ .section .altinstr_replacement, "a", @progbits
30182 .Lmemcpy_c_e:
30183 movq %rdi, %rax
30184 movq %rdx, %rcx
30185 rep movsb
30186+ pax_force_retaddr
30187 ret
30188 .Lmemcpy_e_e:
30189 .previous
30190@@ -136,6 +138,7 @@ ENTRY(memcpy)
30191 movq %r9, 1*8(%rdi)
30192 movq %r10, -2*8(%rdi, %rdx)
30193 movq %r11, -1*8(%rdi, %rdx)
30194+ pax_force_retaddr
30195 retq
30196 .p2align 4
30197 .Lless_16bytes:
30198@@ -148,6 +151,7 @@ ENTRY(memcpy)
30199 movq -1*8(%rsi, %rdx), %r9
30200 movq %r8, 0*8(%rdi)
30201 movq %r9, -1*8(%rdi, %rdx)
30202+ pax_force_retaddr
30203 retq
30204 .p2align 4
30205 .Lless_8bytes:
30206@@ -161,6 +165,7 @@ ENTRY(memcpy)
30207 movl -4(%rsi, %rdx), %r8d
30208 movl %ecx, (%rdi)
30209 movl %r8d, -4(%rdi, %rdx)
30210+ pax_force_retaddr
30211 retq
30212 .p2align 4
30213 .Lless_3bytes:
30214@@ -179,6 +184,7 @@ ENTRY(memcpy)
30215 movb %cl, (%rdi)
30216
30217 .Lend:
30218+ pax_force_retaddr
30219 retq
30220 CFI_ENDPROC
30221 ENDPROC(memcpy)
30222diff --git a/arch/x86/lib/memmove_64.S b/arch/x86/lib/memmove_64.S
30223index 65268a6..dd1de11 100644
30224--- a/arch/x86/lib/memmove_64.S
30225+++ b/arch/x86/lib/memmove_64.S
30226@@ -202,14 +202,16 @@ ENTRY(memmove)
30227 movb (%rsi), %r11b
30228 movb %r11b, (%rdi)
30229 13:
30230+ pax_force_retaddr
30231 retq
30232 CFI_ENDPROC
30233
30234- .section .altinstr_replacement,"ax"
30235+ .section .altinstr_replacement,"a"
30236 .Lmemmove_begin_forward_efs:
30237 /* Forward moving data. */
30238 movq %rdx, %rcx
30239 rep movsb
30240+ pax_force_retaddr
30241 retq
30242 .Lmemmove_end_forward_efs:
30243 .previous
30244diff --git a/arch/x86/lib/memset_64.S b/arch/x86/lib/memset_64.S
30245index 2dcb380..2eb79fe 100644
30246--- a/arch/x86/lib/memset_64.S
30247+++ b/arch/x86/lib/memset_64.S
30248@@ -16,7 +16,7 @@
30249 *
30250 * rax original destination
30251 */
30252- .section .altinstr_replacement, "ax", @progbits
30253+ .section .altinstr_replacement, "a", @progbits
30254 .Lmemset_c:
30255 movq %rdi,%r9
30256 movq %rdx,%rcx
30257@@ -30,6 +30,7 @@
30258 movl %edx,%ecx
30259 rep stosb
30260 movq %r9,%rax
30261+ pax_force_retaddr
30262 ret
30263 .Lmemset_e:
30264 .previous
30265@@ -45,13 +46,14 @@
30266 *
30267 * rax original destination
30268 */
30269- .section .altinstr_replacement, "ax", @progbits
30270+ .section .altinstr_replacement, "a", @progbits
30271 .Lmemset_c_e:
30272 movq %rdi,%r9
30273 movb %sil,%al
30274 movq %rdx,%rcx
30275 rep stosb
30276 movq %r9,%rax
30277+ pax_force_retaddr
30278 ret
30279 .Lmemset_e_e:
30280 .previous
30281@@ -118,6 +120,7 @@ ENTRY(__memset)
30282
30283 .Lende:
30284 movq %r10,%rax
30285+ pax_force_retaddr
30286 ret
30287
30288 CFI_RESTORE_STATE
30289diff --git a/arch/x86/lib/mmx_32.c b/arch/x86/lib/mmx_32.c
30290index c9f2d9b..e7fd2c0 100644
30291--- a/arch/x86/lib/mmx_32.c
30292+++ b/arch/x86/lib/mmx_32.c
30293@@ -29,6 +29,7 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
30294 {
30295 void *p;
30296 int i;
30297+ unsigned long cr0;
30298
30299 if (unlikely(in_interrupt()))
30300 return __memcpy(to, from, len);
30301@@ -39,44 +40,72 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
30302 kernel_fpu_begin();
30303
30304 __asm__ __volatile__ (
30305- "1: prefetch (%0)\n" /* This set is 28 bytes */
30306- " prefetch 64(%0)\n"
30307- " prefetch 128(%0)\n"
30308- " prefetch 192(%0)\n"
30309- " prefetch 256(%0)\n"
30310+ "1: prefetch (%1)\n" /* This set is 28 bytes */
30311+ " prefetch 64(%1)\n"
30312+ " prefetch 128(%1)\n"
30313+ " prefetch 192(%1)\n"
30314+ " prefetch 256(%1)\n"
30315 "2: \n"
30316 ".section .fixup, \"ax\"\n"
30317- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
30318+ "3: \n"
30319+
30320+#ifdef CONFIG_PAX_KERNEXEC
30321+ " movl %%cr0, %0\n"
30322+ " movl %0, %%eax\n"
30323+ " andl $0xFFFEFFFF, %%eax\n"
30324+ " movl %%eax, %%cr0\n"
30325+#endif
30326+
30327+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
30328+
30329+#ifdef CONFIG_PAX_KERNEXEC
30330+ " movl %0, %%cr0\n"
30331+#endif
30332+
30333 " jmp 2b\n"
30334 ".previous\n"
30335 _ASM_EXTABLE(1b, 3b)
30336- : : "r" (from));
30337+ : "=&r" (cr0) : "r" (from) : "ax");
30338
30339 for ( ; i > 5; i--) {
30340 __asm__ __volatile__ (
30341- "1: prefetch 320(%0)\n"
30342- "2: movq (%0), %%mm0\n"
30343- " movq 8(%0), %%mm1\n"
30344- " movq 16(%0), %%mm2\n"
30345- " movq 24(%0), %%mm3\n"
30346- " movq %%mm0, (%1)\n"
30347- " movq %%mm1, 8(%1)\n"
30348- " movq %%mm2, 16(%1)\n"
30349- " movq %%mm3, 24(%1)\n"
30350- " movq 32(%0), %%mm0\n"
30351- " movq 40(%0), %%mm1\n"
30352- " movq 48(%0), %%mm2\n"
30353- " movq 56(%0), %%mm3\n"
30354- " movq %%mm0, 32(%1)\n"
30355- " movq %%mm1, 40(%1)\n"
30356- " movq %%mm2, 48(%1)\n"
30357- " movq %%mm3, 56(%1)\n"
30358+ "1: prefetch 320(%1)\n"
30359+ "2: movq (%1), %%mm0\n"
30360+ " movq 8(%1), %%mm1\n"
30361+ " movq 16(%1), %%mm2\n"
30362+ " movq 24(%1), %%mm3\n"
30363+ " movq %%mm0, (%2)\n"
30364+ " movq %%mm1, 8(%2)\n"
30365+ " movq %%mm2, 16(%2)\n"
30366+ " movq %%mm3, 24(%2)\n"
30367+ " movq 32(%1), %%mm0\n"
30368+ " movq 40(%1), %%mm1\n"
30369+ " movq 48(%1), %%mm2\n"
30370+ " movq 56(%1), %%mm3\n"
30371+ " movq %%mm0, 32(%2)\n"
30372+ " movq %%mm1, 40(%2)\n"
30373+ " movq %%mm2, 48(%2)\n"
30374+ " movq %%mm3, 56(%2)\n"
30375 ".section .fixup, \"ax\"\n"
30376- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
30377+ "3:\n"
30378+
30379+#ifdef CONFIG_PAX_KERNEXEC
30380+ " movl %%cr0, %0\n"
30381+ " movl %0, %%eax\n"
30382+ " andl $0xFFFEFFFF, %%eax\n"
30383+ " movl %%eax, %%cr0\n"
30384+#endif
30385+
30386+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
30387+
30388+#ifdef CONFIG_PAX_KERNEXEC
30389+ " movl %0, %%cr0\n"
30390+#endif
30391+
30392 " jmp 2b\n"
30393 ".previous\n"
30394 _ASM_EXTABLE(1b, 3b)
30395- : : "r" (from), "r" (to) : "memory");
30396+ : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
30397
30398 from += 64;
30399 to += 64;
30400@@ -158,6 +187,7 @@ static void fast_clear_page(void *page)
30401 static void fast_copy_page(void *to, void *from)
30402 {
30403 int i;
30404+ unsigned long cr0;
30405
30406 kernel_fpu_begin();
30407
30408@@ -166,42 +196,70 @@ static void fast_copy_page(void *to, void *from)
30409 * but that is for later. -AV
30410 */
30411 __asm__ __volatile__(
30412- "1: prefetch (%0)\n"
30413- " prefetch 64(%0)\n"
30414- " prefetch 128(%0)\n"
30415- " prefetch 192(%0)\n"
30416- " prefetch 256(%0)\n"
30417+ "1: prefetch (%1)\n"
30418+ " prefetch 64(%1)\n"
30419+ " prefetch 128(%1)\n"
30420+ " prefetch 192(%1)\n"
30421+ " prefetch 256(%1)\n"
30422 "2: \n"
30423 ".section .fixup, \"ax\"\n"
30424- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
30425+ "3: \n"
30426+
30427+#ifdef CONFIG_PAX_KERNEXEC
30428+ " movl %%cr0, %0\n"
30429+ " movl %0, %%eax\n"
30430+ " andl $0xFFFEFFFF, %%eax\n"
30431+ " movl %%eax, %%cr0\n"
30432+#endif
30433+
30434+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
30435+
30436+#ifdef CONFIG_PAX_KERNEXEC
30437+ " movl %0, %%cr0\n"
30438+#endif
30439+
30440 " jmp 2b\n"
30441 ".previous\n"
30442- _ASM_EXTABLE(1b, 3b) : : "r" (from));
30443+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
30444
30445 for (i = 0; i < (4096-320)/64; i++) {
30446 __asm__ __volatile__ (
30447- "1: prefetch 320(%0)\n"
30448- "2: movq (%0), %%mm0\n"
30449- " movntq %%mm0, (%1)\n"
30450- " movq 8(%0), %%mm1\n"
30451- " movntq %%mm1, 8(%1)\n"
30452- " movq 16(%0), %%mm2\n"
30453- " movntq %%mm2, 16(%1)\n"
30454- " movq 24(%0), %%mm3\n"
30455- " movntq %%mm3, 24(%1)\n"
30456- " movq 32(%0), %%mm4\n"
30457- " movntq %%mm4, 32(%1)\n"
30458- " movq 40(%0), %%mm5\n"
30459- " movntq %%mm5, 40(%1)\n"
30460- " movq 48(%0), %%mm6\n"
30461- " movntq %%mm6, 48(%1)\n"
30462- " movq 56(%0), %%mm7\n"
30463- " movntq %%mm7, 56(%1)\n"
30464+ "1: prefetch 320(%1)\n"
30465+ "2: movq (%1), %%mm0\n"
30466+ " movntq %%mm0, (%2)\n"
30467+ " movq 8(%1), %%mm1\n"
30468+ " movntq %%mm1, 8(%2)\n"
30469+ " movq 16(%1), %%mm2\n"
30470+ " movntq %%mm2, 16(%2)\n"
30471+ " movq 24(%1), %%mm3\n"
30472+ " movntq %%mm3, 24(%2)\n"
30473+ " movq 32(%1), %%mm4\n"
30474+ " movntq %%mm4, 32(%2)\n"
30475+ " movq 40(%1), %%mm5\n"
30476+ " movntq %%mm5, 40(%2)\n"
30477+ " movq 48(%1), %%mm6\n"
30478+ " movntq %%mm6, 48(%2)\n"
30479+ " movq 56(%1), %%mm7\n"
30480+ " movntq %%mm7, 56(%2)\n"
30481 ".section .fixup, \"ax\"\n"
30482- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
30483+ "3:\n"
30484+
30485+#ifdef CONFIG_PAX_KERNEXEC
30486+ " movl %%cr0, %0\n"
30487+ " movl %0, %%eax\n"
30488+ " andl $0xFFFEFFFF, %%eax\n"
30489+ " movl %%eax, %%cr0\n"
30490+#endif
30491+
30492+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
30493+
30494+#ifdef CONFIG_PAX_KERNEXEC
30495+ " movl %0, %%cr0\n"
30496+#endif
30497+
30498 " jmp 2b\n"
30499 ".previous\n"
30500- _ASM_EXTABLE(1b, 3b) : : "r" (from), "r" (to) : "memory");
30501+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
30502
30503 from += 64;
30504 to += 64;
30505@@ -280,47 +338,76 @@ static void fast_clear_page(void *page)
30506 static void fast_copy_page(void *to, void *from)
30507 {
30508 int i;
30509+ unsigned long cr0;
30510
30511 kernel_fpu_begin();
30512
30513 __asm__ __volatile__ (
30514- "1: prefetch (%0)\n"
30515- " prefetch 64(%0)\n"
30516- " prefetch 128(%0)\n"
30517- " prefetch 192(%0)\n"
30518- " prefetch 256(%0)\n"
30519+ "1: prefetch (%1)\n"
30520+ " prefetch 64(%1)\n"
30521+ " prefetch 128(%1)\n"
30522+ " prefetch 192(%1)\n"
30523+ " prefetch 256(%1)\n"
30524 "2: \n"
30525 ".section .fixup, \"ax\"\n"
30526- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
30527+ "3: \n"
30528+
30529+#ifdef CONFIG_PAX_KERNEXEC
30530+ " movl %%cr0, %0\n"
30531+ " movl %0, %%eax\n"
30532+ " andl $0xFFFEFFFF, %%eax\n"
30533+ " movl %%eax, %%cr0\n"
30534+#endif
30535+
30536+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
30537+
30538+#ifdef CONFIG_PAX_KERNEXEC
30539+ " movl %0, %%cr0\n"
30540+#endif
30541+
30542 " jmp 2b\n"
30543 ".previous\n"
30544- _ASM_EXTABLE(1b, 3b) : : "r" (from));
30545+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
30546
30547 for (i = 0; i < 4096/64; i++) {
30548 __asm__ __volatile__ (
30549- "1: prefetch 320(%0)\n"
30550- "2: movq (%0), %%mm0\n"
30551- " movq 8(%0), %%mm1\n"
30552- " movq 16(%0), %%mm2\n"
30553- " movq 24(%0), %%mm3\n"
30554- " movq %%mm0, (%1)\n"
30555- " movq %%mm1, 8(%1)\n"
30556- " movq %%mm2, 16(%1)\n"
30557- " movq %%mm3, 24(%1)\n"
30558- " movq 32(%0), %%mm0\n"
30559- " movq 40(%0), %%mm1\n"
30560- " movq 48(%0), %%mm2\n"
30561- " movq 56(%0), %%mm3\n"
30562- " movq %%mm0, 32(%1)\n"
30563- " movq %%mm1, 40(%1)\n"
30564- " movq %%mm2, 48(%1)\n"
30565- " movq %%mm3, 56(%1)\n"
30566+ "1: prefetch 320(%1)\n"
30567+ "2: movq (%1), %%mm0\n"
30568+ " movq 8(%1), %%mm1\n"
30569+ " movq 16(%1), %%mm2\n"
30570+ " movq 24(%1), %%mm3\n"
30571+ " movq %%mm0, (%2)\n"
30572+ " movq %%mm1, 8(%2)\n"
30573+ " movq %%mm2, 16(%2)\n"
30574+ " movq %%mm3, 24(%2)\n"
30575+ " movq 32(%1), %%mm0\n"
30576+ " movq 40(%1), %%mm1\n"
30577+ " movq 48(%1), %%mm2\n"
30578+ " movq 56(%1), %%mm3\n"
30579+ " movq %%mm0, 32(%2)\n"
30580+ " movq %%mm1, 40(%2)\n"
30581+ " movq %%mm2, 48(%2)\n"
30582+ " movq %%mm3, 56(%2)\n"
30583 ".section .fixup, \"ax\"\n"
30584- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
30585+ "3:\n"
30586+
30587+#ifdef CONFIG_PAX_KERNEXEC
30588+ " movl %%cr0, %0\n"
30589+ " movl %0, %%eax\n"
30590+ " andl $0xFFFEFFFF, %%eax\n"
30591+ " movl %%eax, %%cr0\n"
30592+#endif
30593+
30594+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
30595+
30596+#ifdef CONFIG_PAX_KERNEXEC
30597+ " movl %0, %%cr0\n"
30598+#endif
30599+
30600 " jmp 2b\n"
30601 ".previous\n"
30602 _ASM_EXTABLE(1b, 3b)
30603- : : "r" (from), "r" (to) : "memory");
30604+ : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
30605
30606 from += 64;
30607 to += 64;
30608diff --git a/arch/x86/lib/msr-reg.S b/arch/x86/lib/msr-reg.S
30609index f6d13ee..d789440 100644
30610--- a/arch/x86/lib/msr-reg.S
30611+++ b/arch/x86/lib/msr-reg.S
30612@@ -3,6 +3,7 @@
30613 #include <asm/dwarf2.h>
30614 #include <asm/asm.h>
30615 #include <asm/msr.h>
30616+#include <asm/alternative-asm.h>
30617
30618 #ifdef CONFIG_X86_64
30619 /*
30620@@ -37,6 +38,7 @@ ENTRY(\op\()_safe_regs)
30621 movl %edi, 28(%r10)
30622 popq_cfi %rbp
30623 popq_cfi %rbx
30624+ pax_force_retaddr
30625 ret
30626 3:
30627 CFI_RESTORE_STATE
30628diff --git a/arch/x86/lib/putuser.S b/arch/x86/lib/putuser.S
30629index fc6ba17..d4d989d 100644
30630--- a/arch/x86/lib/putuser.S
30631+++ b/arch/x86/lib/putuser.S
30632@@ -16,7 +16,9 @@
30633 #include <asm/errno.h>
30634 #include <asm/asm.h>
30635 #include <asm/smap.h>
30636-
30637+#include <asm/segment.h>
30638+#include <asm/pgtable.h>
30639+#include <asm/alternative-asm.h>
30640
30641 /*
30642 * __put_user_X
30643@@ -30,57 +32,125 @@
30644 * as they get called from within inline assembly.
30645 */
30646
30647-#define ENTER CFI_STARTPROC ; \
30648- GET_THREAD_INFO(%_ASM_BX)
30649-#define EXIT ASM_CLAC ; \
30650- ret ; \
30651+#define ENTER CFI_STARTPROC
30652+#define EXIT ASM_CLAC ; \
30653+ pax_force_retaddr ; \
30654+ ret ; \
30655 CFI_ENDPROC
30656
30657+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30658+#define _DEST %_ASM_CX,%_ASM_BX
30659+#else
30660+#define _DEST %_ASM_CX
30661+#endif
30662+
30663+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
30664+#define __copyuser_seg gs;
30665+#else
30666+#define __copyuser_seg
30667+#endif
30668+
30669 .text
30670 ENTRY(__put_user_1)
30671 ENTER
30672+
30673+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30674+ GET_THREAD_INFO(%_ASM_BX)
30675 cmp TI_addr_limit(%_ASM_BX),%_ASM_CX
30676 jae bad_put_user
30677 ASM_STAC
30678-1: movb %al,(%_ASM_CX)
30679+
30680+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30681+ mov pax_user_shadow_base,%_ASM_BX
30682+ cmp %_ASM_BX,%_ASM_CX
30683+ jb 1234f
30684+ xor %ebx,%ebx
30685+1234:
30686+#endif
30687+
30688+#endif
30689+
30690+1: __copyuser_seg movb %al,(_DEST)
30691 xor %eax,%eax
30692 EXIT
30693 ENDPROC(__put_user_1)
30694
30695 ENTRY(__put_user_2)
30696 ENTER
30697+
30698+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30699+ GET_THREAD_INFO(%_ASM_BX)
30700 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
30701 sub $1,%_ASM_BX
30702 cmp %_ASM_BX,%_ASM_CX
30703 jae bad_put_user
30704 ASM_STAC
30705-2: movw %ax,(%_ASM_CX)
30706+
30707+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30708+ mov pax_user_shadow_base,%_ASM_BX
30709+ cmp %_ASM_BX,%_ASM_CX
30710+ jb 1234f
30711+ xor %ebx,%ebx
30712+1234:
30713+#endif
30714+
30715+#endif
30716+
30717+2: __copyuser_seg movw %ax,(_DEST)
30718 xor %eax,%eax
30719 EXIT
30720 ENDPROC(__put_user_2)
30721
30722 ENTRY(__put_user_4)
30723 ENTER
30724+
30725+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30726+ GET_THREAD_INFO(%_ASM_BX)
30727 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
30728 sub $3,%_ASM_BX
30729 cmp %_ASM_BX,%_ASM_CX
30730 jae bad_put_user
30731 ASM_STAC
30732-3: movl %eax,(%_ASM_CX)
30733+
30734+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30735+ mov pax_user_shadow_base,%_ASM_BX
30736+ cmp %_ASM_BX,%_ASM_CX
30737+ jb 1234f
30738+ xor %ebx,%ebx
30739+1234:
30740+#endif
30741+
30742+#endif
30743+
30744+3: __copyuser_seg movl %eax,(_DEST)
30745 xor %eax,%eax
30746 EXIT
30747 ENDPROC(__put_user_4)
30748
30749 ENTRY(__put_user_8)
30750 ENTER
30751+
30752+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30753+ GET_THREAD_INFO(%_ASM_BX)
30754 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
30755 sub $7,%_ASM_BX
30756 cmp %_ASM_BX,%_ASM_CX
30757 jae bad_put_user
30758 ASM_STAC
30759-4: mov %_ASM_AX,(%_ASM_CX)
30760+
30761+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30762+ mov pax_user_shadow_base,%_ASM_BX
30763+ cmp %_ASM_BX,%_ASM_CX
30764+ jb 1234f
30765+ xor %ebx,%ebx
30766+1234:
30767+#endif
30768+
30769+#endif
30770+
30771+4: __copyuser_seg mov %_ASM_AX,(_DEST)
30772 #ifdef CONFIG_X86_32
30773-5: movl %edx,4(%_ASM_CX)
30774+5: __copyuser_seg movl %edx,4(_DEST)
30775 #endif
30776 xor %eax,%eax
30777 EXIT
30778diff --git a/arch/x86/lib/rwlock.S b/arch/x86/lib/rwlock.S
30779index 1cad221..de671ee 100644
30780--- a/arch/x86/lib/rwlock.S
30781+++ b/arch/x86/lib/rwlock.S
30782@@ -16,13 +16,34 @@ ENTRY(__write_lock_failed)
30783 FRAME
30784 0: LOCK_PREFIX
30785 WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
30786+
30787+#ifdef CONFIG_PAX_REFCOUNT
30788+ jno 1234f
30789+ LOCK_PREFIX
30790+ WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
30791+ int $4
30792+1234:
30793+ _ASM_EXTABLE(1234b, 1234b)
30794+#endif
30795+
30796 1: rep; nop
30797 cmpl $WRITE_LOCK_CMP, (%__lock_ptr)
30798 jne 1b
30799 LOCK_PREFIX
30800 WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
30801+
30802+#ifdef CONFIG_PAX_REFCOUNT
30803+ jno 1234f
30804+ LOCK_PREFIX
30805+ WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
30806+ int $4
30807+1234:
30808+ _ASM_EXTABLE(1234b, 1234b)
30809+#endif
30810+
30811 jnz 0b
30812 ENDFRAME
30813+ pax_force_retaddr
30814 ret
30815 CFI_ENDPROC
30816 END(__write_lock_failed)
30817@@ -32,13 +53,34 @@ ENTRY(__read_lock_failed)
30818 FRAME
30819 0: LOCK_PREFIX
30820 READ_LOCK_SIZE(inc) (%__lock_ptr)
30821+
30822+#ifdef CONFIG_PAX_REFCOUNT
30823+ jno 1234f
30824+ LOCK_PREFIX
30825+ READ_LOCK_SIZE(dec) (%__lock_ptr)
30826+ int $4
30827+1234:
30828+ _ASM_EXTABLE(1234b, 1234b)
30829+#endif
30830+
30831 1: rep; nop
30832 READ_LOCK_SIZE(cmp) $1, (%__lock_ptr)
30833 js 1b
30834 LOCK_PREFIX
30835 READ_LOCK_SIZE(dec) (%__lock_ptr)
30836+
30837+#ifdef CONFIG_PAX_REFCOUNT
30838+ jno 1234f
30839+ LOCK_PREFIX
30840+ READ_LOCK_SIZE(inc) (%__lock_ptr)
30841+ int $4
30842+1234:
30843+ _ASM_EXTABLE(1234b, 1234b)
30844+#endif
30845+
30846 js 0b
30847 ENDFRAME
30848+ pax_force_retaddr
30849 ret
30850 CFI_ENDPROC
30851 END(__read_lock_failed)
30852diff --git a/arch/x86/lib/rwsem.S b/arch/x86/lib/rwsem.S
30853index 5dff5f0..cadebf4 100644
30854--- a/arch/x86/lib/rwsem.S
30855+++ b/arch/x86/lib/rwsem.S
30856@@ -94,6 +94,7 @@ ENTRY(call_rwsem_down_read_failed)
30857 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
30858 CFI_RESTORE __ASM_REG(dx)
30859 restore_common_regs
30860+ pax_force_retaddr
30861 ret
30862 CFI_ENDPROC
30863 ENDPROC(call_rwsem_down_read_failed)
30864@@ -104,6 +105,7 @@ ENTRY(call_rwsem_down_write_failed)
30865 movq %rax,%rdi
30866 call rwsem_down_write_failed
30867 restore_common_regs
30868+ pax_force_retaddr
30869 ret
30870 CFI_ENDPROC
30871 ENDPROC(call_rwsem_down_write_failed)
30872@@ -117,7 +119,8 @@ ENTRY(call_rwsem_wake)
30873 movq %rax,%rdi
30874 call rwsem_wake
30875 restore_common_regs
30876-1: ret
30877+1: pax_force_retaddr
30878+ ret
30879 CFI_ENDPROC
30880 ENDPROC(call_rwsem_wake)
30881
30882@@ -131,6 +134,7 @@ ENTRY(call_rwsem_downgrade_wake)
30883 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
30884 CFI_RESTORE __ASM_REG(dx)
30885 restore_common_regs
30886+ pax_force_retaddr
30887 ret
30888 CFI_ENDPROC
30889 ENDPROC(call_rwsem_downgrade_wake)
30890diff --git a/arch/x86/lib/thunk_64.S b/arch/x86/lib/thunk_64.S
30891index a63efd6..8149fbe 100644
30892--- a/arch/x86/lib/thunk_64.S
30893+++ b/arch/x86/lib/thunk_64.S
30894@@ -8,6 +8,7 @@
30895 #include <linux/linkage.h>
30896 #include <asm/dwarf2.h>
30897 #include <asm/calling.h>
30898+#include <asm/alternative-asm.h>
30899
30900 /* rdi: arg1 ... normal C conventions. rax is saved/restored. */
30901 .macro THUNK name, func, put_ret_addr_in_rdi=0
30902@@ -15,11 +16,11 @@
30903 \name:
30904 CFI_STARTPROC
30905
30906- /* this one pushes 9 elems, the next one would be %rIP */
30907- SAVE_ARGS
30908+ /* this one pushes 15+1 elems, the next one would be %rIP */
30909+ SAVE_ARGS 8
30910
30911 .if \put_ret_addr_in_rdi
30912- movq_cfi_restore 9*8, rdi
30913+ movq_cfi_restore RIP, rdi
30914 .endif
30915
30916 call \func
30917@@ -38,8 +39,9 @@
30918
30919 /* SAVE_ARGS below is used only for the .cfi directives it contains. */
30920 CFI_STARTPROC
30921- SAVE_ARGS
30922+ SAVE_ARGS 8
30923 restore:
30924- RESTORE_ARGS
30925+ RESTORE_ARGS 1,8
30926+ pax_force_retaddr
30927 ret
30928 CFI_ENDPROC
30929diff --git a/arch/x86/lib/usercopy_32.c b/arch/x86/lib/usercopy_32.c
30930index e2f5e21..4b22130 100644
30931--- a/arch/x86/lib/usercopy_32.c
30932+++ b/arch/x86/lib/usercopy_32.c
30933@@ -42,11 +42,13 @@ do { \
30934 int __d0; \
30935 might_fault(); \
30936 __asm__ __volatile__( \
30937+ __COPYUSER_SET_ES \
30938 ASM_STAC "\n" \
30939 "0: rep; stosl\n" \
30940 " movl %2,%0\n" \
30941 "1: rep; stosb\n" \
30942 "2: " ASM_CLAC "\n" \
30943+ __COPYUSER_RESTORE_ES \
30944 ".section .fixup,\"ax\"\n" \
30945 "3: lea 0(%2,%0,4),%0\n" \
30946 " jmp 2b\n" \
30947@@ -98,7 +100,7 @@ EXPORT_SYMBOL(__clear_user);
30948
30949 #ifdef CONFIG_X86_INTEL_USERCOPY
30950 static unsigned long
30951-__copy_user_intel(void __user *to, const void *from, unsigned long size)
30952+__generic_copy_to_user_intel(void __user *to, const void *from, unsigned long size)
30953 {
30954 int d0, d1;
30955 __asm__ __volatile__(
30956@@ -110,36 +112,36 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
30957 " .align 2,0x90\n"
30958 "3: movl 0(%4), %%eax\n"
30959 "4: movl 4(%4), %%edx\n"
30960- "5: movl %%eax, 0(%3)\n"
30961- "6: movl %%edx, 4(%3)\n"
30962+ "5: "__copyuser_seg" movl %%eax, 0(%3)\n"
30963+ "6: "__copyuser_seg" movl %%edx, 4(%3)\n"
30964 "7: movl 8(%4), %%eax\n"
30965 "8: movl 12(%4),%%edx\n"
30966- "9: movl %%eax, 8(%3)\n"
30967- "10: movl %%edx, 12(%3)\n"
30968+ "9: "__copyuser_seg" movl %%eax, 8(%3)\n"
30969+ "10: "__copyuser_seg" movl %%edx, 12(%3)\n"
30970 "11: movl 16(%4), %%eax\n"
30971 "12: movl 20(%4), %%edx\n"
30972- "13: movl %%eax, 16(%3)\n"
30973- "14: movl %%edx, 20(%3)\n"
30974+ "13: "__copyuser_seg" movl %%eax, 16(%3)\n"
30975+ "14: "__copyuser_seg" movl %%edx, 20(%3)\n"
30976 "15: movl 24(%4), %%eax\n"
30977 "16: movl 28(%4), %%edx\n"
30978- "17: movl %%eax, 24(%3)\n"
30979- "18: movl %%edx, 28(%3)\n"
30980+ "17: "__copyuser_seg" movl %%eax, 24(%3)\n"
30981+ "18: "__copyuser_seg" movl %%edx, 28(%3)\n"
30982 "19: movl 32(%4), %%eax\n"
30983 "20: movl 36(%4), %%edx\n"
30984- "21: movl %%eax, 32(%3)\n"
30985- "22: movl %%edx, 36(%3)\n"
30986+ "21: "__copyuser_seg" movl %%eax, 32(%3)\n"
30987+ "22: "__copyuser_seg" movl %%edx, 36(%3)\n"
30988 "23: movl 40(%4), %%eax\n"
30989 "24: movl 44(%4), %%edx\n"
30990- "25: movl %%eax, 40(%3)\n"
30991- "26: movl %%edx, 44(%3)\n"
30992+ "25: "__copyuser_seg" movl %%eax, 40(%3)\n"
30993+ "26: "__copyuser_seg" movl %%edx, 44(%3)\n"
30994 "27: movl 48(%4), %%eax\n"
30995 "28: movl 52(%4), %%edx\n"
30996- "29: movl %%eax, 48(%3)\n"
30997- "30: movl %%edx, 52(%3)\n"
30998+ "29: "__copyuser_seg" movl %%eax, 48(%3)\n"
30999+ "30: "__copyuser_seg" movl %%edx, 52(%3)\n"
31000 "31: movl 56(%4), %%eax\n"
31001 "32: movl 60(%4), %%edx\n"
31002- "33: movl %%eax, 56(%3)\n"
31003- "34: movl %%edx, 60(%3)\n"
31004+ "33: "__copyuser_seg" movl %%eax, 56(%3)\n"
31005+ "34: "__copyuser_seg" movl %%edx, 60(%3)\n"
31006 " addl $-64, %0\n"
31007 " addl $64, %4\n"
31008 " addl $64, %3\n"
31009@@ -149,10 +151,116 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
31010 " shrl $2, %0\n"
31011 " andl $3, %%eax\n"
31012 " cld\n"
31013+ __COPYUSER_SET_ES
31014 "99: rep; movsl\n"
31015 "36: movl %%eax, %0\n"
31016 "37: rep; movsb\n"
31017 "100:\n"
31018+ __COPYUSER_RESTORE_ES
31019+ ".section .fixup,\"ax\"\n"
31020+ "101: lea 0(%%eax,%0,4),%0\n"
31021+ " jmp 100b\n"
31022+ ".previous\n"
31023+ _ASM_EXTABLE(1b,100b)
31024+ _ASM_EXTABLE(2b,100b)
31025+ _ASM_EXTABLE(3b,100b)
31026+ _ASM_EXTABLE(4b,100b)
31027+ _ASM_EXTABLE(5b,100b)
31028+ _ASM_EXTABLE(6b,100b)
31029+ _ASM_EXTABLE(7b,100b)
31030+ _ASM_EXTABLE(8b,100b)
31031+ _ASM_EXTABLE(9b,100b)
31032+ _ASM_EXTABLE(10b,100b)
31033+ _ASM_EXTABLE(11b,100b)
31034+ _ASM_EXTABLE(12b,100b)
31035+ _ASM_EXTABLE(13b,100b)
31036+ _ASM_EXTABLE(14b,100b)
31037+ _ASM_EXTABLE(15b,100b)
31038+ _ASM_EXTABLE(16b,100b)
31039+ _ASM_EXTABLE(17b,100b)
31040+ _ASM_EXTABLE(18b,100b)
31041+ _ASM_EXTABLE(19b,100b)
31042+ _ASM_EXTABLE(20b,100b)
31043+ _ASM_EXTABLE(21b,100b)
31044+ _ASM_EXTABLE(22b,100b)
31045+ _ASM_EXTABLE(23b,100b)
31046+ _ASM_EXTABLE(24b,100b)
31047+ _ASM_EXTABLE(25b,100b)
31048+ _ASM_EXTABLE(26b,100b)
31049+ _ASM_EXTABLE(27b,100b)
31050+ _ASM_EXTABLE(28b,100b)
31051+ _ASM_EXTABLE(29b,100b)
31052+ _ASM_EXTABLE(30b,100b)
31053+ _ASM_EXTABLE(31b,100b)
31054+ _ASM_EXTABLE(32b,100b)
31055+ _ASM_EXTABLE(33b,100b)
31056+ _ASM_EXTABLE(34b,100b)
31057+ _ASM_EXTABLE(35b,100b)
31058+ _ASM_EXTABLE(36b,100b)
31059+ _ASM_EXTABLE(37b,100b)
31060+ _ASM_EXTABLE(99b,101b)
31061+ : "=&c"(size), "=&D" (d0), "=&S" (d1)
31062+ : "1"(to), "2"(from), "0"(size)
31063+ : "eax", "edx", "memory");
31064+ return size;
31065+}
31066+
31067+static unsigned long
31068+__generic_copy_from_user_intel(void *to, const void __user *from, unsigned long size)
31069+{
31070+ int d0, d1;
31071+ __asm__ __volatile__(
31072+ " .align 2,0x90\n"
31073+ "1: "__copyuser_seg" movl 32(%4), %%eax\n"
31074+ " cmpl $67, %0\n"
31075+ " jbe 3f\n"
31076+ "2: "__copyuser_seg" movl 64(%4), %%eax\n"
31077+ " .align 2,0x90\n"
31078+ "3: "__copyuser_seg" movl 0(%4), %%eax\n"
31079+ "4: "__copyuser_seg" movl 4(%4), %%edx\n"
31080+ "5: movl %%eax, 0(%3)\n"
31081+ "6: movl %%edx, 4(%3)\n"
31082+ "7: "__copyuser_seg" movl 8(%4), %%eax\n"
31083+ "8: "__copyuser_seg" movl 12(%4),%%edx\n"
31084+ "9: movl %%eax, 8(%3)\n"
31085+ "10: movl %%edx, 12(%3)\n"
31086+ "11: "__copyuser_seg" movl 16(%4), %%eax\n"
31087+ "12: "__copyuser_seg" movl 20(%4), %%edx\n"
31088+ "13: movl %%eax, 16(%3)\n"
31089+ "14: movl %%edx, 20(%3)\n"
31090+ "15: "__copyuser_seg" movl 24(%4), %%eax\n"
31091+ "16: "__copyuser_seg" movl 28(%4), %%edx\n"
31092+ "17: movl %%eax, 24(%3)\n"
31093+ "18: movl %%edx, 28(%3)\n"
31094+ "19: "__copyuser_seg" movl 32(%4), %%eax\n"
31095+ "20: "__copyuser_seg" movl 36(%4), %%edx\n"
31096+ "21: movl %%eax, 32(%3)\n"
31097+ "22: movl %%edx, 36(%3)\n"
31098+ "23: "__copyuser_seg" movl 40(%4), %%eax\n"
31099+ "24: "__copyuser_seg" movl 44(%4), %%edx\n"
31100+ "25: movl %%eax, 40(%3)\n"
31101+ "26: movl %%edx, 44(%3)\n"
31102+ "27: "__copyuser_seg" movl 48(%4), %%eax\n"
31103+ "28: "__copyuser_seg" movl 52(%4), %%edx\n"
31104+ "29: movl %%eax, 48(%3)\n"
31105+ "30: movl %%edx, 52(%3)\n"
31106+ "31: "__copyuser_seg" movl 56(%4), %%eax\n"
31107+ "32: "__copyuser_seg" movl 60(%4), %%edx\n"
31108+ "33: movl %%eax, 56(%3)\n"
31109+ "34: movl %%edx, 60(%3)\n"
31110+ " addl $-64, %0\n"
31111+ " addl $64, %4\n"
31112+ " addl $64, %3\n"
31113+ " cmpl $63, %0\n"
31114+ " ja 1b\n"
31115+ "35: movl %0, %%eax\n"
31116+ " shrl $2, %0\n"
31117+ " andl $3, %%eax\n"
31118+ " cld\n"
31119+ "99: rep; "__copyuser_seg" movsl\n"
31120+ "36: movl %%eax, %0\n"
31121+ "37: rep; "__copyuser_seg" movsb\n"
31122+ "100:\n"
31123 ".section .fixup,\"ax\"\n"
31124 "101: lea 0(%%eax,%0,4),%0\n"
31125 " jmp 100b\n"
31126@@ -207,41 +315,41 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
31127 int d0, d1;
31128 __asm__ __volatile__(
31129 " .align 2,0x90\n"
31130- "0: movl 32(%4), %%eax\n"
31131+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
31132 " cmpl $67, %0\n"
31133 " jbe 2f\n"
31134- "1: movl 64(%4), %%eax\n"
31135+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
31136 " .align 2,0x90\n"
31137- "2: movl 0(%4), %%eax\n"
31138- "21: movl 4(%4), %%edx\n"
31139+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
31140+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
31141 " movl %%eax, 0(%3)\n"
31142 " movl %%edx, 4(%3)\n"
31143- "3: movl 8(%4), %%eax\n"
31144- "31: movl 12(%4),%%edx\n"
31145+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
31146+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
31147 " movl %%eax, 8(%3)\n"
31148 " movl %%edx, 12(%3)\n"
31149- "4: movl 16(%4), %%eax\n"
31150- "41: movl 20(%4), %%edx\n"
31151+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
31152+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
31153 " movl %%eax, 16(%3)\n"
31154 " movl %%edx, 20(%3)\n"
31155- "10: movl 24(%4), %%eax\n"
31156- "51: movl 28(%4), %%edx\n"
31157+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
31158+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
31159 " movl %%eax, 24(%3)\n"
31160 " movl %%edx, 28(%3)\n"
31161- "11: movl 32(%4), %%eax\n"
31162- "61: movl 36(%4), %%edx\n"
31163+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
31164+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
31165 " movl %%eax, 32(%3)\n"
31166 " movl %%edx, 36(%3)\n"
31167- "12: movl 40(%4), %%eax\n"
31168- "71: movl 44(%4), %%edx\n"
31169+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
31170+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
31171 " movl %%eax, 40(%3)\n"
31172 " movl %%edx, 44(%3)\n"
31173- "13: movl 48(%4), %%eax\n"
31174- "81: movl 52(%4), %%edx\n"
31175+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
31176+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
31177 " movl %%eax, 48(%3)\n"
31178 " movl %%edx, 52(%3)\n"
31179- "14: movl 56(%4), %%eax\n"
31180- "91: movl 60(%4), %%edx\n"
31181+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
31182+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
31183 " movl %%eax, 56(%3)\n"
31184 " movl %%edx, 60(%3)\n"
31185 " addl $-64, %0\n"
31186@@ -253,9 +361,9 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
31187 " shrl $2, %0\n"
31188 " andl $3, %%eax\n"
31189 " cld\n"
31190- "6: rep; movsl\n"
31191+ "6: rep; "__copyuser_seg" movsl\n"
31192 " movl %%eax,%0\n"
31193- "7: rep; movsb\n"
31194+ "7: rep; "__copyuser_seg" movsb\n"
31195 "8:\n"
31196 ".section .fixup,\"ax\"\n"
31197 "9: lea 0(%%eax,%0,4),%0\n"
31198@@ -305,41 +413,41 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
31199
31200 __asm__ __volatile__(
31201 " .align 2,0x90\n"
31202- "0: movl 32(%4), %%eax\n"
31203+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
31204 " cmpl $67, %0\n"
31205 " jbe 2f\n"
31206- "1: movl 64(%4), %%eax\n"
31207+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
31208 " .align 2,0x90\n"
31209- "2: movl 0(%4), %%eax\n"
31210- "21: movl 4(%4), %%edx\n"
31211+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
31212+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
31213 " movnti %%eax, 0(%3)\n"
31214 " movnti %%edx, 4(%3)\n"
31215- "3: movl 8(%4), %%eax\n"
31216- "31: movl 12(%4),%%edx\n"
31217+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
31218+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
31219 " movnti %%eax, 8(%3)\n"
31220 " movnti %%edx, 12(%3)\n"
31221- "4: movl 16(%4), %%eax\n"
31222- "41: movl 20(%4), %%edx\n"
31223+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
31224+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
31225 " movnti %%eax, 16(%3)\n"
31226 " movnti %%edx, 20(%3)\n"
31227- "10: movl 24(%4), %%eax\n"
31228- "51: movl 28(%4), %%edx\n"
31229+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
31230+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
31231 " movnti %%eax, 24(%3)\n"
31232 " movnti %%edx, 28(%3)\n"
31233- "11: movl 32(%4), %%eax\n"
31234- "61: movl 36(%4), %%edx\n"
31235+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
31236+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
31237 " movnti %%eax, 32(%3)\n"
31238 " movnti %%edx, 36(%3)\n"
31239- "12: movl 40(%4), %%eax\n"
31240- "71: movl 44(%4), %%edx\n"
31241+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
31242+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
31243 " movnti %%eax, 40(%3)\n"
31244 " movnti %%edx, 44(%3)\n"
31245- "13: movl 48(%4), %%eax\n"
31246- "81: movl 52(%4), %%edx\n"
31247+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
31248+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
31249 " movnti %%eax, 48(%3)\n"
31250 " movnti %%edx, 52(%3)\n"
31251- "14: movl 56(%4), %%eax\n"
31252- "91: movl 60(%4), %%edx\n"
31253+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
31254+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
31255 " movnti %%eax, 56(%3)\n"
31256 " movnti %%edx, 60(%3)\n"
31257 " addl $-64, %0\n"
31258@@ -352,9 +460,9 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
31259 " shrl $2, %0\n"
31260 " andl $3, %%eax\n"
31261 " cld\n"
31262- "6: rep; movsl\n"
31263+ "6: rep; "__copyuser_seg" movsl\n"
31264 " movl %%eax,%0\n"
31265- "7: rep; movsb\n"
31266+ "7: rep; "__copyuser_seg" movsb\n"
31267 "8:\n"
31268 ".section .fixup,\"ax\"\n"
31269 "9: lea 0(%%eax,%0,4),%0\n"
31270@@ -399,41 +507,41 @@ static unsigned long __copy_user_intel_nocache(void *to,
31271
31272 __asm__ __volatile__(
31273 " .align 2,0x90\n"
31274- "0: movl 32(%4), %%eax\n"
31275+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
31276 " cmpl $67, %0\n"
31277 " jbe 2f\n"
31278- "1: movl 64(%4), %%eax\n"
31279+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
31280 " .align 2,0x90\n"
31281- "2: movl 0(%4), %%eax\n"
31282- "21: movl 4(%4), %%edx\n"
31283+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
31284+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
31285 " movnti %%eax, 0(%3)\n"
31286 " movnti %%edx, 4(%3)\n"
31287- "3: movl 8(%4), %%eax\n"
31288- "31: movl 12(%4),%%edx\n"
31289+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
31290+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
31291 " movnti %%eax, 8(%3)\n"
31292 " movnti %%edx, 12(%3)\n"
31293- "4: movl 16(%4), %%eax\n"
31294- "41: movl 20(%4), %%edx\n"
31295+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
31296+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
31297 " movnti %%eax, 16(%3)\n"
31298 " movnti %%edx, 20(%3)\n"
31299- "10: movl 24(%4), %%eax\n"
31300- "51: movl 28(%4), %%edx\n"
31301+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
31302+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
31303 " movnti %%eax, 24(%3)\n"
31304 " movnti %%edx, 28(%3)\n"
31305- "11: movl 32(%4), %%eax\n"
31306- "61: movl 36(%4), %%edx\n"
31307+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
31308+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
31309 " movnti %%eax, 32(%3)\n"
31310 " movnti %%edx, 36(%3)\n"
31311- "12: movl 40(%4), %%eax\n"
31312- "71: movl 44(%4), %%edx\n"
31313+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
31314+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
31315 " movnti %%eax, 40(%3)\n"
31316 " movnti %%edx, 44(%3)\n"
31317- "13: movl 48(%4), %%eax\n"
31318- "81: movl 52(%4), %%edx\n"
31319+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
31320+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
31321 " movnti %%eax, 48(%3)\n"
31322 " movnti %%edx, 52(%3)\n"
31323- "14: movl 56(%4), %%eax\n"
31324- "91: movl 60(%4), %%edx\n"
31325+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
31326+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
31327 " movnti %%eax, 56(%3)\n"
31328 " movnti %%edx, 60(%3)\n"
31329 " addl $-64, %0\n"
31330@@ -446,9 +554,9 @@ static unsigned long __copy_user_intel_nocache(void *to,
31331 " shrl $2, %0\n"
31332 " andl $3, %%eax\n"
31333 " cld\n"
31334- "6: rep; movsl\n"
31335+ "6: rep; "__copyuser_seg" movsl\n"
31336 " movl %%eax,%0\n"
31337- "7: rep; movsb\n"
31338+ "7: rep; "__copyuser_seg" movsb\n"
31339 "8:\n"
31340 ".section .fixup,\"ax\"\n"
31341 "9: lea 0(%%eax,%0,4),%0\n"
31342@@ -488,32 +596,36 @@ static unsigned long __copy_user_intel_nocache(void *to,
31343 */
31344 unsigned long __copy_user_zeroing_intel(void *to, const void __user *from,
31345 unsigned long size);
31346-unsigned long __copy_user_intel(void __user *to, const void *from,
31347+unsigned long __generic_copy_to_user_intel(void __user *to, const void *from,
31348+ unsigned long size);
31349+unsigned long __generic_copy_from_user_intel(void *to, const void __user *from,
31350 unsigned long size);
31351 unsigned long __copy_user_zeroing_intel_nocache(void *to,
31352 const void __user *from, unsigned long size);
31353 #endif /* CONFIG_X86_INTEL_USERCOPY */
31354
31355 /* Generic arbitrary sized copy. */
31356-#define __copy_user(to, from, size) \
31357+#define __copy_user(to, from, size, prefix, set, restore) \
31358 do { \
31359 int __d0, __d1, __d2; \
31360 __asm__ __volatile__( \
31361+ set \
31362 " cmp $7,%0\n" \
31363 " jbe 1f\n" \
31364 " movl %1,%0\n" \
31365 " negl %0\n" \
31366 " andl $7,%0\n" \
31367 " subl %0,%3\n" \
31368- "4: rep; movsb\n" \
31369+ "4: rep; "prefix"movsb\n" \
31370 " movl %3,%0\n" \
31371 " shrl $2,%0\n" \
31372 " andl $3,%3\n" \
31373 " .align 2,0x90\n" \
31374- "0: rep; movsl\n" \
31375+ "0: rep; "prefix"movsl\n" \
31376 " movl %3,%0\n" \
31377- "1: rep; movsb\n" \
31378+ "1: rep; "prefix"movsb\n" \
31379 "2:\n" \
31380+ restore \
31381 ".section .fixup,\"ax\"\n" \
31382 "5: addl %3,%0\n" \
31383 " jmp 2b\n" \
31384@@ -538,14 +650,14 @@ do { \
31385 " negl %0\n" \
31386 " andl $7,%0\n" \
31387 " subl %0,%3\n" \
31388- "4: rep; movsb\n" \
31389+ "4: rep; "__copyuser_seg"movsb\n" \
31390 " movl %3,%0\n" \
31391 " shrl $2,%0\n" \
31392 " andl $3,%3\n" \
31393 " .align 2,0x90\n" \
31394- "0: rep; movsl\n" \
31395+ "0: rep; "__copyuser_seg"movsl\n" \
31396 " movl %3,%0\n" \
31397- "1: rep; movsb\n" \
31398+ "1: rep; "__copyuser_seg"movsb\n" \
31399 "2:\n" \
31400 ".section .fixup,\"ax\"\n" \
31401 "5: addl %3,%0\n" \
31402@@ -572,9 +684,9 @@ unsigned long __copy_to_user_ll(void __user *to, const void *from,
31403 {
31404 stac();
31405 if (movsl_is_ok(to, from, n))
31406- __copy_user(to, from, n);
31407+ __copy_user(to, from, n, "", __COPYUSER_SET_ES, __COPYUSER_RESTORE_ES);
31408 else
31409- n = __copy_user_intel(to, from, n);
31410+ n = __generic_copy_to_user_intel(to, from, n);
31411 clac();
31412 return n;
31413 }
31414@@ -598,10 +710,9 @@ unsigned long __copy_from_user_ll_nozero(void *to, const void __user *from,
31415 {
31416 stac();
31417 if (movsl_is_ok(to, from, n))
31418- __copy_user(to, from, n);
31419+ __copy_user(to, from, n, __copyuser_seg, "", "");
31420 else
31421- n = __copy_user_intel((void __user *)to,
31422- (const void *)from, n);
31423+ n = __generic_copy_from_user_intel(to, from, n);
31424 clac();
31425 return n;
31426 }
31427@@ -632,58 +743,38 @@ unsigned long __copy_from_user_ll_nocache_nozero(void *to, const void __user *fr
31428 if (n > 64 && cpu_has_xmm2)
31429 n = __copy_user_intel_nocache(to, from, n);
31430 else
31431- __copy_user(to, from, n);
31432+ __copy_user(to, from, n, __copyuser_seg, "", "");
31433 #else
31434- __copy_user(to, from, n);
31435+ __copy_user(to, from, n, __copyuser_seg, "", "");
31436 #endif
31437 clac();
31438 return n;
31439 }
31440 EXPORT_SYMBOL(__copy_from_user_ll_nocache_nozero);
31441
31442-/**
31443- * copy_to_user: - Copy a block of data into user space.
31444- * @to: Destination address, in user space.
31445- * @from: Source address, in kernel space.
31446- * @n: Number of bytes to copy.
31447- *
31448- * Context: User context only. This function may sleep.
31449- *
31450- * Copy data from kernel space to user space.
31451- *
31452- * Returns number of bytes that could not be copied.
31453- * On success, this will be zero.
31454- */
31455-unsigned long _copy_to_user(void __user *to, const void *from, unsigned n)
31456+#ifdef CONFIG_PAX_MEMORY_UDEREF
31457+void __set_fs(mm_segment_t x)
31458 {
31459- if (access_ok(VERIFY_WRITE, to, n))
31460- n = __copy_to_user(to, from, n);
31461- return n;
31462+ switch (x.seg) {
31463+ case 0:
31464+ loadsegment(gs, 0);
31465+ break;
31466+ case TASK_SIZE_MAX:
31467+ loadsegment(gs, __USER_DS);
31468+ break;
31469+ case -1UL:
31470+ loadsegment(gs, __KERNEL_DS);
31471+ break;
31472+ default:
31473+ BUG();
31474+ }
31475 }
31476-EXPORT_SYMBOL(_copy_to_user);
31477+EXPORT_SYMBOL(__set_fs);
31478
31479-/**
31480- * copy_from_user: - Copy a block of data from user space.
31481- * @to: Destination address, in kernel space.
31482- * @from: Source address, in user space.
31483- * @n: Number of bytes to copy.
31484- *
31485- * Context: User context only. This function may sleep.
31486- *
31487- * Copy data from user space to kernel space.
31488- *
31489- * Returns number of bytes that could not be copied.
31490- * On success, this will be zero.
31491- *
31492- * If some data could not be copied, this function will pad the copied
31493- * data to the requested size using zero bytes.
31494- */
31495-unsigned long _copy_from_user(void *to, const void __user *from, unsigned n)
31496+void set_fs(mm_segment_t x)
31497 {
31498- if (access_ok(VERIFY_READ, from, n))
31499- n = __copy_from_user(to, from, n);
31500- else
31501- memset(to, 0, n);
31502- return n;
31503+ current_thread_info()->addr_limit = x;
31504+ __set_fs(x);
31505 }
31506-EXPORT_SYMBOL(_copy_from_user);
31507+EXPORT_SYMBOL(set_fs);
31508+#endif
31509diff --git a/arch/x86/lib/usercopy_64.c b/arch/x86/lib/usercopy_64.c
31510index c905e89..01ab928 100644
31511--- a/arch/x86/lib/usercopy_64.c
31512+++ b/arch/x86/lib/usercopy_64.c
31513@@ -18,6 +18,7 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
31514 might_fault();
31515 /* no memory constraint because it doesn't change any memory gcc knows
31516 about */
31517+ pax_open_userland();
31518 stac();
31519 asm volatile(
31520 " testq %[size8],%[size8]\n"
31521@@ -39,9 +40,10 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
31522 _ASM_EXTABLE(0b,3b)
31523 _ASM_EXTABLE(1b,2b)
31524 : [size8] "=&c"(size), [dst] "=&D" (__d0)
31525- : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(addr),
31526+ : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(____m(addr)),
31527 [zero] "r" (0UL), [eight] "r" (8UL));
31528 clac();
31529+ pax_close_userland();
31530 return size;
31531 }
31532 EXPORT_SYMBOL(__clear_user);
31533@@ -54,12 +56,11 @@ unsigned long clear_user(void __user *to, unsigned long n)
31534 }
31535 EXPORT_SYMBOL(clear_user);
31536
31537-unsigned long copy_in_user(void __user *to, const void __user *from, unsigned len)
31538+unsigned long copy_in_user(void __user *to, const void __user *from, unsigned long len)
31539 {
31540- if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
31541- return copy_user_generic((__force void *)to, (__force void *)from, len);
31542- }
31543- return len;
31544+ if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len))
31545+ return copy_user_generic((void __force_kernel *)____m(to), (void __force_kernel *)____m(from), len);
31546+ return len;
31547 }
31548 EXPORT_SYMBOL(copy_in_user);
31549
31550@@ -69,11 +70,13 @@ EXPORT_SYMBOL(copy_in_user);
31551 * it is not necessary to optimize tail handling.
31552 */
31553 __visible unsigned long
31554-copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
31555+copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest)
31556 {
31557 char c;
31558 unsigned zero_len;
31559
31560+ clac();
31561+ pax_close_userland();
31562 for (; len; --len, to++) {
31563 if (__get_user_nocheck(c, from++, sizeof(char)))
31564 break;
31565@@ -84,6 +87,5 @@ copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
31566 for (c = 0, zero_len = len; zerorest && zero_len; --zero_len)
31567 if (__put_user_nocheck(c, to++, sizeof(char)))
31568 break;
31569- clac();
31570 return len;
31571 }
31572diff --git a/arch/x86/mm/Makefile b/arch/x86/mm/Makefile
31573index 6a19ad9..1c48f9a 100644
31574--- a/arch/x86/mm/Makefile
31575+++ b/arch/x86/mm/Makefile
31576@@ -30,3 +30,7 @@ obj-$(CONFIG_ACPI_NUMA) += srat.o
31577 obj-$(CONFIG_NUMA_EMU) += numa_emulation.o
31578
31579 obj-$(CONFIG_MEMTEST) += memtest.o
31580+
31581+quote:="
31582+obj-$(CONFIG_X86_64) += uderef_64.o
31583+CFLAGS_uderef_64.o := $(subst $(quote),,$(CONFIG_ARCH_HWEIGHT_CFLAGS))
31584diff --git a/arch/x86/mm/extable.c b/arch/x86/mm/extable.c
31585index 903ec1e..c4166b2 100644
31586--- a/arch/x86/mm/extable.c
31587+++ b/arch/x86/mm/extable.c
31588@@ -6,12 +6,24 @@
31589 static inline unsigned long
31590 ex_insn_addr(const struct exception_table_entry *x)
31591 {
31592- return (unsigned long)&x->insn + x->insn;
31593+ unsigned long reloc = 0;
31594+
31595+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
31596+ reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
31597+#endif
31598+
31599+ return (unsigned long)&x->insn + x->insn + reloc;
31600 }
31601 static inline unsigned long
31602 ex_fixup_addr(const struct exception_table_entry *x)
31603 {
31604- return (unsigned long)&x->fixup + x->fixup;
31605+ unsigned long reloc = 0;
31606+
31607+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
31608+ reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
31609+#endif
31610+
31611+ return (unsigned long)&x->fixup + x->fixup + reloc;
31612 }
31613
31614 int fixup_exception(struct pt_regs *regs)
31615@@ -20,7 +32,7 @@ int fixup_exception(struct pt_regs *regs)
31616 unsigned long new_ip;
31617
31618 #ifdef CONFIG_PNPBIOS
31619- if (unlikely(SEGMENT_IS_PNP_CODE(regs->cs))) {
31620+ if (unlikely(!v8086_mode(regs) && SEGMENT_IS_PNP_CODE(regs->cs))) {
31621 extern u32 pnp_bios_fault_eip, pnp_bios_fault_esp;
31622 extern u32 pnp_bios_is_utter_crap;
31623 pnp_bios_is_utter_crap = 1;
31624@@ -145,6 +157,13 @@ void sort_extable(struct exception_table_entry *start,
31625 i += 4;
31626 p->fixup -= i;
31627 i += 4;
31628+
31629+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
31630+ BUILD_BUG_ON(!IS_ENABLED(CONFIG_BUILDTIME_EXTABLE_SORT));
31631+ p->insn -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
31632+ p->fixup -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
31633+#endif
31634+
31635 }
31636 }
31637
31638diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c
31639index a10c8c7..35a5abb 100644
31640--- a/arch/x86/mm/fault.c
31641+++ b/arch/x86/mm/fault.c
31642@@ -14,11 +14,18 @@
31643 #include <linux/hugetlb.h> /* hstate_index_to_shift */
31644 #include <linux/prefetch.h> /* prefetchw */
31645 #include <linux/context_tracking.h> /* exception_enter(), ... */
31646+#include <linux/unistd.h>
31647+#include <linux/compiler.h>
31648
31649 #include <asm/traps.h> /* dotraplinkage, ... */
31650 #include <asm/pgalloc.h> /* pgd_*(), ... */
31651 #include <asm/kmemcheck.h> /* kmemcheck_*(), ... */
31652 #include <asm/fixmap.h> /* VSYSCALL_START */
31653+#include <asm/tlbflush.h>
31654+
31655+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
31656+#include <asm/stacktrace.h>
31657+#endif
31658
31659 #define CREATE_TRACE_POINTS
31660 #include <asm/trace/exceptions.h>
31661@@ -59,7 +66,7 @@ static inline int __kprobes kprobes_fault(struct pt_regs *regs)
31662 int ret = 0;
31663
31664 /* kprobe_running() needs smp_processor_id() */
31665- if (kprobes_built_in() && !user_mode_vm(regs)) {
31666+ if (kprobes_built_in() && !user_mode(regs)) {
31667 preempt_disable();
31668 if (kprobe_running() && kprobe_fault_handler(regs, 14))
31669 ret = 1;
31670@@ -120,7 +127,10 @@ check_prefetch_opcode(struct pt_regs *regs, unsigned char *instr,
31671 return !instr_lo || (instr_lo>>1) == 1;
31672 case 0x00:
31673 /* Prefetch instruction is 0x0F0D or 0x0F18 */
31674- if (probe_kernel_address(instr, opcode))
31675+ if (user_mode(regs)) {
31676+ if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
31677+ return 0;
31678+ } else if (probe_kernel_address(instr, opcode))
31679 return 0;
31680
31681 *prefetch = (instr_lo == 0xF) &&
31682@@ -154,7 +164,10 @@ is_prefetch(struct pt_regs *regs, unsigned long error_code, unsigned long addr)
31683 while (instr < max_instr) {
31684 unsigned char opcode;
31685
31686- if (probe_kernel_address(instr, opcode))
31687+ if (user_mode(regs)) {
31688+ if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
31689+ break;
31690+ } else if (probe_kernel_address(instr, opcode))
31691 break;
31692
31693 instr++;
31694@@ -185,6 +198,34 @@ force_sig_info_fault(int si_signo, int si_code, unsigned long address,
31695 force_sig_info(si_signo, &info, tsk);
31696 }
31697
31698+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
31699+static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address);
31700+#endif
31701+
31702+#ifdef CONFIG_PAX_EMUTRAMP
31703+static int pax_handle_fetch_fault(struct pt_regs *regs);
31704+#endif
31705+
31706+#ifdef CONFIG_PAX_PAGEEXEC
31707+static inline pmd_t * pax_get_pmd(struct mm_struct *mm, unsigned long address)
31708+{
31709+ pgd_t *pgd;
31710+ pud_t *pud;
31711+ pmd_t *pmd;
31712+
31713+ pgd = pgd_offset(mm, address);
31714+ if (!pgd_present(*pgd))
31715+ return NULL;
31716+ pud = pud_offset(pgd, address);
31717+ if (!pud_present(*pud))
31718+ return NULL;
31719+ pmd = pmd_offset(pud, address);
31720+ if (!pmd_present(*pmd))
31721+ return NULL;
31722+ return pmd;
31723+}
31724+#endif
31725+
31726 DEFINE_SPINLOCK(pgd_lock);
31727 LIST_HEAD(pgd_list);
31728
31729@@ -235,10 +276,27 @@ void vmalloc_sync_all(void)
31730 for (address = VMALLOC_START & PMD_MASK;
31731 address >= TASK_SIZE && address < FIXADDR_TOP;
31732 address += PMD_SIZE) {
31733+
31734+#ifdef CONFIG_PAX_PER_CPU_PGD
31735+ unsigned long cpu;
31736+#else
31737 struct page *page;
31738+#endif
31739
31740 spin_lock(&pgd_lock);
31741+
31742+#ifdef CONFIG_PAX_PER_CPU_PGD
31743+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
31744+ pgd_t *pgd = get_cpu_pgd(cpu, user);
31745+ pmd_t *ret;
31746+
31747+ ret = vmalloc_sync_one(pgd, address);
31748+ if (!ret)
31749+ break;
31750+ pgd = get_cpu_pgd(cpu, kernel);
31751+#else
31752 list_for_each_entry(page, &pgd_list, lru) {
31753+ pgd_t *pgd;
31754 spinlock_t *pgt_lock;
31755 pmd_t *ret;
31756
31757@@ -246,8 +304,14 @@ void vmalloc_sync_all(void)
31758 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
31759
31760 spin_lock(pgt_lock);
31761- ret = vmalloc_sync_one(page_address(page), address);
31762+ pgd = page_address(page);
31763+#endif
31764+
31765+ ret = vmalloc_sync_one(pgd, address);
31766+
31767+#ifndef CONFIG_PAX_PER_CPU_PGD
31768 spin_unlock(pgt_lock);
31769+#endif
31770
31771 if (!ret)
31772 break;
31773@@ -281,6 +345,12 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
31774 * an interrupt in the middle of a task switch..
31775 */
31776 pgd_paddr = read_cr3();
31777+
31778+#ifdef CONFIG_PAX_PER_CPU_PGD
31779+ BUG_ON(__pa(get_cpu_pgd(smp_processor_id(), kernel)) != (pgd_paddr & __PHYSICAL_MASK));
31780+ vmalloc_sync_one(__va(pgd_paddr + PAGE_SIZE), address);
31781+#endif
31782+
31783 pmd_k = vmalloc_sync_one(__va(pgd_paddr), address);
31784 if (!pmd_k)
31785 return -1;
31786@@ -376,11 +446,25 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
31787 * happen within a race in page table update. In the later
31788 * case just flush:
31789 */
31790- pgd = pgd_offset(current->active_mm, address);
31791+
31792 pgd_ref = pgd_offset_k(address);
31793 if (pgd_none(*pgd_ref))
31794 return -1;
31795
31796+#ifdef CONFIG_PAX_PER_CPU_PGD
31797+ BUG_ON(__pa(get_cpu_pgd(smp_processor_id(), kernel)) != (read_cr3() & __PHYSICAL_MASK));
31798+ pgd = pgd_offset_cpu(smp_processor_id(), user, address);
31799+ if (pgd_none(*pgd)) {
31800+ set_pgd(pgd, *pgd_ref);
31801+ arch_flush_lazy_mmu_mode();
31802+ } else {
31803+ BUG_ON(pgd_page_vaddr(*pgd) != pgd_page_vaddr(*pgd_ref));
31804+ }
31805+ pgd = pgd_offset_cpu(smp_processor_id(), kernel, address);
31806+#else
31807+ pgd = pgd_offset(current->active_mm, address);
31808+#endif
31809+
31810 if (pgd_none(*pgd)) {
31811 set_pgd(pgd, *pgd_ref);
31812 arch_flush_lazy_mmu_mode();
31813@@ -546,7 +630,7 @@ static int is_errata93(struct pt_regs *regs, unsigned long address)
31814 static int is_errata100(struct pt_regs *regs, unsigned long address)
31815 {
31816 #ifdef CONFIG_X86_64
31817- if ((regs->cs == __USER32_CS || (regs->cs & (1<<2))) && (address >> 32))
31818+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)) && (address >> 32))
31819 return 1;
31820 #endif
31821 return 0;
31822@@ -573,7 +657,7 @@ static int is_f00f_bug(struct pt_regs *regs, unsigned long address)
31823 }
31824
31825 static const char nx_warning[] = KERN_CRIT
31826-"kernel tried to execute NX-protected page - exploit attempt? (uid: %d)\n";
31827+"kernel tried to execute NX-protected page - exploit attempt? (uid: %d, task: %s, pid: %d)\n";
31828
31829 static void
31830 show_fault_oops(struct pt_regs *regs, unsigned long error_code,
31831@@ -582,15 +666,27 @@ show_fault_oops(struct pt_regs *regs, unsigned long error_code,
31832 if (!oops_may_print())
31833 return;
31834
31835- if (error_code & PF_INSTR) {
31836+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR)) {
31837 unsigned int level;
31838
31839 pte_t *pte = lookup_address(address, &level);
31840
31841 if (pte && pte_present(*pte) && !pte_exec(*pte))
31842- printk(nx_warning, from_kuid(&init_user_ns, current_uid()));
31843+ printk(nx_warning, from_kuid_munged(&init_user_ns, current_uid()), current->comm, task_pid_nr(current));
31844 }
31845
31846+#ifdef CONFIG_PAX_KERNEXEC
31847+ if (init_mm.start_code <= address && address < init_mm.end_code) {
31848+ if (current->signal->curr_ip)
31849+ printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
31850+ &current->signal->curr_ip, current->comm, task_pid_nr(current),
31851+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
31852+ else
31853+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n", current->comm, task_pid_nr(current),
31854+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
31855+ }
31856+#endif
31857+
31858 printk(KERN_ALERT "BUG: unable to handle kernel ");
31859 if (address < PAGE_SIZE)
31860 printk(KERN_CONT "NULL pointer dereference");
31861@@ -771,6 +867,22 @@ __bad_area_nosemaphore(struct pt_regs *regs, unsigned long error_code,
31862 return;
31863 }
31864 #endif
31865+
31866+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
31867+ if (pax_is_fetch_fault(regs, error_code, address)) {
31868+
31869+#ifdef CONFIG_PAX_EMUTRAMP
31870+ switch (pax_handle_fetch_fault(regs)) {
31871+ case 2:
31872+ return;
31873+ }
31874+#endif
31875+
31876+ pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
31877+ do_group_exit(SIGKILL);
31878+ }
31879+#endif
31880+
31881 /* Kernel addresses are always protection faults: */
31882 if (address >= TASK_SIZE)
31883 error_code |= PF_PROT;
31884@@ -856,7 +968,7 @@ do_sigbus(struct pt_regs *regs, unsigned long error_code, unsigned long address,
31885 if (fault & (VM_FAULT_HWPOISON|VM_FAULT_HWPOISON_LARGE)) {
31886 printk(KERN_ERR
31887 "MCE: Killing %s:%d due to hardware memory corruption fault at %lx\n",
31888- tsk->comm, tsk->pid, address);
31889+ tsk->comm, task_pid_nr(tsk), address);
31890 code = BUS_MCEERR_AR;
31891 }
31892 #endif
31893@@ -910,6 +1022,99 @@ static int spurious_fault_check(unsigned long error_code, pte_t *pte)
31894 return 1;
31895 }
31896
31897+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
31898+static int pax_handle_pageexec_fault(struct pt_regs *regs, struct mm_struct *mm, unsigned long address, unsigned long error_code)
31899+{
31900+ pte_t *pte;
31901+ pmd_t *pmd;
31902+ spinlock_t *ptl;
31903+ unsigned char pte_mask;
31904+
31905+ if ((__supported_pte_mask & _PAGE_NX) || (error_code & (PF_PROT|PF_USER)) != (PF_PROT|PF_USER) || v8086_mode(regs) ||
31906+ !(mm->pax_flags & MF_PAX_PAGEEXEC))
31907+ return 0;
31908+
31909+ /* PaX: it's our fault, let's handle it if we can */
31910+
31911+ /* PaX: take a look at read faults before acquiring any locks */
31912+ if (unlikely(!(error_code & PF_WRITE) && (regs->ip == address))) {
31913+ /* instruction fetch attempt from a protected page in user mode */
31914+ up_read(&mm->mmap_sem);
31915+
31916+#ifdef CONFIG_PAX_EMUTRAMP
31917+ switch (pax_handle_fetch_fault(regs)) {
31918+ case 2:
31919+ return 1;
31920+ }
31921+#endif
31922+
31923+ pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
31924+ do_group_exit(SIGKILL);
31925+ }
31926+
31927+ pmd = pax_get_pmd(mm, address);
31928+ if (unlikely(!pmd))
31929+ return 0;
31930+
31931+ pte = pte_offset_map_lock(mm, pmd, address, &ptl);
31932+ if (unlikely(!(pte_val(*pte) & _PAGE_PRESENT) || pte_user(*pte))) {
31933+ pte_unmap_unlock(pte, ptl);
31934+ return 0;
31935+ }
31936+
31937+ if (unlikely((error_code & PF_WRITE) && !pte_write(*pte))) {
31938+ /* write attempt to a protected page in user mode */
31939+ pte_unmap_unlock(pte, ptl);
31940+ return 0;
31941+ }
31942+
31943+#ifdef CONFIG_SMP
31944+ if (likely(address > get_limit(regs->cs) && cpu_isset(smp_processor_id(), mm->context.cpu_user_cs_mask)))
31945+#else
31946+ if (likely(address > get_limit(regs->cs)))
31947+#endif
31948+ {
31949+ set_pte(pte, pte_mkread(*pte));
31950+ __flush_tlb_one(address);
31951+ pte_unmap_unlock(pte, ptl);
31952+ up_read(&mm->mmap_sem);
31953+ return 1;
31954+ }
31955+
31956+ pte_mask = _PAGE_ACCESSED | _PAGE_USER | ((error_code & PF_WRITE) << (_PAGE_BIT_DIRTY-1));
31957+
31958+ /*
31959+ * PaX: fill DTLB with user rights and retry
31960+ */
31961+ __asm__ __volatile__ (
31962+ "orb %2,(%1)\n"
31963+#if defined(CONFIG_M586) || defined(CONFIG_M586TSC)
31964+/*
31965+ * PaX: let this uncommented 'invlpg' remind us on the behaviour of Intel's
31966+ * (and AMD's) TLBs. namely, they do not cache PTEs that would raise *any*
31967+ * page fault when examined during a TLB load attempt. this is true not only
31968+ * for PTEs holding a non-present entry but also present entries that will
31969+ * raise a page fault (such as those set up by PaX, or the copy-on-write
31970+ * mechanism). in effect it means that we do *not* need to flush the TLBs
31971+ * for our target pages since their PTEs are simply not in the TLBs at all.
31972+
31973+ * the best thing in omitting it is that we gain around 15-20% speed in the
31974+ * fast path of the page fault handler and can get rid of tracing since we
31975+ * can no longer flush unintended entries.
31976+ */
31977+ "invlpg (%0)\n"
31978+#endif
31979+ __copyuser_seg"testb $0,(%0)\n"
31980+ "xorb %3,(%1)\n"
31981+ :
31982+ : "r" (address), "r" (pte), "q" (pte_mask), "i" (_PAGE_USER)
31983+ : "memory", "cc");
31984+ pte_unmap_unlock(pte, ptl);
31985+ up_read(&mm->mmap_sem);
31986+ return 1;
31987+}
31988+#endif
31989+
31990 /*
31991 * Handle a spurious fault caused by a stale TLB entry.
31992 *
31993@@ -976,6 +1181,9 @@ int show_unhandled_signals = 1;
31994 static inline int
31995 access_error(unsigned long error_code, struct vm_area_struct *vma)
31996 {
31997+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR) && !(vma->vm_flags & VM_EXEC))
31998+ return 1;
31999+
32000 if (error_code & PF_WRITE) {
32001 /* write, present and write, not present: */
32002 if (unlikely(!(vma->vm_flags & VM_WRITE)))
32003@@ -1010,7 +1218,7 @@ static inline bool smap_violation(int error_code, struct pt_regs *regs)
32004 if (error_code & PF_USER)
32005 return false;
32006
32007- if (!user_mode_vm(regs) && (regs->flags & X86_EFLAGS_AC))
32008+ if (!user_mode(regs) && (regs->flags & X86_EFLAGS_AC))
32009 return false;
32010
32011 return true;
32012@@ -1038,6 +1246,22 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code,
32013 tsk = current;
32014 mm = tsk->mm;
32015
32016+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
32017+ if (!user_mode(regs) && address < 2 * pax_user_shadow_base) {
32018+ if (!search_exception_tables(regs->ip)) {
32019+ printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
32020+ bad_area_nosemaphore(regs, error_code, address);
32021+ return;
32022+ }
32023+ if (address < pax_user_shadow_base) {
32024+ printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
32025+ printk(KERN_ERR "PAX: faulting IP: %pS\n", (void *)regs->ip);
32026+ show_trace_log_lvl(NULL, NULL, (void *)regs->sp, regs->bp, KERN_ERR);
32027+ } else
32028+ address -= pax_user_shadow_base;
32029+ }
32030+#endif
32031+
32032 /*
32033 * Detect and handle instructions that would cause a page fault for
32034 * both a tracked kernel page and a userspace page.
32035@@ -1115,7 +1339,7 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code,
32036 * User-mode registers count as a user access even for any
32037 * potential system fault or CPU buglet:
32038 */
32039- if (user_mode_vm(regs)) {
32040+ if (user_mode(regs)) {
32041 local_irq_enable();
32042 error_code |= PF_USER;
32043 flags |= FAULT_FLAG_USER;
32044@@ -1162,6 +1386,11 @@ retry:
32045 might_sleep();
32046 }
32047
32048+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
32049+ if (pax_handle_pageexec_fault(regs, mm, address, error_code))
32050+ return;
32051+#endif
32052+
32053 vma = find_vma(mm, address);
32054 if (unlikely(!vma)) {
32055 bad_area(regs, error_code, address);
32056@@ -1173,18 +1402,24 @@ retry:
32057 bad_area(regs, error_code, address);
32058 return;
32059 }
32060- if (error_code & PF_USER) {
32061- /*
32062- * Accessing the stack below %sp is always a bug.
32063- * The large cushion allows instructions like enter
32064- * and pusha to work. ("enter $65535, $31" pushes
32065- * 32 pointers and then decrements %sp by 65535.)
32066- */
32067- if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < regs->sp)) {
32068- bad_area(regs, error_code, address);
32069- return;
32070- }
32071+ /*
32072+ * Accessing the stack below %sp is always a bug.
32073+ * The large cushion allows instructions like enter
32074+ * and pusha to work. ("enter $65535, $31" pushes
32075+ * 32 pointers and then decrements %sp by 65535.)
32076+ */
32077+ if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < task_pt_regs(tsk)->sp)) {
32078+ bad_area(regs, error_code, address);
32079+ return;
32080 }
32081+
32082+#ifdef CONFIG_PAX_SEGMEXEC
32083+ if (unlikely((mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end - SEGMEXEC_TASK_SIZE - 1 < address - SEGMEXEC_TASK_SIZE - 1)) {
32084+ bad_area(regs, error_code, address);
32085+ return;
32086+ }
32087+#endif
32088+
32089 if (unlikely(expand_stack(vma, address))) {
32090 bad_area(regs, error_code, address);
32091 return;
32092@@ -1296,3 +1531,292 @@ trace_do_page_fault(struct pt_regs *regs, unsigned long error_code)
32093 exception_exit(prev_state);
32094 }
32095 #endif /* CONFIG_TRACING */
32096+
32097+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
32098+static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address)
32099+{
32100+ struct mm_struct *mm = current->mm;
32101+ unsigned long ip = regs->ip;
32102+
32103+ if (v8086_mode(regs))
32104+ ip = ((regs->cs & 0xffff) << 4) + (ip & 0xffff);
32105+
32106+#ifdef CONFIG_PAX_PAGEEXEC
32107+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
32108+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR))
32109+ return true;
32110+ if (!(error_code & (PF_PROT | PF_WRITE)) && ip == address)
32111+ return true;
32112+ return false;
32113+ }
32114+#endif
32115+
32116+#ifdef CONFIG_PAX_SEGMEXEC
32117+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
32118+ if (!(error_code & (PF_PROT | PF_WRITE)) && (ip + SEGMEXEC_TASK_SIZE == address))
32119+ return true;
32120+ return false;
32121+ }
32122+#endif
32123+
32124+ return false;
32125+}
32126+#endif
32127+
32128+#ifdef CONFIG_PAX_EMUTRAMP
32129+static int pax_handle_fetch_fault_32(struct pt_regs *regs)
32130+{
32131+ int err;
32132+
32133+ do { /* PaX: libffi trampoline emulation */
32134+ unsigned char mov, jmp;
32135+ unsigned int addr1, addr2;
32136+
32137+#ifdef CONFIG_X86_64
32138+ if ((regs->ip + 9) >> 32)
32139+ break;
32140+#endif
32141+
32142+ err = get_user(mov, (unsigned char __user *)regs->ip);
32143+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
32144+ err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
32145+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
32146+
32147+ if (err)
32148+ break;
32149+
32150+ if (mov == 0xB8 && jmp == 0xE9) {
32151+ regs->ax = addr1;
32152+ regs->ip = (unsigned int)(regs->ip + addr2 + 10);
32153+ return 2;
32154+ }
32155+ } while (0);
32156+
32157+ do { /* PaX: gcc trampoline emulation #1 */
32158+ unsigned char mov1, mov2;
32159+ unsigned short jmp;
32160+ unsigned int addr1, addr2;
32161+
32162+#ifdef CONFIG_X86_64
32163+ if ((regs->ip + 11) >> 32)
32164+ break;
32165+#endif
32166+
32167+ err = get_user(mov1, (unsigned char __user *)regs->ip);
32168+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
32169+ err |= get_user(mov2, (unsigned char __user *)(regs->ip + 5));
32170+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
32171+ err |= get_user(jmp, (unsigned short __user *)(regs->ip + 10));
32172+
32173+ if (err)
32174+ break;
32175+
32176+ if (mov1 == 0xB9 && mov2 == 0xB8 && jmp == 0xE0FF) {
32177+ regs->cx = addr1;
32178+ regs->ax = addr2;
32179+ regs->ip = addr2;
32180+ return 2;
32181+ }
32182+ } while (0);
32183+
32184+ do { /* PaX: gcc trampoline emulation #2 */
32185+ unsigned char mov, jmp;
32186+ unsigned int addr1, addr2;
32187+
32188+#ifdef CONFIG_X86_64
32189+ if ((regs->ip + 9) >> 32)
32190+ break;
32191+#endif
32192+
32193+ err = get_user(mov, (unsigned char __user *)regs->ip);
32194+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
32195+ err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
32196+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
32197+
32198+ if (err)
32199+ break;
32200+
32201+ if (mov == 0xB9 && jmp == 0xE9) {
32202+ regs->cx = addr1;
32203+ regs->ip = (unsigned int)(regs->ip + addr2 + 10);
32204+ return 2;
32205+ }
32206+ } while (0);
32207+
32208+ return 1; /* PaX in action */
32209+}
32210+
32211+#ifdef CONFIG_X86_64
32212+static int pax_handle_fetch_fault_64(struct pt_regs *regs)
32213+{
32214+ int err;
32215+
32216+ do { /* PaX: libffi trampoline emulation */
32217+ unsigned short mov1, mov2, jmp1;
32218+ unsigned char stcclc, jmp2;
32219+ unsigned long addr1, addr2;
32220+
32221+ err = get_user(mov1, (unsigned short __user *)regs->ip);
32222+ err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
32223+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
32224+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
32225+ err |= get_user(stcclc, (unsigned char __user *)(regs->ip + 20));
32226+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 21));
32227+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 23));
32228+
32229+ if (err)
32230+ break;
32231+
32232+ if (mov1 == 0xBB49 && mov2 == 0xBA49 && (stcclc == 0xF8 || stcclc == 0xF9) && jmp1 == 0xFF49 && jmp2 == 0xE3) {
32233+ regs->r11 = addr1;
32234+ regs->r10 = addr2;
32235+ if (stcclc == 0xF8)
32236+ regs->flags &= ~X86_EFLAGS_CF;
32237+ else
32238+ regs->flags |= X86_EFLAGS_CF;
32239+ regs->ip = addr1;
32240+ return 2;
32241+ }
32242+ } while (0);
32243+
32244+ do { /* PaX: gcc trampoline emulation #1 */
32245+ unsigned short mov1, mov2, jmp1;
32246+ unsigned char jmp2;
32247+ unsigned int addr1;
32248+ unsigned long addr2;
32249+
32250+ err = get_user(mov1, (unsigned short __user *)regs->ip);
32251+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 2));
32252+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 6));
32253+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 8));
32254+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 16));
32255+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 18));
32256+
32257+ if (err)
32258+ break;
32259+
32260+ if (mov1 == 0xBB41 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
32261+ regs->r11 = addr1;
32262+ regs->r10 = addr2;
32263+ regs->ip = addr1;
32264+ return 2;
32265+ }
32266+ } while (0);
32267+
32268+ do { /* PaX: gcc trampoline emulation #2 */
32269+ unsigned short mov1, mov2, jmp1;
32270+ unsigned char jmp2;
32271+ unsigned long addr1, addr2;
32272+
32273+ err = get_user(mov1, (unsigned short __user *)regs->ip);
32274+ err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
32275+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
32276+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
32277+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 20));
32278+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 22));
32279+
32280+ if (err)
32281+ break;
32282+
32283+ if (mov1 == 0xBB49 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
32284+ regs->r11 = addr1;
32285+ regs->r10 = addr2;
32286+ regs->ip = addr1;
32287+ return 2;
32288+ }
32289+ } while (0);
32290+
32291+ return 1; /* PaX in action */
32292+}
32293+#endif
32294+
32295+/*
32296+ * PaX: decide what to do with offenders (regs->ip = fault address)
32297+ *
32298+ * returns 1 when task should be killed
32299+ * 2 when gcc trampoline was detected
32300+ */
32301+static int pax_handle_fetch_fault(struct pt_regs *regs)
32302+{
32303+ if (v8086_mode(regs))
32304+ return 1;
32305+
32306+ if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
32307+ return 1;
32308+
32309+#ifdef CONFIG_X86_32
32310+ return pax_handle_fetch_fault_32(regs);
32311+#else
32312+ if (regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))
32313+ return pax_handle_fetch_fault_32(regs);
32314+ else
32315+ return pax_handle_fetch_fault_64(regs);
32316+#endif
32317+}
32318+#endif
32319+
32320+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
32321+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
32322+{
32323+ long i;
32324+
32325+ printk(KERN_ERR "PAX: bytes at PC: ");
32326+ for (i = 0; i < 20; i++) {
32327+ unsigned char c;
32328+ if (get_user(c, (unsigned char __force_user *)pc+i))
32329+ printk(KERN_CONT "?? ");
32330+ else
32331+ printk(KERN_CONT "%02x ", c);
32332+ }
32333+ printk("\n");
32334+
32335+ printk(KERN_ERR "PAX: bytes at SP-%lu: ", (unsigned long)sizeof(long));
32336+ for (i = -1; i < 80 / (long)sizeof(long); i++) {
32337+ unsigned long c;
32338+ if (get_user(c, (unsigned long __force_user *)sp+i)) {
32339+#ifdef CONFIG_X86_32
32340+ printk(KERN_CONT "???????? ");
32341+#else
32342+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)))
32343+ printk(KERN_CONT "???????? ???????? ");
32344+ else
32345+ printk(KERN_CONT "???????????????? ");
32346+#endif
32347+ } else {
32348+#ifdef CONFIG_X86_64
32349+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))) {
32350+ printk(KERN_CONT "%08x ", (unsigned int)c);
32351+ printk(KERN_CONT "%08x ", (unsigned int)(c >> 32));
32352+ } else
32353+#endif
32354+ printk(KERN_CONT "%0*lx ", 2 * (int)sizeof(long), c);
32355+ }
32356+ }
32357+ printk("\n");
32358+}
32359+#endif
32360+
32361+/**
32362+ * probe_kernel_write(): safely attempt to write to a location
32363+ * @dst: address to write to
32364+ * @src: pointer to the data that shall be written
32365+ * @size: size of the data chunk
32366+ *
32367+ * Safely write to address @dst from the buffer at @src. If a kernel fault
32368+ * happens, handle that and return -EFAULT.
32369+ */
32370+long notrace probe_kernel_write(void *dst, const void *src, size_t size)
32371+{
32372+ long ret;
32373+ mm_segment_t old_fs = get_fs();
32374+
32375+ set_fs(KERNEL_DS);
32376+ pagefault_disable();
32377+ pax_open_kernel();
32378+ ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
32379+ pax_close_kernel();
32380+ pagefault_enable();
32381+ set_fs(old_fs);
32382+
32383+ return ret ? -EFAULT : 0;
32384+}
32385diff --git a/arch/x86/mm/gup.c b/arch/x86/mm/gup.c
32386index 207d9aef..69030980 100644
32387--- a/arch/x86/mm/gup.c
32388+++ b/arch/x86/mm/gup.c
32389@@ -268,7 +268,7 @@ int __get_user_pages_fast(unsigned long start, int nr_pages, int write,
32390 addr = start;
32391 len = (unsigned long) nr_pages << PAGE_SHIFT;
32392 end = start + len;
32393- if (unlikely(!access_ok(write ? VERIFY_WRITE : VERIFY_READ,
32394+ if (unlikely(!access_ok_noprefault(write ? VERIFY_WRITE : VERIFY_READ,
32395 (void __user *)start, len)))
32396 return 0;
32397
32398@@ -344,6 +344,10 @@ int get_user_pages_fast(unsigned long start, int nr_pages, int write,
32399 goto slow_irqon;
32400 #endif
32401
32402+ if (unlikely(!access_ok_noprefault(write ? VERIFY_WRITE : VERIFY_READ,
32403+ (void __user *)start, len)))
32404+ return 0;
32405+
32406 /*
32407 * XXX: batch / limit 'nr', to avoid large irq off latency
32408 * needs some instrumenting to determine the common sizes used by
32409diff --git a/arch/x86/mm/highmem_32.c b/arch/x86/mm/highmem_32.c
32410index 4500142..53a363c 100644
32411--- a/arch/x86/mm/highmem_32.c
32412+++ b/arch/x86/mm/highmem_32.c
32413@@ -45,7 +45,11 @@ void *kmap_atomic_prot(struct page *page, pgprot_t prot)
32414 idx = type + KM_TYPE_NR*smp_processor_id();
32415 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
32416 BUG_ON(!pte_none(*(kmap_pte-idx)));
32417+
32418+ pax_open_kernel();
32419 set_pte(kmap_pte-idx, mk_pte(page, prot));
32420+ pax_close_kernel();
32421+
32422 arch_flush_lazy_mmu_mode();
32423
32424 return (void *)vaddr;
32425diff --git a/arch/x86/mm/hugetlbpage.c b/arch/x86/mm/hugetlbpage.c
32426index 8c9f647..57cb402 100644
32427--- a/arch/x86/mm/hugetlbpage.c
32428+++ b/arch/x86/mm/hugetlbpage.c
32429@@ -90,23 +90,24 @@ int pmd_huge_support(void)
32430 #ifdef CONFIG_HUGETLB_PAGE
32431 static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
32432 unsigned long addr, unsigned long len,
32433- unsigned long pgoff, unsigned long flags)
32434+ unsigned long pgoff, unsigned long flags, unsigned long offset)
32435 {
32436 struct hstate *h = hstate_file(file);
32437 struct vm_unmapped_area_info info;
32438-
32439+
32440 info.flags = 0;
32441 info.length = len;
32442 info.low_limit = current->mm->mmap_legacy_base;
32443 info.high_limit = TASK_SIZE;
32444 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
32445 info.align_offset = 0;
32446+ info.threadstack_offset = offset;
32447 return vm_unmapped_area(&info);
32448 }
32449
32450 static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
32451 unsigned long addr0, unsigned long len,
32452- unsigned long pgoff, unsigned long flags)
32453+ unsigned long pgoff, unsigned long flags, unsigned long offset)
32454 {
32455 struct hstate *h = hstate_file(file);
32456 struct vm_unmapped_area_info info;
32457@@ -118,6 +119,7 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
32458 info.high_limit = current->mm->mmap_base;
32459 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
32460 info.align_offset = 0;
32461+ info.threadstack_offset = offset;
32462 addr = vm_unmapped_area(&info);
32463
32464 /*
32465@@ -130,6 +132,12 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
32466 VM_BUG_ON(addr != -ENOMEM);
32467 info.flags = 0;
32468 info.low_limit = TASK_UNMAPPED_BASE;
32469+
32470+#ifdef CONFIG_PAX_RANDMMAP
32471+ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
32472+ info.low_limit += current->mm->delta_mmap;
32473+#endif
32474+
32475 info.high_limit = TASK_SIZE;
32476 addr = vm_unmapped_area(&info);
32477 }
32478@@ -144,10 +152,20 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
32479 struct hstate *h = hstate_file(file);
32480 struct mm_struct *mm = current->mm;
32481 struct vm_area_struct *vma;
32482+ unsigned long pax_task_size = TASK_SIZE;
32483+ unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
32484
32485 if (len & ~huge_page_mask(h))
32486 return -EINVAL;
32487- if (len > TASK_SIZE)
32488+
32489+#ifdef CONFIG_PAX_SEGMEXEC
32490+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
32491+ pax_task_size = SEGMEXEC_TASK_SIZE;
32492+#endif
32493+
32494+ pax_task_size -= PAGE_SIZE;
32495+
32496+ if (len > pax_task_size)
32497 return -ENOMEM;
32498
32499 if (flags & MAP_FIXED) {
32500@@ -156,19 +174,22 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
32501 return addr;
32502 }
32503
32504+#ifdef CONFIG_PAX_RANDMMAP
32505+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
32506+#endif
32507+
32508 if (addr) {
32509 addr = ALIGN(addr, huge_page_size(h));
32510 vma = find_vma(mm, addr);
32511- if (TASK_SIZE - len >= addr &&
32512- (!vma || addr + len <= vma->vm_start))
32513+ if (pax_task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
32514 return addr;
32515 }
32516 if (mm->get_unmapped_area == arch_get_unmapped_area)
32517 return hugetlb_get_unmapped_area_bottomup(file, addr, len,
32518- pgoff, flags);
32519+ pgoff, flags, offset);
32520 else
32521 return hugetlb_get_unmapped_area_topdown(file, addr, len,
32522- pgoff, flags);
32523+ pgoff, flags, offset);
32524 }
32525 #endif /* CONFIG_HUGETLB_PAGE */
32526
32527diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
32528index f971306..e83e0f6 100644
32529--- a/arch/x86/mm/init.c
32530+++ b/arch/x86/mm/init.c
32531@@ -4,6 +4,7 @@
32532 #include <linux/swap.h>
32533 #include <linux/memblock.h>
32534 #include <linux/bootmem.h> /* for max_low_pfn */
32535+#include <linux/tboot.h>
32536
32537 #include <asm/cacheflush.h>
32538 #include <asm/e820.h>
32539@@ -17,6 +18,8 @@
32540 #include <asm/proto.h>
32541 #include <asm/dma.h> /* for MAX_DMA_PFN */
32542 #include <asm/microcode.h>
32543+#include <asm/desc.h>
32544+#include <asm/bios_ebda.h>
32545
32546 #include "mm_internal.h"
32547
32548@@ -563,7 +566,18 @@ void __init init_mem_mapping(void)
32549 early_ioremap_page_table_range_init();
32550 #endif
32551
32552+#ifdef CONFIG_PAX_PER_CPU_PGD
32553+ clone_pgd_range(get_cpu_pgd(0, kernel) + KERNEL_PGD_BOUNDARY,
32554+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
32555+ KERNEL_PGD_PTRS);
32556+ clone_pgd_range(get_cpu_pgd(0, user) + KERNEL_PGD_BOUNDARY,
32557+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
32558+ KERNEL_PGD_PTRS);
32559+ load_cr3(get_cpu_pgd(0, kernel));
32560+#else
32561 load_cr3(swapper_pg_dir);
32562+#endif
32563+
32564 __flush_tlb_all();
32565
32566 early_memtest(0, max_pfn_mapped << PAGE_SHIFT);
32567@@ -579,10 +593,40 @@ void __init init_mem_mapping(void)
32568 * Access has to be given to non-kernel-ram areas as well, these contain the PCI
32569 * mmio resources as well as potential bios/acpi data regions.
32570 */
32571+
32572+#ifdef CONFIG_GRKERNSEC_KMEM
32573+static unsigned int ebda_start __read_only;
32574+static unsigned int ebda_end __read_only;
32575+#endif
32576+
32577 int devmem_is_allowed(unsigned long pagenr)
32578 {
32579- if (pagenr < 256)
32580+#ifdef CONFIG_GRKERNSEC_KMEM
32581+ /* allow BDA */
32582+ if (!pagenr)
32583 return 1;
32584+ /* allow EBDA */
32585+ if (pagenr >= ebda_start && pagenr < ebda_end)
32586+ return 1;
32587+ /* if tboot is in use, allow access to its hardcoded serial log range */
32588+ if (tboot_enabled() && ((0x60000 >> PAGE_SHIFT) <= pagenr) && (pagenr < (0x68000 >> PAGE_SHIFT)))
32589+ return 1;
32590+#else
32591+ if (!pagenr)
32592+ return 1;
32593+#ifdef CONFIG_VM86
32594+ if (pagenr < (ISA_START_ADDRESS >> PAGE_SHIFT))
32595+ return 1;
32596+#endif
32597+#endif
32598+
32599+ if ((ISA_START_ADDRESS >> PAGE_SHIFT) <= pagenr && pagenr < (ISA_END_ADDRESS >> PAGE_SHIFT))
32600+ return 1;
32601+#ifdef CONFIG_GRKERNSEC_KMEM
32602+ /* throw out everything else below 1MB */
32603+ if (pagenr <= 256)
32604+ return 0;
32605+#endif
32606 if (iomem_is_exclusive(pagenr << PAGE_SHIFT))
32607 return 0;
32608 if (!page_is_ram(pagenr))
32609@@ -628,8 +672,117 @@ void free_init_pages(char *what, unsigned long begin, unsigned long end)
32610 #endif
32611 }
32612
32613+#ifdef CONFIG_GRKERNSEC_KMEM
32614+static inline void gr_init_ebda(void)
32615+{
32616+ unsigned int ebda_addr;
32617+ unsigned int ebda_size = 0;
32618+
32619+ ebda_addr = get_bios_ebda();
32620+ if (ebda_addr) {
32621+ ebda_size = *(unsigned char *)phys_to_virt(ebda_addr);
32622+ ebda_size <<= 10;
32623+ }
32624+ if (ebda_addr && ebda_size) {
32625+ ebda_start = ebda_addr >> PAGE_SHIFT;
32626+ ebda_end = min((unsigned int)PAGE_ALIGN(ebda_addr + ebda_size), (unsigned int)0xa0000) >> PAGE_SHIFT;
32627+ } else {
32628+ ebda_start = 0x9f000 >> PAGE_SHIFT;
32629+ ebda_end = 0xa0000 >> PAGE_SHIFT;
32630+ }
32631+}
32632+#else
32633+static inline void gr_init_ebda(void) { }
32634+#endif
32635+
32636 void free_initmem(void)
32637 {
32638+#ifdef CONFIG_PAX_KERNEXEC
32639+#ifdef CONFIG_X86_32
32640+ /* PaX: limit KERNEL_CS to actual size */
32641+ unsigned long addr, limit;
32642+ struct desc_struct d;
32643+ int cpu;
32644+#else
32645+ pgd_t *pgd;
32646+ pud_t *pud;
32647+ pmd_t *pmd;
32648+ unsigned long addr, end;
32649+#endif
32650+#endif
32651+
32652+ gr_init_ebda();
32653+
32654+#ifdef CONFIG_PAX_KERNEXEC
32655+#ifdef CONFIG_X86_32
32656+ limit = paravirt_enabled() ? ktva_ktla(0xffffffff) : (unsigned long)&_etext;
32657+ limit = (limit - 1UL) >> PAGE_SHIFT;
32658+
32659+ memset(__LOAD_PHYSICAL_ADDR + PAGE_OFFSET, POISON_FREE_INITMEM, PAGE_SIZE);
32660+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
32661+ pack_descriptor(&d, get_desc_base(&get_cpu_gdt_table(cpu)[GDT_ENTRY_KERNEL_CS]), limit, 0x9B, 0xC);
32662+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEL_CS, &d, DESCTYPE_S);
32663+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEXEC_KERNEL_CS, &d, DESCTYPE_S);
32664+ }
32665+
32666+ /* PaX: make KERNEL_CS read-only */
32667+ addr = PFN_ALIGN(ktla_ktva((unsigned long)&_text));
32668+ if (!paravirt_enabled())
32669+ set_memory_ro(addr, (PFN_ALIGN(_sdata) - addr) >> PAGE_SHIFT);
32670+/*
32671+ for (addr = ktla_ktva((unsigned long)&_text); addr < (unsigned long)&_sdata; addr += PMD_SIZE) {
32672+ pgd = pgd_offset_k(addr);
32673+ pud = pud_offset(pgd, addr);
32674+ pmd = pmd_offset(pud, addr);
32675+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
32676+ }
32677+*/
32678+#ifdef CONFIG_X86_PAE
32679+ set_memory_nx(PFN_ALIGN(__init_begin), (PFN_ALIGN(__init_end) - PFN_ALIGN(__init_begin)) >> PAGE_SHIFT);
32680+/*
32681+ for (addr = (unsigned long)&__init_begin; addr < (unsigned long)&__init_end; addr += PMD_SIZE) {
32682+ pgd = pgd_offset_k(addr);
32683+ pud = pud_offset(pgd, addr);
32684+ pmd = pmd_offset(pud, addr);
32685+ set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
32686+ }
32687+*/
32688+#endif
32689+
32690+#ifdef CONFIG_MODULES
32691+ set_memory_4k((unsigned long)MODULES_EXEC_VADDR, (MODULES_EXEC_END - MODULES_EXEC_VADDR) >> PAGE_SHIFT);
32692+#endif
32693+
32694+#else
32695+ /* PaX: make kernel code/rodata read-only, rest non-executable */
32696+ for (addr = __START_KERNEL_map; addr < __START_KERNEL_map + KERNEL_IMAGE_SIZE; addr += PMD_SIZE) {
32697+ pgd = pgd_offset_k(addr);
32698+ pud = pud_offset(pgd, addr);
32699+ pmd = pmd_offset(pud, addr);
32700+ if (!pmd_present(*pmd))
32701+ continue;
32702+ if ((unsigned long)_text <= addr && addr < (unsigned long)_sdata)
32703+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
32704+ else
32705+ set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
32706+ }
32707+
32708+ addr = (unsigned long)__va(__pa(__START_KERNEL_map));
32709+ end = addr + KERNEL_IMAGE_SIZE;
32710+ for (; addr < end; addr += PMD_SIZE) {
32711+ pgd = pgd_offset_k(addr);
32712+ pud = pud_offset(pgd, addr);
32713+ pmd = pmd_offset(pud, addr);
32714+ if (!pmd_present(*pmd))
32715+ continue;
32716+ if ((unsigned long)__va(__pa(_text)) <= addr && addr < (unsigned long)__va(__pa(_sdata)))
32717+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
32718+ }
32719+#endif
32720+
32721+ flush_tlb_all();
32722+#endif
32723+
32724 free_init_pages("unused kernel",
32725 (unsigned long)(&__init_begin),
32726 (unsigned long)(&__init_end));
32727diff --git a/arch/x86/mm/init_32.c b/arch/x86/mm/init_32.c
32728index e395048..cd38278 100644
32729--- a/arch/x86/mm/init_32.c
32730+++ b/arch/x86/mm/init_32.c
32731@@ -62,33 +62,6 @@ static noinline int do_test_wp_bit(void);
32732 bool __read_mostly __vmalloc_start_set = false;
32733
32734 /*
32735- * Creates a middle page table and puts a pointer to it in the
32736- * given global directory entry. This only returns the gd entry
32737- * in non-PAE compilation mode, since the middle layer is folded.
32738- */
32739-static pmd_t * __init one_md_table_init(pgd_t *pgd)
32740-{
32741- pud_t *pud;
32742- pmd_t *pmd_table;
32743-
32744-#ifdef CONFIG_X86_PAE
32745- if (!(pgd_val(*pgd) & _PAGE_PRESENT)) {
32746- pmd_table = (pmd_t *)alloc_low_page();
32747- paravirt_alloc_pmd(&init_mm, __pa(pmd_table) >> PAGE_SHIFT);
32748- set_pgd(pgd, __pgd(__pa(pmd_table) | _PAGE_PRESENT));
32749- pud = pud_offset(pgd, 0);
32750- BUG_ON(pmd_table != pmd_offset(pud, 0));
32751-
32752- return pmd_table;
32753- }
32754-#endif
32755- pud = pud_offset(pgd, 0);
32756- pmd_table = pmd_offset(pud, 0);
32757-
32758- return pmd_table;
32759-}
32760-
32761-/*
32762 * Create a page table and place a pointer to it in a middle page
32763 * directory entry:
32764 */
32765@@ -98,13 +71,28 @@ static pte_t * __init one_page_table_init(pmd_t *pmd)
32766 pte_t *page_table = (pte_t *)alloc_low_page();
32767
32768 paravirt_alloc_pte(&init_mm, __pa(page_table) >> PAGE_SHIFT);
32769+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
32770+ set_pmd(pmd, __pmd(__pa(page_table) | _KERNPG_TABLE));
32771+#else
32772 set_pmd(pmd, __pmd(__pa(page_table) | _PAGE_TABLE));
32773+#endif
32774 BUG_ON(page_table != pte_offset_kernel(pmd, 0));
32775 }
32776
32777 return pte_offset_kernel(pmd, 0);
32778 }
32779
32780+static pmd_t * __init one_md_table_init(pgd_t *pgd)
32781+{
32782+ pud_t *pud;
32783+ pmd_t *pmd_table;
32784+
32785+ pud = pud_offset(pgd, 0);
32786+ pmd_table = pmd_offset(pud, 0);
32787+
32788+ return pmd_table;
32789+}
32790+
32791 pmd_t * __init populate_extra_pmd(unsigned long vaddr)
32792 {
32793 int pgd_idx = pgd_index(vaddr);
32794@@ -208,6 +196,7 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
32795 int pgd_idx, pmd_idx;
32796 unsigned long vaddr;
32797 pgd_t *pgd;
32798+ pud_t *pud;
32799 pmd_t *pmd;
32800 pte_t *pte = NULL;
32801 unsigned long count = page_table_range_init_count(start, end);
32802@@ -222,8 +211,13 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
32803 pgd = pgd_base + pgd_idx;
32804
32805 for ( ; (pgd_idx < PTRS_PER_PGD) && (vaddr != end); pgd++, pgd_idx++) {
32806- pmd = one_md_table_init(pgd);
32807- pmd = pmd + pmd_index(vaddr);
32808+ pud = pud_offset(pgd, vaddr);
32809+ pmd = pmd_offset(pud, vaddr);
32810+
32811+#ifdef CONFIG_X86_PAE
32812+ paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
32813+#endif
32814+
32815 for (; (pmd_idx < PTRS_PER_PMD) && (vaddr != end);
32816 pmd++, pmd_idx++) {
32817 pte = page_table_kmap_check(one_page_table_init(pmd),
32818@@ -235,11 +229,20 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
32819 }
32820 }
32821
32822-static inline int is_kernel_text(unsigned long addr)
32823+static inline int is_kernel_text(unsigned long start, unsigned long end)
32824 {
32825- if (addr >= (unsigned long)_text && addr <= (unsigned long)__init_end)
32826- return 1;
32827- return 0;
32828+ if ((start >= ktla_ktva((unsigned long)_etext) ||
32829+ end <= ktla_ktva((unsigned long)_stext)) &&
32830+ (start >= ktla_ktva((unsigned long)_einittext) ||
32831+ end <= ktla_ktva((unsigned long)_sinittext)) &&
32832+
32833+#ifdef CONFIG_ACPI_SLEEP
32834+ (start >= (unsigned long)__va(acpi_wakeup_address) + 0x4000 || end <= (unsigned long)__va(acpi_wakeup_address)) &&
32835+#endif
32836+
32837+ (start > (unsigned long)__va(0xfffff) || end <= (unsigned long)__va(0xc0000)))
32838+ return 0;
32839+ return 1;
32840 }
32841
32842 /*
32843@@ -256,9 +259,10 @@ kernel_physical_mapping_init(unsigned long start,
32844 unsigned long last_map_addr = end;
32845 unsigned long start_pfn, end_pfn;
32846 pgd_t *pgd_base = swapper_pg_dir;
32847- int pgd_idx, pmd_idx, pte_ofs;
32848+ unsigned int pgd_idx, pmd_idx, pte_ofs;
32849 unsigned long pfn;
32850 pgd_t *pgd;
32851+ pud_t *pud;
32852 pmd_t *pmd;
32853 pte_t *pte;
32854 unsigned pages_2m, pages_4k;
32855@@ -291,8 +295,13 @@ repeat:
32856 pfn = start_pfn;
32857 pgd_idx = pgd_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
32858 pgd = pgd_base + pgd_idx;
32859- for (; pgd_idx < PTRS_PER_PGD; pgd++, pgd_idx++) {
32860- pmd = one_md_table_init(pgd);
32861+ for (; pgd_idx < PTRS_PER_PGD && pfn < max_low_pfn; pgd++, pgd_idx++) {
32862+ pud = pud_offset(pgd, 0);
32863+ pmd = pmd_offset(pud, 0);
32864+
32865+#ifdef CONFIG_X86_PAE
32866+ paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
32867+#endif
32868
32869 if (pfn >= end_pfn)
32870 continue;
32871@@ -304,14 +313,13 @@ repeat:
32872 #endif
32873 for (; pmd_idx < PTRS_PER_PMD && pfn < end_pfn;
32874 pmd++, pmd_idx++) {
32875- unsigned int addr = pfn * PAGE_SIZE + PAGE_OFFSET;
32876+ unsigned long address = pfn * PAGE_SIZE + PAGE_OFFSET;
32877
32878 /*
32879 * Map with big pages if possible, otherwise
32880 * create normal page tables:
32881 */
32882 if (use_pse) {
32883- unsigned int addr2;
32884 pgprot_t prot = PAGE_KERNEL_LARGE;
32885 /*
32886 * first pass will use the same initial
32887@@ -322,11 +330,7 @@ repeat:
32888 _PAGE_PSE);
32889
32890 pfn &= PMD_MASK >> PAGE_SHIFT;
32891- addr2 = (pfn + PTRS_PER_PTE-1) * PAGE_SIZE +
32892- PAGE_OFFSET + PAGE_SIZE-1;
32893-
32894- if (is_kernel_text(addr) ||
32895- is_kernel_text(addr2))
32896+ if (is_kernel_text(address, address + PMD_SIZE))
32897 prot = PAGE_KERNEL_LARGE_EXEC;
32898
32899 pages_2m++;
32900@@ -343,7 +347,7 @@ repeat:
32901 pte_ofs = pte_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
32902 pte += pte_ofs;
32903 for (; pte_ofs < PTRS_PER_PTE && pfn < end_pfn;
32904- pte++, pfn++, pte_ofs++, addr += PAGE_SIZE) {
32905+ pte++, pfn++, pte_ofs++, address += PAGE_SIZE) {
32906 pgprot_t prot = PAGE_KERNEL;
32907 /*
32908 * first pass will use the same initial
32909@@ -351,7 +355,7 @@ repeat:
32910 */
32911 pgprot_t init_prot = __pgprot(PTE_IDENT_ATTR);
32912
32913- if (is_kernel_text(addr))
32914+ if (is_kernel_text(address, address + PAGE_SIZE))
32915 prot = PAGE_KERNEL_EXEC;
32916
32917 pages_4k++;
32918@@ -474,7 +478,7 @@ void __init native_pagetable_init(void)
32919
32920 pud = pud_offset(pgd, va);
32921 pmd = pmd_offset(pud, va);
32922- if (!pmd_present(*pmd))
32923+ if (!pmd_present(*pmd)) // PAX TODO || pmd_large(*pmd))
32924 break;
32925
32926 /* should not be large page here */
32927@@ -532,12 +536,10 @@ void __init early_ioremap_page_table_range_init(void)
32928
32929 static void __init pagetable_init(void)
32930 {
32931- pgd_t *pgd_base = swapper_pg_dir;
32932-
32933- permanent_kmaps_init(pgd_base);
32934+ permanent_kmaps_init(swapper_pg_dir);
32935 }
32936
32937-pteval_t __supported_pte_mask __read_mostly = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
32938+pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
32939 EXPORT_SYMBOL_GPL(__supported_pte_mask);
32940
32941 /* user-defined highmem size */
32942@@ -787,10 +789,10 @@ void __init mem_init(void)
32943 ((unsigned long)&__init_end -
32944 (unsigned long)&__init_begin) >> 10,
32945
32946- (unsigned long)&_etext, (unsigned long)&_edata,
32947- ((unsigned long)&_edata - (unsigned long)&_etext) >> 10,
32948+ (unsigned long)&_sdata, (unsigned long)&_edata,
32949+ ((unsigned long)&_edata - (unsigned long)&_sdata) >> 10,
32950
32951- (unsigned long)&_text, (unsigned long)&_etext,
32952+ ktla_ktva((unsigned long)&_text), ktla_ktva((unsigned long)&_etext),
32953 ((unsigned long)&_etext - (unsigned long)&_text) >> 10);
32954
32955 /*
32956@@ -883,6 +885,7 @@ void set_kernel_text_rw(void)
32957 if (!kernel_set_to_readonly)
32958 return;
32959
32960+ start = ktla_ktva(start);
32961 pr_debug("Set kernel text: %lx - %lx for read write\n",
32962 start, start+size);
32963
32964@@ -897,6 +900,7 @@ void set_kernel_text_ro(void)
32965 if (!kernel_set_to_readonly)
32966 return;
32967
32968+ start = ktla_ktva(start);
32969 pr_debug("Set kernel text: %lx - %lx for read only\n",
32970 start, start+size);
32971
32972@@ -925,6 +929,7 @@ void mark_rodata_ro(void)
32973 unsigned long start = PFN_ALIGN(_text);
32974 unsigned long size = PFN_ALIGN(_etext) - start;
32975
32976+ start = ktla_ktva(start);
32977 set_pages_ro(virt_to_page(start), size >> PAGE_SHIFT);
32978 printk(KERN_INFO "Write protecting the kernel text: %luk\n",
32979 size >> 10);
32980diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c
32981index f35c66c..84b95ef 100644
32982--- a/arch/x86/mm/init_64.c
32983+++ b/arch/x86/mm/init_64.c
32984@@ -151,7 +151,7 @@ early_param("gbpages", parse_direct_gbpages_on);
32985 * around without checking the pgd every time.
32986 */
32987
32988-pteval_t __supported_pte_mask __read_mostly = ~_PAGE_IOMAP;
32989+pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_IOMAP);
32990 EXPORT_SYMBOL_GPL(__supported_pte_mask);
32991
32992 int force_personality32;
32993@@ -184,12 +184,29 @@ void sync_global_pgds(unsigned long start, unsigned long end)
32994
32995 for (address = start; address <= end; address += PGDIR_SIZE) {
32996 const pgd_t *pgd_ref = pgd_offset_k(address);
32997+
32998+#ifdef CONFIG_PAX_PER_CPU_PGD
32999+ unsigned long cpu;
33000+#else
33001 struct page *page;
33002+#endif
33003
33004 if (pgd_none(*pgd_ref))
33005 continue;
33006
33007 spin_lock(&pgd_lock);
33008+
33009+#ifdef CONFIG_PAX_PER_CPU_PGD
33010+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
33011+ pgd_t *pgd = pgd_offset_cpu(cpu, user, address);
33012+
33013+ if (pgd_none(*pgd))
33014+ set_pgd(pgd, *pgd_ref);
33015+ else
33016+ BUG_ON(pgd_page_vaddr(*pgd)
33017+ != pgd_page_vaddr(*pgd_ref));
33018+ pgd = pgd_offset_cpu(cpu, kernel, address);
33019+#else
33020 list_for_each_entry(page, &pgd_list, lru) {
33021 pgd_t *pgd;
33022 spinlock_t *pgt_lock;
33023@@ -198,6 +215,7 @@ void sync_global_pgds(unsigned long start, unsigned long end)
33024 /* the pgt_lock only for Xen */
33025 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
33026 spin_lock(pgt_lock);
33027+#endif
33028
33029 if (pgd_none(*pgd))
33030 set_pgd(pgd, *pgd_ref);
33031@@ -205,7 +223,10 @@ void sync_global_pgds(unsigned long start, unsigned long end)
33032 BUG_ON(pgd_page_vaddr(*pgd)
33033 != pgd_page_vaddr(*pgd_ref));
33034
33035+#ifndef CONFIG_PAX_PER_CPU_PGD
33036 spin_unlock(pgt_lock);
33037+#endif
33038+
33039 }
33040 spin_unlock(&pgd_lock);
33041 }
33042@@ -238,7 +259,7 @@ static pud_t *fill_pud(pgd_t *pgd, unsigned long vaddr)
33043 {
33044 if (pgd_none(*pgd)) {
33045 pud_t *pud = (pud_t *)spp_getpage();
33046- pgd_populate(&init_mm, pgd, pud);
33047+ pgd_populate_kernel(&init_mm, pgd, pud);
33048 if (pud != pud_offset(pgd, 0))
33049 printk(KERN_ERR "PAGETABLE BUG #00! %p <-> %p\n",
33050 pud, pud_offset(pgd, 0));
33051@@ -250,7 +271,7 @@ static pmd_t *fill_pmd(pud_t *pud, unsigned long vaddr)
33052 {
33053 if (pud_none(*pud)) {
33054 pmd_t *pmd = (pmd_t *) spp_getpage();
33055- pud_populate(&init_mm, pud, pmd);
33056+ pud_populate_kernel(&init_mm, pud, pmd);
33057 if (pmd != pmd_offset(pud, 0))
33058 printk(KERN_ERR "PAGETABLE BUG #01! %p <-> %p\n",
33059 pmd, pmd_offset(pud, 0));
33060@@ -279,7 +300,9 @@ void set_pte_vaddr_pud(pud_t *pud_page, unsigned long vaddr, pte_t new_pte)
33061 pmd = fill_pmd(pud, vaddr);
33062 pte = fill_pte(pmd, vaddr);
33063
33064+ pax_open_kernel();
33065 set_pte(pte, new_pte);
33066+ pax_close_kernel();
33067
33068 /*
33069 * It's enough to flush this one mapping.
33070@@ -338,14 +361,12 @@ static void __init __init_extra_mapping(unsigned long phys, unsigned long size,
33071 pgd = pgd_offset_k((unsigned long)__va(phys));
33072 if (pgd_none(*pgd)) {
33073 pud = (pud_t *) spp_getpage();
33074- set_pgd(pgd, __pgd(__pa(pud) | _KERNPG_TABLE |
33075- _PAGE_USER));
33076+ set_pgd(pgd, __pgd(__pa(pud) | _PAGE_TABLE));
33077 }
33078 pud = pud_offset(pgd, (unsigned long)__va(phys));
33079 if (pud_none(*pud)) {
33080 pmd = (pmd_t *) spp_getpage();
33081- set_pud(pud, __pud(__pa(pmd) | _KERNPG_TABLE |
33082- _PAGE_USER));
33083+ set_pud(pud, __pud(__pa(pmd) | _PAGE_TABLE));
33084 }
33085 pmd = pmd_offset(pud, phys);
33086 BUG_ON(!pmd_none(*pmd));
33087@@ -586,7 +607,7 @@ phys_pud_init(pud_t *pud_page, unsigned long addr, unsigned long end,
33088 prot);
33089
33090 spin_lock(&init_mm.page_table_lock);
33091- pud_populate(&init_mm, pud, pmd);
33092+ pud_populate_kernel(&init_mm, pud, pmd);
33093 spin_unlock(&init_mm.page_table_lock);
33094 }
33095 __flush_tlb_all();
33096@@ -627,7 +648,7 @@ kernel_physical_mapping_init(unsigned long start,
33097 page_size_mask);
33098
33099 spin_lock(&init_mm.page_table_lock);
33100- pgd_populate(&init_mm, pgd, pud);
33101+ pgd_populate_kernel(&init_mm, pgd, pud);
33102 spin_unlock(&init_mm.page_table_lock);
33103 pgd_changed = true;
33104 }
33105@@ -1188,8 +1209,8 @@ int kern_addr_valid(unsigned long addr)
33106 static struct vm_area_struct gate_vma = {
33107 .vm_start = VSYSCALL_START,
33108 .vm_end = VSYSCALL_START + (VSYSCALL_MAPPED_PAGES * PAGE_SIZE),
33109- .vm_page_prot = PAGE_READONLY_EXEC,
33110- .vm_flags = VM_READ | VM_EXEC
33111+ .vm_page_prot = PAGE_READONLY,
33112+ .vm_flags = VM_READ
33113 };
33114
33115 struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
33116@@ -1223,7 +1244,7 @@ int in_gate_area_no_mm(unsigned long addr)
33117
33118 const char *arch_vma_name(struct vm_area_struct *vma)
33119 {
33120- if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
33121+ if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
33122 return "[vdso]";
33123 if (vma == &gate_vma)
33124 return "[vsyscall]";
33125diff --git a/arch/x86/mm/iomap_32.c b/arch/x86/mm/iomap_32.c
33126index 7b179b4..6bd17777 100644
33127--- a/arch/x86/mm/iomap_32.c
33128+++ b/arch/x86/mm/iomap_32.c
33129@@ -64,7 +64,11 @@ void *kmap_atomic_prot_pfn(unsigned long pfn, pgprot_t prot)
33130 type = kmap_atomic_idx_push();
33131 idx = type + KM_TYPE_NR * smp_processor_id();
33132 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
33133+
33134+ pax_open_kernel();
33135 set_pte(kmap_pte - idx, pfn_pte(pfn, prot));
33136+ pax_close_kernel();
33137+
33138 arch_flush_lazy_mmu_mode();
33139
33140 return (void *)vaddr;
33141diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c
33142index 799580c..72f9fe0 100644
33143--- a/arch/x86/mm/ioremap.c
33144+++ b/arch/x86/mm/ioremap.c
33145@@ -97,7 +97,7 @@ static void __iomem *__ioremap_caller(resource_size_t phys_addr,
33146 for (pfn = phys_addr >> PAGE_SHIFT; pfn <= last_pfn; pfn++) {
33147 int is_ram = page_is_ram(pfn);
33148
33149- if (is_ram && pfn_valid(pfn) && !PageReserved(pfn_to_page(pfn)))
33150+ if (is_ram && pfn_valid(pfn) && (pfn >= 0x100 || !PageReserved(pfn_to_page(pfn))))
33151 return NULL;
33152 WARN_ON_ONCE(is_ram);
33153 }
33154@@ -256,7 +256,7 @@ EXPORT_SYMBOL(ioremap_prot);
33155 *
33156 * Caller must ensure there is only one unmapping for the same pointer.
33157 */
33158-void iounmap(volatile void __iomem *addr)
33159+void iounmap(const volatile void __iomem *addr)
33160 {
33161 struct vm_struct *p, *o;
33162
33163@@ -310,6 +310,9 @@ void *xlate_dev_mem_ptr(unsigned long phys)
33164
33165 /* If page is RAM, we can use __va. Otherwise ioremap and unmap. */
33166 if (page_is_ram(start >> PAGE_SHIFT))
33167+#ifdef CONFIG_HIGHMEM
33168+ if ((start >> PAGE_SHIFT) < max_low_pfn)
33169+#endif
33170 return __va(phys);
33171
33172 addr = (void __force *)ioremap_cache(start, PAGE_SIZE);
33173@@ -322,6 +325,9 @@ void *xlate_dev_mem_ptr(unsigned long phys)
33174 void unxlate_dev_mem_ptr(unsigned long phys, void *addr)
33175 {
33176 if (page_is_ram(phys >> PAGE_SHIFT))
33177+#ifdef CONFIG_HIGHMEM
33178+ if ((phys >> PAGE_SHIFT) < max_low_pfn)
33179+#endif
33180 return;
33181
33182 iounmap((void __iomem *)((unsigned long)addr & PAGE_MASK));
33183@@ -339,7 +345,7 @@ static int __init early_ioremap_debug_setup(char *str)
33184 early_param("early_ioremap_debug", early_ioremap_debug_setup);
33185
33186 static __initdata int after_paging_init;
33187-static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __page_aligned_bss;
33188+static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __read_only __aligned(PAGE_SIZE);
33189
33190 static inline pmd_t * __init early_ioremap_pmd(unsigned long addr)
33191 {
33192@@ -376,8 +382,7 @@ void __init early_ioremap_init(void)
33193 slot_virt[i] = __fix_to_virt(FIX_BTMAP_BEGIN - NR_FIX_BTMAPS*i);
33194
33195 pmd = early_ioremap_pmd(fix_to_virt(FIX_BTMAP_BEGIN));
33196- memset(bm_pte, 0, sizeof(bm_pte));
33197- pmd_populate_kernel(&init_mm, pmd, bm_pte);
33198+ pmd_populate_user(&init_mm, pmd, bm_pte);
33199
33200 /*
33201 * The boot-ioremap range spans multiple pmds, for which
33202diff --git a/arch/x86/mm/kmemcheck/kmemcheck.c b/arch/x86/mm/kmemcheck/kmemcheck.c
33203index d87dd6d..bf3fa66 100644
33204--- a/arch/x86/mm/kmemcheck/kmemcheck.c
33205+++ b/arch/x86/mm/kmemcheck/kmemcheck.c
33206@@ -622,9 +622,9 @@ bool kmemcheck_fault(struct pt_regs *regs, unsigned long address,
33207 * memory (e.g. tracked pages)? For now, we need this to avoid
33208 * invoking kmemcheck for PnP BIOS calls.
33209 */
33210- if (regs->flags & X86_VM_MASK)
33211+ if (v8086_mode(regs))
33212 return false;
33213- if (regs->cs != __KERNEL_CS)
33214+ if (regs->cs != __KERNEL_CS && regs->cs != __KERNEXEC_KERNEL_CS)
33215 return false;
33216
33217 pte = kmemcheck_pte_lookup(address);
33218diff --git a/arch/x86/mm/mmap.c b/arch/x86/mm/mmap.c
33219index 25e7e13..1964579 100644
33220--- a/arch/x86/mm/mmap.c
33221+++ b/arch/x86/mm/mmap.c
33222@@ -52,7 +52,7 @@ static unsigned int stack_maxrandom_size(void)
33223 * Leave an at least ~128 MB hole with possible stack randomization.
33224 */
33225 #define MIN_GAP (128*1024*1024UL + stack_maxrandom_size())
33226-#define MAX_GAP (TASK_SIZE/6*5)
33227+#define MAX_GAP (pax_task_size/6*5)
33228
33229 static int mmap_is_legacy(void)
33230 {
33231@@ -82,27 +82,40 @@ static unsigned long mmap_rnd(void)
33232 return rnd << PAGE_SHIFT;
33233 }
33234
33235-static unsigned long mmap_base(void)
33236+static unsigned long mmap_base(struct mm_struct *mm)
33237 {
33238 unsigned long gap = rlimit(RLIMIT_STACK);
33239+ unsigned long pax_task_size = TASK_SIZE;
33240+
33241+#ifdef CONFIG_PAX_SEGMEXEC
33242+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
33243+ pax_task_size = SEGMEXEC_TASK_SIZE;
33244+#endif
33245
33246 if (gap < MIN_GAP)
33247 gap = MIN_GAP;
33248 else if (gap > MAX_GAP)
33249 gap = MAX_GAP;
33250
33251- return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
33252+ return PAGE_ALIGN(pax_task_size - gap - mmap_rnd());
33253 }
33254
33255 /*
33256 * Bottom-up (legacy) layout on X86_32 did not support randomization, X86_64
33257 * does, but not when emulating X86_32
33258 */
33259-static unsigned long mmap_legacy_base(void)
33260+static unsigned long mmap_legacy_base(struct mm_struct *mm)
33261 {
33262- if (mmap_is_ia32())
33263+ if (mmap_is_ia32()) {
33264+
33265+#ifdef CONFIG_PAX_SEGMEXEC
33266+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
33267+ return SEGMEXEC_TASK_UNMAPPED_BASE;
33268+ else
33269+#endif
33270+
33271 return TASK_UNMAPPED_BASE;
33272- else
33273+ } else
33274 return TASK_UNMAPPED_BASE + mmap_rnd();
33275 }
33276
33277@@ -112,8 +125,15 @@ static unsigned long mmap_legacy_base(void)
33278 */
33279 void arch_pick_mmap_layout(struct mm_struct *mm)
33280 {
33281- mm->mmap_legacy_base = mmap_legacy_base();
33282- mm->mmap_base = mmap_base();
33283+ mm->mmap_legacy_base = mmap_legacy_base(mm);
33284+ mm->mmap_base = mmap_base(mm);
33285+
33286+#ifdef CONFIG_PAX_RANDMMAP
33287+ if (mm->pax_flags & MF_PAX_RANDMMAP) {
33288+ mm->mmap_legacy_base += mm->delta_mmap;
33289+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
33290+ }
33291+#endif
33292
33293 if (mmap_is_legacy()) {
33294 mm->mmap_base = mm->mmap_legacy_base;
33295diff --git a/arch/x86/mm/mmio-mod.c b/arch/x86/mm/mmio-mod.c
33296index 0057a7a..95c7edd 100644
33297--- a/arch/x86/mm/mmio-mod.c
33298+++ b/arch/x86/mm/mmio-mod.c
33299@@ -194,7 +194,7 @@ static void pre(struct kmmio_probe *p, struct pt_regs *regs,
33300 break;
33301 default:
33302 {
33303- unsigned char *ip = (unsigned char *)instptr;
33304+ unsigned char *ip = (unsigned char *)ktla_ktva(instptr);
33305 my_trace->opcode = MMIO_UNKNOWN_OP;
33306 my_trace->width = 0;
33307 my_trace->value = (*ip) << 16 | *(ip + 1) << 8 |
33308@@ -234,7 +234,7 @@ static void post(struct kmmio_probe *p, unsigned long condition,
33309 static void ioremap_trace_core(resource_size_t offset, unsigned long size,
33310 void __iomem *addr)
33311 {
33312- static atomic_t next_id;
33313+ static atomic_unchecked_t next_id;
33314 struct remap_trace *trace = kmalloc(sizeof(*trace), GFP_KERNEL);
33315 /* These are page-unaligned. */
33316 struct mmiotrace_map map = {
33317@@ -258,7 +258,7 @@ static void ioremap_trace_core(resource_size_t offset, unsigned long size,
33318 .private = trace
33319 },
33320 .phys = offset,
33321- .id = atomic_inc_return(&next_id)
33322+ .id = atomic_inc_return_unchecked(&next_id)
33323 };
33324 map.map_id = trace->id;
33325
33326@@ -290,7 +290,7 @@ void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
33327 ioremap_trace_core(offset, size, addr);
33328 }
33329
33330-static void iounmap_trace_core(volatile void __iomem *addr)
33331+static void iounmap_trace_core(const volatile void __iomem *addr)
33332 {
33333 struct mmiotrace_map map = {
33334 .phys = 0,
33335@@ -328,7 +328,7 @@ not_enabled:
33336 }
33337 }
33338
33339-void mmiotrace_iounmap(volatile void __iomem *addr)
33340+void mmiotrace_iounmap(const volatile void __iomem *addr)
33341 {
33342 might_sleep();
33343 if (is_enabled()) /* recheck and proper locking in *_core() */
33344diff --git a/arch/x86/mm/numa.c b/arch/x86/mm/numa.c
33345index 27aa0455..0eb1406 100644
33346--- a/arch/x86/mm/numa.c
33347+++ b/arch/x86/mm/numa.c
33348@@ -478,7 +478,7 @@ static bool __init numa_meminfo_cover_memory(const struct numa_meminfo *mi)
33349 return true;
33350 }
33351
33352-static int __init numa_register_memblks(struct numa_meminfo *mi)
33353+static int __init __intentional_overflow(-1) numa_register_memblks(struct numa_meminfo *mi)
33354 {
33355 unsigned long uninitialized_var(pfn_align);
33356 int i, nid;
33357diff --git a/arch/x86/mm/pageattr-test.c b/arch/x86/mm/pageattr-test.c
33358index 461bc82..4e091a3 100644
33359--- a/arch/x86/mm/pageattr-test.c
33360+++ b/arch/x86/mm/pageattr-test.c
33361@@ -35,7 +35,7 @@ enum {
33362
33363 static int pte_testbit(pte_t pte)
33364 {
33365- return pte_flags(pte) & _PAGE_UNUSED1;
33366+ return pte_flags(pte) & _PAGE_CPA_TEST;
33367 }
33368
33369 struct split_state {
33370diff --git a/arch/x86/mm/pageattr.c b/arch/x86/mm/pageattr.c
33371index a348868..3c64310 100644
33372--- a/arch/x86/mm/pageattr.c
33373+++ b/arch/x86/mm/pageattr.c
33374@@ -262,7 +262,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
33375 */
33376 #ifdef CONFIG_PCI_BIOS
33377 if (pcibios_enabled && within(pfn, BIOS_BEGIN >> PAGE_SHIFT, BIOS_END >> PAGE_SHIFT))
33378- pgprot_val(forbidden) |= _PAGE_NX;
33379+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
33380 #endif
33381
33382 /*
33383@@ -270,9 +270,10 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
33384 * Does not cover __inittext since that is gone later on. On
33385 * 64bit we do not enforce !NX on the low mapping
33386 */
33387- if (within(address, (unsigned long)_text, (unsigned long)_etext))
33388- pgprot_val(forbidden) |= _PAGE_NX;
33389+ if (within(address, ktla_ktva((unsigned long)_text), ktla_ktva((unsigned long)_etext)))
33390+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
33391
33392+#ifdef CONFIG_DEBUG_RODATA
33393 /*
33394 * The .rodata section needs to be read-only. Using the pfn
33395 * catches all aliases.
33396@@ -280,6 +281,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
33397 if (within(pfn, __pa_symbol(__start_rodata) >> PAGE_SHIFT,
33398 __pa_symbol(__end_rodata) >> PAGE_SHIFT))
33399 pgprot_val(forbidden) |= _PAGE_RW;
33400+#endif
33401
33402 #if defined(CONFIG_X86_64) && defined(CONFIG_DEBUG_RODATA)
33403 /*
33404@@ -318,6 +320,13 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
33405 }
33406 #endif
33407
33408+#ifdef CONFIG_PAX_KERNEXEC
33409+ if (within(pfn, __pa(ktla_ktva((unsigned long)&_text)), __pa((unsigned long)&_sdata))) {
33410+ pgprot_val(forbidden) |= _PAGE_RW;
33411+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
33412+ }
33413+#endif
33414+
33415 prot = __pgprot(pgprot_val(prot) & ~pgprot_val(forbidden));
33416
33417 return prot;
33418@@ -416,23 +425,37 @@ EXPORT_SYMBOL_GPL(slow_virt_to_phys);
33419 static void __set_pmd_pte(pte_t *kpte, unsigned long address, pte_t pte)
33420 {
33421 /* change init_mm */
33422+ pax_open_kernel();
33423 set_pte_atomic(kpte, pte);
33424+
33425 #ifdef CONFIG_X86_32
33426 if (!SHARED_KERNEL_PMD) {
33427+
33428+#ifdef CONFIG_PAX_PER_CPU_PGD
33429+ unsigned long cpu;
33430+#else
33431 struct page *page;
33432+#endif
33433
33434+#ifdef CONFIG_PAX_PER_CPU_PGD
33435+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
33436+ pgd_t *pgd = get_cpu_pgd(cpu, kernel);
33437+#else
33438 list_for_each_entry(page, &pgd_list, lru) {
33439- pgd_t *pgd;
33440+ pgd_t *pgd = (pgd_t *)page_address(page);
33441+#endif
33442+
33443 pud_t *pud;
33444 pmd_t *pmd;
33445
33446- pgd = (pgd_t *)page_address(page) + pgd_index(address);
33447+ pgd += pgd_index(address);
33448 pud = pud_offset(pgd, address);
33449 pmd = pmd_offset(pud, address);
33450 set_pte_atomic((pte_t *)pmd, pte);
33451 }
33452 }
33453 #endif
33454+ pax_close_kernel();
33455 }
33456
33457 static int
33458diff --git a/arch/x86/mm/pat.c b/arch/x86/mm/pat.c
33459index 6574388..87e9bef 100644
33460--- a/arch/x86/mm/pat.c
33461+++ b/arch/x86/mm/pat.c
33462@@ -376,7 +376,7 @@ int free_memtype(u64 start, u64 end)
33463
33464 if (!entry) {
33465 printk(KERN_INFO "%s:%d freeing invalid memtype [mem %#010Lx-%#010Lx]\n",
33466- current->comm, current->pid, start, end - 1);
33467+ current->comm, task_pid_nr(current), start, end - 1);
33468 return -EINVAL;
33469 }
33470
33471@@ -506,8 +506,8 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
33472
33473 while (cursor < to) {
33474 if (!devmem_is_allowed(pfn)) {
33475- printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx]\n",
33476- current->comm, from, to - 1);
33477+ printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx] (%#010Lx)\n",
33478+ current->comm, from, to - 1, cursor);
33479 return 0;
33480 }
33481 cursor += PAGE_SIZE;
33482@@ -577,7 +577,7 @@ int kernel_map_sync_memtype(u64 base, unsigned long size, unsigned long flags)
33483 if (ioremap_change_attr((unsigned long)__va(base), id_sz, flags) < 0) {
33484 printk(KERN_INFO "%s:%d ioremap_change_attr failed %s "
33485 "for [mem %#010Lx-%#010Lx]\n",
33486- current->comm, current->pid,
33487+ current->comm, task_pid_nr(current),
33488 cattr_name(flags),
33489 base, (unsigned long long)(base + size-1));
33490 return -EINVAL;
33491@@ -612,7 +612,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
33492 flags = lookup_memtype(paddr);
33493 if (want_flags != flags) {
33494 printk(KERN_WARNING "%s:%d map pfn RAM range req %s for [mem %#010Lx-%#010Lx], got %s\n",
33495- current->comm, current->pid,
33496+ current->comm, task_pid_nr(current),
33497 cattr_name(want_flags),
33498 (unsigned long long)paddr,
33499 (unsigned long long)(paddr + size - 1),
33500@@ -634,7 +634,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
33501 free_memtype(paddr, paddr + size);
33502 printk(KERN_ERR "%s:%d map pfn expected mapping type %s"
33503 " for [mem %#010Lx-%#010Lx], got %s\n",
33504- current->comm, current->pid,
33505+ current->comm, task_pid_nr(current),
33506 cattr_name(want_flags),
33507 (unsigned long long)paddr,
33508 (unsigned long long)(paddr + size - 1),
33509diff --git a/arch/x86/mm/pat_rbtree.c b/arch/x86/mm/pat_rbtree.c
33510index 415f6c4..d319983 100644
33511--- a/arch/x86/mm/pat_rbtree.c
33512+++ b/arch/x86/mm/pat_rbtree.c
33513@@ -160,7 +160,7 @@ success:
33514
33515 failure:
33516 printk(KERN_INFO "%s:%d conflicting memory types "
33517- "%Lx-%Lx %s<->%s\n", current->comm, current->pid, start,
33518+ "%Lx-%Lx %s<->%s\n", current->comm, task_pid_nr(current), start,
33519 end, cattr_name(found_type), cattr_name(match->type));
33520 return -EBUSY;
33521 }
33522diff --git a/arch/x86/mm/pf_in.c b/arch/x86/mm/pf_in.c
33523index 9f0614d..92ae64a 100644
33524--- a/arch/x86/mm/pf_in.c
33525+++ b/arch/x86/mm/pf_in.c
33526@@ -148,7 +148,7 @@ enum reason_type get_ins_type(unsigned long ins_addr)
33527 int i;
33528 enum reason_type rv = OTHERS;
33529
33530- p = (unsigned char *)ins_addr;
33531+ p = (unsigned char *)ktla_ktva(ins_addr);
33532 p += skip_prefix(p, &prf);
33533 p += get_opcode(p, &opcode);
33534
33535@@ -168,7 +168,7 @@ static unsigned int get_ins_reg_width(unsigned long ins_addr)
33536 struct prefix_bits prf;
33537 int i;
33538
33539- p = (unsigned char *)ins_addr;
33540+ p = (unsigned char *)ktla_ktva(ins_addr);
33541 p += skip_prefix(p, &prf);
33542 p += get_opcode(p, &opcode);
33543
33544@@ -191,7 +191,7 @@ unsigned int get_ins_mem_width(unsigned long ins_addr)
33545 struct prefix_bits prf;
33546 int i;
33547
33548- p = (unsigned char *)ins_addr;
33549+ p = (unsigned char *)ktla_ktva(ins_addr);
33550 p += skip_prefix(p, &prf);
33551 p += get_opcode(p, &opcode);
33552
33553@@ -415,7 +415,7 @@ unsigned long get_ins_reg_val(unsigned long ins_addr, struct pt_regs *regs)
33554 struct prefix_bits prf;
33555 int i;
33556
33557- p = (unsigned char *)ins_addr;
33558+ p = (unsigned char *)ktla_ktva(ins_addr);
33559 p += skip_prefix(p, &prf);
33560 p += get_opcode(p, &opcode);
33561 for (i = 0; i < ARRAY_SIZE(reg_rop); i++)
33562@@ -470,7 +470,7 @@ unsigned long get_ins_imm_val(unsigned long ins_addr)
33563 struct prefix_bits prf;
33564 int i;
33565
33566- p = (unsigned char *)ins_addr;
33567+ p = (unsigned char *)ktla_ktva(ins_addr);
33568 p += skip_prefix(p, &prf);
33569 p += get_opcode(p, &opcode);
33570 for (i = 0; i < ARRAY_SIZE(imm_wop); i++)
33571diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c
33572index c96314a..433b127 100644
33573--- a/arch/x86/mm/pgtable.c
33574+++ b/arch/x86/mm/pgtable.c
33575@@ -97,10 +97,71 @@ static inline void pgd_list_del(pgd_t *pgd)
33576 list_del(&page->lru);
33577 }
33578
33579-#define UNSHARED_PTRS_PER_PGD \
33580- (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
33581+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
33582+pgdval_t clone_pgd_mask __read_only = ~_PAGE_PRESENT;
33583
33584+void __shadow_user_pgds(pgd_t *dst, const pgd_t *src)
33585+{
33586+ unsigned int count = USER_PGD_PTRS;
33587
33588+ if (!pax_user_shadow_base)
33589+ return;
33590+
33591+ while (count--)
33592+ *dst++ = __pgd((pgd_val(*src++) | (_PAGE_NX & __supported_pte_mask)) & ~_PAGE_USER);
33593+}
33594+#endif
33595+
33596+#ifdef CONFIG_PAX_PER_CPU_PGD
33597+void __clone_user_pgds(pgd_t *dst, const pgd_t *src)
33598+{
33599+ unsigned int count = USER_PGD_PTRS;
33600+
33601+ while (count--) {
33602+ pgd_t pgd;
33603+
33604+#ifdef CONFIG_X86_64
33605+ pgd = __pgd(pgd_val(*src++) | _PAGE_USER);
33606+#else
33607+ pgd = *src++;
33608+#endif
33609+
33610+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
33611+ pgd = __pgd(pgd_val(pgd) & clone_pgd_mask);
33612+#endif
33613+
33614+ *dst++ = pgd;
33615+ }
33616+
33617+}
33618+#endif
33619+
33620+#ifdef CONFIG_X86_64
33621+#define pxd_t pud_t
33622+#define pyd_t pgd_t
33623+#define paravirt_release_pxd(pfn) paravirt_release_pud(pfn)
33624+#define pgtable_pxd_page_ctor(page) true
33625+#define pgtable_pxd_page_dtor(page)
33626+#define pxd_free(mm, pud) pud_free((mm), (pud))
33627+#define pyd_populate(mm, pgd, pud) pgd_populate((mm), (pgd), (pud))
33628+#define pyd_offset(mm, address) pgd_offset((mm), (address))
33629+#define PYD_SIZE PGDIR_SIZE
33630+#else
33631+#define pxd_t pmd_t
33632+#define pyd_t pud_t
33633+#define paravirt_release_pxd(pfn) paravirt_release_pmd(pfn)
33634+#define pgtable_pxd_page_ctor(page) pgtable_pmd_page_ctor(page)
33635+#define pgtable_pxd_page_dtor(page) pgtable_pmd_page_dtor(page)
33636+#define pxd_free(mm, pud) pmd_free((mm), (pud))
33637+#define pyd_populate(mm, pgd, pud) pud_populate((mm), (pgd), (pud))
33638+#define pyd_offset(mm, address) pud_offset((mm), (address))
33639+#define PYD_SIZE PUD_SIZE
33640+#endif
33641+
33642+#ifdef CONFIG_PAX_PER_CPU_PGD
33643+static inline void pgd_ctor(struct mm_struct *mm, pgd_t *pgd) {}
33644+static inline void pgd_dtor(pgd_t *pgd) {}
33645+#else
33646 static void pgd_set_mm(pgd_t *pgd, struct mm_struct *mm)
33647 {
33648 BUILD_BUG_ON(sizeof(virt_to_page(pgd)->index) < sizeof(mm));
33649@@ -141,6 +202,7 @@ static void pgd_dtor(pgd_t *pgd)
33650 pgd_list_del(pgd);
33651 spin_unlock(&pgd_lock);
33652 }
33653+#endif
33654
33655 /*
33656 * List of all pgd's needed for non-PAE so it can invalidate entries
33657@@ -153,7 +215,7 @@ static void pgd_dtor(pgd_t *pgd)
33658 * -- nyc
33659 */
33660
33661-#ifdef CONFIG_X86_PAE
33662+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
33663 /*
33664 * In PAE mode, we need to do a cr3 reload (=tlb flush) when
33665 * updating the top-level pagetable entries to guarantee the
33666@@ -165,7 +227,7 @@ static void pgd_dtor(pgd_t *pgd)
33667 * not shared between pagetables (!SHARED_KERNEL_PMDS), we allocate
33668 * and initialize the kernel pmds here.
33669 */
33670-#define PREALLOCATED_PMDS UNSHARED_PTRS_PER_PGD
33671+#define PREALLOCATED_PXDS (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
33672
33673 void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
33674 {
33675@@ -183,43 +245,45 @@ void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
33676 */
33677 flush_tlb_mm(mm);
33678 }
33679+#elif defined(CONFIG_X86_64) && defined(CONFIG_PAX_PER_CPU_PGD)
33680+#define PREALLOCATED_PXDS USER_PGD_PTRS
33681 #else /* !CONFIG_X86_PAE */
33682
33683 /* No need to prepopulate any pagetable entries in non-PAE modes. */
33684-#define PREALLOCATED_PMDS 0
33685+#define PREALLOCATED_PXDS 0
33686
33687 #endif /* CONFIG_X86_PAE */
33688
33689-static void free_pmds(pmd_t *pmds[])
33690+static void free_pxds(pxd_t *pxds[])
33691 {
33692 int i;
33693
33694- for(i = 0; i < PREALLOCATED_PMDS; i++)
33695- if (pmds[i]) {
33696- pgtable_pmd_page_dtor(virt_to_page(pmds[i]));
33697- free_page((unsigned long)pmds[i]);
33698+ for(i = 0; i < PREALLOCATED_PXDS; i++)
33699+ if (pxds[i]) {
33700+ pgtable_pxd_page_dtor(virt_to_page(pxds[i]));
33701+ free_page((unsigned long)pxds[i]);
33702 }
33703 }
33704
33705-static int preallocate_pmds(pmd_t *pmds[])
33706+static int preallocate_pxds(pxd_t *pxds[])
33707 {
33708 int i;
33709 bool failed = false;
33710
33711- for(i = 0; i < PREALLOCATED_PMDS; i++) {
33712- pmd_t *pmd = (pmd_t *)__get_free_page(PGALLOC_GFP);
33713- if (!pmd)
33714+ for(i = 0; i < PREALLOCATED_PXDS; i++) {
33715+ pxd_t *pxd = (pxd_t *)__get_free_page(PGALLOC_GFP);
33716+ if (!pxd)
33717 failed = true;
33718- if (pmd && !pgtable_pmd_page_ctor(virt_to_page(pmd))) {
33719- free_page((unsigned long)pmd);
33720- pmd = NULL;
33721+ if (pxd && !pgtable_pxd_page_ctor(virt_to_page(pxd))) {
33722+ free_page((unsigned long)pxd);
33723+ pxd = NULL;
33724 failed = true;
33725 }
33726- pmds[i] = pmd;
33727+ pxds[i] = pxd;
33728 }
33729
33730 if (failed) {
33731- free_pmds(pmds);
33732+ free_pxds(pxds);
33733 return -ENOMEM;
33734 }
33735
33736@@ -232,49 +296,52 @@ static int preallocate_pmds(pmd_t *pmds[])
33737 * preallocate which never got a corresponding vma will need to be
33738 * freed manually.
33739 */
33740-static void pgd_mop_up_pmds(struct mm_struct *mm, pgd_t *pgdp)
33741+static void pgd_mop_up_pxds(struct mm_struct *mm, pgd_t *pgdp)
33742 {
33743 int i;
33744
33745- for(i = 0; i < PREALLOCATED_PMDS; i++) {
33746+ for(i = 0; i < PREALLOCATED_PXDS; i++) {
33747 pgd_t pgd = pgdp[i];
33748
33749 if (pgd_val(pgd) != 0) {
33750- pmd_t *pmd = (pmd_t *)pgd_page_vaddr(pgd);
33751+ pxd_t *pxd = (pxd_t *)pgd_page_vaddr(pgd);
33752
33753- pgdp[i] = native_make_pgd(0);
33754+ set_pgd(pgdp + i, native_make_pgd(0));
33755
33756- paravirt_release_pmd(pgd_val(pgd) >> PAGE_SHIFT);
33757- pmd_free(mm, pmd);
33758+ paravirt_release_pxd(pgd_val(pgd) >> PAGE_SHIFT);
33759+ pxd_free(mm, pxd);
33760 }
33761 }
33762 }
33763
33764-static void pgd_prepopulate_pmd(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmds[])
33765+static void pgd_prepopulate_pxd(struct mm_struct *mm, pgd_t *pgd, pxd_t *pxds[])
33766 {
33767- pud_t *pud;
33768+ pyd_t *pyd;
33769 int i;
33770
33771- if (PREALLOCATED_PMDS == 0) /* Work around gcc-3.4.x bug */
33772+ if (PREALLOCATED_PXDS == 0) /* Work around gcc-3.4.x bug */
33773 return;
33774
33775- pud = pud_offset(pgd, 0);
33776-
33777- for (i = 0; i < PREALLOCATED_PMDS; i++, pud++) {
33778- pmd_t *pmd = pmds[i];
33779+#ifdef CONFIG_X86_64
33780+ pyd = pyd_offset(mm, 0L);
33781+#else
33782+ pyd = pyd_offset(pgd, 0L);
33783+#endif
33784
33785+ for (i = 0; i < PREALLOCATED_PXDS; i++, pyd++) {
33786+ pxd_t *pxd = pxds[i];
33787 if (i >= KERNEL_PGD_BOUNDARY)
33788- memcpy(pmd, (pmd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
33789- sizeof(pmd_t) * PTRS_PER_PMD);
33790+ memcpy(pxd, (pxd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
33791+ sizeof(pxd_t) * PTRS_PER_PMD);
33792
33793- pud_populate(mm, pud, pmd);
33794+ pyd_populate(mm, pyd, pxd);
33795 }
33796 }
33797
33798 pgd_t *pgd_alloc(struct mm_struct *mm)
33799 {
33800 pgd_t *pgd;
33801- pmd_t *pmds[PREALLOCATED_PMDS];
33802+ pxd_t *pxds[PREALLOCATED_PXDS];
33803
33804 pgd = (pgd_t *)__get_free_page(PGALLOC_GFP);
33805
33806@@ -283,11 +350,11 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
33807
33808 mm->pgd = pgd;
33809
33810- if (preallocate_pmds(pmds) != 0)
33811+ if (preallocate_pxds(pxds) != 0)
33812 goto out_free_pgd;
33813
33814 if (paravirt_pgd_alloc(mm) != 0)
33815- goto out_free_pmds;
33816+ goto out_free_pxds;
33817
33818 /*
33819 * Make sure that pre-populating the pmds is atomic with
33820@@ -297,14 +364,14 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
33821 spin_lock(&pgd_lock);
33822
33823 pgd_ctor(mm, pgd);
33824- pgd_prepopulate_pmd(mm, pgd, pmds);
33825+ pgd_prepopulate_pxd(mm, pgd, pxds);
33826
33827 spin_unlock(&pgd_lock);
33828
33829 return pgd;
33830
33831-out_free_pmds:
33832- free_pmds(pmds);
33833+out_free_pxds:
33834+ free_pxds(pxds);
33835 out_free_pgd:
33836 free_page((unsigned long)pgd);
33837 out:
33838@@ -313,7 +380,7 @@ out:
33839
33840 void pgd_free(struct mm_struct *mm, pgd_t *pgd)
33841 {
33842- pgd_mop_up_pmds(mm, pgd);
33843+ pgd_mop_up_pxds(mm, pgd);
33844 pgd_dtor(pgd);
33845 paravirt_pgd_free(mm, pgd);
33846 free_page((unsigned long)pgd);
33847diff --git a/arch/x86/mm/pgtable_32.c b/arch/x86/mm/pgtable_32.c
33848index a69bcb8..19068ab 100644
33849--- a/arch/x86/mm/pgtable_32.c
33850+++ b/arch/x86/mm/pgtable_32.c
33851@@ -47,10 +47,13 @@ void set_pte_vaddr(unsigned long vaddr, pte_t pteval)
33852 return;
33853 }
33854 pte = pte_offset_kernel(pmd, vaddr);
33855+
33856+ pax_open_kernel();
33857 if (pte_val(pteval))
33858 set_pte_at(&init_mm, vaddr, pte, pteval);
33859 else
33860 pte_clear(&init_mm, vaddr, pte);
33861+ pax_close_kernel();
33862
33863 /*
33864 * It's enough to flush this one mapping.
33865diff --git a/arch/x86/mm/physaddr.c b/arch/x86/mm/physaddr.c
33866index e666cbb..61788c45 100644
33867--- a/arch/x86/mm/physaddr.c
33868+++ b/arch/x86/mm/physaddr.c
33869@@ -10,7 +10,7 @@
33870 #ifdef CONFIG_X86_64
33871
33872 #ifdef CONFIG_DEBUG_VIRTUAL
33873-unsigned long __phys_addr(unsigned long x)
33874+unsigned long __intentional_overflow(-1) __phys_addr(unsigned long x)
33875 {
33876 unsigned long y = x - __START_KERNEL_map;
33877
33878@@ -67,7 +67,7 @@ EXPORT_SYMBOL(__virt_addr_valid);
33879 #else
33880
33881 #ifdef CONFIG_DEBUG_VIRTUAL
33882-unsigned long __phys_addr(unsigned long x)
33883+unsigned long __intentional_overflow(-1) __phys_addr(unsigned long x)
33884 {
33885 unsigned long phys_addr = x - PAGE_OFFSET;
33886 /* VMALLOC_* aren't constants */
33887diff --git a/arch/x86/mm/setup_nx.c b/arch/x86/mm/setup_nx.c
33888index 90555bf..f5f1828 100644
33889--- a/arch/x86/mm/setup_nx.c
33890+++ b/arch/x86/mm/setup_nx.c
33891@@ -5,8 +5,10 @@
33892 #include <asm/pgtable.h>
33893 #include <asm/proto.h>
33894
33895+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
33896 static int disable_nx;
33897
33898+#ifndef CONFIG_PAX_PAGEEXEC
33899 /*
33900 * noexec = on|off
33901 *
33902@@ -28,12 +30,17 @@ static int __init noexec_setup(char *str)
33903 return 0;
33904 }
33905 early_param("noexec", noexec_setup);
33906+#endif
33907+
33908+#endif
33909
33910 void x86_configure_nx(void)
33911 {
33912+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
33913 if (cpu_has_nx && !disable_nx)
33914 __supported_pte_mask |= _PAGE_NX;
33915 else
33916+#endif
33917 __supported_pte_mask &= ~_PAGE_NX;
33918 }
33919
33920diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c
33921index dd8dda1..9e9b0f6 100644
33922--- a/arch/x86/mm/tlb.c
33923+++ b/arch/x86/mm/tlb.c
33924@@ -48,7 +48,11 @@ void leave_mm(int cpu)
33925 BUG();
33926 if (cpumask_test_cpu(cpu, mm_cpumask(active_mm))) {
33927 cpumask_clear_cpu(cpu, mm_cpumask(active_mm));
33928+
33929+#ifndef CONFIG_PAX_PER_CPU_PGD
33930 load_cr3(swapper_pg_dir);
33931+#endif
33932+
33933 }
33934 }
33935 EXPORT_SYMBOL_GPL(leave_mm);
33936diff --git a/arch/x86/mm/uderef_64.c b/arch/x86/mm/uderef_64.c
33937new file mode 100644
33938index 0000000..dace51c
33939--- /dev/null
33940+++ b/arch/x86/mm/uderef_64.c
33941@@ -0,0 +1,37 @@
33942+#include <linux/mm.h>
33943+#include <asm/pgtable.h>
33944+#include <asm/uaccess.h>
33945+
33946+#ifdef CONFIG_PAX_MEMORY_UDEREF
33947+/* PaX: due to the special call convention these functions must
33948+ * - remain leaf functions under all configurations,
33949+ * - never be called directly, only dereferenced from the wrappers.
33950+ */
33951+void __pax_open_userland(void)
33952+{
33953+ unsigned int cpu;
33954+
33955+ if (unlikely(!segment_eq(get_fs(), USER_DS)))
33956+ return;
33957+
33958+ cpu = raw_get_cpu();
33959+ BUG_ON((read_cr3() & ~PAGE_MASK) != PCID_KERNEL);
33960+ write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER | PCID_NOFLUSH);
33961+ raw_put_cpu_no_resched();
33962+}
33963+EXPORT_SYMBOL(__pax_open_userland);
33964+
33965+void __pax_close_userland(void)
33966+{
33967+ unsigned int cpu;
33968+
33969+ if (unlikely(!segment_eq(get_fs(), USER_DS)))
33970+ return;
33971+
33972+ cpu = raw_get_cpu();
33973+ BUG_ON((read_cr3() & ~PAGE_MASK) != PCID_USER);
33974+ write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
33975+ raw_put_cpu_no_resched();
33976+}
33977+EXPORT_SYMBOL(__pax_close_userland);
33978+#endif
33979diff --git a/arch/x86/net/bpf_jit.S b/arch/x86/net/bpf_jit.S
33980index 0149575..f746de8 100644
33981--- a/arch/x86/net/bpf_jit.S
33982+++ b/arch/x86/net/bpf_jit.S
33983@@ -9,6 +9,7 @@
33984 */
33985 #include <linux/linkage.h>
33986 #include <asm/dwarf2.h>
33987+#include <asm/alternative-asm.h>
33988
33989 /*
33990 * Calling convention :
33991@@ -35,6 +36,7 @@ sk_load_word_positive_offset:
33992 jle bpf_slow_path_word
33993 mov (SKBDATA,%rsi),%eax
33994 bswap %eax /* ntohl() */
33995+ pax_force_retaddr
33996 ret
33997
33998 sk_load_half:
33999@@ -52,6 +54,7 @@ sk_load_half_positive_offset:
34000 jle bpf_slow_path_half
34001 movzwl (SKBDATA,%rsi),%eax
34002 rol $8,%ax # ntohs()
34003+ pax_force_retaddr
34004 ret
34005
34006 sk_load_byte:
34007@@ -66,6 +69,7 @@ sk_load_byte_positive_offset:
34008 cmp %esi,%r9d /* if (offset >= hlen) goto bpf_slow_path_byte */
34009 jle bpf_slow_path_byte
34010 movzbl (SKBDATA,%rsi),%eax
34011+ pax_force_retaddr
34012 ret
34013
34014 /**
34015@@ -87,6 +91,7 @@ sk_load_byte_msh_positive_offset:
34016 movzbl (SKBDATA,%rsi),%ebx
34017 and $15,%bl
34018 shl $2,%bl
34019+ pax_force_retaddr
34020 ret
34021
34022 /* rsi contains offset and can be scratched */
34023@@ -109,6 +114,7 @@ bpf_slow_path_word:
34024 js bpf_error
34025 mov -12(%rbp),%eax
34026 bswap %eax
34027+ pax_force_retaddr
34028 ret
34029
34030 bpf_slow_path_half:
34031@@ -117,12 +123,14 @@ bpf_slow_path_half:
34032 mov -12(%rbp),%ax
34033 rol $8,%ax
34034 movzwl %ax,%eax
34035+ pax_force_retaddr
34036 ret
34037
34038 bpf_slow_path_byte:
34039 bpf_slow_path_common(1)
34040 js bpf_error
34041 movzbl -12(%rbp),%eax
34042+ pax_force_retaddr
34043 ret
34044
34045 bpf_slow_path_byte_msh:
34046@@ -133,6 +141,7 @@ bpf_slow_path_byte_msh:
34047 and $15,%al
34048 shl $2,%al
34049 xchg %eax,%ebx
34050+ pax_force_retaddr
34051 ret
34052
34053 #define sk_negative_common(SIZE) \
34054@@ -157,6 +166,7 @@ sk_load_word_negative_offset:
34055 sk_negative_common(4)
34056 mov (%rax), %eax
34057 bswap %eax
34058+ pax_force_retaddr
34059 ret
34060
34061 bpf_slow_path_half_neg:
34062@@ -168,6 +178,7 @@ sk_load_half_negative_offset:
34063 mov (%rax),%ax
34064 rol $8,%ax
34065 movzwl %ax,%eax
34066+ pax_force_retaddr
34067 ret
34068
34069 bpf_slow_path_byte_neg:
34070@@ -177,6 +188,7 @@ sk_load_byte_negative_offset:
34071 .globl sk_load_byte_negative_offset
34072 sk_negative_common(1)
34073 movzbl (%rax), %eax
34074+ pax_force_retaddr
34075 ret
34076
34077 bpf_slow_path_byte_msh_neg:
34078@@ -190,6 +202,7 @@ sk_load_byte_msh_negative_offset:
34079 and $15,%al
34080 shl $2,%al
34081 xchg %eax,%ebx
34082+ pax_force_retaddr
34083 ret
34084
34085 bpf_error:
34086@@ -197,4 +210,5 @@ bpf_error:
34087 xor %eax,%eax
34088 mov -8(%rbp),%rbx
34089 leaveq
34090+ pax_force_retaddr
34091 ret
34092diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
34093index 4ed75dd..3cf24f0b 100644
34094--- a/arch/x86/net/bpf_jit_comp.c
34095+++ b/arch/x86/net/bpf_jit_comp.c
34096@@ -50,13 +50,90 @@ static inline u8 *emit_code(u8 *ptr, u32 bytes, unsigned int len)
34097 return ptr + len;
34098 }
34099
34100+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
34101+#define MAX_INSTR_CODE_SIZE 96
34102+#else
34103+#define MAX_INSTR_CODE_SIZE 64
34104+#endif
34105+
34106 #define EMIT(bytes, len) do { prog = emit_code(prog, bytes, len); } while (0)
34107
34108 #define EMIT1(b1) EMIT(b1, 1)
34109 #define EMIT2(b1, b2) EMIT((b1) + ((b2) << 8), 2)
34110 #define EMIT3(b1, b2, b3) EMIT((b1) + ((b2) << 8) + ((b3) << 16), 3)
34111 #define EMIT4(b1, b2, b3, b4) EMIT((b1) + ((b2) << 8) + ((b3) << 16) + ((b4) << 24), 4)
34112+
34113+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
34114+/* original constant will appear in ecx */
34115+#define DILUTE_CONST_SEQUENCE(_off, _key) \
34116+do { \
34117+ /* mov ecx, randkey */ \
34118+ EMIT1(0xb9); \
34119+ EMIT(_key, 4); \
34120+ /* xor ecx, randkey ^ off */ \
34121+ EMIT2(0x81, 0xf1); \
34122+ EMIT((_key) ^ (_off), 4); \
34123+} while (0)
34124+
34125+#define EMIT1_off32(b1, _off) \
34126+do { \
34127+ switch (b1) { \
34128+ case 0x05: /* add eax, imm32 */ \
34129+ case 0x2d: /* sub eax, imm32 */ \
34130+ case 0x25: /* and eax, imm32 */ \
34131+ case 0x0d: /* or eax, imm32 */ \
34132+ case 0xb8: /* mov eax, imm32 */ \
34133+ case 0x35: /* xor eax, imm32 */ \
34134+ case 0x3d: /* cmp eax, imm32 */ \
34135+ case 0xa9: /* test eax, imm32 */ \
34136+ DILUTE_CONST_SEQUENCE(_off, randkey); \
34137+ EMIT2((b1) - 4, 0xc8); /* convert imm instruction to eax, ecx */\
34138+ break; \
34139+ case 0xbb: /* mov ebx, imm32 */ \
34140+ DILUTE_CONST_SEQUENCE(_off, randkey); \
34141+ /* mov ebx, ecx */ \
34142+ EMIT2(0x89, 0xcb); \
34143+ break; \
34144+ case 0xbe: /* mov esi, imm32 */ \
34145+ DILUTE_CONST_SEQUENCE(_off, randkey); \
34146+ /* mov esi, ecx */ \
34147+ EMIT2(0x89, 0xce); \
34148+ break; \
34149+ case 0xe8: /* call rel imm32, always to known funcs */ \
34150+ EMIT1(b1); \
34151+ EMIT(_off, 4); \
34152+ break; \
34153+ case 0xe9: /* jmp rel imm32 */ \
34154+ EMIT1(b1); \
34155+ EMIT(_off, 4); \
34156+ /* prevent fall-through, we're not called if off = 0 */ \
34157+ EMIT(0xcccccccc, 4); \
34158+ EMIT(0xcccccccc, 4); \
34159+ break; \
34160+ default: \
34161+ BUILD_BUG(); \
34162+ } \
34163+} while (0)
34164+
34165+#define EMIT2_off32(b1, b2, _off) \
34166+do { \
34167+ if ((b1) == 0x8d && (b2) == 0xb3) { /* lea esi, [rbx+imm32] */ \
34168+ EMIT2(0x8d, 0xb3); /* lea esi, [rbx+randkey] */ \
34169+ EMIT(randkey, 4); \
34170+ EMIT2(0x8d, 0xb6); /* lea esi, [esi+off-randkey] */ \
34171+ EMIT((_off) - randkey, 4); \
34172+ } else if ((b1) == 0x69 && (b2) == 0xc0) { /* imul eax, imm32 */\
34173+ DILUTE_CONST_SEQUENCE(_off, randkey); \
34174+ /* imul eax, ecx */ \
34175+ EMIT3(0x0f, 0xaf, 0xc1); \
34176+ } else { \
34177+ BUILD_BUG(); \
34178+ } \
34179+} while (0)
34180+#else
34181 #define EMIT1_off32(b1, off) do { EMIT1(b1); EMIT(off, 4);} while (0)
34182+#define EMIT2_off32(b1, b2, off) do { EMIT2(b1, b2); EMIT(off, 4);} while (0)
34183+#endif
34184
34185 #define CLEAR_A() EMIT2(0x31, 0xc0) /* xor %eax,%eax */
34186 #define CLEAR_X() EMIT2(0x31, 0xdb) /* xor %ebx,%ebx */
34187@@ -91,6 +168,24 @@ do { \
34188 #define X86_JBE 0x76
34189 #define X86_JA 0x77
34190
34191+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
34192+#define APPEND_FLOW_VERIFY() \
34193+do { \
34194+ /* mov ecx, randkey */ \
34195+ EMIT1(0xb9); \
34196+ EMIT(randkey, 4); \
34197+ /* cmp ecx, randkey */ \
34198+ EMIT2(0x81, 0xf9); \
34199+ EMIT(randkey, 4); \
34200+ /* jz after 8 int 3s */ \
34201+ EMIT2(0x74, 0x08); \
34202+ EMIT(0xcccccccc, 4); \
34203+ EMIT(0xcccccccc, 4); \
34204+} while (0)
34205+#else
34206+#define APPEND_FLOW_VERIFY() do { } while (0)
34207+#endif
34208+
34209 #define EMIT_COND_JMP(op, offset) \
34210 do { \
34211 if (is_near(offset)) \
34212@@ -98,6 +193,7 @@ do { \
34213 else { \
34214 EMIT2(0x0f, op + 0x10); \
34215 EMIT(offset, 4); /* jxx .+off32 */ \
34216+ APPEND_FLOW_VERIFY(); \
34217 } \
34218 } while (0)
34219
34220@@ -145,55 +241,54 @@ static int pkt_type_offset(void)
34221 return -1;
34222 }
34223
34224-struct bpf_binary_header {
34225- unsigned int pages;
34226- /* Note : for security reasons, bpf code will follow a randomly
34227- * sized amount of int3 instructions
34228- */
34229- u8 image[];
34230-};
34231-
34232-static struct bpf_binary_header *bpf_alloc_binary(unsigned int proglen,
34233+/* Note : for security reasons, bpf code will follow a randomly
34234+ * sized amount of int3 instructions
34235+ */
34236+static u8 *bpf_alloc_binary(unsigned int proglen,
34237 u8 **image_ptr)
34238 {
34239 unsigned int sz, hole;
34240- struct bpf_binary_header *header;
34241+ u8 *header;
34242
34243 /* Most of BPF filters are really small,
34244 * but if some of them fill a page, allow at least
34245 * 128 extra bytes to insert a random section of int3
34246 */
34247- sz = round_up(proglen + sizeof(*header) + 128, PAGE_SIZE);
34248- header = module_alloc(sz);
34249+ sz = round_up(proglen + 128, PAGE_SIZE);
34250+ header = module_alloc_exec(sz);
34251 if (!header)
34252 return NULL;
34253
34254+ pax_open_kernel();
34255 memset(header, 0xcc, sz); /* fill whole space with int3 instructions */
34256+ pax_close_kernel();
34257
34258- header->pages = sz / PAGE_SIZE;
34259- hole = sz - (proglen + sizeof(*header));
34260+ hole = PAGE_SIZE - (proglen & ~PAGE_MASK);
34261
34262 /* insert a random number of int3 instructions before BPF code */
34263- *image_ptr = &header->image[prandom_u32() % hole];
34264+ *image_ptr = &header[prandom_u32() % hole];
34265 return header;
34266 }
34267
34268 void bpf_jit_compile(struct sk_filter *fp)
34269 {
34270- u8 temp[64];
34271+ u8 temp[MAX_INSTR_CODE_SIZE];
34272 u8 *prog;
34273 unsigned int proglen, oldproglen = 0;
34274 int ilen, i;
34275 int t_offset, f_offset;
34276 u8 t_op, f_op, seen = 0, pass;
34277 u8 *image = NULL;
34278- struct bpf_binary_header *header = NULL;
34279+ u8 *header = NULL;
34280 u8 *func;
34281 int pc_ret0 = -1; /* bpf index of first RET #0 instruction (if any) */
34282 unsigned int cleanup_addr; /* epilogue code offset */
34283 unsigned int *addrs;
34284 const struct sock_filter *filter = fp->insns;
34285 int flen = fp->len;
34286+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
34287+ unsigned int randkey;
34288+#endif
34289
34290 if (!bpf_jit_enable)
34291 return;
34292@@ -203,10 +298,10 @@ void bpf_jit_compile(struct sk_filter *fp)
34293 return;
34294
34295 /* Before first pass, make a rough estimation of addrs[]
34296- * each bpf instruction is translated to less than 64 bytes
34297+ * each bpf instruction is translated to less than MAX_INSTR_CODE_SIZE bytes
34298 */
34299 for (proglen = 0, i = 0; i < flen; i++) {
34300- proglen += 64;
34301+ proglen += MAX_INSTR_CODE_SIZE;
34302 addrs[i] = proglen;
34303 }
34304 cleanup_addr = proglen; /* epilogue address */
34305@@ -285,6 +380,10 @@ void bpf_jit_compile(struct sk_filter *fp)
34306 for (i = 0; i < flen; i++) {
34307 unsigned int K = filter[i].k;
34308
34309+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
34310+ randkey = prandom_u32();
34311+#endif
34312+
34313 switch (filter[i].code) {
34314 case BPF_S_ALU_ADD_X: /* A += X; */
34315 seen |= SEEN_XREG;
34316@@ -317,10 +416,8 @@ void bpf_jit_compile(struct sk_filter *fp)
34317 case BPF_S_ALU_MUL_K: /* A *= K */
34318 if (is_imm8(K))
34319 EMIT3(0x6b, 0xc0, K); /* imul imm8,%eax,%eax */
34320- else {
34321- EMIT2(0x69, 0xc0); /* imul imm32,%eax */
34322- EMIT(K, 4);
34323- }
34324+ else
34325+ EMIT2_off32(0x69, 0xc0, K); /* imul imm32,%eax */
34326 break;
34327 case BPF_S_ALU_DIV_X: /* A /= X; */
34328 seen |= SEEN_XREG;
34329@@ -364,7 +461,11 @@ void bpf_jit_compile(struct sk_filter *fp)
34330 break;
34331 }
34332 EMIT2(0x31, 0xd2); /* xor %edx,%edx */
34333+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
34334+ DILUTE_CONST_SEQUENCE(K, randkey);
34335+#else
34336 EMIT1(0xb9);EMIT(K, 4); /* mov imm32,%ecx */
34337+#endif
34338 EMIT2(0xf7, 0xf1); /* div %ecx */
34339 EMIT2(0x89, 0xd0); /* mov %edx,%eax */
34340 break;
34341@@ -372,7 +473,11 @@ void bpf_jit_compile(struct sk_filter *fp)
34342 if (K == 1)
34343 break;
34344 EMIT2(0x31, 0xd2); /* xor %edx,%edx */
34345+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
34346+ DILUTE_CONST_SEQUENCE(K, randkey);
34347+#else
34348 EMIT1(0xb9);EMIT(K, 4); /* mov imm32,%ecx */
34349+#endif
34350 EMIT2(0xf7, 0xf1); /* div %ecx */
34351 break;
34352 case BPF_S_ALU_AND_X:
34353@@ -643,8 +748,7 @@ common_load_ind: seen |= SEEN_DATAREF | SEEN_XREG;
34354 if (is_imm8(K)) {
34355 EMIT3(0x8d, 0x73, K); /* lea imm8(%rbx), %esi */
34356 } else {
34357- EMIT2(0x8d, 0xb3); /* lea imm32(%rbx),%esi */
34358- EMIT(K, 4);
34359+ EMIT2_off32(0x8d, 0xb3, K); /* lea imm32(%rbx),%esi */
34360 }
34361 } else {
34362 EMIT2(0x89,0xde); /* mov %ebx,%esi */
34363@@ -734,10 +838,12 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
34364 if (unlikely(proglen + ilen > oldproglen)) {
34365 pr_err("bpb_jit_compile fatal error\n");
34366 kfree(addrs);
34367- module_free(NULL, header);
34368+ module_free_exec(NULL, image);
34369 return;
34370 }
34371+ pax_open_kernel();
34372 memcpy(image + proglen, temp, ilen);
34373+ pax_close_kernel();
34374 }
34375 proglen += ilen;
34376 addrs[i] = proglen;
34377@@ -770,7 +876,6 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
34378
34379 if (image) {
34380 bpf_flush_icache(header, image + proglen);
34381- set_memory_ro((unsigned long)header, header->pages);
34382 fp->bpf_func = (void *)image;
34383 }
34384 out:
34385@@ -782,10 +887,9 @@ static void bpf_jit_free_deferred(struct work_struct *work)
34386 {
34387 struct sk_filter *fp = container_of(work, struct sk_filter, work);
34388 unsigned long addr = (unsigned long)fp->bpf_func & PAGE_MASK;
34389- struct bpf_binary_header *header = (void *)addr;
34390
34391- set_memory_rw(addr, header->pages);
34392- module_free(NULL, header);
34393+ set_memory_rw(addr, 1);
34394+ module_free_exec(NULL, (void *)addr);
34395 kfree(fp);
34396 }
34397
34398diff --git a/arch/x86/oprofile/backtrace.c b/arch/x86/oprofile/backtrace.c
34399index 5d04be5..2beeaa2 100644
34400--- a/arch/x86/oprofile/backtrace.c
34401+++ b/arch/x86/oprofile/backtrace.c
34402@@ -46,11 +46,11 @@ dump_user_backtrace_32(struct stack_frame_ia32 *head)
34403 struct stack_frame_ia32 *fp;
34404 unsigned long bytes;
34405
34406- bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
34407+ bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
34408 if (bytes != 0)
34409 return NULL;
34410
34411- fp = (struct stack_frame_ia32 *) compat_ptr(bufhead[0].next_frame);
34412+ fp = (struct stack_frame_ia32 __force_kernel *) compat_ptr(bufhead[0].next_frame);
34413
34414 oprofile_add_trace(bufhead[0].return_address);
34415
34416@@ -92,7 +92,7 @@ static struct stack_frame *dump_user_backtrace(struct stack_frame *head)
34417 struct stack_frame bufhead[2];
34418 unsigned long bytes;
34419
34420- bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
34421+ bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
34422 if (bytes != 0)
34423 return NULL;
34424
34425@@ -111,7 +111,7 @@ x86_backtrace(struct pt_regs * const regs, unsigned int depth)
34426 {
34427 struct stack_frame *head = (struct stack_frame *)frame_pointer(regs);
34428
34429- if (!user_mode_vm(regs)) {
34430+ if (!user_mode(regs)) {
34431 unsigned long stack = kernel_stack_pointer(regs);
34432 if (depth)
34433 dump_trace(NULL, regs, (unsigned long *)stack, 0,
34434diff --git a/arch/x86/oprofile/nmi_int.c b/arch/x86/oprofile/nmi_int.c
34435index 6890d84..1dad1f1 100644
34436--- a/arch/x86/oprofile/nmi_int.c
34437+++ b/arch/x86/oprofile/nmi_int.c
34438@@ -23,6 +23,7 @@
34439 #include <asm/nmi.h>
34440 #include <asm/msr.h>
34441 #include <asm/apic.h>
34442+#include <asm/pgtable.h>
34443
34444 #include "op_counter.h"
34445 #include "op_x86_model.h"
34446@@ -774,8 +775,11 @@ int __init op_nmi_init(struct oprofile_operations *ops)
34447 if (ret)
34448 return ret;
34449
34450- if (!model->num_virt_counters)
34451- model->num_virt_counters = model->num_counters;
34452+ if (!model->num_virt_counters) {
34453+ pax_open_kernel();
34454+ *(unsigned int *)&model->num_virt_counters = model->num_counters;
34455+ pax_close_kernel();
34456+ }
34457
34458 mux_init(ops);
34459
34460diff --git a/arch/x86/oprofile/op_model_amd.c b/arch/x86/oprofile/op_model_amd.c
34461index 50d86c0..7985318 100644
34462--- a/arch/x86/oprofile/op_model_amd.c
34463+++ b/arch/x86/oprofile/op_model_amd.c
34464@@ -519,9 +519,11 @@ static int op_amd_init(struct oprofile_operations *ops)
34465 num_counters = AMD64_NUM_COUNTERS;
34466 }
34467
34468- op_amd_spec.num_counters = num_counters;
34469- op_amd_spec.num_controls = num_counters;
34470- op_amd_spec.num_virt_counters = max(num_counters, NUM_VIRT_COUNTERS);
34471+ pax_open_kernel();
34472+ *(unsigned int *)&op_amd_spec.num_counters = num_counters;
34473+ *(unsigned int *)&op_amd_spec.num_controls = num_counters;
34474+ *(unsigned int *)&op_amd_spec.num_virt_counters = max(num_counters, NUM_VIRT_COUNTERS);
34475+ pax_close_kernel();
34476
34477 return 0;
34478 }
34479diff --git a/arch/x86/oprofile/op_model_ppro.c b/arch/x86/oprofile/op_model_ppro.c
34480index d90528e..0127e2b 100644
34481--- a/arch/x86/oprofile/op_model_ppro.c
34482+++ b/arch/x86/oprofile/op_model_ppro.c
34483@@ -19,6 +19,7 @@
34484 #include <asm/msr.h>
34485 #include <asm/apic.h>
34486 #include <asm/nmi.h>
34487+#include <asm/pgtable.h>
34488
34489 #include "op_x86_model.h"
34490 #include "op_counter.h"
34491@@ -221,8 +222,10 @@ static void arch_perfmon_setup_counters(void)
34492
34493 num_counters = min((int)eax.split.num_counters, OP_MAX_COUNTER);
34494
34495- op_arch_perfmon_spec.num_counters = num_counters;
34496- op_arch_perfmon_spec.num_controls = num_counters;
34497+ pax_open_kernel();
34498+ *(unsigned int *)&op_arch_perfmon_spec.num_counters = num_counters;
34499+ *(unsigned int *)&op_arch_perfmon_spec.num_controls = num_counters;
34500+ pax_close_kernel();
34501 }
34502
34503 static int arch_perfmon_init(struct oprofile_operations *ignore)
34504diff --git a/arch/x86/oprofile/op_x86_model.h b/arch/x86/oprofile/op_x86_model.h
34505index 71e8a67..6a313bb 100644
34506--- a/arch/x86/oprofile/op_x86_model.h
34507+++ b/arch/x86/oprofile/op_x86_model.h
34508@@ -52,7 +52,7 @@ struct op_x86_model_spec {
34509 void (*switch_ctrl)(struct op_x86_model_spec const *model,
34510 struct op_msrs const * const msrs);
34511 #endif
34512-};
34513+} __do_const;
34514
34515 struct op_counter_config;
34516
34517diff --git a/arch/x86/pci/intel_mid_pci.c b/arch/x86/pci/intel_mid_pci.c
34518index 84b9d67..260e5ff 100644
34519--- a/arch/x86/pci/intel_mid_pci.c
34520+++ b/arch/x86/pci/intel_mid_pci.c
34521@@ -245,7 +245,7 @@ int __init intel_mid_pci_init(void)
34522 pr_info("Intel MID platform detected, using MID PCI ops\n");
34523 pci_mmcfg_late_init();
34524 pcibios_enable_irq = intel_mid_pci_irq_enable;
34525- pci_root_ops = intel_mid_pci_ops;
34526+ memcpy((void *)&pci_root_ops, &intel_mid_pci_ops, sizeof pci_root_ops);
34527 pci_soc_mode = 1;
34528 /* Continue with standard init */
34529 return 1;
34530diff --git a/arch/x86/pci/irq.c b/arch/x86/pci/irq.c
34531index 372e9b8..e775a6c 100644
34532--- a/arch/x86/pci/irq.c
34533+++ b/arch/x86/pci/irq.c
34534@@ -50,7 +50,7 @@ struct irq_router {
34535 struct irq_router_handler {
34536 u16 vendor;
34537 int (*probe)(struct irq_router *r, struct pci_dev *router, u16 device);
34538-};
34539+} __do_const;
34540
34541 int (*pcibios_enable_irq)(struct pci_dev *dev) = pirq_enable_irq;
34542 void (*pcibios_disable_irq)(struct pci_dev *dev) = NULL;
34543@@ -794,7 +794,7 @@ static __init int pico_router_probe(struct irq_router *r, struct pci_dev *router
34544 return 0;
34545 }
34546
34547-static __initdata struct irq_router_handler pirq_routers[] = {
34548+static __initconst const struct irq_router_handler pirq_routers[] = {
34549 { PCI_VENDOR_ID_INTEL, intel_router_probe },
34550 { PCI_VENDOR_ID_AL, ali_router_probe },
34551 { PCI_VENDOR_ID_ITE, ite_router_probe },
34552@@ -821,7 +821,7 @@ static struct pci_dev *pirq_router_dev;
34553 static void __init pirq_find_router(struct irq_router *r)
34554 {
34555 struct irq_routing_table *rt = pirq_table;
34556- struct irq_router_handler *h;
34557+ const struct irq_router_handler *h;
34558
34559 #ifdef CONFIG_PCI_BIOS
34560 if (!rt->signature) {
34561@@ -1094,7 +1094,7 @@ static int __init fix_acer_tm360_irqrouting(const struct dmi_system_id *d)
34562 return 0;
34563 }
34564
34565-static struct dmi_system_id __initdata pciirq_dmi_table[] = {
34566+static const struct dmi_system_id __initconst pciirq_dmi_table[] = {
34567 {
34568 .callback = fix_broken_hp_bios_irq9,
34569 .ident = "HP Pavilion N5400 Series Laptop",
34570diff --git a/arch/x86/pci/pcbios.c b/arch/x86/pci/pcbios.c
34571index c77b24a..c979855 100644
34572--- a/arch/x86/pci/pcbios.c
34573+++ b/arch/x86/pci/pcbios.c
34574@@ -79,7 +79,7 @@ union bios32 {
34575 static struct {
34576 unsigned long address;
34577 unsigned short segment;
34578-} bios32_indirect = { 0, __KERNEL_CS };
34579+} bios32_indirect __read_only = { 0, __PCIBIOS_CS };
34580
34581 /*
34582 * Returns the entry point for the given service, NULL on error
34583@@ -92,37 +92,80 @@ static unsigned long bios32_service(unsigned long service)
34584 unsigned long length; /* %ecx */
34585 unsigned long entry; /* %edx */
34586 unsigned long flags;
34587+ struct desc_struct d, *gdt;
34588
34589 local_irq_save(flags);
34590- __asm__("lcall *(%%edi); cld"
34591+
34592+ gdt = get_cpu_gdt_table(smp_processor_id());
34593+
34594+ pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x9B, 0xC);
34595+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
34596+ pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x93, 0xC);
34597+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
34598+
34599+ __asm__("movw %w7, %%ds; lcall *(%%edi); push %%ss; pop %%ds; cld"
34600 : "=a" (return_code),
34601 "=b" (address),
34602 "=c" (length),
34603 "=d" (entry)
34604 : "0" (service),
34605 "1" (0),
34606- "D" (&bios32_indirect));
34607+ "D" (&bios32_indirect),
34608+ "r"(__PCIBIOS_DS)
34609+ : "memory");
34610+
34611+ pax_open_kernel();
34612+ gdt[GDT_ENTRY_PCIBIOS_CS].a = 0;
34613+ gdt[GDT_ENTRY_PCIBIOS_CS].b = 0;
34614+ gdt[GDT_ENTRY_PCIBIOS_DS].a = 0;
34615+ gdt[GDT_ENTRY_PCIBIOS_DS].b = 0;
34616+ pax_close_kernel();
34617+
34618 local_irq_restore(flags);
34619
34620 switch (return_code) {
34621- case 0:
34622- return address + entry;
34623- case 0x80: /* Not present */
34624- printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
34625- return 0;
34626- default: /* Shouldn't happen */
34627- printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
34628- service, return_code);
34629+ case 0: {
34630+ int cpu;
34631+ unsigned char flags;
34632+
34633+ printk(KERN_INFO "bios32_service: base:%08lx length:%08lx entry:%08lx\n", address, length, entry);
34634+ if (address >= 0xFFFF0 || length > 0x100000 - address || length <= entry) {
34635+ printk(KERN_WARNING "bios32_service: not valid\n");
34636 return 0;
34637+ }
34638+ address = address + PAGE_OFFSET;
34639+ length += 16UL; /* some BIOSs underreport this... */
34640+ flags = 4;
34641+ if (length >= 64*1024*1024) {
34642+ length >>= PAGE_SHIFT;
34643+ flags |= 8;
34644+ }
34645+
34646+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
34647+ gdt = get_cpu_gdt_table(cpu);
34648+ pack_descriptor(&d, address, length, 0x9b, flags);
34649+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
34650+ pack_descriptor(&d, address, length, 0x93, flags);
34651+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
34652+ }
34653+ return entry;
34654+ }
34655+ case 0x80: /* Not present */
34656+ printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
34657+ return 0;
34658+ default: /* Shouldn't happen */
34659+ printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
34660+ service, return_code);
34661+ return 0;
34662 }
34663 }
34664
34665 static struct {
34666 unsigned long address;
34667 unsigned short segment;
34668-} pci_indirect = { 0, __KERNEL_CS };
34669+} pci_indirect __read_only = { 0, __PCIBIOS_CS };
34670
34671-static int pci_bios_present;
34672+static int pci_bios_present __read_only;
34673
34674 static int check_pcibios(void)
34675 {
34676@@ -131,11 +174,13 @@ static int check_pcibios(void)
34677 unsigned long flags, pcibios_entry;
34678
34679 if ((pcibios_entry = bios32_service(PCI_SERVICE))) {
34680- pci_indirect.address = pcibios_entry + PAGE_OFFSET;
34681+ pci_indirect.address = pcibios_entry;
34682
34683 local_irq_save(flags);
34684- __asm__(
34685- "lcall *(%%edi); cld\n\t"
34686+ __asm__("movw %w6, %%ds\n\t"
34687+ "lcall *%%ss:(%%edi); cld\n\t"
34688+ "push %%ss\n\t"
34689+ "pop %%ds\n\t"
34690 "jc 1f\n\t"
34691 "xor %%ah, %%ah\n"
34692 "1:"
34693@@ -144,7 +189,8 @@ static int check_pcibios(void)
34694 "=b" (ebx),
34695 "=c" (ecx)
34696 : "1" (PCIBIOS_PCI_BIOS_PRESENT),
34697- "D" (&pci_indirect)
34698+ "D" (&pci_indirect),
34699+ "r" (__PCIBIOS_DS)
34700 : "memory");
34701 local_irq_restore(flags);
34702
34703@@ -189,7 +235,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
34704
34705 switch (len) {
34706 case 1:
34707- __asm__("lcall *(%%esi); cld\n\t"
34708+ __asm__("movw %w6, %%ds\n\t"
34709+ "lcall *%%ss:(%%esi); cld\n\t"
34710+ "push %%ss\n\t"
34711+ "pop %%ds\n\t"
34712 "jc 1f\n\t"
34713 "xor %%ah, %%ah\n"
34714 "1:"
34715@@ -198,7 +247,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
34716 : "1" (PCIBIOS_READ_CONFIG_BYTE),
34717 "b" (bx),
34718 "D" ((long)reg),
34719- "S" (&pci_indirect));
34720+ "S" (&pci_indirect),
34721+ "r" (__PCIBIOS_DS));
34722 /*
34723 * Zero-extend the result beyond 8 bits, do not trust the
34724 * BIOS having done it:
34725@@ -206,7 +256,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
34726 *value &= 0xff;
34727 break;
34728 case 2:
34729- __asm__("lcall *(%%esi); cld\n\t"
34730+ __asm__("movw %w6, %%ds\n\t"
34731+ "lcall *%%ss:(%%esi); cld\n\t"
34732+ "push %%ss\n\t"
34733+ "pop %%ds\n\t"
34734 "jc 1f\n\t"
34735 "xor %%ah, %%ah\n"
34736 "1:"
34737@@ -215,7 +268,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
34738 : "1" (PCIBIOS_READ_CONFIG_WORD),
34739 "b" (bx),
34740 "D" ((long)reg),
34741- "S" (&pci_indirect));
34742+ "S" (&pci_indirect),
34743+ "r" (__PCIBIOS_DS));
34744 /*
34745 * Zero-extend the result beyond 16 bits, do not trust the
34746 * BIOS having done it:
34747@@ -223,7 +277,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
34748 *value &= 0xffff;
34749 break;
34750 case 4:
34751- __asm__("lcall *(%%esi); cld\n\t"
34752+ __asm__("movw %w6, %%ds\n\t"
34753+ "lcall *%%ss:(%%esi); cld\n\t"
34754+ "push %%ss\n\t"
34755+ "pop %%ds\n\t"
34756 "jc 1f\n\t"
34757 "xor %%ah, %%ah\n"
34758 "1:"
34759@@ -232,7 +289,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
34760 : "1" (PCIBIOS_READ_CONFIG_DWORD),
34761 "b" (bx),
34762 "D" ((long)reg),
34763- "S" (&pci_indirect));
34764+ "S" (&pci_indirect),
34765+ "r" (__PCIBIOS_DS));
34766 break;
34767 }
34768
34769@@ -256,7 +314,10 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
34770
34771 switch (len) {
34772 case 1:
34773- __asm__("lcall *(%%esi); cld\n\t"
34774+ __asm__("movw %w6, %%ds\n\t"
34775+ "lcall *%%ss:(%%esi); cld\n\t"
34776+ "push %%ss\n\t"
34777+ "pop %%ds\n\t"
34778 "jc 1f\n\t"
34779 "xor %%ah, %%ah\n"
34780 "1:"
34781@@ -265,10 +326,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
34782 "c" (value),
34783 "b" (bx),
34784 "D" ((long)reg),
34785- "S" (&pci_indirect));
34786+ "S" (&pci_indirect),
34787+ "r" (__PCIBIOS_DS));
34788 break;
34789 case 2:
34790- __asm__("lcall *(%%esi); cld\n\t"
34791+ __asm__("movw %w6, %%ds\n\t"
34792+ "lcall *%%ss:(%%esi); cld\n\t"
34793+ "push %%ss\n\t"
34794+ "pop %%ds\n\t"
34795 "jc 1f\n\t"
34796 "xor %%ah, %%ah\n"
34797 "1:"
34798@@ -277,10 +342,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
34799 "c" (value),
34800 "b" (bx),
34801 "D" ((long)reg),
34802- "S" (&pci_indirect));
34803+ "S" (&pci_indirect),
34804+ "r" (__PCIBIOS_DS));
34805 break;
34806 case 4:
34807- __asm__("lcall *(%%esi); cld\n\t"
34808+ __asm__("movw %w6, %%ds\n\t"
34809+ "lcall *%%ss:(%%esi); cld\n\t"
34810+ "push %%ss\n\t"
34811+ "pop %%ds\n\t"
34812 "jc 1f\n\t"
34813 "xor %%ah, %%ah\n"
34814 "1:"
34815@@ -289,7 +358,8 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
34816 "c" (value),
34817 "b" (bx),
34818 "D" ((long)reg),
34819- "S" (&pci_indirect));
34820+ "S" (&pci_indirect),
34821+ "r" (__PCIBIOS_DS));
34822 break;
34823 }
34824
34825@@ -394,10 +464,13 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
34826
34827 DBG("PCI: Fetching IRQ routing table... ");
34828 __asm__("push %%es\n\t"
34829+ "movw %w8, %%ds\n\t"
34830 "push %%ds\n\t"
34831 "pop %%es\n\t"
34832- "lcall *(%%esi); cld\n\t"
34833+ "lcall *%%ss:(%%esi); cld\n\t"
34834 "pop %%es\n\t"
34835+ "push %%ss\n\t"
34836+ "pop %%ds\n"
34837 "jc 1f\n\t"
34838 "xor %%ah, %%ah\n"
34839 "1:"
34840@@ -408,7 +481,8 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
34841 "1" (0),
34842 "D" ((long) &opt),
34843 "S" (&pci_indirect),
34844- "m" (opt)
34845+ "m" (opt),
34846+ "r" (__PCIBIOS_DS)
34847 : "memory");
34848 DBG("OK ret=%d, size=%d, map=%x\n", ret, opt.size, map);
34849 if (ret & 0xff00)
34850@@ -432,7 +506,10 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
34851 {
34852 int ret;
34853
34854- __asm__("lcall *(%%esi); cld\n\t"
34855+ __asm__("movw %w5, %%ds\n\t"
34856+ "lcall *%%ss:(%%esi); cld\n\t"
34857+ "push %%ss\n\t"
34858+ "pop %%ds\n"
34859 "jc 1f\n\t"
34860 "xor %%ah, %%ah\n"
34861 "1:"
34862@@ -440,7 +517,8 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
34863 : "0" (PCIBIOS_SET_PCI_HW_INT),
34864 "b" ((dev->bus->number << 8) | dev->devfn),
34865 "c" ((irq << 8) | (pin + 10)),
34866- "S" (&pci_indirect));
34867+ "S" (&pci_indirect),
34868+ "r" (__PCIBIOS_DS));
34869 return !(ret & 0xff00);
34870 }
34871 EXPORT_SYMBOL(pcibios_set_irq_routing);
34872diff --git a/arch/x86/platform/efi/efi_32.c b/arch/x86/platform/efi/efi_32.c
34873index 9ee3491..872192f 100644
34874--- a/arch/x86/platform/efi/efi_32.c
34875+++ b/arch/x86/platform/efi/efi_32.c
34876@@ -59,11 +59,22 @@ void efi_call_phys_prelog(void)
34877 {
34878 struct desc_ptr gdt_descr;
34879
34880+#ifdef CONFIG_PAX_KERNEXEC
34881+ struct desc_struct d;
34882+#endif
34883+
34884 local_irq_save(efi_rt_eflags);
34885
34886 load_cr3(initial_page_table);
34887 __flush_tlb_all();
34888
34889+#ifdef CONFIG_PAX_KERNEXEC
34890+ pack_descriptor(&d, 0, 0xFFFFF, 0x9B, 0xC);
34891+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
34892+ pack_descriptor(&d, 0, 0xFFFFF, 0x93, 0xC);
34893+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
34894+#endif
34895+
34896 gdt_descr.address = __pa(get_cpu_gdt_table(0));
34897 gdt_descr.size = GDT_SIZE - 1;
34898 load_gdt(&gdt_descr);
34899@@ -73,11 +84,24 @@ void efi_call_phys_epilog(void)
34900 {
34901 struct desc_ptr gdt_descr;
34902
34903+#ifdef CONFIG_PAX_KERNEXEC
34904+ struct desc_struct d;
34905+
34906+ memset(&d, 0, sizeof d);
34907+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
34908+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
34909+#endif
34910+
34911 gdt_descr.address = (unsigned long)get_cpu_gdt_table(0);
34912 gdt_descr.size = GDT_SIZE - 1;
34913 load_gdt(&gdt_descr);
34914
34915+#ifdef CONFIG_PAX_PER_CPU_PGD
34916+ load_cr3(get_cpu_pgd(smp_processor_id(), kernel));
34917+#else
34918 load_cr3(swapper_pg_dir);
34919+#endif
34920+
34921 __flush_tlb_all();
34922
34923 local_irq_restore(efi_rt_eflags);
34924diff --git a/arch/x86/platform/efi/efi_64.c b/arch/x86/platform/efi/efi_64.c
34925index 666b74a..673d88f 100644
34926--- a/arch/x86/platform/efi/efi_64.c
34927+++ b/arch/x86/platform/efi/efi_64.c
34928@@ -97,6 +97,11 @@ void __init efi_call_phys_prelog(void)
34929 vaddress = (unsigned long)__va(pgd * PGDIR_SIZE);
34930 set_pgd(pgd_offset_k(pgd * PGDIR_SIZE), *pgd_offset_k(vaddress));
34931 }
34932+
34933+#ifdef CONFIG_PAX_PER_CPU_PGD
34934+ load_cr3(swapper_pg_dir);
34935+#endif
34936+
34937 __flush_tlb_all();
34938 }
34939
34940@@ -114,6 +119,11 @@ void __init efi_call_phys_epilog(void)
34941 for (pgd = 0; pgd < n_pgds; pgd++)
34942 set_pgd(pgd_offset_k(pgd * PGDIR_SIZE), save_pgd[pgd]);
34943 kfree(save_pgd);
34944+
34945+#ifdef CONFIG_PAX_PER_CPU_PGD
34946+ load_cr3(get_cpu_pgd(smp_processor_id(), kernel));
34947+#endif
34948+
34949 __flush_tlb_all();
34950 local_irq_restore(efi_flags);
34951 early_code_mapping_set_exec(0);
34952diff --git a/arch/x86/platform/efi/efi_stub_32.S b/arch/x86/platform/efi/efi_stub_32.S
34953index fbe66e6..eae5e38 100644
34954--- a/arch/x86/platform/efi/efi_stub_32.S
34955+++ b/arch/x86/platform/efi/efi_stub_32.S
34956@@ -6,7 +6,9 @@
34957 */
34958
34959 #include <linux/linkage.h>
34960+#include <linux/init.h>
34961 #include <asm/page_types.h>
34962+#include <asm/segment.h>
34963
34964 /*
34965 * efi_call_phys(void *, ...) is a function with variable parameters.
34966@@ -20,7 +22,7 @@
34967 * service functions will comply with gcc calling convention, too.
34968 */
34969
34970-.text
34971+__INIT
34972 ENTRY(efi_call_phys)
34973 /*
34974 * 0. The function can only be called in Linux kernel. So CS has been
34975@@ -36,10 +38,24 @@ ENTRY(efi_call_phys)
34976 * The mapping of lower virtual memory has been created in prelog and
34977 * epilog.
34978 */
34979- movl $1f, %edx
34980- subl $__PAGE_OFFSET, %edx
34981- jmp *%edx
34982+#ifdef CONFIG_PAX_KERNEXEC
34983+ movl $(__KERNEXEC_EFI_DS), %edx
34984+ mov %edx, %ds
34985+ mov %edx, %es
34986+ mov %edx, %ss
34987+ addl $2f,(1f)
34988+ ljmp *(1f)
34989+
34990+__INITDATA
34991+1: .long __LOAD_PHYSICAL_ADDR, __KERNEXEC_EFI_CS
34992+.previous
34993+
34994+2:
34995+ subl $2b,(1b)
34996+#else
34997+ jmp 1f-__PAGE_OFFSET
34998 1:
34999+#endif
35000
35001 /*
35002 * 2. Now on the top of stack is the return
35003@@ -47,14 +63,8 @@ ENTRY(efi_call_phys)
35004 * parameter 2, ..., param n. To make things easy, we save the return
35005 * address of efi_call_phys in a global variable.
35006 */
35007- popl %edx
35008- movl %edx, saved_return_addr
35009- /* get the function pointer into ECX*/
35010- popl %ecx
35011- movl %ecx, efi_rt_function_ptr
35012- movl $2f, %edx
35013- subl $__PAGE_OFFSET, %edx
35014- pushl %edx
35015+ popl (saved_return_addr)
35016+ popl (efi_rt_function_ptr)
35017
35018 /*
35019 * 3. Clear PG bit in %CR0.
35020@@ -73,9 +83,8 @@ ENTRY(efi_call_phys)
35021 /*
35022 * 5. Call the physical function.
35023 */
35024- jmp *%ecx
35025+ call *(efi_rt_function_ptr-__PAGE_OFFSET)
35026
35027-2:
35028 /*
35029 * 6. After EFI runtime service returns, control will return to
35030 * following instruction. We'd better readjust stack pointer first.
35031@@ -88,35 +97,36 @@ ENTRY(efi_call_phys)
35032 movl %cr0, %edx
35033 orl $0x80000000, %edx
35034 movl %edx, %cr0
35035- jmp 1f
35036-1:
35037+
35038 /*
35039 * 8. Now restore the virtual mode from flat mode by
35040 * adding EIP with PAGE_OFFSET.
35041 */
35042- movl $1f, %edx
35043- jmp *%edx
35044+#ifdef CONFIG_PAX_KERNEXEC
35045+ movl $(__KERNEL_DS), %edx
35046+ mov %edx, %ds
35047+ mov %edx, %es
35048+ mov %edx, %ss
35049+ ljmp $(__KERNEL_CS),$1f
35050+#else
35051+ jmp 1f+__PAGE_OFFSET
35052+#endif
35053 1:
35054
35055 /*
35056 * 9. Balance the stack. And because EAX contain the return value,
35057 * we'd better not clobber it.
35058 */
35059- leal efi_rt_function_ptr, %edx
35060- movl (%edx), %ecx
35061- pushl %ecx
35062+ pushl (efi_rt_function_ptr)
35063
35064 /*
35065- * 10. Push the saved return address onto the stack and return.
35066+ * 10. Return to the saved return address.
35067 */
35068- leal saved_return_addr, %edx
35069- movl (%edx), %ecx
35070- pushl %ecx
35071- ret
35072+ jmpl *(saved_return_addr)
35073 ENDPROC(efi_call_phys)
35074 .previous
35075
35076-.data
35077+__INITDATA
35078 saved_return_addr:
35079 .long 0
35080 efi_rt_function_ptr:
35081diff --git a/arch/x86/platform/efi/efi_stub_64.S b/arch/x86/platform/efi/efi_stub_64.S
35082index 88073b1..1cc2f53 100644
35083--- a/arch/x86/platform/efi/efi_stub_64.S
35084+++ b/arch/x86/platform/efi/efi_stub_64.S
35085@@ -7,6 +7,7 @@
35086 */
35087
35088 #include <linux/linkage.h>
35089+#include <asm/alternative-asm.h>
35090
35091 #define SAVE_XMM \
35092 mov %rsp, %rax; \
35093@@ -77,6 +78,7 @@ ENTRY(efi_call0)
35094 RESTORE_PGT
35095 addq $32, %rsp
35096 RESTORE_XMM
35097+ pax_force_retaddr 0, 1
35098 ret
35099 ENDPROC(efi_call0)
35100
35101@@ -89,6 +91,7 @@ ENTRY(efi_call1)
35102 RESTORE_PGT
35103 addq $32, %rsp
35104 RESTORE_XMM
35105+ pax_force_retaddr 0, 1
35106 ret
35107 ENDPROC(efi_call1)
35108
35109@@ -101,6 +104,7 @@ ENTRY(efi_call2)
35110 RESTORE_PGT
35111 addq $32, %rsp
35112 RESTORE_XMM
35113+ pax_force_retaddr 0, 1
35114 ret
35115 ENDPROC(efi_call2)
35116
35117@@ -114,6 +118,7 @@ ENTRY(efi_call3)
35118 RESTORE_PGT
35119 addq $32, %rsp
35120 RESTORE_XMM
35121+ pax_force_retaddr 0, 1
35122 ret
35123 ENDPROC(efi_call3)
35124
35125@@ -128,6 +133,7 @@ ENTRY(efi_call4)
35126 RESTORE_PGT
35127 addq $32, %rsp
35128 RESTORE_XMM
35129+ pax_force_retaddr 0, 1
35130 ret
35131 ENDPROC(efi_call4)
35132
35133@@ -143,6 +149,7 @@ ENTRY(efi_call5)
35134 RESTORE_PGT
35135 addq $48, %rsp
35136 RESTORE_XMM
35137+ pax_force_retaddr 0, 1
35138 ret
35139 ENDPROC(efi_call5)
35140
35141@@ -161,6 +168,7 @@ ENTRY(efi_call6)
35142 RESTORE_PGT
35143 addq $48, %rsp
35144 RESTORE_XMM
35145+ pax_force_retaddr 0, 1
35146 ret
35147 ENDPROC(efi_call6)
35148
35149diff --git a/arch/x86/platform/intel-mid/intel-mid.c b/arch/x86/platform/intel-mid/intel-mid.c
35150index 1bbedc4..eb795b5 100644
35151--- a/arch/x86/platform/intel-mid/intel-mid.c
35152+++ b/arch/x86/platform/intel-mid/intel-mid.c
35153@@ -71,9 +71,10 @@ static void intel_mid_power_off(void)
35154 {
35155 };
35156
35157-static void intel_mid_reboot(void)
35158+static void __noreturn intel_mid_reboot(void)
35159 {
35160 intel_scu_ipc_simple_command(IPCMSG_COLD_BOOT, 0);
35161+ BUG();
35162 }
35163
35164 static unsigned long __init intel_mid_calibrate_tsc(void)
35165diff --git a/arch/x86/platform/olpc/olpc_dt.c b/arch/x86/platform/olpc/olpc_dt.c
35166index d6ee929..3637cb5 100644
35167--- a/arch/x86/platform/olpc/olpc_dt.c
35168+++ b/arch/x86/platform/olpc/olpc_dt.c
35169@@ -156,7 +156,7 @@ void * __init prom_early_alloc(unsigned long size)
35170 return res;
35171 }
35172
35173-static struct of_pdt_ops prom_olpc_ops __initdata = {
35174+static struct of_pdt_ops prom_olpc_ops __initconst = {
35175 .nextprop = olpc_dt_nextprop,
35176 .getproplen = olpc_dt_getproplen,
35177 .getproperty = olpc_dt_getproperty,
35178diff --git a/arch/x86/power/cpu.c b/arch/x86/power/cpu.c
35179index 424f4c9..f2a2988 100644
35180--- a/arch/x86/power/cpu.c
35181+++ b/arch/x86/power/cpu.c
35182@@ -137,11 +137,8 @@ static void do_fpu_end(void)
35183 static void fix_processor_context(void)
35184 {
35185 int cpu = smp_processor_id();
35186- struct tss_struct *t = &per_cpu(init_tss, cpu);
35187-#ifdef CONFIG_X86_64
35188- struct desc_struct *desc = get_cpu_gdt_table(cpu);
35189- tss_desc tss;
35190-#endif
35191+ struct tss_struct *t = init_tss + cpu;
35192+
35193 set_tss_desc(cpu, t); /*
35194 * This just modifies memory; should not be
35195 * necessary. But... This is necessary, because
35196@@ -150,10 +147,6 @@ static void fix_processor_context(void)
35197 */
35198
35199 #ifdef CONFIG_X86_64
35200- memcpy(&tss, &desc[GDT_ENTRY_TSS], sizeof(tss_desc));
35201- tss.type = 0x9; /* The available 64-bit TSS (see AMD vol 2, pg 91 */
35202- write_gdt_entry(desc, GDT_ENTRY_TSS, &tss, DESC_TSS);
35203-
35204 syscall_init(); /* This sets MSR_*STAR and related */
35205 #endif
35206 load_TR_desc(); /* This does ltr */
35207diff --git a/arch/x86/realmode/init.c b/arch/x86/realmode/init.c
35208index bad628a..a102610 100644
35209--- a/arch/x86/realmode/init.c
35210+++ b/arch/x86/realmode/init.c
35211@@ -68,7 +68,13 @@ void __init setup_real_mode(void)
35212 __va(real_mode_header->trampoline_header);
35213
35214 #ifdef CONFIG_X86_32
35215- trampoline_header->start = __pa_symbol(startup_32_smp);
35216+ trampoline_header->start = __pa_symbol(ktla_ktva(startup_32_smp));
35217+
35218+#ifdef CONFIG_PAX_KERNEXEC
35219+ trampoline_header->start -= LOAD_PHYSICAL_ADDR;
35220+#endif
35221+
35222+ trampoline_header->boot_cs = __BOOT_CS;
35223 trampoline_header->gdt_limit = __BOOT_DS + 7;
35224 trampoline_header->gdt_base = __pa_symbol(boot_gdt);
35225 #else
35226@@ -84,7 +90,7 @@ void __init setup_real_mode(void)
35227 *trampoline_cr4_features = read_cr4();
35228
35229 trampoline_pgd = (u64 *) __va(real_mode_header->trampoline_pgd);
35230- trampoline_pgd[0] = init_level4_pgt[pgd_index(__PAGE_OFFSET)].pgd;
35231+ trampoline_pgd[0] = init_level4_pgt[pgd_index(__PAGE_OFFSET)].pgd & ~_PAGE_NX;
35232 trampoline_pgd[511] = init_level4_pgt[511].pgd;
35233 #endif
35234 }
35235diff --git a/arch/x86/realmode/rm/Makefile b/arch/x86/realmode/rm/Makefile
35236index 3497f14..cc73b92 100644
35237--- a/arch/x86/realmode/rm/Makefile
35238+++ b/arch/x86/realmode/rm/Makefile
35239@@ -66,5 +66,8 @@ $(obj)/realmode.relocs: $(obj)/realmode.elf FORCE
35240
35241 KBUILD_CFLAGS := $(LINUXINCLUDE) $(REALMODE_CFLAGS) -D_SETUP -D_WAKEUP \
35242 -I$(srctree)/arch/x86/boot
35243+ifdef CONSTIFY_PLUGIN
35244+KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
35245+endif
35246 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
35247 GCOV_PROFILE := n
35248diff --git a/arch/x86/realmode/rm/header.S b/arch/x86/realmode/rm/header.S
35249index a28221d..93c40f1 100644
35250--- a/arch/x86/realmode/rm/header.S
35251+++ b/arch/x86/realmode/rm/header.S
35252@@ -30,7 +30,9 @@ GLOBAL(real_mode_header)
35253 #endif
35254 /* APM/BIOS reboot */
35255 .long pa_machine_real_restart_asm
35256-#ifdef CONFIG_X86_64
35257+#ifdef CONFIG_X86_32
35258+ .long __KERNEL_CS
35259+#else
35260 .long __KERNEL32_CS
35261 #endif
35262 END(real_mode_header)
35263diff --git a/arch/x86/realmode/rm/trampoline_32.S b/arch/x86/realmode/rm/trampoline_32.S
35264index 48ddd76..c26749f 100644
35265--- a/arch/x86/realmode/rm/trampoline_32.S
35266+++ b/arch/x86/realmode/rm/trampoline_32.S
35267@@ -24,6 +24,12 @@
35268 #include <asm/page_types.h>
35269 #include "realmode.h"
35270
35271+#ifdef CONFIG_PAX_KERNEXEC
35272+#define ta(X) (X)
35273+#else
35274+#define ta(X) (pa_ ## X)
35275+#endif
35276+
35277 .text
35278 .code16
35279
35280@@ -38,8 +44,6 @@ ENTRY(trampoline_start)
35281
35282 cli # We should be safe anyway
35283
35284- movl tr_start, %eax # where we need to go
35285-
35286 movl $0xA5A5A5A5, trampoline_status
35287 # write marker for master knows we're running
35288
35289@@ -55,7 +59,7 @@ ENTRY(trampoline_start)
35290 movw $1, %dx # protected mode (PE) bit
35291 lmsw %dx # into protected mode
35292
35293- ljmpl $__BOOT_CS, $pa_startup_32
35294+ ljmpl *(trampoline_header)
35295
35296 .section ".text32","ax"
35297 .code32
35298@@ -66,7 +70,7 @@ ENTRY(startup_32) # note: also used from wakeup_asm.S
35299 .balign 8
35300 GLOBAL(trampoline_header)
35301 tr_start: .space 4
35302- tr_gdt_pad: .space 2
35303+ tr_boot_cs: .space 2
35304 tr_gdt: .space 6
35305 END(trampoline_header)
35306
35307diff --git a/arch/x86/realmode/rm/trampoline_64.S b/arch/x86/realmode/rm/trampoline_64.S
35308index dac7b20..72dbaca 100644
35309--- a/arch/x86/realmode/rm/trampoline_64.S
35310+++ b/arch/x86/realmode/rm/trampoline_64.S
35311@@ -93,6 +93,7 @@ ENTRY(startup_32)
35312 movl %edx, %gs
35313
35314 movl pa_tr_cr4, %eax
35315+ andl $~X86_CR4_PCIDE, %eax
35316 movl %eax, %cr4 # Enable PAE mode
35317
35318 # Setup trampoline 4 level pagetables
35319@@ -106,7 +107,7 @@ ENTRY(startup_32)
35320 wrmsr
35321
35322 # Enable paging and in turn activate Long Mode
35323- movl $(X86_CR0_PG | X86_CR0_WP | X86_CR0_PE), %eax
35324+ movl $(X86_CR0_PG | X86_CR0_PE), %eax
35325 movl %eax, %cr0
35326
35327 /*
35328diff --git a/arch/x86/realmode/rm/wakeup_asm.S b/arch/x86/realmode/rm/wakeup_asm.S
35329index 9e7e147..25a4158 100644
35330--- a/arch/x86/realmode/rm/wakeup_asm.S
35331+++ b/arch/x86/realmode/rm/wakeup_asm.S
35332@@ -126,11 +126,10 @@ ENTRY(wakeup_start)
35333 lgdtl pmode_gdt
35334
35335 /* This really couldn't... */
35336- movl pmode_entry, %eax
35337 movl pmode_cr0, %ecx
35338 movl %ecx, %cr0
35339- ljmpl $__KERNEL_CS, $pa_startup_32
35340- /* -> jmp *%eax in trampoline_32.S */
35341+
35342+ ljmpl *pmode_entry
35343 #else
35344 jmp trampoline_start
35345 #endif
35346diff --git a/arch/x86/tools/Makefile b/arch/x86/tools/Makefile
35347index e812034..c747134 100644
35348--- a/arch/x86/tools/Makefile
35349+++ b/arch/x86/tools/Makefile
35350@@ -37,7 +37,7 @@ $(obj)/test_get_len.o: $(srctree)/arch/x86/lib/insn.c $(srctree)/arch/x86/lib/in
35351
35352 $(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
35353
35354-HOST_EXTRACFLAGS += -I$(srctree)/tools/include
35355+HOST_EXTRACFLAGS += -I$(srctree)/tools/include -ggdb
35356 hostprogs-y += relocs
35357 relocs-objs := relocs_32.o relocs_64.o relocs_common.o
35358 relocs: $(obj)/relocs
35359diff --git a/arch/x86/tools/relocs.c b/arch/x86/tools/relocs.c
35360index cfbdbdb..1aa763c 100644
35361--- a/arch/x86/tools/relocs.c
35362+++ b/arch/x86/tools/relocs.c
35363@@ -1,5 +1,7 @@
35364 /* This is included from relocs_32/64.c */
35365
35366+#include "../../../include/generated/autoconf.h"
35367+
35368 #define ElfW(type) _ElfW(ELF_BITS, type)
35369 #define _ElfW(bits, type) __ElfW(bits, type)
35370 #define __ElfW(bits, type) Elf##bits##_##type
35371@@ -11,6 +13,7 @@
35372 #define Elf_Sym ElfW(Sym)
35373
35374 static Elf_Ehdr ehdr;
35375+static Elf_Phdr *phdr;
35376
35377 struct relocs {
35378 uint32_t *offset;
35379@@ -383,9 +386,39 @@ static void read_ehdr(FILE *fp)
35380 }
35381 }
35382
35383+static void read_phdrs(FILE *fp)
35384+{
35385+ unsigned int i;
35386+
35387+ phdr = calloc(ehdr.e_phnum, sizeof(Elf_Phdr));
35388+ if (!phdr) {
35389+ die("Unable to allocate %d program headers\n",
35390+ ehdr.e_phnum);
35391+ }
35392+ if (fseek(fp, ehdr.e_phoff, SEEK_SET) < 0) {
35393+ die("Seek to %d failed: %s\n",
35394+ ehdr.e_phoff, strerror(errno));
35395+ }
35396+ if (fread(phdr, sizeof(*phdr), ehdr.e_phnum, fp) != ehdr.e_phnum) {
35397+ die("Cannot read ELF program headers: %s\n",
35398+ strerror(errno));
35399+ }
35400+ for(i = 0; i < ehdr.e_phnum; i++) {
35401+ phdr[i].p_type = elf_word_to_cpu(phdr[i].p_type);
35402+ phdr[i].p_offset = elf_off_to_cpu(phdr[i].p_offset);
35403+ phdr[i].p_vaddr = elf_addr_to_cpu(phdr[i].p_vaddr);
35404+ phdr[i].p_paddr = elf_addr_to_cpu(phdr[i].p_paddr);
35405+ phdr[i].p_filesz = elf_word_to_cpu(phdr[i].p_filesz);
35406+ phdr[i].p_memsz = elf_word_to_cpu(phdr[i].p_memsz);
35407+ phdr[i].p_flags = elf_word_to_cpu(phdr[i].p_flags);
35408+ phdr[i].p_align = elf_word_to_cpu(phdr[i].p_align);
35409+ }
35410+
35411+}
35412+
35413 static void read_shdrs(FILE *fp)
35414 {
35415- int i;
35416+ unsigned int i;
35417 Elf_Shdr shdr;
35418
35419 secs = calloc(ehdr.e_shnum, sizeof(struct section));
35420@@ -420,7 +453,7 @@ static void read_shdrs(FILE *fp)
35421
35422 static void read_strtabs(FILE *fp)
35423 {
35424- int i;
35425+ unsigned int i;
35426 for (i = 0; i < ehdr.e_shnum; i++) {
35427 struct section *sec = &secs[i];
35428 if (sec->shdr.sh_type != SHT_STRTAB) {
35429@@ -445,7 +478,7 @@ static void read_strtabs(FILE *fp)
35430
35431 static void read_symtabs(FILE *fp)
35432 {
35433- int i,j;
35434+ unsigned int i,j;
35435 for (i = 0; i < ehdr.e_shnum; i++) {
35436 struct section *sec = &secs[i];
35437 if (sec->shdr.sh_type != SHT_SYMTAB) {
35438@@ -476,9 +509,11 @@ static void read_symtabs(FILE *fp)
35439 }
35440
35441
35442-static void read_relocs(FILE *fp)
35443+static void read_relocs(FILE *fp, int use_real_mode)
35444 {
35445- int i,j;
35446+ unsigned int i,j;
35447+ uint32_t base;
35448+
35449 for (i = 0; i < ehdr.e_shnum; i++) {
35450 struct section *sec = &secs[i];
35451 if (sec->shdr.sh_type != SHT_REL_TYPE) {
35452@@ -498,9 +533,22 @@ static void read_relocs(FILE *fp)
35453 die("Cannot read symbol table: %s\n",
35454 strerror(errno));
35455 }
35456+ base = 0;
35457+
35458+#ifdef CONFIG_X86_32
35459+ for (j = 0; !use_real_mode && j < ehdr.e_phnum; j++) {
35460+ if (phdr[j].p_type != PT_LOAD )
35461+ continue;
35462+ 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)
35463+ continue;
35464+ base = CONFIG_PAGE_OFFSET + phdr[j].p_paddr - phdr[j].p_vaddr;
35465+ break;
35466+ }
35467+#endif
35468+
35469 for (j = 0; j < sec->shdr.sh_size/sizeof(Elf_Rel); j++) {
35470 Elf_Rel *rel = &sec->reltab[j];
35471- rel->r_offset = elf_addr_to_cpu(rel->r_offset);
35472+ rel->r_offset = elf_addr_to_cpu(rel->r_offset) + base;
35473 rel->r_info = elf_xword_to_cpu(rel->r_info);
35474 #if (SHT_REL_TYPE == SHT_RELA)
35475 rel->r_addend = elf_xword_to_cpu(rel->r_addend);
35476@@ -512,7 +560,7 @@ static void read_relocs(FILE *fp)
35477
35478 static void print_absolute_symbols(void)
35479 {
35480- int i;
35481+ unsigned int i;
35482 const char *format;
35483
35484 if (ELF_BITS == 64)
35485@@ -525,7 +573,7 @@ static void print_absolute_symbols(void)
35486 for (i = 0; i < ehdr.e_shnum; i++) {
35487 struct section *sec = &secs[i];
35488 char *sym_strtab;
35489- int j;
35490+ unsigned int j;
35491
35492 if (sec->shdr.sh_type != SHT_SYMTAB) {
35493 continue;
35494@@ -552,7 +600,7 @@ static void print_absolute_symbols(void)
35495
35496 static void print_absolute_relocs(void)
35497 {
35498- int i, printed = 0;
35499+ unsigned int i, printed = 0;
35500 const char *format;
35501
35502 if (ELF_BITS == 64)
35503@@ -565,7 +613,7 @@ static void print_absolute_relocs(void)
35504 struct section *sec_applies, *sec_symtab;
35505 char *sym_strtab;
35506 Elf_Sym *sh_symtab;
35507- int j;
35508+ unsigned int j;
35509 if (sec->shdr.sh_type != SHT_REL_TYPE) {
35510 continue;
35511 }
35512@@ -642,13 +690,13 @@ static void add_reloc(struct relocs *r, uint32_t offset)
35513 static void walk_relocs(int (*process)(struct section *sec, Elf_Rel *rel,
35514 Elf_Sym *sym, const char *symname))
35515 {
35516- int i;
35517+ unsigned int i;
35518 /* Walk through the relocations */
35519 for (i = 0; i < ehdr.e_shnum; i++) {
35520 char *sym_strtab;
35521 Elf_Sym *sh_symtab;
35522 struct section *sec_applies, *sec_symtab;
35523- int j;
35524+ unsigned int j;
35525 struct section *sec = &secs[i];
35526
35527 if (sec->shdr.sh_type != SHT_REL_TYPE) {
35528@@ -822,6 +870,23 @@ static int do_reloc32(struct section *sec, Elf_Rel *rel, Elf_Sym *sym,
35529 {
35530 unsigned r_type = ELF32_R_TYPE(rel->r_info);
35531 int shn_abs = (sym->st_shndx == SHN_ABS) && !is_reloc(S_REL, symname);
35532+ char *sym_strtab = sec->link->link->strtab;
35533+
35534+ /* Don't relocate actual per-cpu variables, they are absolute indices, not addresses */
35535+ if (!strcmp(sec_name(sym->st_shndx), ".data..percpu") && strcmp(sym_name(sym_strtab, sym), "__per_cpu_load"))
35536+ return 0;
35537+
35538+#ifdef CONFIG_PAX_KERNEXEC
35539+ /* Don't relocate actual code, they are relocated implicitly by the base address of KERNEL_CS */
35540+ if (!strcmp(sec_name(sym->st_shndx), ".text.end") && !strcmp(sym_name(sym_strtab, sym), "_etext"))
35541+ return 0;
35542+ if (!strcmp(sec_name(sym->st_shndx), ".init.text"))
35543+ return 0;
35544+ if (!strcmp(sec_name(sym->st_shndx), ".exit.text"))
35545+ return 0;
35546+ if (!strcmp(sec_name(sym->st_shndx), ".text") && strcmp(sym_name(sym_strtab, sym), "__LOAD_PHYSICAL_ADDR"))
35547+ return 0;
35548+#endif
35549
35550 switch (r_type) {
35551 case R_386_NONE:
35552@@ -960,7 +1025,7 @@ static int write32_as_text(uint32_t v, FILE *f)
35553
35554 static void emit_relocs(int as_text, int use_real_mode)
35555 {
35556- int i;
35557+ unsigned int i;
35558 int (*write_reloc)(uint32_t, FILE *) = write32;
35559 int (*do_reloc)(struct section *sec, Elf_Rel *rel, Elf_Sym *sym,
35560 const char *symname);
35561@@ -1060,10 +1125,11 @@ void process(FILE *fp, int use_real_mode, int as_text,
35562 {
35563 regex_init(use_real_mode);
35564 read_ehdr(fp);
35565+ read_phdrs(fp);
35566 read_shdrs(fp);
35567 read_strtabs(fp);
35568 read_symtabs(fp);
35569- read_relocs(fp);
35570+ read_relocs(fp, use_real_mode);
35571 if (ELF_BITS == 64)
35572 percpu_init();
35573 if (show_absolute_syms) {
35574diff --git a/arch/x86/um/tls_32.c b/arch/x86/um/tls_32.c
35575index 80ffa5b..a33bd15 100644
35576--- a/arch/x86/um/tls_32.c
35577+++ b/arch/x86/um/tls_32.c
35578@@ -260,7 +260,7 @@ out:
35579 if (unlikely(task == current &&
35580 !t->arch.tls_array[idx - GDT_ENTRY_TLS_MIN].flushed)) {
35581 printk(KERN_ERR "get_tls_entry: task with pid %d got here "
35582- "without flushed TLS.", current->pid);
35583+ "without flushed TLS.", task_pid_nr(current));
35584 }
35585
35586 return 0;
35587diff --git a/arch/x86/vdso/Makefile b/arch/x86/vdso/Makefile
35588index fd14be1..e3c79c0 100644
35589--- a/arch/x86/vdso/Makefile
35590+++ b/arch/x86/vdso/Makefile
35591@@ -181,7 +181,7 @@ quiet_cmd_vdso = VDSO $@
35592 -Wl,-T,$(filter %.lds,$^) $(filter %.o,$^) && \
35593 sh $(srctree)/$(src)/checkundef.sh '$(NM)' '$@'
35594
35595-VDSO_LDFLAGS = -fPIC -shared $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
35596+VDSO_LDFLAGS = -fPIC -shared -Wl,--no-undefined $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
35597 GCOV_PROFILE := n
35598
35599 #
35600diff --git a/arch/x86/vdso/vdso32-setup.c b/arch/x86/vdso/vdso32-setup.c
35601index d6bfb87..876ee18 100644
35602--- a/arch/x86/vdso/vdso32-setup.c
35603+++ b/arch/x86/vdso/vdso32-setup.c
35604@@ -25,6 +25,7 @@
35605 #include <asm/tlbflush.h>
35606 #include <asm/vdso.h>
35607 #include <asm/proto.h>
35608+#include <asm/mman.h>
35609
35610 enum {
35611 VDSO_DISABLED = 0,
35612@@ -226,7 +227,7 @@ static inline void map_compat_vdso(int map)
35613 void enable_sep_cpu(void)
35614 {
35615 int cpu = get_cpu();
35616- struct tss_struct *tss = &per_cpu(init_tss, cpu);
35617+ struct tss_struct *tss = init_tss + cpu;
35618
35619 if (!boot_cpu_has(X86_FEATURE_SEP)) {
35620 put_cpu();
35621@@ -249,7 +250,7 @@ static int __init gate_vma_init(void)
35622 gate_vma.vm_start = FIXADDR_USER_START;
35623 gate_vma.vm_end = FIXADDR_USER_END;
35624 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
35625- gate_vma.vm_page_prot = __P101;
35626+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
35627
35628 return 0;
35629 }
35630@@ -330,14 +331,14 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
35631 if (compat)
35632 addr = VDSO_HIGH_BASE;
35633 else {
35634- addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
35635+ addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, MAP_EXECUTABLE);
35636 if (IS_ERR_VALUE(addr)) {
35637 ret = addr;
35638 goto up_fail;
35639 }
35640 }
35641
35642- current->mm->context.vdso = (void *)addr;
35643+ current->mm->context.vdso = addr;
35644
35645 if (compat_uses_vma || !compat) {
35646 /*
35647@@ -353,11 +354,11 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
35648 }
35649
35650 current_thread_info()->sysenter_return =
35651- VDSO32_SYMBOL(addr, SYSENTER_RETURN);
35652+ (__force void __user *)VDSO32_SYMBOL(addr, SYSENTER_RETURN);
35653
35654 up_fail:
35655 if (ret)
35656- current->mm->context.vdso = NULL;
35657+ current->mm->context.vdso = 0;
35658
35659 up_write(&mm->mmap_sem);
35660
35661@@ -404,8 +405,14 @@ __initcall(ia32_binfmt_init);
35662
35663 const char *arch_vma_name(struct vm_area_struct *vma)
35664 {
35665- if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
35666+ if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
35667 return "[vdso]";
35668+
35669+#ifdef CONFIG_PAX_SEGMEXEC
35670+ if (vma->vm_mm && vma->vm_mirror && vma->vm_mirror->vm_start == vma->vm_mm->context.vdso)
35671+ return "[vdso]";
35672+#endif
35673+
35674 return NULL;
35675 }
35676
35677@@ -415,7 +422,7 @@ struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
35678 * Check to see if the corresponding task was created in compat vdso
35679 * mode.
35680 */
35681- if (mm && mm->context.vdso == (void *)VDSO_HIGH_BASE)
35682+ if (mm && mm->context.vdso == VDSO_HIGH_BASE)
35683 return &gate_vma;
35684 return NULL;
35685 }
35686diff --git a/arch/x86/vdso/vma.c b/arch/x86/vdso/vma.c
35687index 431e875..cbb23f3 100644
35688--- a/arch/x86/vdso/vma.c
35689+++ b/arch/x86/vdso/vma.c
35690@@ -16,8 +16,6 @@
35691 #include <asm/vdso.h>
35692 #include <asm/page.h>
35693
35694-unsigned int __read_mostly vdso_enabled = 1;
35695-
35696 extern char vdso_start[], vdso_end[];
35697 extern unsigned short vdso_sync_cpuid;
35698
35699@@ -141,7 +139,6 @@ static unsigned long vdso_addr(unsigned long start, unsigned len)
35700 * unaligned here as a result of stack start randomization.
35701 */
35702 addr = PAGE_ALIGN(addr);
35703- addr = align_vdso_addr(addr);
35704
35705 return addr;
35706 }
35707@@ -154,30 +151,31 @@ static int setup_additional_pages(struct linux_binprm *bprm,
35708 unsigned size)
35709 {
35710 struct mm_struct *mm = current->mm;
35711- unsigned long addr;
35712+ unsigned long addr = 0;
35713 int ret;
35714
35715- if (!vdso_enabled)
35716- return 0;
35717-
35718 down_write(&mm->mmap_sem);
35719+
35720+#ifdef CONFIG_PAX_RANDMMAP
35721+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
35722+#endif
35723+
35724 addr = vdso_addr(mm->start_stack, size);
35725+ addr = align_vdso_addr(addr);
35726 addr = get_unmapped_area(NULL, addr, size, 0, 0);
35727 if (IS_ERR_VALUE(addr)) {
35728 ret = addr;
35729 goto up_fail;
35730 }
35731
35732- current->mm->context.vdso = (void *)addr;
35733+ mm->context.vdso = addr;
35734
35735 ret = install_special_mapping(mm, addr, size,
35736 VM_READ|VM_EXEC|
35737 VM_MAYREAD|VM_MAYWRITE|VM_MAYEXEC,
35738 pages);
35739- if (ret) {
35740- current->mm->context.vdso = NULL;
35741- goto up_fail;
35742- }
35743+ if (ret)
35744+ mm->context.vdso = 0;
35745
35746 up_fail:
35747 up_write(&mm->mmap_sem);
35748@@ -197,10 +195,3 @@ int x32_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
35749 vdsox32_size);
35750 }
35751 #endif
35752-
35753-static __init int vdso_setup(char *s)
35754-{
35755- vdso_enabled = simple_strtoul(s, NULL, 0);
35756- return 0;
35757-}
35758-__setup("vdso=", vdso_setup);
35759diff --git a/arch/x86/xen/Kconfig b/arch/x86/xen/Kconfig
35760index 01b9026..1e476df 100644
35761--- a/arch/x86/xen/Kconfig
35762+++ b/arch/x86/xen/Kconfig
35763@@ -9,6 +9,7 @@ config XEN
35764 select XEN_HAVE_PVMMU
35765 depends on X86_64 || (X86_32 && X86_PAE && !X86_VISWS)
35766 depends on X86_TSC
35767+ depends on !GRKERNSEC_CONFIG_AUTO || GRKERNSEC_CONFIG_VIRT_XEN
35768 help
35769 This is the Linux Xen port. Enabling this will allow the
35770 kernel to boot in a paravirtualized environment under the
35771diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c
35772index 201d09a..e4723e5 100644
35773--- a/arch/x86/xen/enlighten.c
35774+++ b/arch/x86/xen/enlighten.c
35775@@ -123,8 +123,6 @@ EXPORT_SYMBOL_GPL(xen_start_info);
35776
35777 struct shared_info xen_dummy_shared_info;
35778
35779-void *xen_initial_gdt;
35780-
35781 RESERVE_BRK(shared_info_page_brk, PAGE_SIZE);
35782 __read_mostly int xen_have_vector_callback;
35783 EXPORT_SYMBOL_GPL(xen_have_vector_callback);
35784@@ -542,8 +540,7 @@ static void xen_load_gdt(const struct desc_ptr *dtr)
35785 {
35786 unsigned long va = dtr->address;
35787 unsigned int size = dtr->size + 1;
35788- unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
35789- unsigned long frames[pages];
35790+ unsigned long frames[65536 / PAGE_SIZE];
35791 int f;
35792
35793 /*
35794@@ -591,8 +588,7 @@ static void __init xen_load_gdt_boot(const struct desc_ptr *dtr)
35795 {
35796 unsigned long va = dtr->address;
35797 unsigned int size = dtr->size + 1;
35798- unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
35799- unsigned long frames[pages];
35800+ unsigned long frames[(GDT_SIZE + PAGE_SIZE - 1) / PAGE_SIZE];
35801 int f;
35802
35803 /*
35804@@ -600,7 +596,7 @@ static void __init xen_load_gdt_boot(const struct desc_ptr *dtr)
35805 * 8-byte entries, or 16 4k pages..
35806 */
35807
35808- BUG_ON(size > 65536);
35809+ BUG_ON(size > GDT_SIZE);
35810 BUG_ON(va & ~PAGE_MASK);
35811
35812 for (f = 0; va < dtr->address + size; va += PAGE_SIZE, f++) {
35813@@ -989,7 +985,7 @@ static u32 xen_safe_apic_wait_icr_idle(void)
35814 return 0;
35815 }
35816
35817-static void set_xen_basic_apic_ops(void)
35818+static void __init set_xen_basic_apic_ops(void)
35819 {
35820 apic->read = xen_apic_read;
35821 apic->write = xen_apic_write;
35822@@ -1295,30 +1291,30 @@ static const struct pv_apic_ops xen_apic_ops __initconst = {
35823 #endif
35824 };
35825
35826-static void xen_reboot(int reason)
35827+static __noreturn void xen_reboot(int reason)
35828 {
35829 struct sched_shutdown r = { .reason = reason };
35830
35831- if (HYPERVISOR_sched_op(SCHEDOP_shutdown, &r))
35832- BUG();
35833+ HYPERVISOR_sched_op(SCHEDOP_shutdown, &r);
35834+ BUG();
35835 }
35836
35837-static void xen_restart(char *msg)
35838+static __noreturn void xen_restart(char *msg)
35839 {
35840 xen_reboot(SHUTDOWN_reboot);
35841 }
35842
35843-static void xen_emergency_restart(void)
35844+static __noreturn void xen_emergency_restart(void)
35845 {
35846 xen_reboot(SHUTDOWN_reboot);
35847 }
35848
35849-static void xen_machine_halt(void)
35850+static __noreturn void xen_machine_halt(void)
35851 {
35852 xen_reboot(SHUTDOWN_poweroff);
35853 }
35854
35855-static void xen_machine_power_off(void)
35856+static __noreturn void xen_machine_power_off(void)
35857 {
35858 if (pm_power_off)
35859 pm_power_off();
35860@@ -1564,7 +1560,17 @@ asmlinkage void __init xen_start_kernel(void)
35861 __userpte_alloc_gfp &= ~__GFP_HIGHMEM;
35862
35863 /* Work out if we support NX */
35864- x86_configure_nx();
35865+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
35866+ if ((cpuid_eax(0x80000000) & 0xffff0000) == 0x80000000 &&
35867+ (cpuid_edx(0x80000001) & (1U << (X86_FEATURE_NX & 31)))) {
35868+ unsigned l, h;
35869+
35870+ __supported_pte_mask |= _PAGE_NX;
35871+ rdmsr(MSR_EFER, l, h);
35872+ l |= EFER_NX;
35873+ wrmsr(MSR_EFER, l, h);
35874+ }
35875+#endif
35876
35877 /* Get mfn list */
35878 xen_build_dynamic_phys_to_machine();
35879@@ -1592,13 +1598,6 @@ asmlinkage void __init xen_start_kernel(void)
35880
35881 machine_ops = xen_machine_ops;
35882
35883- /*
35884- * The only reliable way to retain the initial address of the
35885- * percpu gdt_page is to remember it here, so we can go and
35886- * mark it RW later, when the initial percpu area is freed.
35887- */
35888- xen_initial_gdt = &per_cpu(gdt_page, 0);
35889-
35890 xen_smp_init();
35891
35892 #ifdef CONFIG_ACPI_NUMA
35893diff --git a/arch/x86/xen/mmu.c b/arch/x86/xen/mmu.c
35894index 2423ef0..4f6fb5b 100644
35895--- a/arch/x86/xen/mmu.c
35896+++ b/arch/x86/xen/mmu.c
35897@@ -379,7 +379,7 @@ static pteval_t pte_mfn_to_pfn(pteval_t val)
35898 return val;
35899 }
35900
35901-static pteval_t pte_pfn_to_mfn(pteval_t val)
35902+static pteval_t __intentional_overflow(-1) pte_pfn_to_mfn(pteval_t val)
35903 {
35904 if (val & _PAGE_PRESENT) {
35905 unsigned long pfn = (val & PTE_PFN_MASK) >> PAGE_SHIFT;
35906@@ -1904,6 +1904,9 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
35907 /* L3_k[510] -> level2_kernel_pgt
35908 * L3_i[511] -> level2_fixmap_pgt */
35909 convert_pfn_mfn(level3_kernel_pgt);
35910+ convert_pfn_mfn(level3_vmalloc_start_pgt);
35911+ convert_pfn_mfn(level3_vmalloc_end_pgt);
35912+ convert_pfn_mfn(level3_vmemmap_pgt);
35913 }
35914 /* We get [511][511] and have Xen's version of level2_kernel_pgt */
35915 l3 = m2v(pgd[pgd_index(__START_KERNEL_map)].pgd);
35916@@ -1933,8 +1936,12 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
35917 set_page_prot(init_level4_pgt, PAGE_KERNEL_RO);
35918 set_page_prot(level3_ident_pgt, PAGE_KERNEL_RO);
35919 set_page_prot(level3_kernel_pgt, PAGE_KERNEL_RO);
35920+ set_page_prot(level3_vmalloc_start_pgt, PAGE_KERNEL_RO);
35921+ set_page_prot(level3_vmalloc_end_pgt, PAGE_KERNEL_RO);
35922+ set_page_prot(level3_vmemmap_pgt, PAGE_KERNEL_RO);
35923 set_page_prot(level3_user_vsyscall, PAGE_KERNEL_RO);
35924 set_page_prot(level2_ident_pgt, PAGE_KERNEL_RO);
35925+ set_page_prot(level2_vmemmap_pgt, PAGE_KERNEL_RO);
35926 set_page_prot(level2_kernel_pgt, PAGE_KERNEL_RO);
35927 set_page_prot(level2_fixmap_pgt, PAGE_KERNEL_RO);
35928
35929@@ -2123,6 +2130,7 @@ static void __init xen_post_allocator_init(void)
35930 pv_mmu_ops.set_pud = xen_set_pud;
35931 #if PAGETABLE_LEVELS == 4
35932 pv_mmu_ops.set_pgd = xen_set_pgd;
35933+ pv_mmu_ops.set_pgd_batched = xen_set_pgd;
35934 #endif
35935
35936 /* This will work as long as patching hasn't happened yet
35937@@ -2201,6 +2209,7 @@ static const struct pv_mmu_ops xen_mmu_ops __initconst = {
35938 .pud_val = PV_CALLEE_SAVE(xen_pud_val),
35939 .make_pud = PV_CALLEE_SAVE(xen_make_pud),
35940 .set_pgd = xen_set_pgd_hyper,
35941+ .set_pgd_batched = xen_set_pgd_hyper,
35942
35943 .alloc_pud = xen_alloc_pmd_init,
35944 .release_pud = xen_release_pmd_init,
35945diff --git a/arch/x86/xen/smp.c b/arch/x86/xen/smp.c
35946index a18eadd..2e2f10e 100644
35947--- a/arch/x86/xen/smp.c
35948+++ b/arch/x86/xen/smp.c
35949@@ -283,17 +283,13 @@ static void __init xen_smp_prepare_boot_cpu(void)
35950
35951 if (xen_pv_domain()) {
35952 if (!xen_feature(XENFEAT_writable_page_tables))
35953- /* We've switched to the "real" per-cpu gdt, so make
35954- * sure the old memory can be recycled. */
35955- make_lowmem_page_readwrite(xen_initial_gdt);
35956-
35957 #ifdef CONFIG_X86_32
35958 /*
35959 * Xen starts us with XEN_FLAT_RING1_DS, but linux code
35960 * expects __USER_DS
35961 */
35962- loadsegment(ds, __USER_DS);
35963- loadsegment(es, __USER_DS);
35964+ loadsegment(ds, __KERNEL_DS);
35965+ loadsegment(es, __KERNEL_DS);
35966 #endif
35967
35968 xen_filter_cpu_maps();
35969@@ -372,7 +368,7 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
35970 #ifdef CONFIG_X86_32
35971 /* Note: PVH is not yet supported on x86_32. */
35972 ctxt->user_regs.fs = __KERNEL_PERCPU;
35973- ctxt->user_regs.gs = __KERNEL_STACK_CANARY;
35974+ savesegment(gs, ctxt->user_regs.gs);
35975 #endif
35976 ctxt->user_regs.eip = (unsigned long)cpu_bringup_and_idle;
35977
35978@@ -381,8 +377,8 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
35979 if (!xen_feature(XENFEAT_auto_translated_physmap)) {
35980 ctxt->flags = VGCF_IN_KERNEL;
35981 ctxt->user_regs.eflags = 0x1000; /* IOPL_RING1 */
35982- ctxt->user_regs.ds = __USER_DS;
35983- ctxt->user_regs.es = __USER_DS;
35984+ ctxt->user_regs.ds = __KERNEL_DS;
35985+ ctxt->user_regs.es = __KERNEL_DS;
35986 ctxt->user_regs.ss = __KERNEL_DS;
35987
35988 xen_copy_trap_info(ctxt->trap_ctxt);
35989@@ -437,13 +433,12 @@ static int xen_cpu_up(unsigned int cpu, struct task_struct *idle)
35990 int rc;
35991
35992 per_cpu(current_task, cpu) = idle;
35993+ per_cpu(current_tinfo, cpu) = &idle->tinfo;
35994 #ifdef CONFIG_X86_32
35995 irq_ctx_init(cpu);
35996 #else
35997 clear_tsk_thread_flag(idle, TIF_FORK);
35998- per_cpu(kernel_stack, cpu) =
35999- (unsigned long)task_stack_page(idle) -
36000- KERNEL_STACK_OFFSET + THREAD_SIZE;
36001+ per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
36002 #endif
36003 xen_setup_runstate_info(cpu);
36004 xen_setup_timer(cpu);
36005@@ -719,7 +714,7 @@ static const struct smp_ops xen_smp_ops __initconst = {
36006
36007 void __init xen_smp_init(void)
36008 {
36009- smp_ops = xen_smp_ops;
36010+ memcpy((void *)&smp_ops, &xen_smp_ops, sizeof smp_ops);
36011 xen_fill_possible_map();
36012 }
36013
36014diff --git a/arch/x86/xen/xen-asm_32.S b/arch/x86/xen/xen-asm_32.S
36015index 33ca6e4..0ded929 100644
36016--- a/arch/x86/xen/xen-asm_32.S
36017+++ b/arch/x86/xen/xen-asm_32.S
36018@@ -84,14 +84,14 @@ ENTRY(xen_iret)
36019 ESP_OFFSET=4 # bytes pushed onto stack
36020
36021 /*
36022- * Store vcpu_info pointer for easy access. Do it this way to
36023- * avoid having to reload %fs
36024+ * Store vcpu_info pointer for easy access.
36025 */
36026 #ifdef CONFIG_SMP
36027- GET_THREAD_INFO(%eax)
36028- movl %ss:TI_cpu(%eax), %eax
36029- movl %ss:__per_cpu_offset(,%eax,4), %eax
36030- mov %ss:xen_vcpu(%eax), %eax
36031+ push %fs
36032+ mov $(__KERNEL_PERCPU), %eax
36033+ mov %eax, %fs
36034+ mov PER_CPU_VAR(xen_vcpu), %eax
36035+ pop %fs
36036 #else
36037 movl %ss:xen_vcpu, %eax
36038 #endif
36039diff --git a/arch/x86/xen/xen-head.S b/arch/x86/xen/xen-head.S
36040index 485b695..fda3e7c 100644
36041--- a/arch/x86/xen/xen-head.S
36042+++ b/arch/x86/xen/xen-head.S
36043@@ -39,6 +39,17 @@ ENTRY(startup_xen)
36044 #ifdef CONFIG_X86_32
36045 mov %esi,xen_start_info
36046 mov $init_thread_union+THREAD_SIZE,%esp
36047+#ifdef CONFIG_SMP
36048+ movl $cpu_gdt_table,%edi
36049+ movl $__per_cpu_load,%eax
36050+ movw %ax,__KERNEL_PERCPU + 2(%edi)
36051+ rorl $16,%eax
36052+ movb %al,__KERNEL_PERCPU + 4(%edi)
36053+ movb %ah,__KERNEL_PERCPU + 7(%edi)
36054+ movl $__per_cpu_end - 1,%eax
36055+ subl $__per_cpu_start,%eax
36056+ movw %ax,__KERNEL_PERCPU + 0(%edi)
36057+#endif
36058 #else
36059 mov %rsi,xen_start_info
36060 mov $init_thread_union+THREAD_SIZE,%rsp
36061diff --git a/arch/x86/xen/xen-ops.h b/arch/x86/xen/xen-ops.h
36062index 1cb6f4c..9981524 100644
36063--- a/arch/x86/xen/xen-ops.h
36064+++ b/arch/x86/xen/xen-ops.h
36065@@ -10,8 +10,6 @@
36066 extern const char xen_hypervisor_callback[];
36067 extern const char xen_failsafe_callback[];
36068
36069-extern void *xen_initial_gdt;
36070-
36071 struct trap_info;
36072 void xen_copy_trap_info(struct trap_info *traps);
36073
36074diff --git a/arch/xtensa/variants/dc232b/include/variant/core.h b/arch/xtensa/variants/dc232b/include/variant/core.h
36075index 525bd3d..ef888b1 100644
36076--- a/arch/xtensa/variants/dc232b/include/variant/core.h
36077+++ b/arch/xtensa/variants/dc232b/include/variant/core.h
36078@@ -119,9 +119,9 @@
36079 ----------------------------------------------------------------------*/
36080
36081 #define XCHAL_ICACHE_LINESIZE 32 /* I-cache line size in bytes */
36082-#define XCHAL_DCACHE_LINESIZE 32 /* D-cache line size in bytes */
36083 #define XCHAL_ICACHE_LINEWIDTH 5 /* log2(I line size in bytes) */
36084 #define XCHAL_DCACHE_LINEWIDTH 5 /* log2(D line size in bytes) */
36085+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
36086
36087 #define XCHAL_ICACHE_SIZE 16384 /* I-cache size in bytes or 0 */
36088 #define XCHAL_DCACHE_SIZE 16384 /* D-cache size in bytes or 0 */
36089diff --git a/arch/xtensa/variants/fsf/include/variant/core.h b/arch/xtensa/variants/fsf/include/variant/core.h
36090index 2f33760..835e50a 100644
36091--- a/arch/xtensa/variants/fsf/include/variant/core.h
36092+++ b/arch/xtensa/variants/fsf/include/variant/core.h
36093@@ -11,6 +11,7 @@
36094 #ifndef _XTENSA_CORE_H
36095 #define _XTENSA_CORE_H
36096
36097+#include <linux/const.h>
36098
36099 /****************************************************************************
36100 Parameters Useful for Any Code, USER or PRIVILEGED
36101@@ -112,9 +113,9 @@
36102 ----------------------------------------------------------------------*/
36103
36104 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
36105-#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
36106 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
36107 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
36108+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
36109
36110 #define XCHAL_ICACHE_SIZE 8192 /* I-cache size in bytes or 0 */
36111 #define XCHAL_DCACHE_SIZE 8192 /* D-cache size in bytes or 0 */
36112diff --git a/arch/xtensa/variants/s6000/include/variant/core.h b/arch/xtensa/variants/s6000/include/variant/core.h
36113index af00795..2bb8105 100644
36114--- a/arch/xtensa/variants/s6000/include/variant/core.h
36115+++ b/arch/xtensa/variants/s6000/include/variant/core.h
36116@@ -11,6 +11,7 @@
36117 #ifndef _XTENSA_CORE_CONFIGURATION_H
36118 #define _XTENSA_CORE_CONFIGURATION_H
36119
36120+#include <linux/const.h>
36121
36122 /****************************************************************************
36123 Parameters Useful for Any Code, USER or PRIVILEGED
36124@@ -118,9 +119,9 @@
36125 ----------------------------------------------------------------------*/
36126
36127 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
36128-#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
36129 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
36130 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
36131+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
36132
36133 #define XCHAL_ICACHE_SIZE 32768 /* I-cache size in bytes or 0 */
36134 #define XCHAL_DCACHE_SIZE 32768 /* D-cache size in bytes or 0 */
36135diff --git a/block/blk-cgroup.c b/block/blk-cgroup.c
36136index 4e491d9..c8e18e4 100644
36137--- a/block/blk-cgroup.c
36138+++ b/block/blk-cgroup.c
36139@@ -812,7 +812,7 @@ static void blkcg_css_free(struct cgroup_subsys_state *css)
36140 static struct cgroup_subsys_state *
36141 blkcg_css_alloc(struct cgroup_subsys_state *parent_css)
36142 {
36143- static atomic64_t id_seq = ATOMIC64_INIT(0);
36144+ static atomic64_unchecked_t id_seq = ATOMIC64_INIT(0);
36145 struct blkcg *blkcg;
36146
36147 if (!parent_css) {
36148@@ -826,7 +826,7 @@ blkcg_css_alloc(struct cgroup_subsys_state *parent_css)
36149
36150 blkcg->cfq_weight = CFQ_WEIGHT_DEFAULT;
36151 blkcg->cfq_leaf_weight = CFQ_WEIGHT_DEFAULT;
36152- blkcg->id = atomic64_inc_return(&id_seq); /* root is 0, start from 1 */
36153+ blkcg->id = atomic64_inc_return_unchecked(&id_seq); /* root is 0, start from 1 */
36154 done:
36155 spin_lock_init(&blkcg->lock);
36156 INIT_RADIX_TREE(&blkcg->blkg_tree, GFP_ATOMIC);
36157diff --git a/block/blk-iopoll.c b/block/blk-iopoll.c
36158index 1855bf5..af12b06 100644
36159--- a/block/blk-iopoll.c
36160+++ b/block/blk-iopoll.c
36161@@ -77,7 +77,7 @@ void blk_iopoll_complete(struct blk_iopoll *iopoll)
36162 }
36163 EXPORT_SYMBOL(blk_iopoll_complete);
36164
36165-static void blk_iopoll_softirq(struct softirq_action *h)
36166+static __latent_entropy void blk_iopoll_softirq(void)
36167 {
36168 struct list_head *list = this_cpu_ptr(&blk_cpu_iopoll);
36169 int rearm = 0, budget = blk_iopoll_budget;
36170diff --git a/block/blk-map.c b/block/blk-map.c
36171index ae4ae10..c470b8d 100644
36172--- a/block/blk-map.c
36173+++ b/block/blk-map.c
36174@@ -302,7 +302,7 @@ int blk_rq_map_kern(struct request_queue *q, struct request *rq, void *kbuf,
36175 if (!len || !kbuf)
36176 return -EINVAL;
36177
36178- do_copy = !blk_rq_aligned(q, addr, len) || object_is_on_stack(kbuf);
36179+ do_copy = !blk_rq_aligned(q, addr, len) || object_starts_on_stack(kbuf);
36180 if (do_copy)
36181 bio = bio_copy_kern(q, kbuf, len, gfp_mask, reading);
36182 else
36183diff --git a/block/blk-softirq.c b/block/blk-softirq.c
36184index 57790c1..5e988dd 100644
36185--- a/block/blk-softirq.c
36186+++ b/block/blk-softirq.c
36187@@ -18,7 +18,7 @@ static DEFINE_PER_CPU(struct list_head, blk_cpu_done);
36188 * Softirq action handler - move entries to local list and loop over them
36189 * while passing them to the queue registered handler.
36190 */
36191-static void blk_done_softirq(struct softirq_action *h)
36192+static __latent_entropy void blk_done_softirq(void)
36193 {
36194 struct list_head *cpu_list, local_list;
36195
36196diff --git a/block/bsg.c b/block/bsg.c
36197index 420a5a9..23834aa 100644
36198--- a/block/bsg.c
36199+++ b/block/bsg.c
36200@@ -176,16 +176,24 @@ static int blk_fill_sgv4_hdr_rq(struct request_queue *q, struct request *rq,
36201 struct sg_io_v4 *hdr, struct bsg_device *bd,
36202 fmode_t has_write_perm)
36203 {
36204+ unsigned char tmpcmd[sizeof(rq->__cmd)];
36205+ unsigned char *cmdptr;
36206+
36207 if (hdr->request_len > BLK_MAX_CDB) {
36208 rq->cmd = kzalloc(hdr->request_len, GFP_KERNEL);
36209 if (!rq->cmd)
36210 return -ENOMEM;
36211- }
36212+ cmdptr = rq->cmd;
36213+ } else
36214+ cmdptr = tmpcmd;
36215
36216- if (copy_from_user(rq->cmd, (void __user *)(unsigned long)hdr->request,
36217+ if (copy_from_user(cmdptr, (void __user *)(unsigned long)hdr->request,
36218 hdr->request_len))
36219 return -EFAULT;
36220
36221+ if (cmdptr != rq->cmd)
36222+ memcpy(rq->cmd, cmdptr, hdr->request_len);
36223+
36224 if (hdr->subprotocol == BSG_SUB_PROTOCOL_SCSI_CMD) {
36225 if (blk_verify_command(rq->cmd, has_write_perm))
36226 return -EPERM;
36227diff --git a/block/compat_ioctl.c b/block/compat_ioctl.c
36228index fbd5a67..f24fd95 100644
36229--- a/block/compat_ioctl.c
36230+++ b/block/compat_ioctl.c
36231@@ -156,7 +156,7 @@ static int compat_cdrom_generic_command(struct block_device *bdev, fmode_t mode,
36232 cgc = compat_alloc_user_space(sizeof(*cgc));
36233 cgc32 = compat_ptr(arg);
36234
36235- if (copy_in_user(&cgc->cmd, &cgc32->cmd, sizeof(cgc->cmd)) ||
36236+ if (copy_in_user(cgc->cmd, cgc32->cmd, sizeof(cgc->cmd)) ||
36237 get_user(data, &cgc32->buffer) ||
36238 put_user(compat_ptr(data), &cgc->buffer) ||
36239 copy_in_user(&cgc->buflen, &cgc32->buflen,
36240@@ -341,7 +341,7 @@ static int compat_fd_ioctl(struct block_device *bdev, fmode_t mode,
36241 err |= __get_user(f->spec1, &uf->spec1);
36242 err |= __get_user(f->fmt_gap, &uf->fmt_gap);
36243 err |= __get_user(name, &uf->name);
36244- f->name = compat_ptr(name);
36245+ f->name = (void __force_kernel *)compat_ptr(name);
36246 if (err) {
36247 err = -EFAULT;
36248 goto out;
36249diff --git a/block/genhd.c b/block/genhd.c
36250index 791f419..89f21c4 100644
36251--- a/block/genhd.c
36252+++ b/block/genhd.c
36253@@ -467,21 +467,24 @@ static char *bdevt_str(dev_t devt, char *buf)
36254
36255 /*
36256 * Register device numbers dev..(dev+range-1)
36257- * range must be nonzero
36258+ * Noop if @range is zero.
36259 * The hash chain is sorted on range, so that subranges can override.
36260 */
36261 void blk_register_region(dev_t devt, unsigned long range, struct module *module,
36262 struct kobject *(*probe)(dev_t, int *, void *),
36263 int (*lock)(dev_t, void *), void *data)
36264 {
36265- kobj_map(bdev_map, devt, range, module, probe, lock, data);
36266+ if (range)
36267+ kobj_map(bdev_map, devt, range, module, probe, lock, data);
36268 }
36269
36270 EXPORT_SYMBOL(blk_register_region);
36271
36272+/* undo blk_register_region(), noop if @range is zero */
36273 void blk_unregister_region(dev_t devt, unsigned long range)
36274 {
36275- kobj_unmap(bdev_map, devt, range);
36276+ if (range)
36277+ kobj_unmap(bdev_map, devt, range);
36278 }
36279
36280 EXPORT_SYMBOL(blk_unregister_region);
36281diff --git a/block/partitions/efi.c b/block/partitions/efi.c
36282index dc51f46..d5446a8 100644
36283--- a/block/partitions/efi.c
36284+++ b/block/partitions/efi.c
36285@@ -293,14 +293,14 @@ static gpt_entry *alloc_read_gpt_entries(struct parsed_partitions *state,
36286 if (!gpt)
36287 return NULL;
36288
36289+ if (!le32_to_cpu(gpt->num_partition_entries))
36290+ return NULL;
36291+ pte = kcalloc(le32_to_cpu(gpt->num_partition_entries), le32_to_cpu(gpt->sizeof_partition_entry), GFP_KERNEL);
36292+ if (!pte)
36293+ return NULL;
36294+
36295 count = le32_to_cpu(gpt->num_partition_entries) *
36296 le32_to_cpu(gpt->sizeof_partition_entry);
36297- if (!count)
36298- return NULL;
36299- pte = kmalloc(count, GFP_KERNEL);
36300- if (!pte)
36301- return NULL;
36302-
36303 if (read_lba(state, le64_to_cpu(gpt->partition_entry_lba),
36304 (u8 *) pte, count) < count) {
36305 kfree(pte);
36306diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c
36307index 2648797..92ed21f 100644
36308--- a/block/scsi_ioctl.c
36309+++ b/block/scsi_ioctl.c
36310@@ -67,7 +67,7 @@ static int scsi_get_bus(struct request_queue *q, int __user *p)
36311 return put_user(0, p);
36312 }
36313
36314-static int sg_get_timeout(struct request_queue *q)
36315+static int __intentional_overflow(-1) sg_get_timeout(struct request_queue *q)
36316 {
36317 return jiffies_to_clock_t(q->sg_timeout);
36318 }
36319@@ -224,8 +224,20 @@ EXPORT_SYMBOL(blk_verify_command);
36320 static int blk_fill_sghdr_rq(struct request_queue *q, struct request *rq,
36321 struct sg_io_hdr *hdr, fmode_t mode)
36322 {
36323- if (copy_from_user(rq->cmd, hdr->cmdp, hdr->cmd_len))
36324+ unsigned char tmpcmd[sizeof(rq->__cmd)];
36325+ unsigned char *cmdptr;
36326+
36327+ if (rq->cmd != rq->__cmd)
36328+ cmdptr = rq->cmd;
36329+ else
36330+ cmdptr = tmpcmd;
36331+
36332+ if (copy_from_user(cmdptr, hdr->cmdp, hdr->cmd_len))
36333 return -EFAULT;
36334+
36335+ if (cmdptr != rq->cmd)
36336+ memcpy(rq->cmd, cmdptr, hdr->cmd_len);
36337+
36338 if (blk_verify_command(rq->cmd, mode & FMODE_WRITE))
36339 return -EPERM;
36340
36341@@ -417,6 +429,8 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
36342 int err;
36343 unsigned int in_len, out_len, bytes, opcode, cmdlen;
36344 char *buffer = NULL, sense[SCSI_SENSE_BUFFERSIZE];
36345+ unsigned char tmpcmd[sizeof(rq->__cmd)];
36346+ unsigned char *cmdptr;
36347
36348 if (!sic)
36349 return -EINVAL;
36350@@ -450,9 +464,18 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
36351 */
36352 err = -EFAULT;
36353 rq->cmd_len = cmdlen;
36354- if (copy_from_user(rq->cmd, sic->data, cmdlen))
36355+
36356+ if (rq->cmd != rq->__cmd)
36357+ cmdptr = rq->cmd;
36358+ else
36359+ cmdptr = tmpcmd;
36360+
36361+ if (copy_from_user(cmdptr, sic->data, cmdlen))
36362 goto error;
36363
36364+ if (rq->cmd != cmdptr)
36365+ memcpy(rq->cmd, cmdptr, cmdlen);
36366+
36367 if (in_len && copy_from_user(buffer, sic->data + cmdlen, in_len))
36368 goto error;
36369
36370diff --git a/crypto/cryptd.c b/crypto/cryptd.c
36371index 7bdd61b..afec999 100644
36372--- a/crypto/cryptd.c
36373+++ b/crypto/cryptd.c
36374@@ -63,7 +63,7 @@ struct cryptd_blkcipher_ctx {
36375
36376 struct cryptd_blkcipher_request_ctx {
36377 crypto_completion_t complete;
36378-};
36379+} __no_const;
36380
36381 struct cryptd_hash_ctx {
36382 struct crypto_shash *child;
36383@@ -80,7 +80,7 @@ struct cryptd_aead_ctx {
36384
36385 struct cryptd_aead_request_ctx {
36386 crypto_completion_t complete;
36387-};
36388+} __no_const;
36389
36390 static void cryptd_queue_worker(struct work_struct *work);
36391
36392diff --git a/crypto/pcrypt.c b/crypto/pcrypt.c
36393index 309d345..1632720 100644
36394--- a/crypto/pcrypt.c
36395+++ b/crypto/pcrypt.c
36396@@ -440,7 +440,7 @@ static int pcrypt_sysfs_add(struct padata_instance *pinst, const char *name)
36397 int ret;
36398
36399 pinst->kobj.kset = pcrypt_kset;
36400- ret = kobject_add(&pinst->kobj, NULL, name);
36401+ ret = kobject_add(&pinst->kobj, NULL, "%s", name);
36402 if (!ret)
36403 kobject_uevent(&pinst->kobj, KOBJ_ADD);
36404
36405diff --git a/drivers/acpi/acpica/hwxfsleep.c b/drivers/acpi/acpica/hwxfsleep.c
36406index 15dddc1..b61cf0c 100644
36407--- a/drivers/acpi/acpica/hwxfsleep.c
36408+++ b/drivers/acpi/acpica/hwxfsleep.c
36409@@ -63,11 +63,12 @@ static acpi_status acpi_hw_sleep_dispatch(u8 sleep_state, u32 function_id);
36410 /* Legacy functions are optional, based upon ACPI_REDUCED_HARDWARE */
36411
36412 static struct acpi_sleep_functions acpi_sleep_dispatch[] = {
36413- {ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_sleep),
36414- acpi_hw_extended_sleep},
36415- {ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake_prep),
36416- acpi_hw_extended_wake_prep},
36417- {ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake), acpi_hw_extended_wake}
36418+ {.legacy_function = ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_sleep),
36419+ .extended_function = acpi_hw_extended_sleep},
36420+ {.legacy_function = ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake_prep),
36421+ .extended_function = acpi_hw_extended_wake_prep},
36422+ {.legacy_function = ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake),
36423+ .extended_function = acpi_hw_extended_wake}
36424 };
36425
36426 /*
36427diff --git a/drivers/acpi/apei/apei-internal.h b/drivers/acpi/apei/apei-internal.h
36428index e5bcd91..74f050d 100644
36429--- a/drivers/acpi/apei/apei-internal.h
36430+++ b/drivers/acpi/apei/apei-internal.h
36431@@ -19,7 +19,7 @@ typedef int (*apei_exec_ins_func_t)(struct apei_exec_context *ctx,
36432 struct apei_exec_ins_type {
36433 u32 flags;
36434 apei_exec_ins_func_t run;
36435-};
36436+} __do_const;
36437
36438 struct apei_exec_context {
36439 u32 ip;
36440diff --git a/drivers/acpi/apei/ghes.c b/drivers/acpi/apei/ghes.c
36441index dab7cb7..f0d2994 100644
36442--- a/drivers/acpi/apei/ghes.c
36443+++ b/drivers/acpi/apei/ghes.c
36444@@ -500,7 +500,7 @@ static void __ghes_print_estatus(const char *pfx,
36445 const struct acpi_hest_generic *generic,
36446 const struct acpi_generic_status *estatus)
36447 {
36448- static atomic_t seqno;
36449+ static atomic_unchecked_t seqno;
36450 unsigned int curr_seqno;
36451 char pfx_seq[64];
36452
36453@@ -511,7 +511,7 @@ static void __ghes_print_estatus(const char *pfx,
36454 else
36455 pfx = KERN_ERR;
36456 }
36457- curr_seqno = atomic_inc_return(&seqno);
36458+ curr_seqno = atomic_inc_return_unchecked(&seqno);
36459 snprintf(pfx_seq, sizeof(pfx_seq), "%s{%u}" HW_ERR, pfx, curr_seqno);
36460 printk("%s""Hardware error from APEI Generic Hardware Error Source: %d\n",
36461 pfx_seq, generic->header.source_id);
36462diff --git a/drivers/acpi/bgrt.c b/drivers/acpi/bgrt.c
36463index a83e3c6..c3d617f 100644
36464--- a/drivers/acpi/bgrt.c
36465+++ b/drivers/acpi/bgrt.c
36466@@ -86,8 +86,10 @@ static int __init bgrt_init(void)
36467 if (!bgrt_image)
36468 return -ENODEV;
36469
36470- bin_attr_image.private = bgrt_image;
36471- bin_attr_image.size = bgrt_image_size;
36472+ pax_open_kernel();
36473+ *(void **)&bin_attr_image.private = bgrt_image;
36474+ *(size_t *)&bin_attr_image.size = bgrt_image_size;
36475+ pax_close_kernel();
36476
36477 bgrt_kobj = kobject_create_and_add("bgrt", acpi_kobj);
36478 if (!bgrt_kobj)
36479diff --git a/drivers/acpi/blacklist.c b/drivers/acpi/blacklist.c
36480index afec452..c5d8b96 100644
36481--- a/drivers/acpi/blacklist.c
36482+++ b/drivers/acpi/blacklist.c
36483@@ -51,7 +51,7 @@ struct acpi_blacklist_item {
36484 u32 is_critical_error;
36485 };
36486
36487-static struct dmi_system_id acpi_osi_dmi_table[] __initdata;
36488+static const struct dmi_system_id acpi_osi_dmi_table[] __initconst;
36489
36490 /*
36491 * POLICY: If *anything* doesn't work, put it on the blacklist.
36492@@ -163,7 +163,7 @@ static int __init dmi_disable_osi_win8(const struct dmi_system_id *d)
36493 return 0;
36494 }
36495
36496-static struct dmi_system_id acpi_osi_dmi_table[] __initdata = {
36497+static const struct dmi_system_id acpi_osi_dmi_table[] __initconst = {
36498 {
36499 .callback = dmi_disable_osi_vista,
36500 .ident = "Fujitsu Siemens",
36501diff --git a/drivers/acpi/custom_method.c b/drivers/acpi/custom_method.c
36502index c68e724..e863008 100644
36503--- a/drivers/acpi/custom_method.c
36504+++ b/drivers/acpi/custom_method.c
36505@@ -29,6 +29,10 @@ static ssize_t cm_write(struct file *file, const char __user * user_buf,
36506 struct acpi_table_header table;
36507 acpi_status status;
36508
36509+#ifdef CONFIG_GRKERNSEC_KMEM
36510+ return -EPERM;
36511+#endif
36512+
36513 if (!(*ppos)) {
36514 /* parse the table header to get the table length */
36515 if (count <= sizeof(struct acpi_table_header))
36516diff --git a/drivers/acpi/processor_idle.c b/drivers/acpi/processor_idle.c
36517index 3dca36d..abaf070 100644
36518--- a/drivers/acpi/processor_idle.c
36519+++ b/drivers/acpi/processor_idle.c
36520@@ -952,7 +952,7 @@ static int acpi_processor_setup_cpuidle_states(struct acpi_processor *pr)
36521 {
36522 int i, count = CPUIDLE_DRIVER_STATE_START;
36523 struct acpi_processor_cx *cx;
36524- struct cpuidle_state *state;
36525+ cpuidle_state_no_const *state;
36526 struct cpuidle_driver *drv = &acpi_idle_driver;
36527
36528 if (!pr->flags.power_setup_done)
36529diff --git a/drivers/acpi/sysfs.c b/drivers/acpi/sysfs.c
36530index 91a32ce..d77fcaf 100644
36531--- a/drivers/acpi/sysfs.c
36532+++ b/drivers/acpi/sysfs.c
36533@@ -425,11 +425,11 @@ static u32 num_counters;
36534 static struct attribute **all_attrs;
36535 static u32 acpi_gpe_count;
36536
36537-static struct attribute_group interrupt_stats_attr_group = {
36538+static attribute_group_no_const interrupt_stats_attr_group = {
36539 .name = "interrupts",
36540 };
36541
36542-static struct kobj_attribute *counter_attrs;
36543+static kobj_attribute_no_const *counter_attrs;
36544
36545 static void delete_gpe_attr_array(void)
36546 {
36547diff --git a/drivers/ata/libahci.c b/drivers/ata/libahci.c
36548index 36605ab..6ef6d4b 100644
36549--- a/drivers/ata/libahci.c
36550+++ b/drivers/ata/libahci.c
36551@@ -1239,7 +1239,7 @@ int ahci_kick_engine(struct ata_port *ap)
36552 }
36553 EXPORT_SYMBOL_GPL(ahci_kick_engine);
36554
36555-static int ahci_exec_polled_cmd(struct ata_port *ap, int pmp,
36556+static int __intentional_overflow(-1) ahci_exec_polled_cmd(struct ata_port *ap, int pmp,
36557 struct ata_taskfile *tf, int is_cmd, u16 flags,
36558 unsigned long timeout_msec)
36559 {
36560diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
36561index 0a79c54..c1b92ed 100644
36562--- a/drivers/ata/libata-core.c
36563+++ b/drivers/ata/libata-core.c
36564@@ -98,7 +98,7 @@ static unsigned int ata_dev_set_xfermode(struct ata_device *dev);
36565 static void ata_dev_xfermask(struct ata_device *dev);
36566 static unsigned long ata_dev_blacklisted(const struct ata_device *dev);
36567
36568-atomic_t ata_print_id = ATOMIC_INIT(0);
36569+atomic_unchecked_t ata_print_id = ATOMIC_INIT(0);
36570
36571 struct ata_force_param {
36572 const char *name;
36573@@ -4858,7 +4858,7 @@ void ata_qc_free(struct ata_queued_cmd *qc)
36574 struct ata_port *ap;
36575 unsigned int tag;
36576
36577- WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
36578+ BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
36579 ap = qc->ap;
36580
36581 qc->flags = 0;
36582@@ -4874,7 +4874,7 @@ void __ata_qc_complete(struct ata_queued_cmd *qc)
36583 struct ata_port *ap;
36584 struct ata_link *link;
36585
36586- WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
36587+ BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
36588 WARN_ON_ONCE(!(qc->flags & ATA_QCFLAG_ACTIVE));
36589 ap = qc->ap;
36590 link = qc->dev->link;
36591@@ -5993,6 +5993,7 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
36592 return;
36593
36594 spin_lock(&lock);
36595+ pax_open_kernel();
36596
36597 for (cur = ops->inherits; cur; cur = cur->inherits) {
36598 void **inherit = (void **)cur;
36599@@ -6006,8 +6007,9 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
36600 if (IS_ERR(*pp))
36601 *pp = NULL;
36602
36603- ops->inherits = NULL;
36604+ *(struct ata_port_operations **)&ops->inherits = NULL;
36605
36606+ pax_close_kernel();
36607 spin_unlock(&lock);
36608 }
36609
36610@@ -6200,7 +6202,7 @@ int ata_host_register(struct ata_host *host, struct scsi_host_template *sht)
36611
36612 /* give ports names and add SCSI hosts */
36613 for (i = 0; i < host->n_ports; i++) {
36614- host->ports[i]->print_id = atomic_inc_return(&ata_print_id);
36615+ host->ports[i]->print_id = atomic_inc_return_unchecked(&ata_print_id);
36616 host->ports[i]->local_port_no = i + 1;
36617 }
36618
36619diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c
36620index ef8567d..8bdbd03 100644
36621--- a/drivers/ata/libata-scsi.c
36622+++ b/drivers/ata/libata-scsi.c
36623@@ -4147,7 +4147,7 @@ int ata_sas_port_init(struct ata_port *ap)
36624
36625 if (rc)
36626 return rc;
36627- ap->print_id = atomic_inc_return(&ata_print_id);
36628+ ap->print_id = atomic_inc_return_unchecked(&ata_print_id);
36629 return 0;
36630 }
36631 EXPORT_SYMBOL_GPL(ata_sas_port_init);
36632diff --git a/drivers/ata/libata.h b/drivers/ata/libata.h
36633index 45b5ab3..98446b8 100644
36634--- a/drivers/ata/libata.h
36635+++ b/drivers/ata/libata.h
36636@@ -53,7 +53,7 @@ enum {
36637 ATA_DNXFER_QUIET = (1 << 31),
36638 };
36639
36640-extern atomic_t ata_print_id;
36641+extern atomic_unchecked_t ata_print_id;
36642 extern int atapi_passthru16;
36643 extern int libata_fua;
36644 extern int libata_noacpi;
36645diff --git a/drivers/ata/pata_arasan_cf.c b/drivers/ata/pata_arasan_cf.c
36646index 73492dd..ca2bff5 100644
36647--- a/drivers/ata/pata_arasan_cf.c
36648+++ b/drivers/ata/pata_arasan_cf.c
36649@@ -865,7 +865,9 @@ static int arasan_cf_probe(struct platform_device *pdev)
36650 /* Handle platform specific quirks */
36651 if (quirk) {
36652 if (quirk & CF_BROKEN_PIO) {
36653- ap->ops->set_piomode = NULL;
36654+ pax_open_kernel();
36655+ *(void **)&ap->ops->set_piomode = NULL;
36656+ pax_close_kernel();
36657 ap->pio_mask = 0;
36658 }
36659 if (quirk & CF_BROKEN_MWDMA)
36660diff --git a/drivers/atm/adummy.c b/drivers/atm/adummy.c
36661index f9b983a..887b9d8 100644
36662--- a/drivers/atm/adummy.c
36663+++ b/drivers/atm/adummy.c
36664@@ -114,7 +114,7 @@ adummy_send(struct atm_vcc *vcc, struct sk_buff *skb)
36665 vcc->pop(vcc, skb);
36666 else
36667 dev_kfree_skb_any(skb);
36668- atomic_inc(&vcc->stats->tx);
36669+ atomic_inc_unchecked(&vcc->stats->tx);
36670
36671 return 0;
36672 }
36673diff --git a/drivers/atm/ambassador.c b/drivers/atm/ambassador.c
36674index 62a7607..cc4be104 100644
36675--- a/drivers/atm/ambassador.c
36676+++ b/drivers/atm/ambassador.c
36677@@ -454,7 +454,7 @@ static void tx_complete (amb_dev * dev, tx_out * tx) {
36678 PRINTD (DBG_FLOW|DBG_TX, "tx_complete %p %p", dev, tx);
36679
36680 // VC layer stats
36681- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
36682+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
36683
36684 // free the descriptor
36685 kfree (tx_descr);
36686@@ -495,7 +495,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
36687 dump_skb ("<<<", vc, skb);
36688
36689 // VC layer stats
36690- atomic_inc(&atm_vcc->stats->rx);
36691+ atomic_inc_unchecked(&atm_vcc->stats->rx);
36692 __net_timestamp(skb);
36693 // end of our responsibility
36694 atm_vcc->push (atm_vcc, skb);
36695@@ -510,7 +510,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
36696 } else {
36697 PRINTK (KERN_INFO, "dropped over-size frame");
36698 // should we count this?
36699- atomic_inc(&atm_vcc->stats->rx_drop);
36700+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
36701 }
36702
36703 } else {
36704@@ -1338,7 +1338,7 @@ static int amb_send (struct atm_vcc * atm_vcc, struct sk_buff * skb) {
36705 }
36706
36707 if (check_area (skb->data, skb->len)) {
36708- atomic_inc(&atm_vcc->stats->tx_err);
36709+ atomic_inc_unchecked(&atm_vcc->stats->tx_err);
36710 return -ENOMEM; // ?
36711 }
36712
36713diff --git a/drivers/atm/atmtcp.c b/drivers/atm/atmtcp.c
36714index 0e3f8f9..765a7a5 100644
36715--- a/drivers/atm/atmtcp.c
36716+++ b/drivers/atm/atmtcp.c
36717@@ -206,7 +206,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
36718 if (vcc->pop) vcc->pop(vcc,skb);
36719 else dev_kfree_skb(skb);
36720 if (dev_data) return 0;
36721- atomic_inc(&vcc->stats->tx_err);
36722+ atomic_inc_unchecked(&vcc->stats->tx_err);
36723 return -ENOLINK;
36724 }
36725 size = skb->len+sizeof(struct atmtcp_hdr);
36726@@ -214,7 +214,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
36727 if (!new_skb) {
36728 if (vcc->pop) vcc->pop(vcc,skb);
36729 else dev_kfree_skb(skb);
36730- atomic_inc(&vcc->stats->tx_err);
36731+ atomic_inc_unchecked(&vcc->stats->tx_err);
36732 return -ENOBUFS;
36733 }
36734 hdr = (void *) skb_put(new_skb,sizeof(struct atmtcp_hdr));
36735@@ -225,8 +225,8 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
36736 if (vcc->pop) vcc->pop(vcc,skb);
36737 else dev_kfree_skb(skb);
36738 out_vcc->push(out_vcc,new_skb);
36739- atomic_inc(&vcc->stats->tx);
36740- atomic_inc(&out_vcc->stats->rx);
36741+ atomic_inc_unchecked(&vcc->stats->tx);
36742+ atomic_inc_unchecked(&out_vcc->stats->rx);
36743 return 0;
36744 }
36745
36746@@ -299,7 +299,7 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
36747 out_vcc = find_vcc(dev, ntohs(hdr->vpi), ntohs(hdr->vci));
36748 read_unlock(&vcc_sklist_lock);
36749 if (!out_vcc) {
36750- atomic_inc(&vcc->stats->tx_err);
36751+ atomic_inc_unchecked(&vcc->stats->tx_err);
36752 goto done;
36753 }
36754 skb_pull(skb,sizeof(struct atmtcp_hdr));
36755@@ -311,8 +311,8 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
36756 __net_timestamp(new_skb);
36757 skb_copy_from_linear_data(skb, skb_put(new_skb, skb->len), skb->len);
36758 out_vcc->push(out_vcc,new_skb);
36759- atomic_inc(&vcc->stats->tx);
36760- atomic_inc(&out_vcc->stats->rx);
36761+ atomic_inc_unchecked(&vcc->stats->tx);
36762+ atomic_inc_unchecked(&out_vcc->stats->rx);
36763 done:
36764 if (vcc->pop) vcc->pop(vcc,skb);
36765 else dev_kfree_skb(skb);
36766diff --git a/drivers/atm/eni.c b/drivers/atm/eni.c
36767index b1955ba..b179940 100644
36768--- a/drivers/atm/eni.c
36769+++ b/drivers/atm/eni.c
36770@@ -522,7 +522,7 @@ static int rx_aal0(struct atm_vcc *vcc)
36771 DPRINTK(DEV_LABEL "(itf %d): trashing empty cell\n",
36772 vcc->dev->number);
36773 length = 0;
36774- atomic_inc(&vcc->stats->rx_err);
36775+ atomic_inc_unchecked(&vcc->stats->rx_err);
36776 }
36777 else {
36778 length = ATM_CELL_SIZE-1; /* no HEC */
36779@@ -577,7 +577,7 @@ static int rx_aal5(struct atm_vcc *vcc)
36780 size);
36781 }
36782 eff = length = 0;
36783- atomic_inc(&vcc->stats->rx_err);
36784+ atomic_inc_unchecked(&vcc->stats->rx_err);
36785 }
36786 else {
36787 size = (descr & MID_RED_COUNT)*(ATM_CELL_PAYLOAD >> 2);
36788@@ -594,7 +594,7 @@ static int rx_aal5(struct atm_vcc *vcc)
36789 "(VCI=%d,length=%ld,size=%ld (descr 0x%lx))\n",
36790 vcc->dev->number,vcc->vci,length,size << 2,descr);
36791 length = eff = 0;
36792- atomic_inc(&vcc->stats->rx_err);
36793+ atomic_inc_unchecked(&vcc->stats->rx_err);
36794 }
36795 }
36796 skb = eff ? atm_alloc_charge(vcc,eff << 2,GFP_ATOMIC) : NULL;
36797@@ -767,7 +767,7 @@ rx_dequeued++;
36798 vcc->push(vcc,skb);
36799 pushed++;
36800 }
36801- atomic_inc(&vcc->stats->rx);
36802+ atomic_inc_unchecked(&vcc->stats->rx);
36803 }
36804 wake_up(&eni_dev->rx_wait);
36805 }
36806@@ -1227,7 +1227,7 @@ static void dequeue_tx(struct atm_dev *dev)
36807 PCI_DMA_TODEVICE);
36808 if (vcc->pop) vcc->pop(vcc,skb);
36809 else dev_kfree_skb_irq(skb);
36810- atomic_inc(&vcc->stats->tx);
36811+ atomic_inc_unchecked(&vcc->stats->tx);
36812 wake_up(&eni_dev->tx_wait);
36813 dma_complete++;
36814 }
36815diff --git a/drivers/atm/firestream.c b/drivers/atm/firestream.c
36816index b41c948..a002b17 100644
36817--- a/drivers/atm/firestream.c
36818+++ b/drivers/atm/firestream.c
36819@@ -749,7 +749,7 @@ static void process_txdone_queue (struct fs_dev *dev, struct queue *q)
36820 }
36821 }
36822
36823- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
36824+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
36825
36826 fs_dprintk (FS_DEBUG_TXMEM, "i");
36827 fs_dprintk (FS_DEBUG_ALLOC, "Free t-skb: %p\n", skb);
36828@@ -816,7 +816,7 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
36829 #endif
36830 skb_put (skb, qe->p1 & 0xffff);
36831 ATM_SKB(skb)->vcc = atm_vcc;
36832- atomic_inc(&atm_vcc->stats->rx);
36833+ atomic_inc_unchecked(&atm_vcc->stats->rx);
36834 __net_timestamp(skb);
36835 fs_dprintk (FS_DEBUG_ALLOC, "Free rec-skb: %p (pushed)\n", skb);
36836 atm_vcc->push (atm_vcc, skb);
36837@@ -837,12 +837,12 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
36838 kfree (pe);
36839 }
36840 if (atm_vcc)
36841- atomic_inc(&atm_vcc->stats->rx_drop);
36842+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
36843 break;
36844 case 0x1f: /* Reassembly abort: no buffers. */
36845 /* Silently increment error counter. */
36846 if (atm_vcc)
36847- atomic_inc(&atm_vcc->stats->rx_drop);
36848+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
36849 break;
36850 default: /* Hmm. Haven't written the code to handle the others yet... -- REW */
36851 printk (KERN_WARNING "Don't know what to do with RX status %x: %s.\n",
36852diff --git a/drivers/atm/fore200e.c b/drivers/atm/fore200e.c
36853index 204814e..cede831 100644
36854--- a/drivers/atm/fore200e.c
36855+++ b/drivers/atm/fore200e.c
36856@@ -931,9 +931,9 @@ fore200e_tx_irq(struct fore200e* fore200e)
36857 #endif
36858 /* check error condition */
36859 if (*entry->status & STATUS_ERROR)
36860- atomic_inc(&vcc->stats->tx_err);
36861+ atomic_inc_unchecked(&vcc->stats->tx_err);
36862 else
36863- atomic_inc(&vcc->stats->tx);
36864+ atomic_inc_unchecked(&vcc->stats->tx);
36865 }
36866 }
36867
36868@@ -1082,7 +1082,7 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
36869 if (skb == NULL) {
36870 DPRINTK(2, "unable to alloc new skb, rx PDU length = %d\n", pdu_len);
36871
36872- atomic_inc(&vcc->stats->rx_drop);
36873+ atomic_inc_unchecked(&vcc->stats->rx_drop);
36874 return -ENOMEM;
36875 }
36876
36877@@ -1125,14 +1125,14 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
36878
36879 dev_kfree_skb_any(skb);
36880
36881- atomic_inc(&vcc->stats->rx_drop);
36882+ atomic_inc_unchecked(&vcc->stats->rx_drop);
36883 return -ENOMEM;
36884 }
36885
36886 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
36887
36888 vcc->push(vcc, skb);
36889- atomic_inc(&vcc->stats->rx);
36890+ atomic_inc_unchecked(&vcc->stats->rx);
36891
36892 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
36893
36894@@ -1210,7 +1210,7 @@ fore200e_rx_irq(struct fore200e* fore200e)
36895 DPRINTK(2, "damaged PDU on %d.%d.%d\n",
36896 fore200e->atm_dev->number,
36897 entry->rpd->atm_header.vpi, entry->rpd->atm_header.vci);
36898- atomic_inc(&vcc->stats->rx_err);
36899+ atomic_inc_unchecked(&vcc->stats->rx_err);
36900 }
36901 }
36902
36903@@ -1655,7 +1655,7 @@ fore200e_send(struct atm_vcc *vcc, struct sk_buff *skb)
36904 goto retry_here;
36905 }
36906
36907- atomic_inc(&vcc->stats->tx_err);
36908+ atomic_inc_unchecked(&vcc->stats->tx_err);
36909
36910 fore200e->tx_sat++;
36911 DPRINTK(2, "tx queue of device %s is saturated, PDU dropped - heartbeat is %08x\n",
36912diff --git a/drivers/atm/he.c b/drivers/atm/he.c
36913index aa6be26..f70a785 100644
36914--- a/drivers/atm/he.c
36915+++ b/drivers/atm/he.c
36916@@ -1690,7 +1690,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
36917
36918 if (RBRQ_HBUF_ERR(he_dev->rbrq_head)) {
36919 hprintk("HBUF_ERR! (cid 0x%x)\n", cid);
36920- atomic_inc(&vcc->stats->rx_drop);
36921+ atomic_inc_unchecked(&vcc->stats->rx_drop);
36922 goto return_host_buffers;
36923 }
36924
36925@@ -1717,7 +1717,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
36926 RBRQ_LEN_ERR(he_dev->rbrq_head)
36927 ? "LEN_ERR" : "",
36928 vcc->vpi, vcc->vci);
36929- atomic_inc(&vcc->stats->rx_err);
36930+ atomic_inc_unchecked(&vcc->stats->rx_err);
36931 goto return_host_buffers;
36932 }
36933
36934@@ -1769,7 +1769,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
36935 vcc->push(vcc, skb);
36936 spin_lock(&he_dev->global_lock);
36937
36938- atomic_inc(&vcc->stats->rx);
36939+ atomic_inc_unchecked(&vcc->stats->rx);
36940
36941 return_host_buffers:
36942 ++pdus_assembled;
36943@@ -2095,7 +2095,7 @@ __enqueue_tpd(struct he_dev *he_dev, struct he_tpd *tpd, unsigned cid)
36944 tpd->vcc->pop(tpd->vcc, tpd->skb);
36945 else
36946 dev_kfree_skb_any(tpd->skb);
36947- atomic_inc(&tpd->vcc->stats->tx_err);
36948+ atomic_inc_unchecked(&tpd->vcc->stats->tx_err);
36949 }
36950 pci_pool_free(he_dev->tpd_pool, tpd, TPD_ADDR(tpd->status));
36951 return;
36952@@ -2507,7 +2507,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
36953 vcc->pop(vcc, skb);
36954 else
36955 dev_kfree_skb_any(skb);
36956- atomic_inc(&vcc->stats->tx_err);
36957+ atomic_inc_unchecked(&vcc->stats->tx_err);
36958 return -EINVAL;
36959 }
36960
36961@@ -2518,7 +2518,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
36962 vcc->pop(vcc, skb);
36963 else
36964 dev_kfree_skb_any(skb);
36965- atomic_inc(&vcc->stats->tx_err);
36966+ atomic_inc_unchecked(&vcc->stats->tx_err);
36967 return -EINVAL;
36968 }
36969 #endif
36970@@ -2530,7 +2530,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
36971 vcc->pop(vcc, skb);
36972 else
36973 dev_kfree_skb_any(skb);
36974- atomic_inc(&vcc->stats->tx_err);
36975+ atomic_inc_unchecked(&vcc->stats->tx_err);
36976 spin_unlock_irqrestore(&he_dev->global_lock, flags);
36977 return -ENOMEM;
36978 }
36979@@ -2572,7 +2572,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
36980 vcc->pop(vcc, skb);
36981 else
36982 dev_kfree_skb_any(skb);
36983- atomic_inc(&vcc->stats->tx_err);
36984+ atomic_inc_unchecked(&vcc->stats->tx_err);
36985 spin_unlock_irqrestore(&he_dev->global_lock, flags);
36986 return -ENOMEM;
36987 }
36988@@ -2603,7 +2603,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
36989 __enqueue_tpd(he_dev, tpd, cid);
36990 spin_unlock_irqrestore(&he_dev->global_lock, flags);
36991
36992- atomic_inc(&vcc->stats->tx);
36993+ atomic_inc_unchecked(&vcc->stats->tx);
36994
36995 return 0;
36996 }
36997diff --git a/drivers/atm/horizon.c b/drivers/atm/horizon.c
36998index 1dc0519..1aadaf7 100644
36999--- a/drivers/atm/horizon.c
37000+++ b/drivers/atm/horizon.c
37001@@ -1034,7 +1034,7 @@ static void rx_schedule (hrz_dev * dev, int irq) {
37002 {
37003 struct atm_vcc * vcc = ATM_SKB(skb)->vcc;
37004 // VC layer stats
37005- atomic_inc(&vcc->stats->rx);
37006+ atomic_inc_unchecked(&vcc->stats->rx);
37007 __net_timestamp(skb);
37008 // end of our responsibility
37009 vcc->push (vcc, skb);
37010@@ -1186,7 +1186,7 @@ static void tx_schedule (hrz_dev * const dev, int irq) {
37011 dev->tx_iovec = NULL;
37012
37013 // VC layer stats
37014- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
37015+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
37016
37017 // free the skb
37018 hrz_kfree_skb (skb);
37019diff --git a/drivers/atm/idt77252.c b/drivers/atm/idt77252.c
37020index 1bdf104..9dc44b1 100644
37021--- a/drivers/atm/idt77252.c
37022+++ b/drivers/atm/idt77252.c
37023@@ -812,7 +812,7 @@ drain_scq(struct idt77252_dev *card, struct vc_map *vc)
37024 else
37025 dev_kfree_skb(skb);
37026
37027- atomic_inc(&vcc->stats->tx);
37028+ atomic_inc_unchecked(&vcc->stats->tx);
37029 }
37030
37031 atomic_dec(&scq->used);
37032@@ -1075,13 +1075,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
37033 if ((sb = dev_alloc_skb(64)) == NULL) {
37034 printk("%s: Can't allocate buffers for aal0.\n",
37035 card->name);
37036- atomic_add(i, &vcc->stats->rx_drop);
37037+ atomic_add_unchecked(i, &vcc->stats->rx_drop);
37038 break;
37039 }
37040 if (!atm_charge(vcc, sb->truesize)) {
37041 RXPRINTK("%s: atm_charge() dropped aal0 packets.\n",
37042 card->name);
37043- atomic_add(i - 1, &vcc->stats->rx_drop);
37044+ atomic_add_unchecked(i - 1, &vcc->stats->rx_drop);
37045 dev_kfree_skb(sb);
37046 break;
37047 }
37048@@ -1098,7 +1098,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
37049 ATM_SKB(sb)->vcc = vcc;
37050 __net_timestamp(sb);
37051 vcc->push(vcc, sb);
37052- atomic_inc(&vcc->stats->rx);
37053+ atomic_inc_unchecked(&vcc->stats->rx);
37054
37055 cell += ATM_CELL_PAYLOAD;
37056 }
37057@@ -1135,13 +1135,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
37058 "(CDC: %08x)\n",
37059 card->name, len, rpp->len, readl(SAR_REG_CDC));
37060 recycle_rx_pool_skb(card, rpp);
37061- atomic_inc(&vcc->stats->rx_err);
37062+ atomic_inc_unchecked(&vcc->stats->rx_err);
37063 return;
37064 }
37065 if (stat & SAR_RSQE_CRC) {
37066 RXPRINTK("%s: AAL5 CRC error.\n", card->name);
37067 recycle_rx_pool_skb(card, rpp);
37068- atomic_inc(&vcc->stats->rx_err);
37069+ atomic_inc_unchecked(&vcc->stats->rx_err);
37070 return;
37071 }
37072 if (skb_queue_len(&rpp->queue) > 1) {
37073@@ -1152,7 +1152,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
37074 RXPRINTK("%s: Can't alloc RX skb.\n",
37075 card->name);
37076 recycle_rx_pool_skb(card, rpp);
37077- atomic_inc(&vcc->stats->rx_err);
37078+ atomic_inc_unchecked(&vcc->stats->rx_err);
37079 return;
37080 }
37081 if (!atm_charge(vcc, skb->truesize)) {
37082@@ -1171,7 +1171,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
37083 __net_timestamp(skb);
37084
37085 vcc->push(vcc, skb);
37086- atomic_inc(&vcc->stats->rx);
37087+ atomic_inc_unchecked(&vcc->stats->rx);
37088
37089 return;
37090 }
37091@@ -1193,7 +1193,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
37092 __net_timestamp(skb);
37093
37094 vcc->push(vcc, skb);
37095- atomic_inc(&vcc->stats->rx);
37096+ atomic_inc_unchecked(&vcc->stats->rx);
37097
37098 if (skb->truesize > SAR_FB_SIZE_3)
37099 add_rx_skb(card, 3, SAR_FB_SIZE_3, 1);
37100@@ -1304,14 +1304,14 @@ idt77252_rx_raw(struct idt77252_dev *card)
37101 if (vcc->qos.aal != ATM_AAL0) {
37102 RPRINTK("%s: raw cell for non AAL0 vc %u.%u\n",
37103 card->name, vpi, vci);
37104- atomic_inc(&vcc->stats->rx_drop);
37105+ atomic_inc_unchecked(&vcc->stats->rx_drop);
37106 goto drop;
37107 }
37108
37109 if ((sb = dev_alloc_skb(64)) == NULL) {
37110 printk("%s: Can't allocate buffers for AAL0.\n",
37111 card->name);
37112- atomic_inc(&vcc->stats->rx_err);
37113+ atomic_inc_unchecked(&vcc->stats->rx_err);
37114 goto drop;
37115 }
37116
37117@@ -1330,7 +1330,7 @@ idt77252_rx_raw(struct idt77252_dev *card)
37118 ATM_SKB(sb)->vcc = vcc;
37119 __net_timestamp(sb);
37120 vcc->push(vcc, sb);
37121- atomic_inc(&vcc->stats->rx);
37122+ atomic_inc_unchecked(&vcc->stats->rx);
37123
37124 drop:
37125 skb_pull(queue, 64);
37126@@ -1955,13 +1955,13 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
37127
37128 if (vc == NULL) {
37129 printk("%s: NULL connection in send().\n", card->name);
37130- atomic_inc(&vcc->stats->tx_err);
37131+ atomic_inc_unchecked(&vcc->stats->tx_err);
37132 dev_kfree_skb(skb);
37133 return -EINVAL;
37134 }
37135 if (!test_bit(VCF_TX, &vc->flags)) {
37136 printk("%s: Trying to transmit on a non-tx VC.\n", card->name);
37137- atomic_inc(&vcc->stats->tx_err);
37138+ atomic_inc_unchecked(&vcc->stats->tx_err);
37139 dev_kfree_skb(skb);
37140 return -EINVAL;
37141 }
37142@@ -1973,14 +1973,14 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
37143 break;
37144 default:
37145 printk("%s: Unsupported AAL: %d\n", card->name, vcc->qos.aal);
37146- atomic_inc(&vcc->stats->tx_err);
37147+ atomic_inc_unchecked(&vcc->stats->tx_err);
37148 dev_kfree_skb(skb);
37149 return -EINVAL;
37150 }
37151
37152 if (skb_shinfo(skb)->nr_frags != 0) {
37153 printk("%s: No scatter-gather yet.\n", card->name);
37154- atomic_inc(&vcc->stats->tx_err);
37155+ atomic_inc_unchecked(&vcc->stats->tx_err);
37156 dev_kfree_skb(skb);
37157 return -EINVAL;
37158 }
37159@@ -1988,7 +1988,7 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
37160
37161 err = queue_skb(card, vc, skb, oam);
37162 if (err) {
37163- atomic_inc(&vcc->stats->tx_err);
37164+ atomic_inc_unchecked(&vcc->stats->tx_err);
37165 dev_kfree_skb(skb);
37166 return err;
37167 }
37168@@ -2011,7 +2011,7 @@ idt77252_send_oam(struct atm_vcc *vcc, void *cell, int flags)
37169 skb = dev_alloc_skb(64);
37170 if (!skb) {
37171 printk("%s: Out of memory in send_oam().\n", card->name);
37172- atomic_inc(&vcc->stats->tx_err);
37173+ atomic_inc_unchecked(&vcc->stats->tx_err);
37174 return -ENOMEM;
37175 }
37176 atomic_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
37177diff --git a/drivers/atm/iphase.c b/drivers/atm/iphase.c
37178index 4217f29..88f547a 100644
37179--- a/drivers/atm/iphase.c
37180+++ b/drivers/atm/iphase.c
37181@@ -1145,7 +1145,7 @@ static int rx_pkt(struct atm_dev *dev)
37182 status = (u_short) (buf_desc_ptr->desc_mode);
37183 if (status & (RX_CER | RX_PTE | RX_OFL))
37184 {
37185- atomic_inc(&vcc->stats->rx_err);
37186+ atomic_inc_unchecked(&vcc->stats->rx_err);
37187 IF_ERR(printk("IA: bad packet, dropping it");)
37188 if (status & RX_CER) {
37189 IF_ERR(printk(" cause: packet CRC error\n");)
37190@@ -1168,7 +1168,7 @@ static int rx_pkt(struct atm_dev *dev)
37191 len = dma_addr - buf_addr;
37192 if (len > iadev->rx_buf_sz) {
37193 printk("Over %d bytes sdu received, dropped!!!\n", iadev->rx_buf_sz);
37194- atomic_inc(&vcc->stats->rx_err);
37195+ atomic_inc_unchecked(&vcc->stats->rx_err);
37196 goto out_free_desc;
37197 }
37198
37199@@ -1318,7 +1318,7 @@ static void rx_dle_intr(struct atm_dev *dev)
37200 ia_vcc = INPH_IA_VCC(vcc);
37201 if (ia_vcc == NULL)
37202 {
37203- atomic_inc(&vcc->stats->rx_err);
37204+ atomic_inc_unchecked(&vcc->stats->rx_err);
37205 atm_return(vcc, skb->truesize);
37206 dev_kfree_skb_any(skb);
37207 goto INCR_DLE;
37208@@ -1330,7 +1330,7 @@ static void rx_dle_intr(struct atm_dev *dev)
37209 if ((length > iadev->rx_buf_sz) || (length >
37210 (skb->len - sizeof(struct cpcs_trailer))))
37211 {
37212- atomic_inc(&vcc->stats->rx_err);
37213+ atomic_inc_unchecked(&vcc->stats->rx_err);
37214 IF_ERR(printk("rx_dle_intr: Bad AAL5 trailer %d (skb len %d)",
37215 length, skb->len);)
37216 atm_return(vcc, skb->truesize);
37217@@ -1346,7 +1346,7 @@ static void rx_dle_intr(struct atm_dev *dev)
37218
37219 IF_RX(printk("rx_dle_intr: skb push");)
37220 vcc->push(vcc,skb);
37221- atomic_inc(&vcc->stats->rx);
37222+ atomic_inc_unchecked(&vcc->stats->rx);
37223 iadev->rx_pkt_cnt++;
37224 }
37225 INCR_DLE:
37226@@ -2826,15 +2826,15 @@ static int ia_ioctl(struct atm_dev *dev, unsigned int cmd, void __user *arg)
37227 {
37228 struct k_sonet_stats *stats;
37229 stats = &PRIV(_ia_dev[board])->sonet_stats;
37230- printk("section_bip: %d\n", atomic_read(&stats->section_bip));
37231- printk("line_bip : %d\n", atomic_read(&stats->line_bip));
37232- printk("path_bip : %d\n", atomic_read(&stats->path_bip));
37233- printk("line_febe : %d\n", atomic_read(&stats->line_febe));
37234- printk("path_febe : %d\n", atomic_read(&stats->path_febe));
37235- printk("corr_hcs : %d\n", atomic_read(&stats->corr_hcs));
37236- printk("uncorr_hcs : %d\n", atomic_read(&stats->uncorr_hcs));
37237- printk("tx_cells : %d\n", atomic_read(&stats->tx_cells));
37238- printk("rx_cells : %d\n", atomic_read(&stats->rx_cells));
37239+ printk("section_bip: %d\n", atomic_read_unchecked(&stats->section_bip));
37240+ printk("line_bip : %d\n", atomic_read_unchecked(&stats->line_bip));
37241+ printk("path_bip : %d\n", atomic_read_unchecked(&stats->path_bip));
37242+ printk("line_febe : %d\n", atomic_read_unchecked(&stats->line_febe));
37243+ printk("path_febe : %d\n", atomic_read_unchecked(&stats->path_febe));
37244+ printk("corr_hcs : %d\n", atomic_read_unchecked(&stats->corr_hcs));
37245+ printk("uncorr_hcs : %d\n", atomic_read_unchecked(&stats->uncorr_hcs));
37246+ printk("tx_cells : %d\n", atomic_read_unchecked(&stats->tx_cells));
37247+ printk("rx_cells : %d\n", atomic_read_unchecked(&stats->rx_cells));
37248 }
37249 ia_cmds.status = 0;
37250 break;
37251@@ -2939,7 +2939,7 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
37252 if ((desc == 0) || (desc > iadev->num_tx_desc))
37253 {
37254 IF_ERR(printk(DEV_LABEL "invalid desc for send: %d\n", desc);)
37255- atomic_inc(&vcc->stats->tx);
37256+ atomic_inc_unchecked(&vcc->stats->tx);
37257 if (vcc->pop)
37258 vcc->pop(vcc, skb);
37259 else
37260@@ -3044,14 +3044,14 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
37261 ATM_DESC(skb) = vcc->vci;
37262 skb_queue_tail(&iadev->tx_dma_q, skb);
37263
37264- atomic_inc(&vcc->stats->tx);
37265+ atomic_inc_unchecked(&vcc->stats->tx);
37266 iadev->tx_pkt_cnt++;
37267 /* Increment transaction counter */
37268 writel(2, iadev->dma+IPHASE5575_TX_COUNTER);
37269
37270 #if 0
37271 /* add flow control logic */
37272- if (atomic_read(&vcc->stats->tx) % 20 == 0) {
37273+ if (atomic_read_unchecked(&vcc->stats->tx) % 20 == 0) {
37274 if (iavcc->vc_desc_cnt > 10) {
37275 vcc->tx_quota = vcc->tx_quota * 3 / 4;
37276 printk("Tx1: vcc->tx_quota = %d \n", (u32)vcc->tx_quota );
37277diff --git a/drivers/atm/lanai.c b/drivers/atm/lanai.c
37278index fa7d701..1e404c7 100644
37279--- a/drivers/atm/lanai.c
37280+++ b/drivers/atm/lanai.c
37281@@ -1303,7 +1303,7 @@ static void lanai_send_one_aal5(struct lanai_dev *lanai,
37282 vcc_tx_add_aal5_trailer(lvcc, skb->len, 0, 0);
37283 lanai_endtx(lanai, lvcc);
37284 lanai_free_skb(lvcc->tx.atmvcc, skb);
37285- atomic_inc(&lvcc->tx.atmvcc->stats->tx);
37286+ atomic_inc_unchecked(&lvcc->tx.atmvcc->stats->tx);
37287 }
37288
37289 /* Try to fill the buffer - don't call unless there is backlog */
37290@@ -1426,7 +1426,7 @@ static void vcc_rx_aal5(struct lanai_vcc *lvcc, int endptr)
37291 ATM_SKB(skb)->vcc = lvcc->rx.atmvcc;
37292 __net_timestamp(skb);
37293 lvcc->rx.atmvcc->push(lvcc->rx.atmvcc, skb);
37294- atomic_inc(&lvcc->rx.atmvcc->stats->rx);
37295+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx);
37296 out:
37297 lvcc->rx.buf.ptr = end;
37298 cardvcc_write(lvcc, endptr, vcc_rxreadptr);
37299@@ -1667,7 +1667,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
37300 DPRINTK("(itf %d) got RX service entry 0x%X for non-AAL5 "
37301 "vcc %d\n", lanai->number, (unsigned int) s, vci);
37302 lanai->stats.service_rxnotaal5++;
37303- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
37304+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
37305 return 0;
37306 }
37307 if (likely(!(s & (SERVICE_TRASH | SERVICE_STREAM | SERVICE_CRCERR)))) {
37308@@ -1679,7 +1679,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
37309 int bytes;
37310 read_unlock(&vcc_sklist_lock);
37311 DPRINTK("got trashed rx pdu on vci %d\n", vci);
37312- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
37313+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
37314 lvcc->stats.x.aal5.service_trash++;
37315 bytes = (SERVICE_GET_END(s) * 16) -
37316 (((unsigned long) lvcc->rx.buf.ptr) -
37317@@ -1691,7 +1691,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
37318 }
37319 if (s & SERVICE_STREAM) {
37320 read_unlock(&vcc_sklist_lock);
37321- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
37322+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
37323 lvcc->stats.x.aal5.service_stream++;
37324 printk(KERN_ERR DEV_LABEL "(itf %d): Got AAL5 stream "
37325 "PDU on VCI %d!\n", lanai->number, vci);
37326@@ -1699,7 +1699,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
37327 return 0;
37328 }
37329 DPRINTK("got rx crc error on vci %d\n", vci);
37330- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
37331+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
37332 lvcc->stats.x.aal5.service_rxcrc++;
37333 lvcc->rx.buf.ptr = &lvcc->rx.buf.start[SERVICE_GET_END(s) * 4];
37334 cardvcc_write(lvcc, SERVICE_GET_END(s), vcc_rxreadptr);
37335diff --git a/drivers/atm/nicstar.c b/drivers/atm/nicstar.c
37336index 9587e95..b45c5cb 100644
37337--- a/drivers/atm/nicstar.c
37338+++ b/drivers/atm/nicstar.c
37339@@ -1640,7 +1640,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
37340 if ((vc = (vc_map *) vcc->dev_data) == NULL) {
37341 printk("nicstar%d: vcc->dev_data == NULL on ns_send().\n",
37342 card->index);
37343- atomic_inc(&vcc->stats->tx_err);
37344+ atomic_inc_unchecked(&vcc->stats->tx_err);
37345 dev_kfree_skb_any(skb);
37346 return -EINVAL;
37347 }
37348@@ -1648,7 +1648,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
37349 if (!vc->tx) {
37350 printk("nicstar%d: Trying to transmit on a non-tx VC.\n",
37351 card->index);
37352- atomic_inc(&vcc->stats->tx_err);
37353+ atomic_inc_unchecked(&vcc->stats->tx_err);
37354 dev_kfree_skb_any(skb);
37355 return -EINVAL;
37356 }
37357@@ -1656,14 +1656,14 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
37358 if (vcc->qos.aal != ATM_AAL5 && vcc->qos.aal != ATM_AAL0) {
37359 printk("nicstar%d: Only AAL0 and AAL5 are supported.\n",
37360 card->index);
37361- atomic_inc(&vcc->stats->tx_err);
37362+ atomic_inc_unchecked(&vcc->stats->tx_err);
37363 dev_kfree_skb_any(skb);
37364 return -EINVAL;
37365 }
37366
37367 if (skb_shinfo(skb)->nr_frags != 0) {
37368 printk("nicstar%d: No scatter-gather yet.\n", card->index);
37369- atomic_inc(&vcc->stats->tx_err);
37370+ atomic_inc_unchecked(&vcc->stats->tx_err);
37371 dev_kfree_skb_any(skb);
37372 return -EINVAL;
37373 }
37374@@ -1711,11 +1711,11 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
37375 }
37376
37377 if (push_scqe(card, vc, scq, &scqe, skb) != 0) {
37378- atomic_inc(&vcc->stats->tx_err);
37379+ atomic_inc_unchecked(&vcc->stats->tx_err);
37380 dev_kfree_skb_any(skb);
37381 return -EIO;
37382 }
37383- atomic_inc(&vcc->stats->tx);
37384+ atomic_inc_unchecked(&vcc->stats->tx);
37385
37386 return 0;
37387 }
37388@@ -2032,14 +2032,14 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37389 printk
37390 ("nicstar%d: Can't allocate buffers for aal0.\n",
37391 card->index);
37392- atomic_add(i, &vcc->stats->rx_drop);
37393+ atomic_add_unchecked(i, &vcc->stats->rx_drop);
37394 break;
37395 }
37396 if (!atm_charge(vcc, sb->truesize)) {
37397 RXPRINTK
37398 ("nicstar%d: atm_charge() dropped aal0 packets.\n",
37399 card->index);
37400- atomic_add(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
37401+ atomic_add_unchecked(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
37402 dev_kfree_skb_any(sb);
37403 break;
37404 }
37405@@ -2054,7 +2054,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37406 ATM_SKB(sb)->vcc = vcc;
37407 __net_timestamp(sb);
37408 vcc->push(vcc, sb);
37409- atomic_inc(&vcc->stats->rx);
37410+ atomic_inc_unchecked(&vcc->stats->rx);
37411 cell += ATM_CELL_PAYLOAD;
37412 }
37413
37414@@ -2071,7 +2071,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37415 if (iovb == NULL) {
37416 printk("nicstar%d: Out of iovec buffers.\n",
37417 card->index);
37418- atomic_inc(&vcc->stats->rx_drop);
37419+ atomic_inc_unchecked(&vcc->stats->rx_drop);
37420 recycle_rx_buf(card, skb);
37421 return;
37422 }
37423@@ -2095,7 +2095,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37424 small or large buffer itself. */
37425 } else if (NS_PRV_IOVCNT(iovb) >= NS_MAX_IOVECS) {
37426 printk("nicstar%d: received too big AAL5 SDU.\n", card->index);
37427- atomic_inc(&vcc->stats->rx_err);
37428+ atomic_inc_unchecked(&vcc->stats->rx_err);
37429 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
37430 NS_MAX_IOVECS);
37431 NS_PRV_IOVCNT(iovb) = 0;
37432@@ -2115,7 +2115,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37433 ("nicstar%d: Expected a small buffer, and this is not one.\n",
37434 card->index);
37435 which_list(card, skb);
37436- atomic_inc(&vcc->stats->rx_err);
37437+ atomic_inc_unchecked(&vcc->stats->rx_err);
37438 recycle_rx_buf(card, skb);
37439 vc->rx_iov = NULL;
37440 recycle_iov_buf(card, iovb);
37441@@ -2128,7 +2128,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37442 ("nicstar%d: Expected a large buffer, and this is not one.\n",
37443 card->index);
37444 which_list(card, skb);
37445- atomic_inc(&vcc->stats->rx_err);
37446+ atomic_inc_unchecked(&vcc->stats->rx_err);
37447 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
37448 NS_PRV_IOVCNT(iovb));
37449 vc->rx_iov = NULL;
37450@@ -2151,7 +2151,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37451 printk(" - PDU size mismatch.\n");
37452 else
37453 printk(".\n");
37454- atomic_inc(&vcc->stats->rx_err);
37455+ atomic_inc_unchecked(&vcc->stats->rx_err);
37456 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
37457 NS_PRV_IOVCNT(iovb));
37458 vc->rx_iov = NULL;
37459@@ -2165,7 +2165,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37460 /* skb points to a small buffer */
37461 if (!atm_charge(vcc, skb->truesize)) {
37462 push_rxbufs(card, skb);
37463- atomic_inc(&vcc->stats->rx_drop);
37464+ atomic_inc_unchecked(&vcc->stats->rx_drop);
37465 } else {
37466 skb_put(skb, len);
37467 dequeue_sm_buf(card, skb);
37468@@ -2175,7 +2175,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37469 ATM_SKB(skb)->vcc = vcc;
37470 __net_timestamp(skb);
37471 vcc->push(vcc, skb);
37472- atomic_inc(&vcc->stats->rx);
37473+ atomic_inc_unchecked(&vcc->stats->rx);
37474 }
37475 } else if (NS_PRV_IOVCNT(iovb) == 2) { /* One small plus one large buffer */
37476 struct sk_buff *sb;
37477@@ -2186,7 +2186,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37478 if (len <= NS_SMBUFSIZE) {
37479 if (!atm_charge(vcc, sb->truesize)) {
37480 push_rxbufs(card, sb);
37481- atomic_inc(&vcc->stats->rx_drop);
37482+ atomic_inc_unchecked(&vcc->stats->rx_drop);
37483 } else {
37484 skb_put(sb, len);
37485 dequeue_sm_buf(card, sb);
37486@@ -2196,7 +2196,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37487 ATM_SKB(sb)->vcc = vcc;
37488 __net_timestamp(sb);
37489 vcc->push(vcc, sb);
37490- atomic_inc(&vcc->stats->rx);
37491+ atomic_inc_unchecked(&vcc->stats->rx);
37492 }
37493
37494 push_rxbufs(card, skb);
37495@@ -2205,7 +2205,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37496
37497 if (!atm_charge(vcc, skb->truesize)) {
37498 push_rxbufs(card, skb);
37499- atomic_inc(&vcc->stats->rx_drop);
37500+ atomic_inc_unchecked(&vcc->stats->rx_drop);
37501 } else {
37502 dequeue_lg_buf(card, skb);
37503 #ifdef NS_USE_DESTRUCTORS
37504@@ -2218,7 +2218,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37505 ATM_SKB(skb)->vcc = vcc;
37506 __net_timestamp(skb);
37507 vcc->push(vcc, skb);
37508- atomic_inc(&vcc->stats->rx);
37509+ atomic_inc_unchecked(&vcc->stats->rx);
37510 }
37511
37512 push_rxbufs(card, sb);
37513@@ -2239,7 +2239,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37514 printk
37515 ("nicstar%d: Out of huge buffers.\n",
37516 card->index);
37517- atomic_inc(&vcc->stats->rx_drop);
37518+ atomic_inc_unchecked(&vcc->stats->rx_drop);
37519 recycle_iovec_rx_bufs(card,
37520 (struct iovec *)
37521 iovb->data,
37522@@ -2290,7 +2290,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37523 card->hbpool.count++;
37524 } else
37525 dev_kfree_skb_any(hb);
37526- atomic_inc(&vcc->stats->rx_drop);
37527+ atomic_inc_unchecked(&vcc->stats->rx_drop);
37528 } else {
37529 /* Copy the small buffer to the huge buffer */
37530 sb = (struct sk_buff *)iov->iov_base;
37531@@ -2327,7 +2327,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37532 #endif /* NS_USE_DESTRUCTORS */
37533 __net_timestamp(hb);
37534 vcc->push(vcc, hb);
37535- atomic_inc(&vcc->stats->rx);
37536+ atomic_inc_unchecked(&vcc->stats->rx);
37537 }
37538 }
37539
37540diff --git a/drivers/atm/solos-pci.c b/drivers/atm/solos-pci.c
37541index e3fb496..d9646bf 100644
37542--- a/drivers/atm/solos-pci.c
37543+++ b/drivers/atm/solos-pci.c
37544@@ -838,7 +838,7 @@ void solos_bh(unsigned long card_arg)
37545 }
37546 atm_charge(vcc, skb->truesize);
37547 vcc->push(vcc, skb);
37548- atomic_inc(&vcc->stats->rx);
37549+ atomic_inc_unchecked(&vcc->stats->rx);
37550 break;
37551
37552 case PKT_STATUS:
37553@@ -1116,7 +1116,7 @@ static uint32_t fpga_tx(struct solos_card *card)
37554 vcc = SKB_CB(oldskb)->vcc;
37555
37556 if (vcc) {
37557- atomic_inc(&vcc->stats->tx);
37558+ atomic_inc_unchecked(&vcc->stats->tx);
37559 solos_pop(vcc, oldskb);
37560 } else {
37561 dev_kfree_skb_irq(oldskb);
37562diff --git a/drivers/atm/suni.c b/drivers/atm/suni.c
37563index 0215934..ce9f5b1 100644
37564--- a/drivers/atm/suni.c
37565+++ b/drivers/atm/suni.c
37566@@ -49,8 +49,8 @@ static DEFINE_SPINLOCK(sunis_lock);
37567
37568
37569 #define ADD_LIMITED(s,v) \
37570- atomic_add((v),&stats->s); \
37571- if (atomic_read(&stats->s) < 0) atomic_set(&stats->s,INT_MAX);
37572+ atomic_add_unchecked((v),&stats->s); \
37573+ if (atomic_read_unchecked(&stats->s) < 0) atomic_set_unchecked(&stats->s,INT_MAX);
37574
37575
37576 static void suni_hz(unsigned long from_timer)
37577diff --git a/drivers/atm/uPD98402.c b/drivers/atm/uPD98402.c
37578index 5120a96..e2572bd 100644
37579--- a/drivers/atm/uPD98402.c
37580+++ b/drivers/atm/uPD98402.c
37581@@ -42,7 +42,7 @@ static int fetch_stats(struct atm_dev *dev,struct sonet_stats __user *arg,int ze
37582 struct sonet_stats tmp;
37583 int error = 0;
37584
37585- atomic_add(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
37586+ atomic_add_unchecked(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
37587 sonet_copy_stats(&PRIV(dev)->sonet_stats,&tmp);
37588 if (arg) error = copy_to_user(arg,&tmp,sizeof(tmp));
37589 if (zero && !error) {
37590@@ -161,9 +161,9 @@ static int uPD98402_ioctl(struct atm_dev *dev,unsigned int cmd,void __user *arg)
37591
37592
37593 #define ADD_LIMITED(s,v) \
37594- { atomic_add(GET(v),&PRIV(dev)->sonet_stats.s); \
37595- if (atomic_read(&PRIV(dev)->sonet_stats.s) < 0) \
37596- atomic_set(&PRIV(dev)->sonet_stats.s,INT_MAX); }
37597+ { atomic_add_unchecked(GET(v),&PRIV(dev)->sonet_stats.s); \
37598+ if (atomic_read_unchecked(&PRIV(dev)->sonet_stats.s) < 0) \
37599+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.s,INT_MAX); }
37600
37601
37602 static void stat_event(struct atm_dev *dev)
37603@@ -194,7 +194,7 @@ static void uPD98402_int(struct atm_dev *dev)
37604 if (reason & uPD98402_INT_PFM) stat_event(dev);
37605 if (reason & uPD98402_INT_PCO) {
37606 (void) GET(PCOCR); /* clear interrupt cause */
37607- atomic_add(GET(HECCT),
37608+ atomic_add_unchecked(GET(HECCT),
37609 &PRIV(dev)->sonet_stats.uncorr_hcs);
37610 }
37611 if ((reason & uPD98402_INT_RFO) &&
37612@@ -222,9 +222,9 @@ static int uPD98402_start(struct atm_dev *dev)
37613 PUT(~(uPD98402_INT_PFM | uPD98402_INT_ALM | uPD98402_INT_RFO |
37614 uPD98402_INT_LOS),PIMR); /* enable them */
37615 (void) fetch_stats(dev,NULL,1); /* clear kernel counters */
37616- atomic_set(&PRIV(dev)->sonet_stats.corr_hcs,-1);
37617- atomic_set(&PRIV(dev)->sonet_stats.tx_cells,-1);
37618- atomic_set(&PRIV(dev)->sonet_stats.rx_cells,-1);
37619+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.corr_hcs,-1);
37620+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.tx_cells,-1);
37621+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.rx_cells,-1);
37622 return 0;
37623 }
37624
37625diff --git a/drivers/atm/zatm.c b/drivers/atm/zatm.c
37626index 969c3c2..9b72956 100644
37627--- a/drivers/atm/zatm.c
37628+++ b/drivers/atm/zatm.c
37629@@ -459,7 +459,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
37630 }
37631 if (!size) {
37632 dev_kfree_skb_irq(skb);
37633- if (vcc) atomic_inc(&vcc->stats->rx_err);
37634+ if (vcc) atomic_inc_unchecked(&vcc->stats->rx_err);
37635 continue;
37636 }
37637 if (!atm_charge(vcc,skb->truesize)) {
37638@@ -469,7 +469,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
37639 skb->len = size;
37640 ATM_SKB(skb)->vcc = vcc;
37641 vcc->push(vcc,skb);
37642- atomic_inc(&vcc->stats->rx);
37643+ atomic_inc_unchecked(&vcc->stats->rx);
37644 }
37645 zout(pos & 0xffff,MTA(mbx));
37646 #if 0 /* probably a stupid idea */
37647@@ -733,7 +733,7 @@ if (*ZATM_PRV_DSC(skb) != (uPD98401_TXPD_V | uPD98401_TXPD_DP |
37648 skb_queue_head(&zatm_vcc->backlog,skb);
37649 break;
37650 }
37651- atomic_inc(&vcc->stats->tx);
37652+ atomic_inc_unchecked(&vcc->stats->tx);
37653 wake_up(&zatm_vcc->tx_wait);
37654 }
37655
37656diff --git a/drivers/base/bus.c b/drivers/base/bus.c
37657index 59dc808..f10c74e 100644
37658--- a/drivers/base/bus.c
37659+++ b/drivers/base/bus.c
37660@@ -1124,7 +1124,7 @@ int subsys_interface_register(struct subsys_interface *sif)
37661 return -EINVAL;
37662
37663 mutex_lock(&subsys->p->mutex);
37664- list_add_tail(&sif->node, &subsys->p->interfaces);
37665+ pax_list_add_tail((struct list_head *)&sif->node, &subsys->p->interfaces);
37666 if (sif->add_dev) {
37667 subsys_dev_iter_init(&iter, subsys, NULL, NULL);
37668 while ((dev = subsys_dev_iter_next(&iter)))
37669@@ -1149,7 +1149,7 @@ void subsys_interface_unregister(struct subsys_interface *sif)
37670 subsys = sif->subsys;
37671
37672 mutex_lock(&subsys->p->mutex);
37673- list_del_init(&sif->node);
37674+ pax_list_del_init((struct list_head *)&sif->node);
37675 if (sif->remove_dev) {
37676 subsys_dev_iter_init(&iter, subsys, NULL, NULL);
37677 while ((dev = subsys_dev_iter_next(&iter)))
37678diff --git a/drivers/base/devtmpfs.c b/drivers/base/devtmpfs.c
37679index 25798db..15f130e 100644
37680--- a/drivers/base/devtmpfs.c
37681+++ b/drivers/base/devtmpfs.c
37682@@ -354,7 +354,7 @@ int devtmpfs_mount(const char *mntdir)
37683 if (!thread)
37684 return 0;
37685
37686- err = sys_mount("devtmpfs", (char *)mntdir, "devtmpfs", MS_SILENT, NULL);
37687+ err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)mntdir, (char __force_user *)"devtmpfs", MS_SILENT, NULL);
37688 if (err)
37689 printk(KERN_INFO "devtmpfs: error mounting %i\n", err);
37690 else
37691@@ -380,11 +380,11 @@ static int devtmpfsd(void *p)
37692 *err = sys_unshare(CLONE_NEWNS);
37693 if (*err)
37694 goto out;
37695- *err = sys_mount("devtmpfs", "/", "devtmpfs", MS_SILENT, options);
37696+ *err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)"/", (char __force_user *)"devtmpfs", MS_SILENT, (char __force_user *)options);
37697 if (*err)
37698 goto out;
37699- sys_chdir("/.."); /* will traverse into overmounted root */
37700- sys_chroot(".");
37701+ sys_chdir((char __force_user *)"/.."); /* will traverse into overmounted root */
37702+ sys_chroot((char __force_user *)".");
37703 complete(&setup_done);
37704 while (1) {
37705 spin_lock(&req_lock);
37706diff --git a/drivers/base/node.c b/drivers/base/node.c
37707index bc9f43b..29703b8 100644
37708--- a/drivers/base/node.c
37709+++ b/drivers/base/node.c
37710@@ -620,7 +620,7 @@ static ssize_t print_nodes_state(enum node_states state, char *buf)
37711 struct node_attr {
37712 struct device_attribute attr;
37713 enum node_states state;
37714-};
37715+} __do_const;
37716
37717 static ssize_t show_node_state(struct device *dev,
37718 struct device_attribute *attr, char *buf)
37719diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c
37720index bfb8955..4ebff34 100644
37721--- a/drivers/base/power/domain.c
37722+++ b/drivers/base/power/domain.c
37723@@ -1809,9 +1809,9 @@ int __pm_genpd_remove_callbacks(struct device *dev, bool clear_td)
37724
37725 if (dev->power.subsys_data->domain_data) {
37726 gpd_data = to_gpd_data(dev->power.subsys_data->domain_data);
37727- gpd_data->ops = (struct gpd_dev_ops){ NULL };
37728+ memset(&gpd_data->ops, 0, sizeof(gpd_data->ops));
37729 if (clear_td)
37730- gpd_data->td = (struct gpd_timing_data){ 0 };
37731+ memset(&gpd_data->td, 0, sizeof(gpd_data->td));
37732
37733 if (--gpd_data->refcount == 0) {
37734 dev->power.subsys_data->domain_data = NULL;
37735@@ -1850,7 +1850,7 @@ int pm_genpd_attach_cpuidle(struct generic_pm_domain *genpd, int state)
37736 {
37737 struct cpuidle_driver *cpuidle_drv;
37738 struct gpd_cpu_data *cpu_data;
37739- struct cpuidle_state *idle_state;
37740+ cpuidle_state_no_const *idle_state;
37741 int ret = 0;
37742
37743 if (IS_ERR_OR_NULL(genpd) || state < 0)
37744@@ -1918,7 +1918,7 @@ int pm_genpd_name_attach_cpuidle(const char *name, int state)
37745 int pm_genpd_detach_cpuidle(struct generic_pm_domain *genpd)
37746 {
37747 struct gpd_cpu_data *cpu_data;
37748- struct cpuidle_state *idle_state;
37749+ cpuidle_state_no_const *idle_state;
37750 int ret = 0;
37751
37752 if (IS_ERR_OR_NULL(genpd))
37753diff --git a/drivers/base/power/sysfs.c b/drivers/base/power/sysfs.c
37754index 03e089a..0e9560c 100644
37755--- a/drivers/base/power/sysfs.c
37756+++ b/drivers/base/power/sysfs.c
37757@@ -185,7 +185,7 @@ static ssize_t rtpm_status_show(struct device *dev,
37758 return -EIO;
37759 }
37760 }
37761- return sprintf(buf, p);
37762+ return sprintf(buf, "%s", p);
37763 }
37764
37765 static DEVICE_ATTR(runtime_status, 0444, rtpm_status_show, NULL);
37766diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c
37767index 2d56f41..8830f19 100644
37768--- a/drivers/base/power/wakeup.c
37769+++ b/drivers/base/power/wakeup.c
37770@@ -29,14 +29,14 @@ bool events_check_enabled __read_mostly;
37771 * They need to be modified together atomically, so it's better to use one
37772 * atomic variable to hold them both.
37773 */
37774-static atomic_t combined_event_count = ATOMIC_INIT(0);
37775+static atomic_unchecked_t combined_event_count = ATOMIC_INIT(0);
37776
37777 #define IN_PROGRESS_BITS (sizeof(int) * 4)
37778 #define MAX_IN_PROGRESS ((1 << IN_PROGRESS_BITS) - 1)
37779
37780 static void split_counters(unsigned int *cnt, unsigned int *inpr)
37781 {
37782- unsigned int comb = atomic_read(&combined_event_count);
37783+ unsigned int comb = atomic_read_unchecked(&combined_event_count);
37784
37785 *cnt = (comb >> IN_PROGRESS_BITS);
37786 *inpr = comb & MAX_IN_PROGRESS;
37787@@ -395,7 +395,7 @@ static void wakeup_source_activate(struct wakeup_source *ws)
37788 ws->start_prevent_time = ws->last_time;
37789
37790 /* Increment the counter of events in progress. */
37791- cec = atomic_inc_return(&combined_event_count);
37792+ cec = atomic_inc_return_unchecked(&combined_event_count);
37793
37794 trace_wakeup_source_activate(ws->name, cec);
37795 }
37796@@ -521,7 +521,7 @@ static void wakeup_source_deactivate(struct wakeup_source *ws)
37797 * Increment the counter of registered wakeup events and decrement the
37798 * couter of wakeup events in progress simultaneously.
37799 */
37800- cec = atomic_add_return(MAX_IN_PROGRESS, &combined_event_count);
37801+ cec = atomic_add_return_unchecked(MAX_IN_PROGRESS, &combined_event_count);
37802 trace_wakeup_source_deactivate(ws->name, cec);
37803
37804 split_counters(&cnt, &inpr);
37805diff --git a/drivers/base/syscore.c b/drivers/base/syscore.c
37806index e8d11b6..7b1b36f 100644
37807--- a/drivers/base/syscore.c
37808+++ b/drivers/base/syscore.c
37809@@ -21,7 +21,7 @@ static DEFINE_MUTEX(syscore_ops_lock);
37810 void register_syscore_ops(struct syscore_ops *ops)
37811 {
37812 mutex_lock(&syscore_ops_lock);
37813- list_add_tail(&ops->node, &syscore_ops_list);
37814+ pax_list_add_tail((struct list_head *)&ops->node, &syscore_ops_list);
37815 mutex_unlock(&syscore_ops_lock);
37816 }
37817 EXPORT_SYMBOL_GPL(register_syscore_ops);
37818@@ -33,7 +33,7 @@ EXPORT_SYMBOL_GPL(register_syscore_ops);
37819 void unregister_syscore_ops(struct syscore_ops *ops)
37820 {
37821 mutex_lock(&syscore_ops_lock);
37822- list_del(&ops->node);
37823+ pax_list_del((struct list_head *)&ops->node);
37824 mutex_unlock(&syscore_ops_lock);
37825 }
37826 EXPORT_SYMBOL_GPL(unregister_syscore_ops);
37827diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c
37828index 036e8ab..6221dec 100644
37829--- a/drivers/block/cciss.c
37830+++ b/drivers/block/cciss.c
37831@@ -3011,7 +3011,7 @@ static void start_io(ctlr_info_t *h)
37832 while (!list_empty(&h->reqQ)) {
37833 c = list_entry(h->reqQ.next, CommandList_struct, list);
37834 /* can't do anything if fifo is full */
37835- if ((h->access.fifo_full(h))) {
37836+ if ((h->access->fifo_full(h))) {
37837 dev_warn(&h->pdev->dev, "fifo full\n");
37838 break;
37839 }
37840@@ -3021,7 +3021,7 @@ static void start_io(ctlr_info_t *h)
37841 h->Qdepth--;
37842
37843 /* Tell the controller execute command */
37844- h->access.submit_command(h, c);
37845+ h->access->submit_command(h, c);
37846
37847 /* Put job onto the completed Q */
37848 addQ(&h->cmpQ, c);
37849@@ -3447,17 +3447,17 @@ startio:
37850
37851 static inline unsigned long get_next_completion(ctlr_info_t *h)
37852 {
37853- return h->access.command_completed(h);
37854+ return h->access->command_completed(h);
37855 }
37856
37857 static inline int interrupt_pending(ctlr_info_t *h)
37858 {
37859- return h->access.intr_pending(h);
37860+ return h->access->intr_pending(h);
37861 }
37862
37863 static inline long interrupt_not_for_us(ctlr_info_t *h)
37864 {
37865- return ((h->access.intr_pending(h) == 0) ||
37866+ return ((h->access->intr_pending(h) == 0) ||
37867 (h->interrupts_enabled == 0));
37868 }
37869
37870@@ -3490,7 +3490,7 @@ static inline u32 next_command(ctlr_info_t *h)
37871 u32 a;
37872
37873 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
37874- return h->access.command_completed(h);
37875+ return h->access->command_completed(h);
37876
37877 if ((*(h->reply_pool_head) & 1) == (h->reply_pool_wraparound)) {
37878 a = *(h->reply_pool_head); /* Next cmd in ring buffer */
37879@@ -4047,7 +4047,7 @@ static void cciss_put_controller_into_performant_mode(ctlr_info_t *h)
37880 trans_support & CFGTBL_Trans_use_short_tags);
37881
37882 /* Change the access methods to the performant access methods */
37883- h->access = SA5_performant_access;
37884+ h->access = &SA5_performant_access;
37885 h->transMethod = CFGTBL_Trans_Performant;
37886
37887 return;
37888@@ -4327,7 +4327,7 @@ static int cciss_pci_init(ctlr_info_t *h)
37889 if (prod_index < 0)
37890 return -ENODEV;
37891 h->product_name = products[prod_index].product_name;
37892- h->access = *(products[prod_index].access);
37893+ h->access = products[prod_index].access;
37894
37895 if (cciss_board_disabled(h)) {
37896 dev_warn(&h->pdev->dev, "controller appears to be disabled\n");
37897@@ -5059,7 +5059,7 @@ reinit_after_soft_reset:
37898 }
37899
37900 /* make sure the board interrupts are off */
37901- h->access.set_intr_mask(h, CCISS_INTR_OFF);
37902+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
37903 rc = cciss_request_irq(h, do_cciss_msix_intr, do_cciss_intx);
37904 if (rc)
37905 goto clean2;
37906@@ -5109,7 +5109,7 @@ reinit_after_soft_reset:
37907 * fake ones to scoop up any residual completions.
37908 */
37909 spin_lock_irqsave(&h->lock, flags);
37910- h->access.set_intr_mask(h, CCISS_INTR_OFF);
37911+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
37912 spin_unlock_irqrestore(&h->lock, flags);
37913 free_irq(h->intr[h->intr_mode], h);
37914 rc = cciss_request_irq(h, cciss_msix_discard_completions,
37915@@ -5129,9 +5129,9 @@ reinit_after_soft_reset:
37916 dev_info(&h->pdev->dev, "Board READY.\n");
37917 dev_info(&h->pdev->dev,
37918 "Waiting for stale completions to drain.\n");
37919- h->access.set_intr_mask(h, CCISS_INTR_ON);
37920+ h->access->set_intr_mask(h, CCISS_INTR_ON);
37921 msleep(10000);
37922- h->access.set_intr_mask(h, CCISS_INTR_OFF);
37923+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
37924
37925 rc = controller_reset_failed(h->cfgtable);
37926 if (rc)
37927@@ -5154,7 +5154,7 @@ reinit_after_soft_reset:
37928 cciss_scsi_setup(h);
37929
37930 /* Turn the interrupts on so we can service requests */
37931- h->access.set_intr_mask(h, CCISS_INTR_ON);
37932+ h->access->set_intr_mask(h, CCISS_INTR_ON);
37933
37934 /* Get the firmware version */
37935 inq_buff = kzalloc(sizeof(InquiryData_struct), GFP_KERNEL);
37936@@ -5226,7 +5226,7 @@ static void cciss_shutdown(struct pci_dev *pdev)
37937 kfree(flush_buf);
37938 if (return_code != IO_OK)
37939 dev_warn(&h->pdev->dev, "Error flushing cache\n");
37940- h->access.set_intr_mask(h, CCISS_INTR_OFF);
37941+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
37942 free_irq(h->intr[h->intr_mode], h);
37943 }
37944
37945diff --git a/drivers/block/cciss.h b/drivers/block/cciss.h
37946index 7fda30e..2f27946 100644
37947--- a/drivers/block/cciss.h
37948+++ b/drivers/block/cciss.h
37949@@ -101,7 +101,7 @@ struct ctlr_info
37950 /* information about each logical volume */
37951 drive_info_struct *drv[CISS_MAX_LUN];
37952
37953- struct access_method access;
37954+ struct access_method *access;
37955
37956 /* queue and queue Info */
37957 struct list_head reqQ;
37958@@ -402,27 +402,27 @@ static bool SA5_performant_intr_pending(ctlr_info_t *h)
37959 }
37960
37961 static struct access_method SA5_access = {
37962- SA5_submit_command,
37963- SA5_intr_mask,
37964- SA5_fifo_full,
37965- SA5_intr_pending,
37966- SA5_completed,
37967+ .submit_command = SA5_submit_command,
37968+ .set_intr_mask = SA5_intr_mask,
37969+ .fifo_full = SA5_fifo_full,
37970+ .intr_pending = SA5_intr_pending,
37971+ .command_completed = SA5_completed,
37972 };
37973
37974 static struct access_method SA5B_access = {
37975- SA5_submit_command,
37976- SA5B_intr_mask,
37977- SA5_fifo_full,
37978- SA5B_intr_pending,
37979- SA5_completed,
37980+ .submit_command = SA5_submit_command,
37981+ .set_intr_mask = SA5B_intr_mask,
37982+ .fifo_full = SA5_fifo_full,
37983+ .intr_pending = SA5B_intr_pending,
37984+ .command_completed = SA5_completed,
37985 };
37986
37987 static struct access_method SA5_performant_access = {
37988- SA5_submit_command,
37989- SA5_performant_intr_mask,
37990- SA5_fifo_full,
37991- SA5_performant_intr_pending,
37992- SA5_performant_completed,
37993+ .submit_command = SA5_submit_command,
37994+ .set_intr_mask = SA5_performant_intr_mask,
37995+ .fifo_full = SA5_fifo_full,
37996+ .intr_pending = SA5_performant_intr_pending,
37997+ .command_completed = SA5_performant_completed,
37998 };
37999
38000 struct board_type {
38001diff --git a/drivers/block/cpqarray.c b/drivers/block/cpqarray.c
38002index 2b94403..fd6ad1f 100644
38003--- a/drivers/block/cpqarray.c
38004+++ b/drivers/block/cpqarray.c
38005@@ -404,7 +404,7 @@ static int cpqarray_register_ctlr(int i, struct pci_dev *pdev)
38006 if (register_blkdev(COMPAQ_SMART2_MAJOR+i, hba[i]->devname)) {
38007 goto Enomem4;
38008 }
38009- hba[i]->access.set_intr_mask(hba[i], 0);
38010+ hba[i]->access->set_intr_mask(hba[i], 0);
38011 if (request_irq(hba[i]->intr, do_ida_intr,
38012 IRQF_DISABLED|IRQF_SHARED, hba[i]->devname, hba[i]))
38013 {
38014@@ -459,7 +459,7 @@ static int cpqarray_register_ctlr(int i, struct pci_dev *pdev)
38015 add_timer(&hba[i]->timer);
38016
38017 /* Enable IRQ now that spinlock and rate limit timer are set up */
38018- hba[i]->access.set_intr_mask(hba[i], FIFO_NOT_EMPTY);
38019+ hba[i]->access->set_intr_mask(hba[i], FIFO_NOT_EMPTY);
38020
38021 for(j=0; j<NWD; j++) {
38022 struct gendisk *disk = ida_gendisk[i][j];
38023@@ -694,7 +694,7 @@ DBGINFO(
38024 for(i=0; i<NR_PRODUCTS; i++) {
38025 if (board_id == products[i].board_id) {
38026 c->product_name = products[i].product_name;
38027- c->access = *(products[i].access);
38028+ c->access = products[i].access;
38029 break;
38030 }
38031 }
38032@@ -792,7 +792,7 @@ static int cpqarray_eisa_detect(void)
38033 hba[ctlr]->intr = intr;
38034 sprintf(hba[ctlr]->devname, "ida%d", nr_ctlr);
38035 hba[ctlr]->product_name = products[j].product_name;
38036- hba[ctlr]->access = *(products[j].access);
38037+ hba[ctlr]->access = products[j].access;
38038 hba[ctlr]->ctlr = ctlr;
38039 hba[ctlr]->board_id = board_id;
38040 hba[ctlr]->pci_dev = NULL; /* not PCI */
38041@@ -978,7 +978,7 @@ static void start_io(ctlr_info_t *h)
38042
38043 while((c = h->reqQ) != NULL) {
38044 /* Can't do anything if we're busy */
38045- if (h->access.fifo_full(h) == 0)
38046+ if (h->access->fifo_full(h) == 0)
38047 return;
38048
38049 /* Get the first entry from the request Q */
38050@@ -986,7 +986,7 @@ static void start_io(ctlr_info_t *h)
38051 h->Qdepth--;
38052
38053 /* Tell the controller to do our bidding */
38054- h->access.submit_command(h, c);
38055+ h->access->submit_command(h, c);
38056
38057 /* Get onto the completion Q */
38058 addQ(&h->cmpQ, c);
38059@@ -1048,7 +1048,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
38060 unsigned long flags;
38061 __u32 a,a1;
38062
38063- istat = h->access.intr_pending(h);
38064+ istat = h->access->intr_pending(h);
38065 /* Is this interrupt for us? */
38066 if (istat == 0)
38067 return IRQ_NONE;
38068@@ -1059,7 +1059,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
38069 */
38070 spin_lock_irqsave(IDA_LOCK(h->ctlr), flags);
38071 if (istat & FIFO_NOT_EMPTY) {
38072- while((a = h->access.command_completed(h))) {
38073+ while((a = h->access->command_completed(h))) {
38074 a1 = a; a &= ~3;
38075 if ((c = h->cmpQ) == NULL)
38076 {
38077@@ -1448,11 +1448,11 @@ static int sendcmd(
38078 /*
38079 * Disable interrupt
38080 */
38081- info_p->access.set_intr_mask(info_p, 0);
38082+ info_p->access->set_intr_mask(info_p, 0);
38083 /* Make sure there is room in the command FIFO */
38084 /* Actually it should be completely empty at this time. */
38085 for (i = 200000; i > 0; i--) {
38086- temp = info_p->access.fifo_full(info_p);
38087+ temp = info_p->access->fifo_full(info_p);
38088 if (temp != 0) {
38089 break;
38090 }
38091@@ -1465,7 +1465,7 @@ DBG(
38092 /*
38093 * Send the cmd
38094 */
38095- info_p->access.submit_command(info_p, c);
38096+ info_p->access->submit_command(info_p, c);
38097 complete = pollcomplete(ctlr);
38098
38099 pci_unmap_single(info_p->pci_dev, (dma_addr_t) c->req.sg[0].addr,
38100@@ -1548,9 +1548,9 @@ static int revalidate_allvol(ctlr_info_t *host)
38101 * we check the new geometry. Then turn interrupts back on when
38102 * we're done.
38103 */
38104- host->access.set_intr_mask(host, 0);
38105+ host->access->set_intr_mask(host, 0);
38106 getgeometry(ctlr);
38107- host->access.set_intr_mask(host, FIFO_NOT_EMPTY);
38108+ host->access->set_intr_mask(host, FIFO_NOT_EMPTY);
38109
38110 for(i=0; i<NWD; i++) {
38111 struct gendisk *disk = ida_gendisk[ctlr][i];
38112@@ -1590,7 +1590,7 @@ static int pollcomplete(int ctlr)
38113 /* Wait (up to 2 seconds) for a command to complete */
38114
38115 for (i = 200000; i > 0; i--) {
38116- done = hba[ctlr]->access.command_completed(hba[ctlr]);
38117+ done = hba[ctlr]->access->command_completed(hba[ctlr]);
38118 if (done == 0) {
38119 udelay(10); /* a short fixed delay */
38120 } else
38121diff --git a/drivers/block/cpqarray.h b/drivers/block/cpqarray.h
38122index be73e9d..7fbf140 100644
38123--- a/drivers/block/cpqarray.h
38124+++ b/drivers/block/cpqarray.h
38125@@ -99,7 +99,7 @@ struct ctlr_info {
38126 drv_info_t drv[NWD];
38127 struct proc_dir_entry *proc;
38128
38129- struct access_method access;
38130+ struct access_method *access;
38131
38132 cmdlist_t *reqQ;
38133 cmdlist_t *cmpQ;
38134diff --git a/drivers/block/drbd/drbd_int.h b/drivers/block/drbd/drbd_int.h
38135index 0e06f0c..c47b81d 100644
38136--- a/drivers/block/drbd/drbd_int.h
38137+++ b/drivers/block/drbd/drbd_int.h
38138@@ -582,7 +582,7 @@ struct drbd_epoch {
38139 struct drbd_tconn *tconn;
38140 struct list_head list;
38141 unsigned int barrier_nr;
38142- atomic_t epoch_size; /* increased on every request added. */
38143+ atomic_unchecked_t epoch_size; /* increased on every request added. */
38144 atomic_t active; /* increased on every req. added, and dec on every finished. */
38145 unsigned long flags;
38146 };
38147@@ -1022,7 +1022,7 @@ struct drbd_conf {
38148 unsigned int al_tr_number;
38149 int al_tr_cycle;
38150 wait_queue_head_t seq_wait;
38151- atomic_t packet_seq;
38152+ atomic_unchecked_t packet_seq;
38153 unsigned int peer_seq;
38154 spinlock_t peer_seq_lock;
38155 unsigned int minor;
38156@@ -1573,7 +1573,7 @@ static inline int drbd_setsockopt(struct socket *sock, int level, int optname,
38157 char __user *uoptval;
38158 int err;
38159
38160- uoptval = (char __user __force *)optval;
38161+ uoptval = (char __force_user *)optval;
38162
38163 set_fs(KERNEL_DS);
38164 if (level == SOL_SOCKET)
38165diff --git a/drivers/block/drbd/drbd_interval.c b/drivers/block/drbd/drbd_interval.c
38166index 89c497c..9c736ae 100644
38167--- a/drivers/block/drbd/drbd_interval.c
38168+++ b/drivers/block/drbd/drbd_interval.c
38169@@ -67,9 +67,9 @@ static void augment_rotate(struct rb_node *rb_old, struct rb_node *rb_new)
38170 }
38171
38172 static const struct rb_augment_callbacks augment_callbacks = {
38173- augment_propagate,
38174- augment_copy,
38175- augment_rotate,
38176+ .propagate = augment_propagate,
38177+ .copy = augment_copy,
38178+ .rotate = augment_rotate,
38179 };
38180
38181 /**
38182diff --git a/drivers/block/drbd/drbd_main.c b/drivers/block/drbd/drbd_main.c
38183index 929468e..7d934eb 100644
38184--- a/drivers/block/drbd/drbd_main.c
38185+++ b/drivers/block/drbd/drbd_main.c
38186@@ -1317,7 +1317,7 @@ static int _drbd_send_ack(struct drbd_conf *mdev, enum drbd_packet cmd,
38187 p->sector = sector;
38188 p->block_id = block_id;
38189 p->blksize = blksize;
38190- p->seq_num = cpu_to_be32(atomic_inc_return(&mdev->packet_seq));
38191+ p->seq_num = cpu_to_be32(atomic_inc_return_unchecked(&mdev->packet_seq));
38192 return drbd_send_command(mdev, sock, cmd, sizeof(*p), NULL, 0);
38193 }
38194
38195@@ -1622,7 +1622,7 @@ int drbd_send_dblock(struct drbd_conf *mdev, struct drbd_request *req)
38196 return -EIO;
38197 p->sector = cpu_to_be64(req->i.sector);
38198 p->block_id = (unsigned long)req;
38199- p->seq_num = cpu_to_be32(atomic_inc_return(&mdev->packet_seq));
38200+ p->seq_num = cpu_to_be32(atomic_inc_return_unchecked(&mdev->packet_seq));
38201 dp_flags = bio_flags_to_wire(mdev, req->master_bio->bi_rw);
38202 if (mdev->state.conn >= C_SYNC_SOURCE &&
38203 mdev->state.conn <= C_PAUSED_SYNC_T)
38204@@ -2577,8 +2577,8 @@ void conn_destroy(struct kref *kref)
38205 {
38206 struct drbd_tconn *tconn = container_of(kref, struct drbd_tconn, kref);
38207
38208- if (atomic_read(&tconn->current_epoch->epoch_size) != 0)
38209- conn_err(tconn, "epoch_size:%d\n", atomic_read(&tconn->current_epoch->epoch_size));
38210+ if (atomic_read_unchecked(&tconn->current_epoch->epoch_size) != 0)
38211+ conn_err(tconn, "epoch_size:%d\n", atomic_read_unchecked(&tconn->current_epoch->epoch_size));
38212 kfree(tconn->current_epoch);
38213
38214 idr_destroy(&tconn->volumes);
38215diff --git a/drivers/block/drbd/drbd_nl.c b/drivers/block/drbd/drbd_nl.c
38216index c706d50..5e1b472 100644
38217--- a/drivers/block/drbd/drbd_nl.c
38218+++ b/drivers/block/drbd/drbd_nl.c
38219@@ -3440,7 +3440,7 @@ out:
38220
38221 void drbd_bcast_event(struct drbd_conf *mdev, const struct sib_info *sib)
38222 {
38223- static atomic_t drbd_genl_seq = ATOMIC_INIT(2); /* two. */
38224+ static atomic_unchecked_t drbd_genl_seq = ATOMIC_INIT(2); /* two. */
38225 struct sk_buff *msg;
38226 struct drbd_genlmsghdr *d_out;
38227 unsigned seq;
38228@@ -3453,7 +3453,7 @@ void drbd_bcast_event(struct drbd_conf *mdev, const struct sib_info *sib)
38229 return;
38230 }
38231
38232- seq = atomic_inc_return(&drbd_genl_seq);
38233+ seq = atomic_inc_return_unchecked(&drbd_genl_seq);
38234 msg = genlmsg_new(NLMSG_GOODSIZE, GFP_NOIO);
38235 if (!msg)
38236 goto failed;
38237diff --git a/drivers/block/drbd/drbd_receiver.c b/drivers/block/drbd/drbd_receiver.c
38238index d073305..4998fea 100644
38239--- a/drivers/block/drbd/drbd_receiver.c
38240+++ b/drivers/block/drbd/drbd_receiver.c
38241@@ -834,7 +834,7 @@ int drbd_connected(struct drbd_conf *mdev)
38242 {
38243 int err;
38244
38245- atomic_set(&mdev->packet_seq, 0);
38246+ atomic_set_unchecked(&mdev->packet_seq, 0);
38247 mdev->peer_seq = 0;
38248
38249 mdev->state_mutex = mdev->tconn->agreed_pro_version < 100 ?
38250@@ -1193,7 +1193,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_tconn *tconn,
38251 do {
38252 next_epoch = NULL;
38253
38254- epoch_size = atomic_read(&epoch->epoch_size);
38255+ epoch_size = atomic_read_unchecked(&epoch->epoch_size);
38256
38257 switch (ev & ~EV_CLEANUP) {
38258 case EV_PUT:
38259@@ -1233,7 +1233,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_tconn *tconn,
38260 rv = FE_DESTROYED;
38261 } else {
38262 epoch->flags = 0;
38263- atomic_set(&epoch->epoch_size, 0);
38264+ atomic_set_unchecked(&epoch->epoch_size, 0);
38265 /* atomic_set(&epoch->active, 0); is already zero */
38266 if (rv == FE_STILL_LIVE)
38267 rv = FE_RECYCLED;
38268@@ -1451,7 +1451,7 @@ static int receive_Barrier(struct drbd_tconn *tconn, struct packet_info *pi)
38269 conn_wait_active_ee_empty(tconn);
38270 drbd_flush(tconn);
38271
38272- if (atomic_read(&tconn->current_epoch->epoch_size)) {
38273+ if (atomic_read_unchecked(&tconn->current_epoch->epoch_size)) {
38274 epoch = kmalloc(sizeof(struct drbd_epoch), GFP_NOIO);
38275 if (epoch)
38276 break;
38277@@ -1464,11 +1464,11 @@ static int receive_Barrier(struct drbd_tconn *tconn, struct packet_info *pi)
38278 }
38279
38280 epoch->flags = 0;
38281- atomic_set(&epoch->epoch_size, 0);
38282+ atomic_set_unchecked(&epoch->epoch_size, 0);
38283 atomic_set(&epoch->active, 0);
38284
38285 spin_lock(&tconn->epoch_lock);
38286- if (atomic_read(&tconn->current_epoch->epoch_size)) {
38287+ if (atomic_read_unchecked(&tconn->current_epoch->epoch_size)) {
38288 list_add(&epoch->list, &tconn->current_epoch->list);
38289 tconn->current_epoch = epoch;
38290 tconn->epochs++;
38291@@ -2164,7 +2164,7 @@ static int receive_Data(struct drbd_tconn *tconn, struct packet_info *pi)
38292
38293 err = wait_for_and_update_peer_seq(mdev, peer_seq);
38294 drbd_send_ack_dp(mdev, P_NEG_ACK, p, pi->size);
38295- atomic_inc(&tconn->current_epoch->epoch_size);
38296+ atomic_inc_unchecked(&tconn->current_epoch->epoch_size);
38297 err2 = drbd_drain_block(mdev, pi->size);
38298 if (!err)
38299 err = err2;
38300@@ -2198,7 +2198,7 @@ static int receive_Data(struct drbd_tconn *tconn, struct packet_info *pi)
38301
38302 spin_lock(&tconn->epoch_lock);
38303 peer_req->epoch = tconn->current_epoch;
38304- atomic_inc(&peer_req->epoch->epoch_size);
38305+ atomic_inc_unchecked(&peer_req->epoch->epoch_size);
38306 atomic_inc(&peer_req->epoch->active);
38307 spin_unlock(&tconn->epoch_lock);
38308
38309@@ -4345,7 +4345,7 @@ struct data_cmd {
38310 int expect_payload;
38311 size_t pkt_size;
38312 int (*fn)(struct drbd_tconn *, struct packet_info *);
38313-};
38314+} __do_const;
38315
38316 static struct data_cmd drbd_cmd_handler[] = {
38317 [P_DATA] = { 1, sizeof(struct p_data), receive_Data },
38318@@ -4465,7 +4465,7 @@ static void conn_disconnect(struct drbd_tconn *tconn)
38319 if (!list_empty(&tconn->current_epoch->list))
38320 conn_err(tconn, "ASSERTION FAILED: tconn->current_epoch->list not empty\n");
38321 /* ok, no more ee's on the fly, it is safe to reset the epoch_size */
38322- atomic_set(&tconn->current_epoch->epoch_size, 0);
38323+ atomic_set_unchecked(&tconn->current_epoch->epoch_size, 0);
38324 tconn->send.seen_any_write_yet = false;
38325
38326 conn_info(tconn, "Connection closed\n");
38327@@ -5221,7 +5221,7 @@ static int tconn_finish_peer_reqs(struct drbd_tconn *tconn)
38328 struct asender_cmd {
38329 size_t pkt_size;
38330 int (*fn)(struct drbd_tconn *tconn, struct packet_info *);
38331-};
38332+} __do_const;
38333
38334 static struct asender_cmd asender_tbl[] = {
38335 [P_PING] = { 0, got_Ping },
38336diff --git a/drivers/block/loop.c b/drivers/block/loop.c
38337index 66e8c3b..9b68dd9 100644
38338--- a/drivers/block/loop.c
38339+++ b/drivers/block/loop.c
38340@@ -232,7 +232,7 @@ static int __do_lo_send_write(struct file *file,
38341
38342 file_start_write(file);
38343 set_fs(get_ds());
38344- bw = file->f_op->write(file, buf, len, &pos);
38345+ bw = file->f_op->write(file, (const char __force_user *)buf, len, &pos);
38346 set_fs(old_fs);
38347 file_end_write(file);
38348 if (likely(bw == len))
38349diff --git a/drivers/block/null_blk.c b/drivers/block/null_blk.c
38350index 091b9ea..f5428f8 100644
38351--- a/drivers/block/null_blk.c
38352+++ b/drivers/block/null_blk.c
38353@@ -382,15 +382,25 @@ static int null_init_hctx(struct blk_mq_hw_ctx *hctx, void *data,
38354 return 0;
38355 }
38356
38357-static struct blk_mq_ops null_mq_ops = {
38358- .queue_rq = null_queue_rq,
38359- .map_queue = blk_mq_map_queue,
38360+static struct blk_mq_ops null_mq_single_ops = {
38361+ .queue_rq = null_queue_rq,
38362+ .map_queue = blk_mq_map_queue,
38363 .init_hctx = null_init_hctx,
38364 .complete = null_softirq_done_fn,
38365+ .alloc_hctx = blk_mq_alloc_single_hw_queue,
38366+ .free_hctx = blk_mq_free_single_hw_queue,
38367+};
38368+
38369+static struct blk_mq_ops null_mq_per_node_ops = {
38370+ .queue_rq = null_queue_rq,
38371+ .map_queue = blk_mq_map_queue,
38372+ .init_hctx = null_init_hctx,
38373+ .alloc_hctx = null_alloc_hctx,
38374+ .free_hctx = null_free_hctx,
38375 };
38376
38377 static struct blk_mq_reg null_mq_reg = {
38378- .ops = &null_mq_ops,
38379+ .ops = &null_mq_single_ops,
38380 .queue_depth = 64,
38381 .cmd_size = sizeof(struct nullb_cmd),
38382 .flags = BLK_MQ_F_SHOULD_MERGE,
38383@@ -521,13 +531,8 @@ static int null_add_dev(void)
38384 null_mq_reg.queue_depth = hw_queue_depth;
38385 null_mq_reg.nr_hw_queues = submit_queues;
38386
38387- if (use_per_node_hctx) {
38388- null_mq_reg.ops->alloc_hctx = null_alloc_hctx;
38389- null_mq_reg.ops->free_hctx = null_free_hctx;
38390- } else {
38391- null_mq_reg.ops->alloc_hctx = blk_mq_alloc_single_hw_queue;
38392- null_mq_reg.ops->free_hctx = blk_mq_free_single_hw_queue;
38393- }
38394+ if (use_per_node_hctx)
38395+ null_mq_reg.ops = &null_mq_per_node_ops;
38396
38397 nullb->q = blk_mq_init_queue(&null_mq_reg, nullb);
38398 } else if (queue_mode == NULL_Q_BIO) {
38399diff --git a/drivers/block/pktcdvd.c b/drivers/block/pktcdvd.c
38400index a2af73d..c0b8f61 100644
38401--- a/drivers/block/pktcdvd.c
38402+++ b/drivers/block/pktcdvd.c
38403@@ -108,7 +108,7 @@ static int pkt_seq_show(struct seq_file *m, void *p);
38404
38405 static sector_t get_zone(sector_t sector, struct pktcdvd_device *pd)
38406 {
38407- return (sector + pd->offset) & ~(sector_t)(pd->settings.size - 1);
38408+ return (sector + pd->offset) & ~(sector_t)(pd->settings.size - 1UL);
38409 }
38410
38411 /*
38412@@ -1888,7 +1888,7 @@ static noinline_for_stack int pkt_probe_settings(struct pktcdvd_device *pd)
38413 return -EROFS;
38414 }
38415 pd->settings.fp = ti.fp;
38416- pd->offset = (be32_to_cpu(ti.track_start) << 2) & (pd->settings.size - 1);
38417+ pd->offset = (be32_to_cpu(ti.track_start) << 2) & (pd->settings.size - 1UL);
38418
38419 if (ti.nwa_v) {
38420 pd->nwa = be32_to_cpu(ti.next_writable);
38421diff --git a/drivers/block/smart1,2.h b/drivers/block/smart1,2.h
38422index e5565fb..71be10b4 100644
38423--- a/drivers/block/smart1,2.h
38424+++ b/drivers/block/smart1,2.h
38425@@ -108,11 +108,11 @@ static unsigned long smart4_intr_pending(ctlr_info_t *h)
38426 }
38427
38428 static struct access_method smart4_access = {
38429- smart4_submit_command,
38430- smart4_intr_mask,
38431- smart4_fifo_full,
38432- smart4_intr_pending,
38433- smart4_completed,
38434+ .submit_command = smart4_submit_command,
38435+ .set_intr_mask = smart4_intr_mask,
38436+ .fifo_full = smart4_fifo_full,
38437+ .intr_pending = smart4_intr_pending,
38438+ .command_completed = smart4_completed,
38439 };
38440
38441 /*
38442@@ -144,11 +144,11 @@ static unsigned long smart2_intr_pending(ctlr_info_t *h)
38443 }
38444
38445 static struct access_method smart2_access = {
38446- smart2_submit_command,
38447- smart2_intr_mask,
38448- smart2_fifo_full,
38449- smart2_intr_pending,
38450- smart2_completed,
38451+ .submit_command = smart2_submit_command,
38452+ .set_intr_mask = smart2_intr_mask,
38453+ .fifo_full = smart2_fifo_full,
38454+ .intr_pending = smart2_intr_pending,
38455+ .command_completed = smart2_completed,
38456 };
38457
38458 /*
38459@@ -180,11 +180,11 @@ static unsigned long smart2e_intr_pending(ctlr_info_t *h)
38460 }
38461
38462 static struct access_method smart2e_access = {
38463- smart2e_submit_command,
38464- smart2e_intr_mask,
38465- smart2e_fifo_full,
38466- smart2e_intr_pending,
38467- smart2e_completed,
38468+ .submit_command = smart2e_submit_command,
38469+ .set_intr_mask = smart2e_intr_mask,
38470+ .fifo_full = smart2e_fifo_full,
38471+ .intr_pending = smart2e_intr_pending,
38472+ .command_completed = smart2e_completed,
38473 };
38474
38475 /*
38476@@ -270,9 +270,9 @@ static unsigned long smart1_intr_pending(ctlr_info_t *h)
38477 }
38478
38479 static struct access_method smart1_access = {
38480- smart1_submit_command,
38481- smart1_intr_mask,
38482- smart1_fifo_full,
38483- smart1_intr_pending,
38484- smart1_completed,
38485+ .submit_command = smart1_submit_command,
38486+ .set_intr_mask = smart1_intr_mask,
38487+ .fifo_full = smart1_fifo_full,
38488+ .intr_pending = smart1_intr_pending,
38489+ .command_completed = smart1_completed,
38490 };
38491diff --git a/drivers/bluetooth/btwilink.c b/drivers/bluetooth/btwilink.c
38492index f038dba..bb74c08 100644
38493--- a/drivers/bluetooth/btwilink.c
38494+++ b/drivers/bluetooth/btwilink.c
38495@@ -288,7 +288,7 @@ static int ti_st_send_frame(struct hci_dev *hdev, struct sk_buff *skb)
38496
38497 static int bt_ti_probe(struct platform_device *pdev)
38498 {
38499- static struct ti_st *hst;
38500+ struct ti_st *hst;
38501 struct hci_dev *hdev;
38502 int err;
38503
38504diff --git a/drivers/cdrom/cdrom.c b/drivers/cdrom/cdrom.c
38505index 8a3aff7..d7538c2 100644
38506--- a/drivers/cdrom/cdrom.c
38507+++ b/drivers/cdrom/cdrom.c
38508@@ -416,7 +416,6 @@ int register_cdrom(struct cdrom_device_info *cdi)
38509 ENSURE(reset, CDC_RESET);
38510 ENSURE(generic_packet, CDC_GENERIC_PACKET);
38511 cdi->mc_flags = 0;
38512- cdo->n_minors = 0;
38513 cdi->options = CDO_USE_FFLAGS;
38514
38515 if (autoclose==1 && CDROM_CAN(CDC_CLOSE_TRAY))
38516@@ -436,8 +435,11 @@ int register_cdrom(struct cdrom_device_info *cdi)
38517 else
38518 cdi->cdda_method = CDDA_OLD;
38519
38520- if (!cdo->generic_packet)
38521- cdo->generic_packet = cdrom_dummy_generic_packet;
38522+ if (!cdo->generic_packet) {
38523+ pax_open_kernel();
38524+ *(void **)&cdo->generic_packet = cdrom_dummy_generic_packet;
38525+ pax_close_kernel();
38526+ }
38527
38528 cdinfo(CD_REG_UNREG, "drive \"/dev/%s\" registered\n", cdi->name);
38529 mutex_lock(&cdrom_mutex);
38530@@ -458,7 +460,6 @@ void unregister_cdrom(struct cdrom_device_info *cdi)
38531 if (cdi->exit)
38532 cdi->exit(cdi);
38533
38534- cdi->ops->n_minors--;
38535 cdinfo(CD_REG_UNREG, "drive \"/dev/%s\" unregistered\n", cdi->name);
38536 }
38537
38538@@ -2107,7 +2108,7 @@ static int cdrom_read_cdda_old(struct cdrom_device_info *cdi, __u8 __user *ubuf,
38539 */
38540 nr = nframes;
38541 do {
38542- cgc.buffer = kmalloc(CD_FRAMESIZE_RAW * nr, GFP_KERNEL);
38543+ cgc.buffer = kzalloc(CD_FRAMESIZE_RAW * nr, GFP_KERNEL);
38544 if (cgc.buffer)
38545 break;
38546
38547@@ -3429,7 +3430,7 @@ static int cdrom_print_info(const char *header, int val, char *info,
38548 struct cdrom_device_info *cdi;
38549 int ret;
38550
38551- ret = scnprintf(info + *pos, max_size - *pos, header);
38552+ ret = scnprintf(info + *pos, max_size - *pos, "%s", header);
38553 if (!ret)
38554 return 1;
38555
38556diff --git a/drivers/cdrom/gdrom.c b/drivers/cdrom/gdrom.c
38557index 51e75ad..39c4c76 100644
38558--- a/drivers/cdrom/gdrom.c
38559+++ b/drivers/cdrom/gdrom.c
38560@@ -491,7 +491,6 @@ static struct cdrom_device_ops gdrom_ops = {
38561 .audio_ioctl = gdrom_audio_ioctl,
38562 .capability = CDC_MULTI_SESSION | CDC_MEDIA_CHANGED |
38563 CDC_RESET | CDC_DRIVE_STATUS | CDC_CD_R,
38564- .n_minors = 1,
38565 };
38566
38567 static int gdrom_bdops_open(struct block_device *bdev, fmode_t mode)
38568diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
38569index 1386749..5430258 100644
38570--- a/drivers/char/Kconfig
38571+++ b/drivers/char/Kconfig
38572@@ -8,7 +8,8 @@ source "drivers/tty/Kconfig"
38573
38574 config DEVKMEM
38575 bool "/dev/kmem virtual device support"
38576- default y
38577+ default n
38578+ depends on !GRKERNSEC_KMEM
38579 help
38580 Say Y here if you want to support the /dev/kmem device. The
38581 /dev/kmem device is rarely used, but can be used for certain
38582@@ -577,6 +578,7 @@ config DEVPORT
38583 bool
38584 depends on !M68K
38585 depends on ISA || PCI
38586+ depends on !GRKERNSEC_KMEM
38587 default y
38588
38589 source "drivers/s390/char/Kconfig"
38590diff --git a/drivers/char/agp/compat_ioctl.c b/drivers/char/agp/compat_ioctl.c
38591index a48e05b..6bac831 100644
38592--- a/drivers/char/agp/compat_ioctl.c
38593+++ b/drivers/char/agp/compat_ioctl.c
38594@@ -108,7 +108,7 @@ static int compat_agpioc_reserve_wrap(struct agp_file_private *priv, void __user
38595 return -ENOMEM;
38596 }
38597
38598- if (copy_from_user(usegment, (void __user *) ureserve.seg_list,
38599+ if (copy_from_user(usegment, (void __force_user *) ureserve.seg_list,
38600 sizeof(*usegment) * ureserve.seg_count)) {
38601 kfree(usegment);
38602 kfree(ksegment);
38603diff --git a/drivers/char/agp/frontend.c b/drivers/char/agp/frontend.c
38604index 1b19239..963967b 100644
38605--- a/drivers/char/agp/frontend.c
38606+++ b/drivers/char/agp/frontend.c
38607@@ -731,6 +731,7 @@ static int agpioc_info_wrap(struct agp_file_private *priv, void __user *arg)
38608
38609 agp_copy_info(agp_bridge, &kerninfo);
38610
38611+ memset(&userinfo, 0, sizeof(userinfo));
38612 userinfo.version.major = kerninfo.version.major;
38613 userinfo.version.minor = kerninfo.version.minor;
38614 userinfo.bridge_id = kerninfo.device->vendor |
38615@@ -819,7 +820,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
38616 if (copy_from_user(&reserve, arg, sizeof(struct agp_region)))
38617 return -EFAULT;
38618
38619- if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment))
38620+ if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment_priv))
38621 return -EFAULT;
38622
38623 client = agp_find_client_by_pid(reserve.pid);
38624@@ -849,7 +850,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
38625 if (segment == NULL)
38626 return -ENOMEM;
38627
38628- if (copy_from_user(segment, (void __user *) reserve.seg_list,
38629+ if (copy_from_user(segment, (void __force_user *) reserve.seg_list,
38630 sizeof(struct agp_segment) * reserve.seg_count)) {
38631 kfree(segment);
38632 return -EFAULT;
38633diff --git a/drivers/char/genrtc.c b/drivers/char/genrtc.c
38634index 4f94375..413694e 100644
38635--- a/drivers/char/genrtc.c
38636+++ b/drivers/char/genrtc.c
38637@@ -273,6 +273,7 @@ static int gen_rtc_ioctl(struct file *file,
38638 switch (cmd) {
38639
38640 case RTC_PLL_GET:
38641+ memset(&pll, 0, sizeof(pll));
38642 if (get_rtc_pll(&pll))
38643 return -EINVAL;
38644 else
38645diff --git a/drivers/char/hpet.c b/drivers/char/hpet.c
38646index d5d4cd8..22d561d 100644
38647--- a/drivers/char/hpet.c
38648+++ b/drivers/char/hpet.c
38649@@ -575,7 +575,7 @@ static inline unsigned long hpet_time_div(struct hpets *hpets,
38650 }
38651
38652 static int
38653-hpet_ioctl_common(struct hpet_dev *devp, int cmd, unsigned long arg,
38654+hpet_ioctl_common(struct hpet_dev *devp, unsigned int cmd, unsigned long arg,
38655 struct hpet_info *info)
38656 {
38657 struct hpet_timer __iomem *timer;
38658diff --git a/drivers/char/hw_random/intel-rng.c b/drivers/char/hw_random/intel-rng.c
38659index 86fe45c..c0ea948 100644
38660--- a/drivers/char/hw_random/intel-rng.c
38661+++ b/drivers/char/hw_random/intel-rng.c
38662@@ -314,7 +314,7 @@ PFX "RNG, try using the 'no_fwh_detect' option.\n";
38663
38664 if (no_fwh_detect)
38665 return -ENODEV;
38666- printk(warning);
38667+ printk("%s", warning);
38668 return -EBUSY;
38669 }
38670
38671diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
38672index ec4e10f..f2a763b 100644
38673--- a/drivers/char/ipmi/ipmi_msghandler.c
38674+++ b/drivers/char/ipmi/ipmi_msghandler.c
38675@@ -420,7 +420,7 @@ struct ipmi_smi {
38676 struct proc_dir_entry *proc_dir;
38677 char proc_dir_name[10];
38678
38679- atomic_t stats[IPMI_NUM_STATS];
38680+ atomic_unchecked_t stats[IPMI_NUM_STATS];
38681
38682 /*
38683 * run_to_completion duplicate of smb_info, smi_info
38684@@ -453,9 +453,9 @@ static DEFINE_MUTEX(smi_watchers_mutex);
38685
38686
38687 #define ipmi_inc_stat(intf, stat) \
38688- atomic_inc(&(intf)->stats[IPMI_STAT_ ## stat])
38689+ atomic_inc_unchecked(&(intf)->stats[IPMI_STAT_ ## stat])
38690 #define ipmi_get_stat(intf, stat) \
38691- ((unsigned int) atomic_read(&(intf)->stats[IPMI_STAT_ ## stat]))
38692+ ((unsigned int) atomic_read_unchecked(&(intf)->stats[IPMI_STAT_ ## stat]))
38693
38694 static int is_lan_addr(struct ipmi_addr *addr)
38695 {
38696@@ -2883,7 +2883,7 @@ int ipmi_register_smi(struct ipmi_smi_handlers *handlers,
38697 INIT_LIST_HEAD(&intf->cmd_rcvrs);
38698 init_waitqueue_head(&intf->waitq);
38699 for (i = 0; i < IPMI_NUM_STATS; i++)
38700- atomic_set(&intf->stats[i], 0);
38701+ atomic_set_unchecked(&intf->stats[i], 0);
38702
38703 intf->proc_dir = NULL;
38704
38705diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c
38706index 03f4189..e79f5e0 100644
38707--- a/drivers/char/ipmi/ipmi_si_intf.c
38708+++ b/drivers/char/ipmi/ipmi_si_intf.c
38709@@ -280,7 +280,7 @@ struct smi_info {
38710 unsigned char slave_addr;
38711
38712 /* Counters and things for the proc filesystem. */
38713- atomic_t stats[SI_NUM_STATS];
38714+ atomic_unchecked_t stats[SI_NUM_STATS];
38715
38716 struct task_struct *thread;
38717
38718@@ -289,9 +289,9 @@ struct smi_info {
38719 };
38720
38721 #define smi_inc_stat(smi, stat) \
38722- atomic_inc(&(smi)->stats[SI_STAT_ ## stat])
38723+ atomic_inc_unchecked(&(smi)->stats[SI_STAT_ ## stat])
38724 #define smi_get_stat(smi, stat) \
38725- ((unsigned int) atomic_read(&(smi)->stats[SI_STAT_ ## stat]))
38726+ ((unsigned int) atomic_read_unchecked(&(smi)->stats[SI_STAT_ ## stat]))
38727
38728 #define SI_MAX_PARMS 4
38729
38730@@ -3339,7 +3339,7 @@ static int try_smi_init(struct smi_info *new_smi)
38731 atomic_set(&new_smi->req_events, 0);
38732 new_smi->run_to_completion = 0;
38733 for (i = 0; i < SI_NUM_STATS; i++)
38734- atomic_set(&new_smi->stats[i], 0);
38735+ atomic_set_unchecked(&new_smi->stats[i], 0);
38736
38737 new_smi->interrupt_disabled = 1;
38738 atomic_set(&new_smi->stop_operation, 0);
38739diff --git a/drivers/char/mem.c b/drivers/char/mem.c
38740index 92c5937..1be4e4d 100644
38741--- a/drivers/char/mem.c
38742+++ b/drivers/char/mem.c
38743@@ -18,6 +18,7 @@
38744 #include <linux/raw.h>
38745 #include <linux/tty.h>
38746 #include <linux/capability.h>
38747+#include <linux/security.h>
38748 #include <linux/ptrace.h>
38749 #include <linux/device.h>
38750 #include <linux/highmem.h>
38751@@ -36,6 +37,10 @@
38752
38753 #define DEVPORT_MINOR 4
38754
38755+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
38756+extern const struct file_operations grsec_fops;
38757+#endif
38758+
38759 static inline unsigned long size_inside_page(unsigned long start,
38760 unsigned long size)
38761 {
38762@@ -67,9 +72,13 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
38763
38764 while (cursor < to) {
38765 if (!devmem_is_allowed(pfn)) {
38766+#ifdef CONFIG_GRKERNSEC_KMEM
38767+ gr_handle_mem_readwrite(from, to);
38768+#else
38769 printk(KERN_INFO
38770 "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
38771 current->comm, from, to);
38772+#endif
38773 return 0;
38774 }
38775 cursor += PAGE_SIZE;
38776@@ -77,6 +86,11 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
38777 }
38778 return 1;
38779 }
38780+#elif defined(CONFIG_GRKERNSEC_KMEM)
38781+static inline int range_is_allowed(unsigned long pfn, unsigned long size)
38782+{
38783+ return 0;
38784+}
38785 #else
38786 static inline int range_is_allowed(unsigned long pfn, unsigned long size)
38787 {
38788@@ -119,6 +133,7 @@ static ssize_t read_mem(struct file *file, char __user *buf,
38789
38790 while (count > 0) {
38791 unsigned long remaining;
38792+ char *temp;
38793
38794 sz = size_inside_page(p, count);
38795
38796@@ -134,7 +149,23 @@ static ssize_t read_mem(struct file *file, char __user *buf,
38797 if (!ptr)
38798 return -EFAULT;
38799
38800- remaining = copy_to_user(buf, ptr, sz);
38801+#ifdef CONFIG_PAX_USERCOPY
38802+ temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
38803+ if (!temp) {
38804+ unxlate_dev_mem_ptr(p, ptr);
38805+ return -ENOMEM;
38806+ }
38807+ memcpy(temp, ptr, sz);
38808+#else
38809+ temp = ptr;
38810+#endif
38811+
38812+ remaining = copy_to_user(buf, temp, sz);
38813+
38814+#ifdef CONFIG_PAX_USERCOPY
38815+ kfree(temp);
38816+#endif
38817+
38818 unxlate_dev_mem_ptr(p, ptr);
38819 if (remaining)
38820 return -EFAULT;
38821@@ -363,9 +394,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
38822 size_t count, loff_t *ppos)
38823 {
38824 unsigned long p = *ppos;
38825- ssize_t low_count, read, sz;
38826+ ssize_t low_count, read, sz, err = 0;
38827 char *kbuf; /* k-addr because vread() takes vmlist_lock rwlock */
38828- int err = 0;
38829
38830 read = 0;
38831 if (p < (unsigned long) high_memory) {
38832@@ -387,6 +417,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
38833 }
38834 #endif
38835 while (low_count > 0) {
38836+ char *temp;
38837+
38838 sz = size_inside_page(p, low_count);
38839
38840 /*
38841@@ -396,7 +428,22 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
38842 */
38843 kbuf = xlate_dev_kmem_ptr((char *)p);
38844
38845- if (copy_to_user(buf, kbuf, sz))
38846+#ifdef CONFIG_PAX_USERCOPY
38847+ temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
38848+ if (!temp)
38849+ return -ENOMEM;
38850+ memcpy(temp, kbuf, sz);
38851+#else
38852+ temp = kbuf;
38853+#endif
38854+
38855+ err = copy_to_user(buf, temp, sz);
38856+
38857+#ifdef CONFIG_PAX_USERCOPY
38858+ kfree(temp);
38859+#endif
38860+
38861+ if (err)
38862 return -EFAULT;
38863 buf += sz;
38864 p += sz;
38865@@ -821,6 +868,9 @@ static const struct memdev {
38866 #ifdef CONFIG_PRINTK
38867 [11] = { "kmsg", 0644, &kmsg_fops, NULL },
38868 #endif
38869+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
38870+ [13] = { "grsec",S_IRUSR | S_IWUGO, &grsec_fops, NULL },
38871+#endif
38872 };
38873
38874 static int memory_open(struct inode *inode, struct file *filp)
38875@@ -892,7 +942,7 @@ static int __init chr_dev_init(void)
38876 continue;
38877
38878 device_create(mem_class, NULL, MKDEV(MEM_MAJOR, minor),
38879- NULL, devlist[minor].name);
38880+ NULL, "%s", devlist[minor].name);
38881 }
38882
38883 return tty_init();
38884diff --git a/drivers/char/nvram.c b/drivers/char/nvram.c
38885index 9df78e2..01ba9ae 100644
38886--- a/drivers/char/nvram.c
38887+++ b/drivers/char/nvram.c
38888@@ -247,7 +247,7 @@ static ssize_t nvram_read(struct file *file, char __user *buf,
38889
38890 spin_unlock_irq(&rtc_lock);
38891
38892- if (copy_to_user(buf, contents, tmp - contents))
38893+ if (tmp - contents > sizeof(contents) || copy_to_user(buf, contents, tmp - contents))
38894 return -EFAULT;
38895
38896 *ppos = i;
38897diff --git a/drivers/char/pcmcia/synclink_cs.c b/drivers/char/pcmcia/synclink_cs.c
38898index 8320abd..ec48108 100644
38899--- a/drivers/char/pcmcia/synclink_cs.c
38900+++ b/drivers/char/pcmcia/synclink_cs.c
38901@@ -2345,9 +2345,9 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
38902
38903 if (debug_level >= DEBUG_LEVEL_INFO)
38904 printk("%s(%d):mgslpc_close(%s) entry, count=%d\n",
38905- __FILE__, __LINE__, info->device_name, port->count);
38906+ __FILE__, __LINE__, info->device_name, atomic_read(&port->count));
38907
38908- WARN_ON(!port->count);
38909+ WARN_ON(!atomic_read(&port->count));
38910
38911 if (tty_port_close_start(port, tty, filp) == 0)
38912 goto cleanup;
38913@@ -2365,7 +2365,7 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
38914 cleanup:
38915 if (debug_level >= DEBUG_LEVEL_INFO)
38916 printk("%s(%d):mgslpc_close(%s) exit, count=%d\n", __FILE__, __LINE__,
38917- tty->driver->name, port->count);
38918+ tty->driver->name, atomic_read(&port->count));
38919 }
38920
38921 /* Wait until the transmitter is empty.
38922@@ -2507,7 +2507,7 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
38923
38924 if (debug_level >= DEBUG_LEVEL_INFO)
38925 printk("%s(%d):mgslpc_open(%s), old ref count = %d\n",
38926- __FILE__, __LINE__, tty->driver->name, port->count);
38927+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
38928
38929 /* If port is closing, signal caller to try again */
38930 if (tty_hung_up_p(filp) || port->flags & ASYNC_CLOSING){
38931@@ -2527,11 +2527,11 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
38932 goto cleanup;
38933 }
38934 spin_lock(&port->lock);
38935- port->count++;
38936+ atomic_inc(&port->count);
38937 spin_unlock(&port->lock);
38938 spin_unlock_irqrestore(&info->netlock, flags);
38939
38940- if (port->count == 1) {
38941+ if (atomic_read(&port->count) == 1) {
38942 /* 1st open on this device, init hardware */
38943 retval = startup(info, tty);
38944 if (retval < 0)
38945@@ -3920,7 +3920,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
38946 unsigned short new_crctype;
38947
38948 /* return error if TTY interface open */
38949- if (info->port.count)
38950+ if (atomic_read(&info->port.count))
38951 return -EBUSY;
38952
38953 switch (encoding)
38954@@ -4024,7 +4024,7 @@ static int hdlcdev_open(struct net_device *dev)
38955
38956 /* arbitrate between network and tty opens */
38957 spin_lock_irqsave(&info->netlock, flags);
38958- if (info->port.count != 0 || info->netcount != 0) {
38959+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
38960 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
38961 spin_unlock_irqrestore(&info->netlock, flags);
38962 return -EBUSY;
38963@@ -4114,7 +4114,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
38964 printk("%s:hdlcdev_ioctl(%s)\n", __FILE__, dev->name);
38965
38966 /* return error if TTY interface open */
38967- if (info->port.count)
38968+ if (atomic_read(&info->port.count))
38969 return -EBUSY;
38970
38971 if (cmd != SIOCWANDEV)
38972diff --git a/drivers/char/random.c b/drivers/char/random.c
38973index 429b75b..a7f4145 100644
38974--- a/drivers/char/random.c
38975+++ b/drivers/char/random.c
38976@@ -270,10 +270,17 @@
38977 /*
38978 * Configuration information
38979 */
38980+#ifdef CONFIG_GRKERNSEC_RANDNET
38981+#define INPUT_POOL_SHIFT 14
38982+#define INPUT_POOL_WORDS (1 << (INPUT_POOL_SHIFT-5))
38983+#define OUTPUT_POOL_SHIFT 12
38984+#define OUTPUT_POOL_WORDS (1 << (OUTPUT_POOL_SHIFT-5))
38985+#else
38986 #define INPUT_POOL_SHIFT 12
38987 #define INPUT_POOL_WORDS (1 << (INPUT_POOL_SHIFT-5))
38988 #define OUTPUT_POOL_SHIFT 10
38989 #define OUTPUT_POOL_WORDS (1 << (OUTPUT_POOL_SHIFT-5))
38990+#endif
38991 #define SEC_XFER_SIZE 512
38992 #define EXTRACT_SIZE 10
38993
38994@@ -284,9 +291,6 @@
38995 /*
38996 * To allow fractional bits to be tracked, the entropy_count field is
38997 * denominated in units of 1/8th bits.
38998- *
38999- * 2*(ENTROPY_SHIFT + log2(poolbits)) must <= 31, or the multiply in
39000- * credit_entropy_bits() needs to be 64 bits wide.
39001 */
39002 #define ENTROPY_SHIFT 3
39003 #define ENTROPY_BITS(r) ((r)->entropy_count >> ENTROPY_SHIFT)
39004@@ -361,12 +365,19 @@ static struct poolinfo {
39005 #define S(x) ilog2(x)+5, (x), (x)*4, (x)*32, (x) << (ENTROPY_SHIFT+5)
39006 int tap1, tap2, tap3, tap4, tap5;
39007 } poolinfo_table[] = {
39008+#ifdef CONFIG_GRKERNSEC_RANDNET
39009+ /* x^512 + x^411 + x^308 + x^208 +x^104 + x + 1 -- 225 */
39010+ { S(512), 411, 308, 208, 104, 1 },
39011+ /* x^128 + x^104 + x^76 + x^51 + x^25 + x + 1 -- 105 */
39012+ { S(128), 104, 76, 51, 25, 1 },
39013+#else
39014 /* was: x^128 + x^103 + x^76 + x^51 +x^25 + x + 1 */
39015 /* x^128 + x^104 + x^76 + x^51 +x^25 + x + 1 */
39016 { S(128), 104, 76, 51, 25, 1 },
39017 /* was: x^32 + x^26 + x^20 + x^14 + x^7 + x + 1 */
39018 /* x^32 + x^26 + x^19 + x^14 + x^7 + x + 1 */
39019 { S(32), 26, 19, 14, 7, 1 },
39020+#endif
39021 #if 0
39022 /* x^2048 + x^1638 + x^1231 + x^819 + x^411 + x + 1 -- 115 */
39023 { S(2048), 1638, 1231, 819, 411, 1 },
39024@@ -433,9 +444,9 @@ struct entropy_store {
39025 };
39026
39027 static void push_to_pool(struct work_struct *work);
39028-static __u32 input_pool_data[INPUT_POOL_WORDS];
39029-static __u32 blocking_pool_data[OUTPUT_POOL_WORDS];
39030-static __u32 nonblocking_pool_data[OUTPUT_POOL_WORDS];
39031+static __u32 input_pool_data[INPUT_POOL_WORDS] __latent_entropy;
39032+static __u32 blocking_pool_data[OUTPUT_POOL_WORDS] __latent_entropy;
39033+static __u32 nonblocking_pool_data[OUTPUT_POOL_WORDS] __latent_entropy;
39034
39035 static struct entropy_store input_pool = {
39036 .poolinfo = &poolinfo_table[0],
39037@@ -524,8 +535,8 @@ static void _mix_pool_bytes(struct entropy_store *r, const void *in,
39038 input_rotate = (input_rotate + (i ? 7 : 14)) & 31;
39039 }
39040
39041- ACCESS_ONCE(r->input_rotate) = input_rotate;
39042- ACCESS_ONCE(r->add_ptr) = i;
39043+ ACCESS_ONCE_RW(r->input_rotate) = input_rotate;
39044+ ACCESS_ONCE_RW(r->add_ptr) = i;
39045 smp_wmb();
39046
39047 if (out)
39048@@ -632,7 +643,7 @@ retry:
39049 /* The +2 corresponds to the /4 in the denominator */
39050
39051 do {
39052- unsigned int anfrac = min(pnfrac, pool_size/2);
39053+ u64 anfrac = min(pnfrac, pool_size/2);
39054 unsigned int add =
39055 ((pool_size - entropy_count)*anfrac*3) >> s;
39056
39057@@ -1151,7 +1162,7 @@ static ssize_t extract_entropy_user(struct entropy_store *r, void __user *buf,
39058
39059 extract_buf(r, tmp);
39060 i = min_t(int, nbytes, EXTRACT_SIZE);
39061- if (copy_to_user(buf, tmp, i)) {
39062+ if (i > sizeof(tmp) || copy_to_user(buf, tmp, i)) {
39063 ret = -EFAULT;
39064 break;
39065 }
39066@@ -1507,7 +1518,7 @@ EXPORT_SYMBOL(generate_random_uuid);
39067 #include <linux/sysctl.h>
39068
39069 static int min_read_thresh = 8, min_write_thresh;
39070-static int max_read_thresh = INPUT_POOL_WORDS * 32;
39071+static int max_read_thresh = OUTPUT_POOL_WORDS * 32;
39072 static int max_write_thresh = INPUT_POOL_WORDS * 32;
39073 static char sysctl_bootid[16];
39074
39075@@ -1523,7 +1534,7 @@ static char sysctl_bootid[16];
39076 static int proc_do_uuid(struct ctl_table *table, int write,
39077 void __user *buffer, size_t *lenp, loff_t *ppos)
39078 {
39079- struct ctl_table fake_table;
39080+ ctl_table_no_const fake_table;
39081 unsigned char buf[64], tmp_uuid[16], *uuid;
39082
39083 uuid = table->data;
39084@@ -1553,7 +1564,7 @@ static int proc_do_uuid(struct ctl_table *table, int write,
39085 static int proc_do_entropy(ctl_table *table, int write,
39086 void __user *buffer, size_t *lenp, loff_t *ppos)
39087 {
39088- ctl_table fake_table;
39089+ ctl_table_no_const fake_table;
39090 int entropy_count;
39091
39092 entropy_count = *(int *)table->data >> ENTROPY_SHIFT;
39093diff --git a/drivers/char/sonypi.c b/drivers/char/sonypi.c
39094index 7cc1fe22..b602d6b 100644
39095--- a/drivers/char/sonypi.c
39096+++ b/drivers/char/sonypi.c
39097@@ -54,6 +54,7 @@
39098
39099 #include <asm/uaccess.h>
39100 #include <asm/io.h>
39101+#include <asm/local.h>
39102
39103 #include <linux/sonypi.h>
39104
39105@@ -490,7 +491,7 @@ static struct sonypi_device {
39106 spinlock_t fifo_lock;
39107 wait_queue_head_t fifo_proc_list;
39108 struct fasync_struct *fifo_async;
39109- int open_count;
39110+ local_t open_count;
39111 int model;
39112 struct input_dev *input_jog_dev;
39113 struct input_dev *input_key_dev;
39114@@ -892,7 +893,7 @@ static int sonypi_misc_fasync(int fd, struct file *filp, int on)
39115 static int sonypi_misc_release(struct inode *inode, struct file *file)
39116 {
39117 mutex_lock(&sonypi_device.lock);
39118- sonypi_device.open_count--;
39119+ local_dec(&sonypi_device.open_count);
39120 mutex_unlock(&sonypi_device.lock);
39121 return 0;
39122 }
39123@@ -901,9 +902,9 @@ static int sonypi_misc_open(struct inode *inode, struct file *file)
39124 {
39125 mutex_lock(&sonypi_device.lock);
39126 /* Flush input queue on first open */
39127- if (!sonypi_device.open_count)
39128+ if (!local_read(&sonypi_device.open_count))
39129 kfifo_reset(&sonypi_device.fifo);
39130- sonypi_device.open_count++;
39131+ local_inc(&sonypi_device.open_count);
39132 mutex_unlock(&sonypi_device.lock);
39133
39134 return 0;
39135diff --git a/drivers/char/tpm/tpm_acpi.c b/drivers/char/tpm/tpm_acpi.c
39136index b9a57fa..5bb9e38 100644
39137--- a/drivers/char/tpm/tpm_acpi.c
39138+++ b/drivers/char/tpm/tpm_acpi.c
39139@@ -98,11 +98,12 @@ int read_log(struct tpm_bios_log *log)
39140 virt = acpi_os_map_memory(start, len);
39141 if (!virt) {
39142 kfree(log->bios_event_log);
39143+ log->bios_event_log = NULL;
39144 printk("%s: ERROR - Unable to map memory\n", __func__);
39145 return -EIO;
39146 }
39147
39148- memcpy_fromio(log->bios_event_log, virt, len);
39149+ memcpy_fromio(log->bios_event_log, (const char __force_kernel *)virt, len);
39150
39151 acpi_os_unmap_memory(virt, len);
39152 return 0;
39153diff --git a/drivers/char/tpm/tpm_eventlog.c b/drivers/char/tpm/tpm_eventlog.c
39154index 59f7cb2..bac8b6d 100644
39155--- a/drivers/char/tpm/tpm_eventlog.c
39156+++ b/drivers/char/tpm/tpm_eventlog.c
39157@@ -95,7 +95,7 @@ static void *tpm_bios_measurements_start(struct seq_file *m, loff_t *pos)
39158 event = addr;
39159
39160 if ((event->event_type == 0 && event->event_size == 0) ||
39161- ((addr + sizeof(struct tcpa_event) + event->event_size) >= limit))
39162+ (event->event_size >= limit - addr - sizeof(struct tcpa_event)))
39163 return NULL;
39164
39165 return addr;
39166@@ -120,7 +120,7 @@ static void *tpm_bios_measurements_next(struct seq_file *m, void *v,
39167 return NULL;
39168
39169 if ((event->event_type == 0 && event->event_size == 0) ||
39170- ((v + sizeof(struct tcpa_event) + event->event_size) >= limit))
39171+ (event->event_size >= limit - v - sizeof(struct tcpa_event)))
39172 return NULL;
39173
39174 (*pos)++;
39175@@ -213,7 +213,8 @@ static int tpm_binary_bios_measurements_show(struct seq_file *m, void *v)
39176 int i;
39177
39178 for (i = 0; i < sizeof(struct tcpa_event) + event->event_size; i++)
39179- seq_putc(m, data[i]);
39180+ if (!seq_putc(m, data[i]))
39181+ return -EFAULT;
39182
39183 return 0;
39184 }
39185diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
39186index 6928d09..ff6abe8 100644
39187--- a/drivers/char/virtio_console.c
39188+++ b/drivers/char/virtio_console.c
39189@@ -684,7 +684,7 @@ static ssize_t fill_readbuf(struct port *port, char *out_buf, size_t out_count,
39190 if (to_user) {
39191 ssize_t ret;
39192
39193- ret = copy_to_user(out_buf, buf->buf + buf->offset, out_count);
39194+ ret = copy_to_user((char __force_user *)out_buf, buf->buf + buf->offset, out_count);
39195 if (ret)
39196 return -EFAULT;
39197 } else {
39198@@ -787,7 +787,7 @@ static ssize_t port_fops_read(struct file *filp, char __user *ubuf,
39199 if (!port_has_data(port) && !port->host_connected)
39200 return 0;
39201
39202- return fill_readbuf(port, ubuf, count, true);
39203+ return fill_readbuf(port, (char __force_kernel *)ubuf, count, true);
39204 }
39205
39206 static int wait_port_writable(struct port *port, bool nonblock)
39207diff --git a/drivers/clk/clk-composite.c b/drivers/clk/clk-composite.c
39208index 57a078e..c17cde8 100644
39209--- a/drivers/clk/clk-composite.c
39210+++ b/drivers/clk/clk-composite.c
39211@@ -146,7 +146,7 @@ struct clk *clk_register_composite(struct device *dev, const char *name,
39212 struct clk *clk;
39213 struct clk_init_data init;
39214 struct clk_composite *composite;
39215- struct clk_ops *clk_composite_ops;
39216+ clk_ops_no_const *clk_composite_ops;
39217
39218 composite = kzalloc(sizeof(*composite), GFP_KERNEL);
39219 if (!composite) {
39220diff --git a/drivers/clk/socfpga/clk.c b/drivers/clk/socfpga/clk.c
39221index 5983a26..65d5f46 100644
39222--- a/drivers/clk/socfpga/clk.c
39223+++ b/drivers/clk/socfpga/clk.c
39224@@ -22,6 +22,7 @@
39225 #include <linux/clk-provider.h>
39226 #include <linux/io.h>
39227 #include <linux/of.h>
39228+#include <asm/pgtable.h>
39229
39230 /* Clock Manager offsets */
39231 #define CLKMGR_CTRL 0x0
39232@@ -150,8 +151,10 @@ static __init struct clk *socfpga_clk_init(struct device_node *node,
39233 streq(clk_name, "periph_pll") ||
39234 streq(clk_name, "sdram_pll")) {
39235 socfpga_clk->hw.bit_idx = SOCFPGA_PLL_EXT_ENA;
39236- clk_pll_ops.enable = clk_gate_ops.enable;
39237- clk_pll_ops.disable = clk_gate_ops.disable;
39238+ pax_open_kernel();
39239+ *(void **)&clk_pll_ops.enable = clk_gate_ops.enable;
39240+ *(void **)&clk_pll_ops.disable = clk_gate_ops.disable;
39241+ pax_close_kernel();
39242 }
39243
39244 clk = clk_register(NULL, &socfpga_clk->hw.hw);
39245@@ -242,7 +245,7 @@ static unsigned long socfpga_clk_recalc_rate(struct clk_hw *hwclk,
39246 return parent_rate / div;
39247 }
39248
39249-static struct clk_ops gateclk_ops = {
39250+static clk_ops_no_const gateclk_ops __read_only = {
39251 .recalc_rate = socfpga_clk_recalc_rate,
39252 .get_parent = socfpga_clk_get_parent,
39253 .set_parent = socfpga_clk_set_parent,
39254diff --git a/drivers/cpufreq/acpi-cpufreq.c b/drivers/cpufreq/acpi-cpufreq.c
39255index 18448a7..d5fad43 100644
39256--- a/drivers/cpufreq/acpi-cpufreq.c
39257+++ b/drivers/cpufreq/acpi-cpufreq.c
39258@@ -676,8 +676,11 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
39259 data->acpi_data = per_cpu_ptr(acpi_perf_data, cpu);
39260 per_cpu(acfreq_data, cpu) = data;
39261
39262- if (cpu_has(c, X86_FEATURE_CONSTANT_TSC))
39263- acpi_cpufreq_driver.flags |= CPUFREQ_CONST_LOOPS;
39264+ if (cpu_has(c, X86_FEATURE_CONSTANT_TSC)) {
39265+ pax_open_kernel();
39266+ *(u8 *)&acpi_cpufreq_driver.flags |= CPUFREQ_CONST_LOOPS;
39267+ pax_close_kernel();
39268+ }
39269
39270 result = acpi_processor_register_performance(data->acpi_data, cpu);
39271 if (result)
39272@@ -810,7 +813,9 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
39273 policy->cur = acpi_cpufreq_guess_freq(data, policy->cpu);
39274 break;
39275 case ACPI_ADR_SPACE_FIXED_HARDWARE:
39276- acpi_cpufreq_driver.get = get_cur_freq_on_cpu;
39277+ pax_open_kernel();
39278+ *(void **)&acpi_cpufreq_driver.get = get_cur_freq_on_cpu;
39279+ pax_close_kernel();
39280 break;
39281 default:
39282 break;
39283@@ -905,8 +910,10 @@ static void __init acpi_cpufreq_boost_init(void)
39284 if (!msrs)
39285 return;
39286
39287- acpi_cpufreq_driver.boost_supported = true;
39288- acpi_cpufreq_driver.boost_enabled = boost_state(0);
39289+ pax_open_kernel();
39290+ *(bool *)&acpi_cpufreq_driver.boost_supported = true;
39291+ *(bool *)&acpi_cpufreq_driver.boost_enabled = boost_state(0);
39292+ pax_close_kernel();
39293 get_online_cpus();
39294
39295 /* Force all MSRs to the same value */
39296diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
39297index 199b52b..e3503bb 100644
39298--- a/drivers/cpufreq/cpufreq.c
39299+++ b/drivers/cpufreq/cpufreq.c
39300@@ -1970,7 +1970,7 @@ void cpufreq_unregister_governor(struct cpufreq_governor *governor)
39301 #endif
39302
39303 mutex_lock(&cpufreq_governor_mutex);
39304- list_del(&governor->governor_list);
39305+ pax_list_del(&governor->governor_list);
39306 mutex_unlock(&cpufreq_governor_mutex);
39307 return;
39308 }
39309@@ -2200,7 +2200,7 @@ static int cpufreq_cpu_callback(struct notifier_block *nfb,
39310 return NOTIFY_OK;
39311 }
39312
39313-static struct notifier_block __refdata cpufreq_cpu_notifier = {
39314+static struct notifier_block cpufreq_cpu_notifier = {
39315 .notifier_call = cpufreq_cpu_callback,
39316 };
39317
39318@@ -2240,13 +2240,17 @@ int cpufreq_boost_trigger_state(int state)
39319 return 0;
39320
39321 write_lock_irqsave(&cpufreq_driver_lock, flags);
39322- cpufreq_driver->boost_enabled = state;
39323+ pax_open_kernel();
39324+ *(bool *)&cpufreq_driver->boost_enabled = state;
39325+ pax_close_kernel();
39326 write_unlock_irqrestore(&cpufreq_driver_lock, flags);
39327
39328 ret = cpufreq_driver->set_boost(state);
39329 if (ret) {
39330 write_lock_irqsave(&cpufreq_driver_lock, flags);
39331- cpufreq_driver->boost_enabled = !state;
39332+ pax_open_kernel();
39333+ *(bool *)&cpufreq_driver->boost_enabled = !state;
39334+ pax_close_kernel();
39335 write_unlock_irqrestore(&cpufreq_driver_lock, flags);
39336
39337 pr_err("%s: Cannot %s BOOST\n", __func__,
39338@@ -2300,8 +2304,11 @@ int cpufreq_register_driver(struct cpufreq_driver *driver_data)
39339
39340 pr_debug("trying to register driver %s\n", driver_data->name);
39341
39342- if (driver_data->setpolicy)
39343- driver_data->flags |= CPUFREQ_CONST_LOOPS;
39344+ if (driver_data->setpolicy) {
39345+ pax_open_kernel();
39346+ *(u8 *)&driver_data->flags |= CPUFREQ_CONST_LOOPS;
39347+ pax_close_kernel();
39348+ }
39349
39350 write_lock_irqsave(&cpufreq_driver_lock, flags);
39351 if (cpufreq_driver) {
39352@@ -2316,8 +2323,11 @@ int cpufreq_register_driver(struct cpufreq_driver *driver_data)
39353 * Check if driver provides function to enable boost -
39354 * if not, use cpufreq_boost_set_sw as default
39355 */
39356- if (!cpufreq_driver->set_boost)
39357- cpufreq_driver->set_boost = cpufreq_boost_set_sw;
39358+ if (!cpufreq_driver->set_boost) {
39359+ pax_open_kernel();
39360+ *(void **)&cpufreq_driver->set_boost = cpufreq_boost_set_sw;
39361+ pax_close_kernel();
39362+ }
39363
39364 ret = cpufreq_sysfs_create_file(&boost.attr);
39365 if (ret) {
39366diff --git a/drivers/cpufreq/cpufreq_governor.c b/drivers/cpufreq/cpufreq_governor.c
39367index ba43991..23858ffb 100644
39368--- a/drivers/cpufreq/cpufreq_governor.c
39369+++ b/drivers/cpufreq/cpufreq_governor.c
39370@@ -191,7 +191,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
39371 struct dbs_data *dbs_data;
39372 struct od_cpu_dbs_info_s *od_dbs_info = NULL;
39373 struct cs_cpu_dbs_info_s *cs_dbs_info = NULL;
39374- struct od_ops *od_ops = NULL;
39375+ const struct od_ops *od_ops = NULL;
39376 struct od_dbs_tuners *od_tuners = NULL;
39377 struct cs_dbs_tuners *cs_tuners = NULL;
39378 struct cpu_dbs_common_info *cpu_cdbs;
39379@@ -257,7 +257,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
39380
39381 if ((cdata->governor == GOV_CONSERVATIVE) &&
39382 (!policy->governor->initialized)) {
39383- struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
39384+ const struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
39385
39386 cpufreq_register_notifier(cs_ops->notifier_block,
39387 CPUFREQ_TRANSITION_NOTIFIER);
39388@@ -277,7 +277,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
39389
39390 if ((dbs_data->cdata->governor == GOV_CONSERVATIVE) &&
39391 (policy->governor->initialized == 1)) {
39392- struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
39393+ const struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
39394
39395 cpufreq_unregister_notifier(cs_ops->notifier_block,
39396 CPUFREQ_TRANSITION_NOTIFIER);
39397diff --git a/drivers/cpufreq/cpufreq_governor.h b/drivers/cpufreq/cpufreq_governor.h
39398index bfb9ae1..e1d3a7e 100644
39399--- a/drivers/cpufreq/cpufreq_governor.h
39400+++ b/drivers/cpufreq/cpufreq_governor.h
39401@@ -205,7 +205,7 @@ struct common_dbs_data {
39402 void (*exit)(struct dbs_data *dbs_data);
39403
39404 /* Governor specific ops, see below */
39405- void *gov_ops;
39406+ const void *gov_ops;
39407 };
39408
39409 /* Governor Per policy data */
39410@@ -225,7 +225,7 @@ struct od_ops {
39411 unsigned int (*powersave_bias_target)(struct cpufreq_policy *policy,
39412 unsigned int freq_next, unsigned int relation);
39413 void (*freq_increase)(struct cpufreq_policy *policy, unsigned int freq);
39414-};
39415+} __no_const;
39416
39417 struct cs_ops {
39418 struct notifier_block *notifier_block;
39419diff --git a/drivers/cpufreq/cpufreq_ondemand.c b/drivers/cpufreq/cpufreq_ondemand.c
39420index 18d4091..434be15 100644
39421--- a/drivers/cpufreq/cpufreq_ondemand.c
39422+++ b/drivers/cpufreq/cpufreq_ondemand.c
39423@@ -521,7 +521,7 @@ static void od_exit(struct dbs_data *dbs_data)
39424
39425 define_get_cpu_dbs_routines(od_cpu_dbs_info);
39426
39427-static struct od_ops od_ops = {
39428+static struct od_ops od_ops __read_only = {
39429 .powersave_bias_init_cpu = ondemand_powersave_bias_init_cpu,
39430 .powersave_bias_target = generic_powersave_bias_target,
39431 .freq_increase = dbs_freq_increase,
39432@@ -576,14 +576,18 @@ void od_register_powersave_bias_handler(unsigned int (*f)
39433 (struct cpufreq_policy *, unsigned int, unsigned int),
39434 unsigned int powersave_bias)
39435 {
39436- od_ops.powersave_bias_target = f;
39437+ pax_open_kernel();
39438+ *(void **)&od_ops.powersave_bias_target = f;
39439+ pax_close_kernel();
39440 od_set_powersave_bias(powersave_bias);
39441 }
39442 EXPORT_SYMBOL_GPL(od_register_powersave_bias_handler);
39443
39444 void od_unregister_powersave_bias_handler(void)
39445 {
39446- od_ops.powersave_bias_target = generic_powersave_bias_target;
39447+ pax_open_kernel();
39448+ *(void **)&od_ops.powersave_bias_target = generic_powersave_bias_target;
39449+ pax_close_kernel();
39450 od_set_powersave_bias(0);
39451 }
39452 EXPORT_SYMBOL_GPL(od_unregister_powersave_bias_handler);
39453diff --git a/drivers/cpufreq/intel_pstate.c b/drivers/cpufreq/intel_pstate.c
39454index 2cd36b9..8f07fae 100644
39455--- a/drivers/cpufreq/intel_pstate.c
39456+++ b/drivers/cpufreq/intel_pstate.c
39457@@ -124,10 +124,10 @@ struct pstate_funcs {
39458 struct cpu_defaults {
39459 struct pstate_adjust_policy pid_policy;
39460 struct pstate_funcs funcs;
39461-};
39462+} __do_const;
39463
39464 static struct pstate_adjust_policy pid_params;
39465-static struct pstate_funcs pstate_funcs;
39466+static struct pstate_funcs *pstate_funcs;
39467
39468 struct perf_limits {
39469 int no_turbo;
39470@@ -518,7 +518,7 @@ static void intel_pstate_set_pstate(struct cpudata *cpu, int pstate)
39471
39472 cpu->pstate.current_pstate = pstate;
39473
39474- pstate_funcs.set(cpu, pstate);
39475+ pstate_funcs->set(cpu, pstate);
39476 }
39477
39478 static inline void intel_pstate_pstate_increase(struct cpudata *cpu, int steps)
39479@@ -540,12 +540,12 @@ static void intel_pstate_get_cpu_pstates(struct cpudata *cpu)
39480 {
39481 sprintf(cpu->name, "Intel 2nd generation core");
39482
39483- cpu->pstate.min_pstate = pstate_funcs.get_min();
39484- cpu->pstate.max_pstate = pstate_funcs.get_max();
39485- cpu->pstate.turbo_pstate = pstate_funcs.get_turbo();
39486+ cpu->pstate.min_pstate = pstate_funcs->get_min();
39487+ cpu->pstate.max_pstate = pstate_funcs->get_max();
39488+ cpu->pstate.turbo_pstate = pstate_funcs->get_turbo();
39489
39490- if (pstate_funcs.get_vid)
39491- pstate_funcs.get_vid(cpu);
39492+ if (pstate_funcs->get_vid)
39493+ pstate_funcs->get_vid(cpu);
39494
39495 /*
39496 * goto max pstate so we don't slow up boot if we are built-in if we are
39497@@ -832,9 +832,9 @@ static int intel_pstate_msrs_not_valid(void)
39498 rdmsrl(MSR_IA32_APERF, aperf);
39499 rdmsrl(MSR_IA32_MPERF, mperf);
39500
39501- if (!pstate_funcs.get_max() ||
39502- !pstate_funcs.get_min() ||
39503- !pstate_funcs.get_turbo())
39504+ if (!pstate_funcs->get_max() ||
39505+ !pstate_funcs->get_min() ||
39506+ !pstate_funcs->get_turbo())
39507 return -ENODEV;
39508
39509 rdmsrl(MSR_IA32_APERF, tmp);
39510@@ -848,7 +848,7 @@ static int intel_pstate_msrs_not_valid(void)
39511 return 0;
39512 }
39513
39514-static void copy_pid_params(struct pstate_adjust_policy *policy)
39515+static void copy_pid_params(const struct pstate_adjust_policy *policy)
39516 {
39517 pid_params.sample_rate_ms = policy->sample_rate_ms;
39518 pid_params.p_gain_pct = policy->p_gain_pct;
39519@@ -860,11 +860,7 @@ static void copy_pid_params(struct pstate_adjust_policy *policy)
39520
39521 static void copy_cpu_funcs(struct pstate_funcs *funcs)
39522 {
39523- pstate_funcs.get_max = funcs->get_max;
39524- pstate_funcs.get_min = funcs->get_min;
39525- pstate_funcs.get_turbo = funcs->get_turbo;
39526- pstate_funcs.set = funcs->set;
39527- pstate_funcs.get_vid = funcs->get_vid;
39528+ pstate_funcs = funcs;
39529 }
39530
39531 #if IS_ENABLED(CONFIG_ACPI)
39532diff --git a/drivers/cpufreq/p4-clockmod.c b/drivers/cpufreq/p4-clockmod.c
39533index 3d1cba9..0ab21d2 100644
39534--- a/drivers/cpufreq/p4-clockmod.c
39535+++ b/drivers/cpufreq/p4-clockmod.c
39536@@ -134,10 +134,14 @@ static unsigned int cpufreq_p4_get_frequency(struct cpuinfo_x86 *c)
39537 case 0x0F: /* Core Duo */
39538 case 0x16: /* Celeron Core */
39539 case 0x1C: /* Atom */
39540- p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39541+ pax_open_kernel();
39542+ *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39543+ pax_close_kernel();
39544 return speedstep_get_frequency(SPEEDSTEP_CPU_PCORE);
39545 case 0x0D: /* Pentium M (Dothan) */
39546- p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39547+ pax_open_kernel();
39548+ *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39549+ pax_close_kernel();
39550 /* fall through */
39551 case 0x09: /* Pentium M (Banias) */
39552 return speedstep_get_frequency(SPEEDSTEP_CPU_PM);
39553@@ -149,7 +153,9 @@ static unsigned int cpufreq_p4_get_frequency(struct cpuinfo_x86 *c)
39554
39555 /* on P-4s, the TSC runs with constant frequency independent whether
39556 * throttling is active or not. */
39557- p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39558+ pax_open_kernel();
39559+ *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39560+ pax_close_kernel();
39561
39562 if (speedstep_detect_processor() == SPEEDSTEP_CPU_P4M) {
39563 printk(KERN_WARNING PFX "Warning: Pentium 4-M detected. "
39564diff --git a/drivers/cpufreq/sparc-us3-cpufreq.c b/drivers/cpufreq/sparc-us3-cpufreq.c
39565index 724ffbd..f06aaaa 100644
39566--- a/drivers/cpufreq/sparc-us3-cpufreq.c
39567+++ b/drivers/cpufreq/sparc-us3-cpufreq.c
39568@@ -18,14 +18,12 @@
39569 #include <asm/head.h>
39570 #include <asm/timer.h>
39571
39572-static struct cpufreq_driver *cpufreq_us3_driver;
39573-
39574 struct us3_freq_percpu_info {
39575 struct cpufreq_frequency_table table[4];
39576 };
39577
39578 /* Indexed by cpu number. */
39579-static struct us3_freq_percpu_info *us3_freq_table;
39580+static struct us3_freq_percpu_info us3_freq_table[NR_CPUS];
39581
39582 /* UltraSPARC-III has three dividers: 1, 2, and 32. These are controlled
39583 * in the Safari config register.
39584@@ -156,18 +154,28 @@ static int __init us3_freq_cpu_init(struct cpufreq_policy *policy)
39585
39586 static int us3_freq_cpu_exit(struct cpufreq_policy *policy)
39587 {
39588- if (cpufreq_us3_driver) {
39589- cpufreq_frequency_table_put_attr(policy->cpu);
39590- us3_freq_target(policy, 0);
39591- }
39592+ cpufreq_frequency_table_put_attr(policy->cpu);
39593+ us3_freq_target(policy, 0);
39594
39595 return 0;
39596 }
39597
39598+static int __init us3_freq_init(void);
39599+static void __exit us3_freq_exit(void);
39600+
39601+static struct cpufreq_driver cpufreq_us3_driver = {
39602+ .init = us3_freq_cpu_init,
39603+ .verify = cpufreq_generic_frequency_table_verify,
39604+ .target_index = us3_freq_target,
39605+ .get = us3_freq_get,
39606+ .exit = us3_freq_cpu_exit,
39607+ .name = "UltraSPARC-III",
39608+
39609+};
39610+
39611 static int __init us3_freq_init(void)
39612 {
39613 unsigned long manuf, impl, ver;
39614- int ret;
39615
39616 if (tlb_type != cheetah && tlb_type != cheetah_plus)
39617 return -ENODEV;
39618@@ -180,55 +188,15 @@ static int __init us3_freq_init(void)
39619 (impl == CHEETAH_IMPL ||
39620 impl == CHEETAH_PLUS_IMPL ||
39621 impl == JAGUAR_IMPL ||
39622- impl == PANTHER_IMPL)) {
39623- struct cpufreq_driver *driver;
39624-
39625- ret = -ENOMEM;
39626- driver = kzalloc(sizeof(*driver), GFP_KERNEL);
39627- if (!driver)
39628- goto err_out;
39629-
39630- us3_freq_table = kzalloc((NR_CPUS * sizeof(*us3_freq_table)),
39631- GFP_KERNEL);
39632- if (!us3_freq_table)
39633- goto err_out;
39634-
39635- driver->init = us3_freq_cpu_init;
39636- driver->verify = cpufreq_generic_frequency_table_verify;
39637- driver->target_index = us3_freq_target;
39638- driver->get = us3_freq_get;
39639- driver->exit = us3_freq_cpu_exit;
39640- strcpy(driver->name, "UltraSPARC-III");
39641-
39642- cpufreq_us3_driver = driver;
39643- ret = cpufreq_register_driver(driver);
39644- if (ret)
39645- goto err_out;
39646-
39647- return 0;
39648-
39649-err_out:
39650- if (driver) {
39651- kfree(driver);
39652- cpufreq_us3_driver = NULL;
39653- }
39654- kfree(us3_freq_table);
39655- us3_freq_table = NULL;
39656- return ret;
39657- }
39658+ impl == PANTHER_IMPL))
39659+ return cpufreq_register_driver(&cpufreq_us3_driver);
39660
39661 return -ENODEV;
39662 }
39663
39664 static void __exit us3_freq_exit(void)
39665 {
39666- if (cpufreq_us3_driver) {
39667- cpufreq_unregister_driver(cpufreq_us3_driver);
39668- kfree(cpufreq_us3_driver);
39669- cpufreq_us3_driver = NULL;
39670- kfree(us3_freq_table);
39671- us3_freq_table = NULL;
39672- }
39673+ cpufreq_unregister_driver(&cpufreq_us3_driver);
39674 }
39675
39676 MODULE_AUTHOR("David S. Miller <davem@redhat.com>");
39677diff --git a/drivers/cpufreq/speedstep-centrino.c b/drivers/cpufreq/speedstep-centrino.c
39678index 4e1daca..e707b61 100644
39679--- a/drivers/cpufreq/speedstep-centrino.c
39680+++ b/drivers/cpufreq/speedstep-centrino.c
39681@@ -351,8 +351,11 @@ static int centrino_cpu_init(struct cpufreq_policy *policy)
39682 !cpu_has(cpu, X86_FEATURE_EST))
39683 return -ENODEV;
39684
39685- if (cpu_has(cpu, X86_FEATURE_CONSTANT_TSC))
39686- centrino_driver.flags |= CPUFREQ_CONST_LOOPS;
39687+ if (cpu_has(cpu, X86_FEATURE_CONSTANT_TSC)) {
39688+ pax_open_kernel();
39689+ *(u8 *)&centrino_driver.flags |= CPUFREQ_CONST_LOOPS;
39690+ pax_close_kernel();
39691+ }
39692
39693 if (policy->cpu != 0)
39694 return -ENODEV;
39695diff --git a/drivers/cpuidle/driver.c b/drivers/cpuidle/driver.c
39696index 06dbe7c..c2c8671 100644
39697--- a/drivers/cpuidle/driver.c
39698+++ b/drivers/cpuidle/driver.c
39699@@ -202,7 +202,7 @@ static int poll_idle(struct cpuidle_device *dev,
39700
39701 static void poll_idle_init(struct cpuidle_driver *drv)
39702 {
39703- struct cpuidle_state *state = &drv->states[0];
39704+ cpuidle_state_no_const *state = &drv->states[0];
39705
39706 snprintf(state->name, CPUIDLE_NAME_LEN, "POLL");
39707 snprintf(state->desc, CPUIDLE_DESC_LEN, "CPUIDLE CORE POLL IDLE");
39708diff --git a/drivers/cpuidle/governor.c b/drivers/cpuidle/governor.c
39709index ca89412..a7b9c49 100644
39710--- a/drivers/cpuidle/governor.c
39711+++ b/drivers/cpuidle/governor.c
39712@@ -87,7 +87,7 @@ int cpuidle_register_governor(struct cpuidle_governor *gov)
39713 mutex_lock(&cpuidle_lock);
39714 if (__cpuidle_find_governor(gov->name) == NULL) {
39715 ret = 0;
39716- list_add_tail(&gov->governor_list, &cpuidle_governors);
39717+ pax_list_add_tail((struct list_head *)&gov->governor_list, &cpuidle_governors);
39718 if (!cpuidle_curr_governor ||
39719 cpuidle_curr_governor->rating < gov->rating)
39720 cpuidle_switch_governor(gov);
39721diff --git a/drivers/cpuidle/sysfs.c b/drivers/cpuidle/sysfs.c
39722index e918b6d..f87ea80 100644
39723--- a/drivers/cpuidle/sysfs.c
39724+++ b/drivers/cpuidle/sysfs.c
39725@@ -135,7 +135,7 @@ static struct attribute *cpuidle_switch_attrs[] = {
39726 NULL
39727 };
39728
39729-static struct attribute_group cpuidle_attr_group = {
39730+static attribute_group_no_const cpuidle_attr_group = {
39731 .attrs = cpuidle_default_attrs,
39732 .name = "cpuidle",
39733 };
39734diff --git a/drivers/crypto/hifn_795x.c b/drivers/crypto/hifn_795x.c
39735index 12fea3e..1e28f47 100644
39736--- a/drivers/crypto/hifn_795x.c
39737+++ b/drivers/crypto/hifn_795x.c
39738@@ -51,7 +51,7 @@ module_param_string(hifn_pll_ref, hifn_pll_ref, sizeof(hifn_pll_ref), 0444);
39739 MODULE_PARM_DESC(hifn_pll_ref,
39740 "PLL reference clock (pci[freq] or ext[freq], default ext)");
39741
39742-static atomic_t hifn_dev_number;
39743+static atomic_unchecked_t hifn_dev_number;
39744
39745 #define ACRYPTO_OP_DECRYPT 0
39746 #define ACRYPTO_OP_ENCRYPT 1
39747@@ -2577,7 +2577,7 @@ static int hifn_probe(struct pci_dev *pdev, const struct pci_device_id *id)
39748 goto err_out_disable_pci_device;
39749
39750 snprintf(name, sizeof(name), "hifn%d",
39751- atomic_inc_return(&hifn_dev_number)-1);
39752+ atomic_inc_return_unchecked(&hifn_dev_number)-1);
39753
39754 err = pci_request_regions(pdev, name);
39755 if (err)
39756diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c
39757index a0b2f7e..1b6f028 100644
39758--- a/drivers/devfreq/devfreq.c
39759+++ b/drivers/devfreq/devfreq.c
39760@@ -607,7 +607,7 @@ int devfreq_add_governor(struct devfreq_governor *governor)
39761 goto err_out;
39762 }
39763
39764- list_add(&governor->node, &devfreq_governor_list);
39765+ pax_list_add((struct list_head *)&governor->node, &devfreq_governor_list);
39766
39767 list_for_each_entry(devfreq, &devfreq_list, node) {
39768 int ret = 0;
39769@@ -695,7 +695,7 @@ int devfreq_remove_governor(struct devfreq_governor *governor)
39770 }
39771 }
39772
39773- list_del(&governor->node);
39774+ pax_list_del((struct list_head *)&governor->node);
39775 err_out:
39776 mutex_unlock(&devfreq_list_lock);
39777
39778diff --git a/drivers/dma/sh/shdma-base.c b/drivers/dma/sh/shdma-base.c
39779index 2e7b394..1371a64 100644
39780--- a/drivers/dma/sh/shdma-base.c
39781+++ b/drivers/dma/sh/shdma-base.c
39782@@ -267,8 +267,8 @@ static int shdma_alloc_chan_resources(struct dma_chan *chan)
39783 schan->slave_id = -EINVAL;
39784 }
39785
39786- schan->desc = kcalloc(NR_DESCS_PER_CHANNEL,
39787- sdev->desc_size, GFP_KERNEL);
39788+ schan->desc = kcalloc(sdev->desc_size,
39789+ NR_DESCS_PER_CHANNEL, GFP_KERNEL);
39790 if (!schan->desc) {
39791 ret = -ENOMEM;
39792 goto edescalloc;
39793diff --git a/drivers/dma/sh/shdmac.c b/drivers/dma/sh/shdmac.c
39794index 0d765c0..60b7480 100644
39795--- a/drivers/dma/sh/shdmac.c
39796+++ b/drivers/dma/sh/shdmac.c
39797@@ -511,7 +511,7 @@ static int sh_dmae_nmi_handler(struct notifier_block *self,
39798 return ret;
39799 }
39800
39801-static struct notifier_block sh_dmae_nmi_notifier __read_mostly = {
39802+static struct notifier_block sh_dmae_nmi_notifier = {
39803 .notifier_call = sh_dmae_nmi_handler,
39804
39805 /* Run before NMI debug handler and KGDB */
39806diff --git a/drivers/edac/edac_device.c b/drivers/edac/edac_device.c
39807index 592af5f..bb1d583 100644
39808--- a/drivers/edac/edac_device.c
39809+++ b/drivers/edac/edac_device.c
39810@@ -477,9 +477,9 @@ void edac_device_reset_delay_period(struct edac_device_ctl_info *edac_dev,
39811 */
39812 int edac_device_alloc_index(void)
39813 {
39814- static atomic_t device_indexes = ATOMIC_INIT(0);
39815+ static atomic_unchecked_t device_indexes = ATOMIC_INIT(0);
39816
39817- return atomic_inc_return(&device_indexes) - 1;
39818+ return atomic_inc_return_unchecked(&device_indexes) - 1;
39819 }
39820 EXPORT_SYMBOL_GPL(edac_device_alloc_index);
39821
39822diff --git a/drivers/edac/edac_mc_sysfs.c b/drivers/edac/edac_mc_sysfs.c
39823index b335c6a..db65b44 100644
39824--- a/drivers/edac/edac_mc_sysfs.c
39825+++ b/drivers/edac/edac_mc_sysfs.c
39826@@ -152,7 +152,7 @@ static const char * const edac_caps[] = {
39827 struct dev_ch_attribute {
39828 struct device_attribute attr;
39829 int channel;
39830-};
39831+} __do_const;
39832
39833 #define DEVICE_CHANNEL(_name, _mode, _show, _store, _var) \
39834 struct dev_ch_attribute dev_attr_legacy_##_name = \
39835@@ -1009,14 +1009,16 @@ int edac_create_sysfs_mci_device(struct mem_ctl_info *mci)
39836 }
39837
39838 if (mci->set_sdram_scrub_rate || mci->get_sdram_scrub_rate) {
39839+ pax_open_kernel();
39840 if (mci->get_sdram_scrub_rate) {
39841- dev_attr_sdram_scrub_rate.attr.mode |= S_IRUGO;
39842- dev_attr_sdram_scrub_rate.show = &mci_sdram_scrub_rate_show;
39843+ *(umode_t *)&dev_attr_sdram_scrub_rate.attr.mode |= S_IRUGO;
39844+ *(void **)&dev_attr_sdram_scrub_rate.show = &mci_sdram_scrub_rate_show;
39845 }
39846 if (mci->set_sdram_scrub_rate) {
39847- dev_attr_sdram_scrub_rate.attr.mode |= S_IWUSR;
39848- dev_attr_sdram_scrub_rate.store = &mci_sdram_scrub_rate_store;
39849+ *(umode_t *)&dev_attr_sdram_scrub_rate.attr.mode |= S_IWUSR;
39850+ *(void **)&dev_attr_sdram_scrub_rate.store = &mci_sdram_scrub_rate_store;
39851 }
39852+ pax_close_kernel();
39853 err = device_create_file(&mci->dev,
39854 &dev_attr_sdram_scrub_rate);
39855 if (err) {
39856diff --git a/drivers/edac/edac_pci.c b/drivers/edac/edac_pci.c
39857index 2cf44b4d..6dd2dc7 100644
39858--- a/drivers/edac/edac_pci.c
39859+++ b/drivers/edac/edac_pci.c
39860@@ -29,7 +29,7 @@
39861
39862 static DEFINE_MUTEX(edac_pci_ctls_mutex);
39863 static LIST_HEAD(edac_pci_list);
39864-static atomic_t pci_indexes = ATOMIC_INIT(0);
39865+static atomic_unchecked_t pci_indexes = ATOMIC_INIT(0);
39866
39867 /*
39868 * edac_pci_alloc_ctl_info
39869@@ -315,7 +315,7 @@ EXPORT_SYMBOL_GPL(edac_pci_reset_delay_period);
39870 */
39871 int edac_pci_alloc_index(void)
39872 {
39873- return atomic_inc_return(&pci_indexes) - 1;
39874+ return atomic_inc_return_unchecked(&pci_indexes) - 1;
39875 }
39876 EXPORT_SYMBOL_GPL(edac_pci_alloc_index);
39877
39878diff --git a/drivers/edac/edac_pci_sysfs.c b/drivers/edac/edac_pci_sysfs.c
39879index e8658e4..22746d6 100644
39880--- a/drivers/edac/edac_pci_sysfs.c
39881+++ b/drivers/edac/edac_pci_sysfs.c
39882@@ -26,8 +26,8 @@ static int edac_pci_log_pe = 1; /* log PCI parity errors */
39883 static int edac_pci_log_npe = 1; /* log PCI non-parity error errors */
39884 static int edac_pci_poll_msec = 1000; /* one second workq period */
39885
39886-static atomic_t pci_parity_count = ATOMIC_INIT(0);
39887-static atomic_t pci_nonparity_count = ATOMIC_INIT(0);
39888+static atomic_unchecked_t pci_parity_count = ATOMIC_INIT(0);
39889+static atomic_unchecked_t pci_nonparity_count = ATOMIC_INIT(0);
39890
39891 static struct kobject *edac_pci_top_main_kobj;
39892 static atomic_t edac_pci_sysfs_refcount = ATOMIC_INIT(0);
39893@@ -235,7 +235,7 @@ struct edac_pci_dev_attribute {
39894 void *value;
39895 ssize_t(*show) (void *, char *);
39896 ssize_t(*store) (void *, const char *, size_t);
39897-};
39898+} __do_const;
39899
39900 /* Set of show/store abstract level functions for PCI Parity object */
39901 static ssize_t edac_pci_dev_show(struct kobject *kobj, struct attribute *attr,
39902@@ -579,7 +579,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39903 edac_printk(KERN_CRIT, EDAC_PCI,
39904 "Signaled System Error on %s\n",
39905 pci_name(dev));
39906- atomic_inc(&pci_nonparity_count);
39907+ atomic_inc_unchecked(&pci_nonparity_count);
39908 }
39909
39910 if (status & (PCI_STATUS_PARITY)) {
39911@@ -587,7 +587,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39912 "Master Data Parity Error on %s\n",
39913 pci_name(dev));
39914
39915- atomic_inc(&pci_parity_count);
39916+ atomic_inc_unchecked(&pci_parity_count);
39917 }
39918
39919 if (status & (PCI_STATUS_DETECTED_PARITY)) {
39920@@ -595,7 +595,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39921 "Detected Parity Error on %s\n",
39922 pci_name(dev));
39923
39924- atomic_inc(&pci_parity_count);
39925+ atomic_inc_unchecked(&pci_parity_count);
39926 }
39927 }
39928
39929@@ -618,7 +618,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39930 edac_printk(KERN_CRIT, EDAC_PCI, "Bridge "
39931 "Signaled System Error on %s\n",
39932 pci_name(dev));
39933- atomic_inc(&pci_nonparity_count);
39934+ atomic_inc_unchecked(&pci_nonparity_count);
39935 }
39936
39937 if (status & (PCI_STATUS_PARITY)) {
39938@@ -626,7 +626,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39939 "Master Data Parity Error on "
39940 "%s\n", pci_name(dev));
39941
39942- atomic_inc(&pci_parity_count);
39943+ atomic_inc_unchecked(&pci_parity_count);
39944 }
39945
39946 if (status & (PCI_STATUS_DETECTED_PARITY)) {
39947@@ -634,7 +634,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39948 "Detected Parity Error on %s\n",
39949 pci_name(dev));
39950
39951- atomic_inc(&pci_parity_count);
39952+ atomic_inc_unchecked(&pci_parity_count);
39953 }
39954 }
39955 }
39956@@ -672,7 +672,7 @@ void edac_pci_do_parity_check(void)
39957 if (!check_pci_errors)
39958 return;
39959
39960- before_count = atomic_read(&pci_parity_count);
39961+ before_count = atomic_read_unchecked(&pci_parity_count);
39962
39963 /* scan all PCI devices looking for a Parity Error on devices and
39964 * bridges.
39965@@ -684,7 +684,7 @@ void edac_pci_do_parity_check(void)
39966 /* Only if operator has selected panic on PCI Error */
39967 if (edac_pci_get_panic_on_pe()) {
39968 /* If the count is different 'after' from 'before' */
39969- if (before_count != atomic_read(&pci_parity_count))
39970+ if (before_count != atomic_read_unchecked(&pci_parity_count))
39971 panic("EDAC: PCI Parity Error");
39972 }
39973 }
39974diff --git a/drivers/edac/mce_amd.h b/drivers/edac/mce_amd.h
39975index 51b7e3a..aa8a3e8 100644
39976--- a/drivers/edac/mce_amd.h
39977+++ b/drivers/edac/mce_amd.h
39978@@ -77,7 +77,7 @@ struct amd_decoder_ops {
39979 bool (*mc0_mce)(u16, u8);
39980 bool (*mc1_mce)(u16, u8);
39981 bool (*mc2_mce)(u16, u8);
39982-};
39983+} __no_const;
39984
39985 void amd_report_gart_errors(bool);
39986 void amd_register_ecc_decoder(void (*f)(int, struct mce *));
39987diff --git a/drivers/firewire/core-card.c b/drivers/firewire/core-card.c
39988index 57ea7f4..af06b76 100644
39989--- a/drivers/firewire/core-card.c
39990+++ b/drivers/firewire/core-card.c
39991@@ -528,9 +528,9 @@ void fw_card_initialize(struct fw_card *card,
39992 const struct fw_card_driver *driver,
39993 struct device *device)
39994 {
39995- static atomic_t index = ATOMIC_INIT(-1);
39996+ static atomic_unchecked_t index = ATOMIC_INIT(-1);
39997
39998- card->index = atomic_inc_return(&index);
39999+ card->index = atomic_inc_return_unchecked(&index);
40000 card->driver = driver;
40001 card->device = device;
40002 card->current_tlabel = 0;
40003@@ -680,7 +680,7 @@ EXPORT_SYMBOL_GPL(fw_card_release);
40004
40005 void fw_core_remove_card(struct fw_card *card)
40006 {
40007- struct fw_card_driver dummy_driver = dummy_driver_template;
40008+ fw_card_driver_no_const dummy_driver = dummy_driver_template;
40009
40010 card->driver->update_phy_reg(card, 4,
40011 PHY_LINK_ACTIVE | PHY_CONTENDER, 0);
40012diff --git a/drivers/firewire/core-device.c b/drivers/firewire/core-device.c
40013index 2c6d5e1..a2cca6b 100644
40014--- a/drivers/firewire/core-device.c
40015+++ b/drivers/firewire/core-device.c
40016@@ -253,7 +253,7 @@ EXPORT_SYMBOL(fw_device_enable_phys_dma);
40017 struct config_rom_attribute {
40018 struct device_attribute attr;
40019 u32 key;
40020-};
40021+} __do_const;
40022
40023 static ssize_t show_immediate(struct device *dev,
40024 struct device_attribute *dattr, char *buf)
40025diff --git a/drivers/firewire/core-transaction.c b/drivers/firewire/core-transaction.c
40026index eb6935c..3cc2bfa 100644
40027--- a/drivers/firewire/core-transaction.c
40028+++ b/drivers/firewire/core-transaction.c
40029@@ -38,6 +38,7 @@
40030 #include <linux/timer.h>
40031 #include <linux/types.h>
40032 #include <linux/workqueue.h>
40033+#include <linux/sched.h>
40034
40035 #include <asm/byteorder.h>
40036
40037diff --git a/drivers/firewire/core.h b/drivers/firewire/core.h
40038index c98764a..551b520 100644
40039--- a/drivers/firewire/core.h
40040+++ b/drivers/firewire/core.h
40041@@ -111,6 +111,7 @@ struct fw_card_driver {
40042
40043 int (*stop_iso)(struct fw_iso_context *ctx);
40044 };
40045+typedef struct fw_card_driver __no_const fw_card_driver_no_const;
40046
40047 void fw_card_initialize(struct fw_card *card,
40048 const struct fw_card_driver *driver, struct device *device);
40049diff --git a/drivers/firewire/ohci.c b/drivers/firewire/ohci.c
40050index 8db6632..9bbc8ca 100644
40051--- a/drivers/firewire/ohci.c
40052+++ b/drivers/firewire/ohci.c
40053@@ -2049,10 +2049,12 @@ static void bus_reset_work(struct work_struct *work)
40054 be32_to_cpu(ohci->next_header));
40055 }
40056
40057+#ifndef CONFIG_GRKERNSEC
40058 if (param_remote_dma) {
40059 reg_write(ohci, OHCI1394_PhyReqFilterHiSet, ~0);
40060 reg_write(ohci, OHCI1394_PhyReqFilterLoSet, ~0);
40061 }
40062+#endif
40063
40064 spin_unlock_irq(&ohci->lock);
40065
40066@@ -2584,8 +2586,10 @@ static int ohci_enable_phys_dma(struct fw_card *card,
40067 unsigned long flags;
40068 int n, ret = 0;
40069
40070+#ifndef CONFIG_GRKERNSEC
40071 if (param_remote_dma)
40072 return 0;
40073+#endif
40074
40075 /*
40076 * FIXME: Make sure this bitmask is cleared when we clear the busReset
40077diff --git a/drivers/firmware/dmi-id.c b/drivers/firmware/dmi-id.c
40078index 94a58a0..f5eba42 100644
40079--- a/drivers/firmware/dmi-id.c
40080+++ b/drivers/firmware/dmi-id.c
40081@@ -16,7 +16,7 @@
40082 struct dmi_device_attribute{
40083 struct device_attribute dev_attr;
40084 int field;
40085-};
40086+} __do_const;
40087 #define to_dmi_dev_attr(_dev_attr) \
40088 container_of(_dev_attr, struct dmi_device_attribute, dev_attr)
40089
40090diff --git a/drivers/firmware/dmi_scan.c b/drivers/firmware/dmi_scan.c
40091index 17afc51..0ef90cd 100644
40092--- a/drivers/firmware/dmi_scan.c
40093+++ b/drivers/firmware/dmi_scan.c
40094@@ -835,7 +835,7 @@ int dmi_walk(void (*decode)(const struct dmi_header *, void *),
40095 if (buf == NULL)
40096 return -1;
40097
40098- dmi_table(buf, dmi_len, dmi_num, decode, private_data);
40099+ dmi_table((char __force_kernel *)buf, dmi_len, dmi_num, decode, private_data);
40100
40101 dmi_unmap(buf);
40102 return 0;
40103diff --git a/drivers/firmware/efi/cper.c b/drivers/firmware/efi/cper.c
40104index 1491dd4..aa910db 100644
40105--- a/drivers/firmware/efi/cper.c
40106+++ b/drivers/firmware/efi/cper.c
40107@@ -41,12 +41,12 @@
40108 */
40109 u64 cper_next_record_id(void)
40110 {
40111- static atomic64_t seq;
40112+ static atomic64_unchecked_t seq;
40113
40114- if (!atomic64_read(&seq))
40115- atomic64_set(&seq, ((u64)get_seconds()) << 32);
40116+ if (!atomic64_read_unchecked(&seq))
40117+ atomic64_set_unchecked(&seq, ((u64)get_seconds()) << 32);
40118
40119- return atomic64_inc_return(&seq);
40120+ return atomic64_inc_return_unchecked(&seq);
40121 }
40122 EXPORT_SYMBOL_GPL(cper_next_record_id);
40123
40124diff --git a/drivers/firmware/efi/efi.c b/drivers/firmware/efi/efi.c
40125index 4753bac..02861a2 100644
40126--- a/drivers/firmware/efi/efi.c
40127+++ b/drivers/firmware/efi/efi.c
40128@@ -120,14 +120,16 @@ static struct attribute_group efi_subsys_attr_group = {
40129 };
40130
40131 static struct efivars generic_efivars;
40132-static struct efivar_operations generic_ops;
40133+static efivar_operations_no_const generic_ops __read_only;
40134
40135 static int generic_ops_register(void)
40136 {
40137- generic_ops.get_variable = efi.get_variable;
40138- generic_ops.set_variable = efi.set_variable;
40139- generic_ops.get_next_variable = efi.get_next_variable;
40140- generic_ops.query_variable_store = efi_query_variable_store;
40141+ pax_open_kernel();
40142+ *(void **)&generic_ops.get_variable = efi.get_variable;
40143+ *(void **)&generic_ops.set_variable = efi.set_variable;
40144+ *(void **)&generic_ops.get_next_variable = efi.get_next_variable;
40145+ *(void **)&generic_ops.query_variable_store = efi_query_variable_store;
40146+ pax_close_kernel();
40147
40148 return efivars_register(&generic_efivars, &generic_ops, efi_kobj);
40149 }
40150diff --git a/drivers/firmware/efi/efivars.c b/drivers/firmware/efi/efivars.c
40151index 3dc2482..7bd2f61 100644
40152--- a/drivers/firmware/efi/efivars.c
40153+++ b/drivers/firmware/efi/efivars.c
40154@@ -456,7 +456,7 @@ efivar_create_sysfs_entry(struct efivar_entry *new_var)
40155 static int
40156 create_efivars_bin_attributes(void)
40157 {
40158- struct bin_attribute *attr;
40159+ bin_attribute_no_const *attr;
40160 int error;
40161
40162 /* new_var */
40163diff --git a/drivers/firmware/google/memconsole.c b/drivers/firmware/google/memconsole.c
40164index 2a90ba6..07f3733 100644
40165--- a/drivers/firmware/google/memconsole.c
40166+++ b/drivers/firmware/google/memconsole.c
40167@@ -147,7 +147,9 @@ static int __init memconsole_init(void)
40168 if (!found_memconsole())
40169 return -ENODEV;
40170
40171- memconsole_bin_attr.size = memconsole_length;
40172+ pax_open_kernel();
40173+ *(size_t *)&memconsole_bin_attr.size = memconsole_length;
40174+ pax_close_kernel();
40175
40176 ret = sysfs_create_bin_file(firmware_kobj, &memconsole_bin_attr);
40177
40178diff --git a/drivers/gpio/gpio-em.c b/drivers/gpio/gpio-em.c
40179index 1e98a98..b444372 100644
40180--- a/drivers/gpio/gpio-em.c
40181+++ b/drivers/gpio/gpio-em.c
40182@@ -278,7 +278,7 @@ static int em_gio_probe(struct platform_device *pdev)
40183 struct em_gio_priv *p;
40184 struct resource *io[2], *irq[2];
40185 struct gpio_chip *gpio_chip;
40186- struct irq_chip *irq_chip;
40187+ irq_chip_no_const *irq_chip;
40188 const char *name = dev_name(&pdev->dev);
40189 int ret;
40190
40191diff --git a/drivers/gpio/gpio-ich.c b/drivers/gpio/gpio-ich.c
40192index f5bf3c3..7baaa59 100644
40193--- a/drivers/gpio/gpio-ich.c
40194+++ b/drivers/gpio/gpio-ich.c
40195@@ -71,7 +71,7 @@ struct ichx_desc {
40196 /* Some chipsets have quirks, let these use their own request/get */
40197 int (*request)(struct gpio_chip *chip, unsigned offset);
40198 int (*get)(struct gpio_chip *chip, unsigned offset);
40199-};
40200+} __do_const;
40201
40202 static struct {
40203 spinlock_t lock;
40204diff --git a/drivers/gpio/gpio-rcar.c b/drivers/gpio/gpio-rcar.c
40205index ca76ce7..68b384b 100644
40206--- a/drivers/gpio/gpio-rcar.c
40207+++ b/drivers/gpio/gpio-rcar.c
40208@@ -355,7 +355,7 @@ static int gpio_rcar_probe(struct platform_device *pdev)
40209 struct gpio_rcar_priv *p;
40210 struct resource *io, *irq;
40211 struct gpio_chip *gpio_chip;
40212- struct irq_chip *irq_chip;
40213+ irq_chip_no_const *irq_chip;
40214 const char *name = dev_name(&pdev->dev);
40215 int ret;
40216
40217diff --git a/drivers/gpio/gpio-vr41xx.c b/drivers/gpio/gpio-vr41xx.c
40218index 9902732..64b62dd 100644
40219--- a/drivers/gpio/gpio-vr41xx.c
40220+++ b/drivers/gpio/gpio-vr41xx.c
40221@@ -204,7 +204,7 @@ static int giu_get_irq(unsigned int irq)
40222 printk(KERN_ERR "spurious GIU interrupt: %04x(%04x),%04x(%04x)\n",
40223 maskl, pendl, maskh, pendh);
40224
40225- atomic_inc(&irq_err_count);
40226+ atomic_inc_unchecked(&irq_err_count);
40227
40228 return -EINVAL;
40229 }
40230diff --git a/drivers/gpu/drm/drm_crtc.c b/drivers/gpu/drm/drm_crtc.c
40231index 3b7d32d..05c2f74 100644
40232--- a/drivers/gpu/drm/drm_crtc.c
40233+++ b/drivers/gpu/drm/drm_crtc.c
40234@@ -3123,7 +3123,7 @@ int drm_mode_getproperty_ioctl(struct drm_device *dev,
40235 goto done;
40236 }
40237
40238- if (copy_to_user(&enum_ptr[copied].name,
40239+ if (copy_to_user(enum_ptr[copied].name,
40240 &prop_enum->name, DRM_PROP_NAME_LEN)) {
40241 ret = -EFAULT;
40242 goto done;
40243diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
40244index 345be03..158368d 100644
40245--- a/drivers/gpu/drm/drm_drv.c
40246+++ b/drivers/gpu/drm/drm_drv.c
40247@@ -233,7 +233,7 @@ module_exit(drm_core_exit);
40248 /**
40249 * Copy and IOCTL return string to user space
40250 */
40251-static int drm_copy_field(char *buf, size_t *buf_len, const char *value)
40252+static int drm_copy_field(char __user *buf, size_t *buf_len, const char *value)
40253 {
40254 int len;
40255
40256@@ -303,7 +303,7 @@ long drm_ioctl(struct file *filp,
40257 struct drm_file *file_priv = filp->private_data;
40258 struct drm_device *dev;
40259 const struct drm_ioctl_desc *ioctl = NULL;
40260- drm_ioctl_t *func;
40261+ drm_ioctl_no_const_t func;
40262 unsigned int nr = DRM_IOCTL_NR(cmd);
40263 int retcode = -EINVAL;
40264 char stack_kdata[128];
40265diff --git a/drivers/gpu/drm/drm_fops.c b/drivers/gpu/drm/drm_fops.c
40266index 7f2af9a..1561914 100644
40267--- a/drivers/gpu/drm/drm_fops.c
40268+++ b/drivers/gpu/drm/drm_fops.c
40269@@ -97,7 +97,7 @@ int drm_open(struct inode *inode, struct file *filp)
40270 if (drm_device_is_unplugged(dev))
40271 return -ENODEV;
40272
40273- if (!dev->open_count++)
40274+ if (local_inc_return(&dev->open_count) == 1)
40275 need_setup = 1;
40276 mutex_lock(&dev->struct_mutex);
40277 old_imapping = inode->i_mapping;
40278@@ -127,7 +127,7 @@ err_undo:
40279 iput(container_of(dev->dev_mapping, struct inode, i_data));
40280 dev->dev_mapping = old_mapping;
40281 mutex_unlock(&dev->struct_mutex);
40282- dev->open_count--;
40283+ local_dec(&dev->open_count);
40284 return retcode;
40285 }
40286 EXPORT_SYMBOL(drm_open);
40287@@ -463,7 +463,7 @@ int drm_release(struct inode *inode, struct file *filp)
40288
40289 mutex_lock(&drm_global_mutex);
40290
40291- DRM_DEBUG("open_count = %d\n", dev->open_count);
40292+ DRM_DEBUG("open_count = %ld\n", local_read(&dev->open_count));
40293
40294 if (dev->driver->preclose)
40295 dev->driver->preclose(dev, file_priv);
40296@@ -472,10 +472,10 @@ int drm_release(struct inode *inode, struct file *filp)
40297 * Begin inline drm_release
40298 */
40299
40300- DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %d\n",
40301+ DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %ld\n",
40302 task_pid_nr(current),
40303 (long)old_encode_dev(file_priv->minor->device),
40304- dev->open_count);
40305+ local_read(&dev->open_count));
40306
40307 /* Release any auth tokens that might point to this file_priv,
40308 (do that under the drm_global_mutex) */
40309@@ -573,7 +573,7 @@ int drm_release(struct inode *inode, struct file *filp)
40310 * End inline drm_release
40311 */
40312
40313- if (!--dev->open_count) {
40314+ if (local_dec_and_test(&dev->open_count)) {
40315 retcode = drm_lastclose(dev);
40316 if (drm_device_is_unplugged(dev))
40317 drm_put_dev(dev);
40318diff --git a/drivers/gpu/drm/drm_global.c b/drivers/gpu/drm/drm_global.c
40319index 3d2e91c..d31c4c9 100644
40320--- a/drivers/gpu/drm/drm_global.c
40321+++ b/drivers/gpu/drm/drm_global.c
40322@@ -36,7 +36,7 @@
40323 struct drm_global_item {
40324 struct mutex mutex;
40325 void *object;
40326- int refcount;
40327+ atomic_t refcount;
40328 };
40329
40330 static struct drm_global_item glob[DRM_GLOBAL_NUM];
40331@@ -49,7 +49,7 @@ void drm_global_init(void)
40332 struct drm_global_item *item = &glob[i];
40333 mutex_init(&item->mutex);
40334 item->object = NULL;
40335- item->refcount = 0;
40336+ atomic_set(&item->refcount, 0);
40337 }
40338 }
40339
40340@@ -59,7 +59,7 @@ void drm_global_release(void)
40341 for (i = 0; i < DRM_GLOBAL_NUM; ++i) {
40342 struct drm_global_item *item = &glob[i];
40343 BUG_ON(item->object != NULL);
40344- BUG_ON(item->refcount != 0);
40345+ BUG_ON(atomic_read(&item->refcount) != 0);
40346 }
40347 }
40348
40349@@ -69,7 +69,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
40350 struct drm_global_item *item = &glob[ref->global_type];
40351
40352 mutex_lock(&item->mutex);
40353- if (item->refcount == 0) {
40354+ if (atomic_read(&item->refcount) == 0) {
40355 item->object = kzalloc(ref->size, GFP_KERNEL);
40356 if (unlikely(item->object == NULL)) {
40357 ret = -ENOMEM;
40358@@ -82,7 +82,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
40359 goto out_err;
40360
40361 }
40362- ++item->refcount;
40363+ atomic_inc(&item->refcount);
40364 ref->object = item->object;
40365 mutex_unlock(&item->mutex);
40366 return 0;
40367@@ -98,9 +98,9 @@ void drm_global_item_unref(struct drm_global_reference *ref)
40368 struct drm_global_item *item = &glob[ref->global_type];
40369
40370 mutex_lock(&item->mutex);
40371- BUG_ON(item->refcount == 0);
40372+ BUG_ON(atomic_read(&item->refcount) == 0);
40373 BUG_ON(ref->object != item->object);
40374- if (--item->refcount == 0) {
40375+ if (atomic_dec_and_test(&item->refcount)) {
40376 ref->release(ref);
40377 item->object = NULL;
40378 }
40379diff --git a/drivers/gpu/drm/drm_info.c b/drivers/gpu/drm/drm_info.c
40380index 7473035..a48b9c5 100644
40381--- a/drivers/gpu/drm/drm_info.c
40382+++ b/drivers/gpu/drm/drm_info.c
40383@@ -75,10 +75,13 @@ int drm_vm_info(struct seq_file *m, void *data)
40384 struct drm_local_map *map;
40385 struct drm_map_list *r_list;
40386
40387- /* Hardcoded from _DRM_FRAME_BUFFER,
40388- _DRM_REGISTERS, _DRM_SHM, _DRM_AGP, and
40389- _DRM_SCATTER_GATHER and _DRM_CONSISTENT */
40390- const char *types[] = { "FB", "REG", "SHM", "AGP", "SG", "PCI" };
40391+ static const char * const types[] = {
40392+ [_DRM_FRAME_BUFFER] = "FB",
40393+ [_DRM_REGISTERS] = "REG",
40394+ [_DRM_SHM] = "SHM",
40395+ [_DRM_AGP] = "AGP",
40396+ [_DRM_SCATTER_GATHER] = "SG",
40397+ [_DRM_CONSISTENT] = "PCI"};
40398 const char *type;
40399 int i;
40400
40401@@ -89,7 +92,7 @@ int drm_vm_info(struct seq_file *m, void *data)
40402 map = r_list->map;
40403 if (!map)
40404 continue;
40405- if (map->type < 0 || map->type > 5)
40406+ if (map->type >= ARRAY_SIZE(types))
40407 type = "??";
40408 else
40409 type = types[map->type];
40410@@ -261,7 +264,11 @@ int drm_vma_info(struct seq_file *m, void *data)
40411 vma->vm_flags & VM_MAYSHARE ? 's' : 'p',
40412 vma->vm_flags & VM_LOCKED ? 'l' : '-',
40413 vma->vm_flags & VM_IO ? 'i' : '-',
40414+#ifdef CONFIG_GRKERNSEC_HIDESYM
40415+ 0);
40416+#else
40417 vma->vm_pgoff);
40418+#endif
40419
40420 #if defined(__i386__)
40421 pgprot = pgprot_val(vma->vm_page_prot);
40422diff --git a/drivers/gpu/drm/drm_ioc32.c b/drivers/gpu/drm/drm_ioc32.c
40423index 2f4c4343..dd12cd2 100644
40424--- a/drivers/gpu/drm/drm_ioc32.c
40425+++ b/drivers/gpu/drm/drm_ioc32.c
40426@@ -457,7 +457,7 @@ static int compat_drm_infobufs(struct file *file, unsigned int cmd,
40427 request = compat_alloc_user_space(nbytes);
40428 if (!access_ok(VERIFY_WRITE, request, nbytes))
40429 return -EFAULT;
40430- list = (struct drm_buf_desc *) (request + 1);
40431+ list = (struct drm_buf_desc __user *) (request + 1);
40432
40433 if (__put_user(count, &request->count)
40434 || __put_user(list, &request->list))
40435@@ -518,7 +518,7 @@ static int compat_drm_mapbufs(struct file *file, unsigned int cmd,
40436 request = compat_alloc_user_space(nbytes);
40437 if (!access_ok(VERIFY_WRITE, request, nbytes))
40438 return -EFAULT;
40439- list = (struct drm_buf_pub *) (request + 1);
40440+ list = (struct drm_buf_pub __user *) (request + 1);
40441
40442 if (__put_user(count, &request->count)
40443 || __put_user(list, &request->list))
40444@@ -1016,7 +1016,7 @@ static int compat_drm_wait_vblank(struct file *file, unsigned int cmd,
40445 return 0;
40446 }
40447
40448-drm_ioctl_compat_t *drm_compat_ioctls[] = {
40449+drm_ioctl_compat_t drm_compat_ioctls[] = {
40450 [DRM_IOCTL_NR(DRM_IOCTL_VERSION32)] = compat_drm_version,
40451 [DRM_IOCTL_NR(DRM_IOCTL_GET_UNIQUE32)] = compat_drm_getunique,
40452 [DRM_IOCTL_NR(DRM_IOCTL_GET_MAP32)] = compat_drm_getmap,
40453@@ -1062,7 +1062,6 @@ drm_ioctl_compat_t *drm_compat_ioctls[] = {
40454 long drm_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
40455 {
40456 unsigned int nr = DRM_IOCTL_NR(cmd);
40457- drm_ioctl_compat_t *fn;
40458 int ret;
40459
40460 /* Assume that ioctls without an explicit compat routine will just
40461@@ -1072,10 +1071,8 @@ long drm_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
40462 if (nr >= ARRAY_SIZE(drm_compat_ioctls))
40463 return drm_ioctl(filp, cmd, arg);
40464
40465- fn = drm_compat_ioctls[nr];
40466-
40467- if (fn != NULL)
40468- ret = (*fn) (filp, cmd, arg);
40469+ if (drm_compat_ioctls[nr] != NULL)
40470+ ret = (*drm_compat_ioctls[nr]) (filp, cmd, arg);
40471 else
40472 ret = drm_ioctl(filp, cmd, arg);
40473
40474diff --git a/drivers/gpu/drm/drm_stub.c b/drivers/gpu/drm/drm_stub.c
40475index 98a33c580..8fd1c2b 100644
40476--- a/drivers/gpu/drm/drm_stub.c
40477+++ b/drivers/gpu/drm/drm_stub.c
40478@@ -409,7 +409,7 @@ void drm_unplug_dev(struct drm_device *dev)
40479
40480 drm_device_set_unplugged(dev);
40481
40482- if (dev->open_count == 0) {
40483+ if (local_read(&dev->open_count) == 0) {
40484 drm_put_dev(dev);
40485 }
40486 mutex_unlock(&drm_global_mutex);
40487diff --git a/drivers/gpu/drm/drm_sysfs.c b/drivers/gpu/drm/drm_sysfs.c
40488index c22c309..ae758c3 100644
40489--- a/drivers/gpu/drm/drm_sysfs.c
40490+++ b/drivers/gpu/drm/drm_sysfs.c
40491@@ -505,7 +505,7 @@ static void drm_sysfs_release(struct device *dev)
40492 */
40493 int drm_sysfs_device_add(struct drm_minor *minor)
40494 {
40495- char *minor_str;
40496+ const char *minor_str;
40497 int r;
40498
40499 if (minor->type == DRM_MINOR_CONTROL)
40500diff --git a/drivers/gpu/drm/i810/i810_drv.h b/drivers/gpu/drm/i810/i810_drv.h
40501index d4d16ed..8fb0b51 100644
40502--- a/drivers/gpu/drm/i810/i810_drv.h
40503+++ b/drivers/gpu/drm/i810/i810_drv.h
40504@@ -108,8 +108,8 @@ typedef struct drm_i810_private {
40505 int page_flipping;
40506
40507 wait_queue_head_t irq_queue;
40508- atomic_t irq_received;
40509- atomic_t irq_emitted;
40510+ atomic_unchecked_t irq_received;
40511+ atomic_unchecked_t irq_emitted;
40512
40513 int front_offset;
40514 } drm_i810_private_t;
40515diff --git a/drivers/gpu/drm/i915/i915_debugfs.c b/drivers/gpu/drm/i915/i915_debugfs.c
40516index b2b46c5..feb9fe7 100644
40517--- a/drivers/gpu/drm/i915/i915_debugfs.c
40518+++ b/drivers/gpu/drm/i915/i915_debugfs.c
40519@@ -713,7 +713,7 @@ static int i915_interrupt_info(struct seq_file *m, void *data)
40520 I915_READ(GTIMR));
40521 }
40522 seq_printf(m, "Interrupts received: %d\n",
40523- atomic_read(&dev_priv->irq_received));
40524+ atomic_read_unchecked(&dev_priv->irq_received));
40525 for_each_ring(ring, dev_priv, i) {
40526 if (INTEL_INFO(dev)->gen >= 6) {
40527 seq_printf(m,
40528diff --git a/drivers/gpu/drm/i915/i915_dma.c b/drivers/gpu/drm/i915/i915_dma.c
40529index 15a74f9..4278889 100644
40530--- a/drivers/gpu/drm/i915/i915_dma.c
40531+++ b/drivers/gpu/drm/i915/i915_dma.c
40532@@ -1273,7 +1273,7 @@ static bool i915_switcheroo_can_switch(struct pci_dev *pdev)
40533 bool can_switch;
40534
40535 spin_lock(&dev->count_lock);
40536- can_switch = (dev->open_count == 0);
40537+ can_switch = (local_read(&dev->open_count) == 0);
40538 spin_unlock(&dev->count_lock);
40539 return can_switch;
40540 }
40541diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
40542index df77e20..d3fda9f 100644
40543--- a/drivers/gpu/drm/i915/i915_drv.h
40544+++ b/drivers/gpu/drm/i915/i915_drv.h
40545@@ -1361,7 +1361,7 @@ typedef struct drm_i915_private {
40546 drm_dma_handle_t *status_page_dmah;
40547 struct resource mch_res;
40548
40549- atomic_t irq_received;
40550+ atomic_unchecked_t irq_received;
40551
40552 /* protects the irq masks */
40553 spinlock_t irq_lock;
40554diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
40555index d269ecf..6d857bc 100644
40556--- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c
40557+++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
40558@@ -860,9 +860,9 @@ i915_gem_check_execbuffer(struct drm_i915_gem_execbuffer2 *exec)
40559
40560 static int
40561 validate_exec_list(struct drm_i915_gem_exec_object2 *exec,
40562- int count)
40563+ unsigned int count)
40564 {
40565- int i;
40566+ unsigned int i;
40567 unsigned relocs_total = 0;
40568 unsigned relocs_max = UINT_MAX / sizeof(struct drm_i915_gem_relocation_entry);
40569
40570diff --git a/drivers/gpu/drm/i915/i915_ioc32.c b/drivers/gpu/drm/i915/i915_ioc32.c
40571index 3c59584..500f2e9 100644
40572--- a/drivers/gpu/drm/i915/i915_ioc32.c
40573+++ b/drivers/gpu/drm/i915/i915_ioc32.c
40574@@ -181,7 +181,7 @@ static int compat_i915_alloc(struct file *file, unsigned int cmd,
40575 (unsigned long)request);
40576 }
40577
40578-static drm_ioctl_compat_t *i915_compat_ioctls[] = {
40579+static drm_ioctl_compat_t i915_compat_ioctls[] = {
40580 [DRM_I915_BATCHBUFFER] = compat_i915_batchbuffer,
40581 [DRM_I915_CMDBUFFER] = compat_i915_cmdbuffer,
40582 [DRM_I915_GETPARAM] = compat_i915_getparam,
40583@@ -202,18 +202,15 @@ static drm_ioctl_compat_t *i915_compat_ioctls[] = {
40584 long i915_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
40585 {
40586 unsigned int nr = DRM_IOCTL_NR(cmd);
40587- drm_ioctl_compat_t *fn = NULL;
40588 int ret;
40589
40590 if (nr < DRM_COMMAND_BASE)
40591 return drm_compat_ioctl(filp, cmd, arg);
40592
40593- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(i915_compat_ioctls))
40594- fn = i915_compat_ioctls[nr - DRM_COMMAND_BASE];
40595-
40596- if (fn != NULL)
40597+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(i915_compat_ioctls)) {
40598+ drm_ioctl_compat_t fn = i915_compat_ioctls[nr - DRM_COMMAND_BASE];
40599 ret = (*fn) (filp, cmd, arg);
40600- else
40601+ } else
40602 ret = drm_ioctl(filp, cmd, arg);
40603
40604 return ret;
40605diff --git a/drivers/gpu/drm/i915/i915_irq.c b/drivers/gpu/drm/i915/i915_irq.c
40606index d554169..f4426bb 100644
40607--- a/drivers/gpu/drm/i915/i915_irq.c
40608+++ b/drivers/gpu/drm/i915/i915_irq.c
40609@@ -1438,7 +1438,7 @@ static irqreturn_t valleyview_irq_handler(int irq, void *arg)
40610 int pipe;
40611 u32 pipe_stats[I915_MAX_PIPES];
40612
40613- atomic_inc(&dev_priv->irq_received);
40614+ atomic_inc_unchecked(&dev_priv->irq_received);
40615
40616 while (true) {
40617 iir = I915_READ(VLV_IIR);
40618@@ -1751,7 +1751,7 @@ static irqreturn_t ironlake_irq_handler(int irq, void *arg)
40619 u32 de_iir, gt_iir, de_ier, sde_ier = 0;
40620 irqreturn_t ret = IRQ_NONE;
40621
40622- atomic_inc(&dev_priv->irq_received);
40623+ atomic_inc_unchecked(&dev_priv->irq_received);
40624
40625 /* We get interrupts on unclaimed registers, so check for this before we
40626 * do any I915_{READ,WRITE}. */
40627@@ -1821,7 +1821,7 @@ static irqreturn_t gen8_irq_handler(int irq, void *arg)
40628 uint32_t tmp = 0;
40629 enum pipe pipe;
40630
40631- atomic_inc(&dev_priv->irq_received);
40632+ atomic_inc_unchecked(&dev_priv->irq_received);
40633
40634 master_ctl = I915_READ(GEN8_MASTER_IRQ);
40635 master_ctl &= ~GEN8_MASTER_IRQ_CONTROL;
40636@@ -2645,7 +2645,7 @@ static void ironlake_irq_preinstall(struct drm_device *dev)
40637 {
40638 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
40639
40640- atomic_set(&dev_priv->irq_received, 0);
40641+ atomic_set_unchecked(&dev_priv->irq_received, 0);
40642
40643 I915_WRITE(HWSTAM, 0xeffe);
40644
40645@@ -2663,7 +2663,7 @@ static void valleyview_irq_preinstall(struct drm_device *dev)
40646 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
40647 int pipe;
40648
40649- atomic_set(&dev_priv->irq_received, 0);
40650+ atomic_set_unchecked(&dev_priv->irq_received, 0);
40651
40652 /* VLV magic */
40653 I915_WRITE(VLV_IMR, 0);
40654@@ -2694,7 +2694,7 @@ static void gen8_irq_preinstall(struct drm_device *dev)
40655 struct drm_i915_private *dev_priv = dev->dev_private;
40656 int pipe;
40657
40658- atomic_set(&dev_priv->irq_received, 0);
40659+ atomic_set_unchecked(&dev_priv->irq_received, 0);
40660
40661 I915_WRITE(GEN8_MASTER_IRQ, 0);
40662 POSTING_READ(GEN8_MASTER_IRQ);
40663@@ -3018,7 +3018,7 @@ static void gen8_irq_uninstall(struct drm_device *dev)
40664 if (!dev_priv)
40665 return;
40666
40667- atomic_set(&dev_priv->irq_received, 0);
40668+ atomic_set_unchecked(&dev_priv->irq_received, 0);
40669
40670 I915_WRITE(GEN8_MASTER_IRQ, 0);
40671
40672@@ -3112,7 +3112,7 @@ static void i8xx_irq_preinstall(struct drm_device * dev)
40673 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
40674 int pipe;
40675
40676- atomic_set(&dev_priv->irq_received, 0);
40677+ atomic_set_unchecked(&dev_priv->irq_received, 0);
40678
40679 for_each_pipe(pipe)
40680 I915_WRITE(PIPESTAT(pipe), 0);
40681@@ -3198,7 +3198,7 @@ static irqreturn_t i8xx_irq_handler(int irq, void *arg)
40682 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
40683 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
40684
40685- atomic_inc(&dev_priv->irq_received);
40686+ atomic_inc_unchecked(&dev_priv->irq_received);
40687
40688 iir = I915_READ16(IIR);
40689 if (iir == 0)
40690@@ -3277,7 +3277,7 @@ static void i915_irq_preinstall(struct drm_device * dev)
40691 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
40692 int pipe;
40693
40694- atomic_set(&dev_priv->irq_received, 0);
40695+ atomic_set_unchecked(&dev_priv->irq_received, 0);
40696
40697 if (I915_HAS_HOTPLUG(dev)) {
40698 I915_WRITE(PORT_HOTPLUG_EN, 0);
40699@@ -3384,7 +3384,7 @@ static irqreturn_t i915_irq_handler(int irq, void *arg)
40700 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
40701 int pipe, ret = IRQ_NONE;
40702
40703- atomic_inc(&dev_priv->irq_received);
40704+ atomic_inc_unchecked(&dev_priv->irq_received);
40705
40706 iir = I915_READ(IIR);
40707 do {
40708@@ -3511,7 +3511,7 @@ static void i965_irq_preinstall(struct drm_device * dev)
40709 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
40710 int pipe;
40711
40712- atomic_set(&dev_priv->irq_received, 0);
40713+ atomic_set_unchecked(&dev_priv->irq_received, 0);
40714
40715 I915_WRITE(PORT_HOTPLUG_EN, 0);
40716 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
40717@@ -3627,7 +3627,7 @@ static irqreturn_t i965_irq_handler(int irq, void *arg)
40718 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
40719 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
40720
40721- atomic_inc(&dev_priv->irq_received);
40722+ atomic_inc_unchecked(&dev_priv->irq_received);
40723
40724 iir = I915_READ(IIR);
40725
40726diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
40727index 9b8a7c7..60f6003 100644
40728--- a/drivers/gpu/drm/i915/intel_display.c
40729+++ b/drivers/gpu/drm/i915/intel_display.c
40730@@ -10776,13 +10776,13 @@ struct intel_quirk {
40731 int subsystem_vendor;
40732 int subsystem_device;
40733 void (*hook)(struct drm_device *dev);
40734-};
40735+} __do_const;
40736
40737 /* For systems that don't have a meaningful PCI subdevice/subvendor ID */
40738 struct intel_dmi_quirk {
40739 void (*hook)(struct drm_device *dev);
40740 const struct dmi_system_id (*dmi_id_list)[];
40741-};
40742+} __do_const;
40743
40744 static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
40745 {
40746@@ -10790,18 +10790,20 @@ static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
40747 return 1;
40748 }
40749
40750-static const struct intel_dmi_quirk intel_dmi_quirks[] = {
40751+static const struct dmi_system_id intel_dmi_quirks_table[] = {
40752 {
40753- .dmi_id_list = &(const struct dmi_system_id[]) {
40754- {
40755- .callback = intel_dmi_reverse_brightness,
40756- .ident = "NCR Corporation",
40757- .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
40758- DMI_MATCH(DMI_PRODUCT_NAME, ""),
40759- },
40760- },
40761- { } /* terminating entry */
40762+ .callback = intel_dmi_reverse_brightness,
40763+ .ident = "NCR Corporation",
40764+ .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
40765+ DMI_MATCH(DMI_PRODUCT_NAME, ""),
40766 },
40767+ },
40768+ { } /* terminating entry */
40769+};
40770+
40771+static const struct intel_dmi_quirk intel_dmi_quirks[] = {
40772+ {
40773+ .dmi_id_list = &intel_dmi_quirks_table,
40774 .hook = quirk_invert_brightness,
40775 },
40776 };
40777diff --git a/drivers/gpu/drm/mga/mga_drv.h b/drivers/gpu/drm/mga/mga_drv.h
40778index fe45321..836fdca 100644
40779--- a/drivers/gpu/drm/mga/mga_drv.h
40780+++ b/drivers/gpu/drm/mga/mga_drv.h
40781@@ -120,9 +120,9 @@ typedef struct drm_mga_private {
40782 u32 clear_cmd;
40783 u32 maccess;
40784
40785- atomic_t vbl_received; /**< Number of vblanks received. */
40786+ atomic_unchecked_t vbl_received; /**< Number of vblanks received. */
40787 wait_queue_head_t fence_queue;
40788- atomic_t last_fence_retired;
40789+ atomic_unchecked_t last_fence_retired;
40790 u32 next_fence_to_post;
40791
40792 unsigned int fb_cpp;
40793diff --git a/drivers/gpu/drm/mga/mga_ioc32.c b/drivers/gpu/drm/mga/mga_ioc32.c
40794index 86b4bb8..ae237ad 100644
40795--- a/drivers/gpu/drm/mga/mga_ioc32.c
40796+++ b/drivers/gpu/drm/mga/mga_ioc32.c
40797@@ -190,7 +190,7 @@ static int compat_mga_dma_bootstrap(struct file *file, unsigned int cmd,
40798 return 0;
40799 }
40800
40801-drm_ioctl_compat_t *mga_compat_ioctls[] = {
40802+drm_ioctl_compat_t mga_compat_ioctls[] = {
40803 [DRM_MGA_INIT] = compat_mga_init,
40804 [DRM_MGA_GETPARAM] = compat_mga_getparam,
40805 [DRM_MGA_DMA_BOOTSTRAP] = compat_mga_dma_bootstrap,
40806@@ -208,18 +208,15 @@ drm_ioctl_compat_t *mga_compat_ioctls[] = {
40807 long mga_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
40808 {
40809 unsigned int nr = DRM_IOCTL_NR(cmd);
40810- drm_ioctl_compat_t *fn = NULL;
40811 int ret;
40812
40813 if (nr < DRM_COMMAND_BASE)
40814 return drm_compat_ioctl(filp, cmd, arg);
40815
40816- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(mga_compat_ioctls))
40817- fn = mga_compat_ioctls[nr - DRM_COMMAND_BASE];
40818-
40819- if (fn != NULL)
40820+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(mga_compat_ioctls)) {
40821+ drm_ioctl_compat_t fn = mga_compat_ioctls[nr - DRM_COMMAND_BASE];
40822 ret = (*fn) (filp, cmd, arg);
40823- else
40824+ } else
40825 ret = drm_ioctl(filp, cmd, arg);
40826
40827 return ret;
40828diff --git a/drivers/gpu/drm/mga/mga_irq.c b/drivers/gpu/drm/mga/mga_irq.c
40829index 1b071b8..de8601a 100644
40830--- a/drivers/gpu/drm/mga/mga_irq.c
40831+++ b/drivers/gpu/drm/mga/mga_irq.c
40832@@ -43,7 +43,7 @@ u32 mga_get_vblank_counter(struct drm_device *dev, int crtc)
40833 if (crtc != 0)
40834 return 0;
40835
40836- return atomic_read(&dev_priv->vbl_received);
40837+ return atomic_read_unchecked(&dev_priv->vbl_received);
40838 }
40839
40840
40841@@ -59,7 +59,7 @@ irqreturn_t mga_driver_irq_handler(int irq, void *arg)
40842 /* VBLANK interrupt */
40843 if (status & MGA_VLINEPEN) {
40844 MGA_WRITE(MGA_ICLEAR, MGA_VLINEICLR);
40845- atomic_inc(&dev_priv->vbl_received);
40846+ atomic_inc_unchecked(&dev_priv->vbl_received);
40847 drm_handle_vblank(dev, 0);
40848 handled = 1;
40849 }
40850@@ -78,7 +78,7 @@ irqreturn_t mga_driver_irq_handler(int irq, void *arg)
40851 if ((prim_start & ~0x03) != (prim_end & ~0x03))
40852 MGA_WRITE(MGA_PRIMEND, prim_end);
40853
40854- atomic_inc(&dev_priv->last_fence_retired);
40855+ atomic_inc_unchecked(&dev_priv->last_fence_retired);
40856 wake_up(&dev_priv->fence_queue);
40857 handled = 1;
40858 }
40859@@ -129,7 +129,7 @@ int mga_driver_fence_wait(struct drm_device *dev, unsigned int *sequence)
40860 * using fences.
40861 */
40862 DRM_WAIT_ON(ret, dev_priv->fence_queue, 3 * HZ,
40863- (((cur_fence = atomic_read(&dev_priv->last_fence_retired))
40864+ (((cur_fence = atomic_read_unchecked(&dev_priv->last_fence_retired))
40865 - *sequence) <= (1 << 23)));
40866
40867 *sequence = cur_fence;
40868diff --git a/drivers/gpu/drm/nouveau/nouveau_bios.c b/drivers/gpu/drm/nouveau/nouveau_bios.c
40869index 4c3feaa..26391ce 100644
40870--- a/drivers/gpu/drm/nouveau/nouveau_bios.c
40871+++ b/drivers/gpu/drm/nouveau/nouveau_bios.c
40872@@ -965,7 +965,7 @@ static int parse_bit_tmds_tbl_entry(struct drm_device *dev, struct nvbios *bios,
40873 struct bit_table {
40874 const char id;
40875 int (* const parse_fn)(struct drm_device *, struct nvbios *, struct bit_entry *);
40876-};
40877+} __no_const;
40878
40879 #define BIT_TABLE(id, funcid) ((struct bit_table){ id, parse_bit_##funcid##_tbl_entry })
40880
40881diff --git a/drivers/gpu/drm/nouveau/nouveau_drm.h b/drivers/gpu/drm/nouveau/nouveau_drm.h
40882index 23ca7a5..b6c955d 100644
40883--- a/drivers/gpu/drm/nouveau/nouveau_drm.h
40884+++ b/drivers/gpu/drm/nouveau/nouveau_drm.h
40885@@ -97,7 +97,6 @@ struct nouveau_drm {
40886 struct drm_global_reference mem_global_ref;
40887 struct ttm_bo_global_ref bo_global_ref;
40888 struct ttm_bo_device bdev;
40889- atomic_t validate_sequence;
40890 int (*move)(struct nouveau_channel *,
40891 struct ttm_buffer_object *,
40892 struct ttm_mem_reg *, struct ttm_mem_reg *);
40893diff --git a/drivers/gpu/drm/nouveau/nouveau_ioc32.c b/drivers/gpu/drm/nouveau/nouveau_ioc32.c
40894index c1a7e5a..38b8539 100644
40895--- a/drivers/gpu/drm/nouveau/nouveau_ioc32.c
40896+++ b/drivers/gpu/drm/nouveau/nouveau_ioc32.c
40897@@ -50,7 +50,7 @@ long nouveau_compat_ioctl(struct file *filp, unsigned int cmd,
40898 unsigned long arg)
40899 {
40900 unsigned int nr = DRM_IOCTL_NR(cmd);
40901- drm_ioctl_compat_t *fn = NULL;
40902+ drm_ioctl_compat_t fn = NULL;
40903 int ret;
40904
40905 if (nr < DRM_COMMAND_BASE)
40906diff --git a/drivers/gpu/drm/nouveau/nouveau_ttm.c b/drivers/gpu/drm/nouveau/nouveau_ttm.c
40907index d45d50d..72a5dd2 100644
40908--- a/drivers/gpu/drm/nouveau/nouveau_ttm.c
40909+++ b/drivers/gpu/drm/nouveau/nouveau_ttm.c
40910@@ -130,11 +130,11 @@ nouveau_vram_manager_debug(struct ttm_mem_type_manager *man, const char *prefix)
40911 }
40912
40913 const struct ttm_mem_type_manager_func nouveau_vram_manager = {
40914- nouveau_vram_manager_init,
40915- nouveau_vram_manager_fini,
40916- nouveau_vram_manager_new,
40917- nouveau_vram_manager_del,
40918- nouveau_vram_manager_debug
40919+ .init = nouveau_vram_manager_init,
40920+ .takedown = nouveau_vram_manager_fini,
40921+ .get_node = nouveau_vram_manager_new,
40922+ .put_node = nouveau_vram_manager_del,
40923+ .debug = nouveau_vram_manager_debug
40924 };
40925
40926 static int
40927@@ -199,11 +199,11 @@ nouveau_gart_manager_debug(struct ttm_mem_type_manager *man, const char *prefix)
40928 }
40929
40930 const struct ttm_mem_type_manager_func nouveau_gart_manager = {
40931- nouveau_gart_manager_init,
40932- nouveau_gart_manager_fini,
40933- nouveau_gart_manager_new,
40934- nouveau_gart_manager_del,
40935- nouveau_gart_manager_debug
40936+ .init = nouveau_gart_manager_init,
40937+ .takedown = nouveau_gart_manager_fini,
40938+ .get_node = nouveau_gart_manager_new,
40939+ .put_node = nouveau_gart_manager_del,
40940+ .debug = nouveau_gart_manager_debug
40941 };
40942
40943 #include <core/subdev/vm/nv04.h>
40944@@ -271,11 +271,11 @@ nv04_gart_manager_debug(struct ttm_mem_type_manager *man, const char *prefix)
40945 }
40946
40947 const struct ttm_mem_type_manager_func nv04_gart_manager = {
40948- nv04_gart_manager_init,
40949- nv04_gart_manager_fini,
40950- nv04_gart_manager_new,
40951- nv04_gart_manager_del,
40952- nv04_gart_manager_debug
40953+ .init = nv04_gart_manager_init,
40954+ .takedown = nv04_gart_manager_fini,
40955+ .get_node = nv04_gart_manager_new,
40956+ .put_node = nv04_gart_manager_del,
40957+ .debug = nv04_gart_manager_debug
40958 };
40959
40960 int
40961diff --git a/drivers/gpu/drm/nouveau/nouveau_vga.c b/drivers/gpu/drm/nouveau/nouveau_vga.c
40962index 471347e..5adc6b9 100644
40963--- a/drivers/gpu/drm/nouveau/nouveau_vga.c
40964+++ b/drivers/gpu/drm/nouveau/nouveau_vga.c
40965@@ -67,7 +67,7 @@ nouveau_switcheroo_can_switch(struct pci_dev *pdev)
40966 bool can_switch;
40967
40968 spin_lock(&dev->count_lock);
40969- can_switch = (dev->open_count == 0);
40970+ can_switch = (local_read(&dev->open_count) == 0);
40971 spin_unlock(&dev->count_lock);
40972 return can_switch;
40973 }
40974diff --git a/drivers/gpu/drm/qxl/qxl_cmd.c b/drivers/gpu/drm/qxl/qxl_cmd.c
40975index eb89653..613cf71 100644
40976--- a/drivers/gpu/drm/qxl/qxl_cmd.c
40977+++ b/drivers/gpu/drm/qxl/qxl_cmd.c
40978@@ -285,27 +285,27 @@ static int wait_for_io_cmd_user(struct qxl_device *qdev, uint8_t val, long port,
40979 int ret;
40980
40981 mutex_lock(&qdev->async_io_mutex);
40982- irq_num = atomic_read(&qdev->irq_received_io_cmd);
40983+ irq_num = atomic_read_unchecked(&qdev->irq_received_io_cmd);
40984 if (qdev->last_sent_io_cmd > irq_num) {
40985 if (intr)
40986 ret = wait_event_interruptible_timeout(qdev->io_cmd_event,
40987- atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40988+ atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40989 else
40990 ret = wait_event_timeout(qdev->io_cmd_event,
40991- atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40992+ atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40993 /* 0 is timeout, just bail the "hw" has gone away */
40994 if (ret <= 0)
40995 goto out;
40996- irq_num = atomic_read(&qdev->irq_received_io_cmd);
40997+ irq_num = atomic_read_unchecked(&qdev->irq_received_io_cmd);
40998 }
40999 outb(val, addr);
41000 qdev->last_sent_io_cmd = irq_num + 1;
41001 if (intr)
41002 ret = wait_event_interruptible_timeout(qdev->io_cmd_event,
41003- atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
41004+ atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
41005 else
41006 ret = wait_event_timeout(qdev->io_cmd_event,
41007- atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
41008+ atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
41009 out:
41010 if (ret > 0)
41011 ret = 0;
41012diff --git a/drivers/gpu/drm/qxl/qxl_debugfs.c b/drivers/gpu/drm/qxl/qxl_debugfs.c
41013index c3c2bbd..bc3c0fb 100644
41014--- a/drivers/gpu/drm/qxl/qxl_debugfs.c
41015+++ b/drivers/gpu/drm/qxl/qxl_debugfs.c
41016@@ -42,10 +42,10 @@ qxl_debugfs_irq_received(struct seq_file *m, void *data)
41017 struct drm_info_node *node = (struct drm_info_node *) m->private;
41018 struct qxl_device *qdev = node->minor->dev->dev_private;
41019
41020- seq_printf(m, "%d\n", atomic_read(&qdev->irq_received));
41021- seq_printf(m, "%d\n", atomic_read(&qdev->irq_received_display));
41022- seq_printf(m, "%d\n", atomic_read(&qdev->irq_received_cursor));
41023- seq_printf(m, "%d\n", atomic_read(&qdev->irq_received_io_cmd));
41024+ seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received));
41025+ seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received_display));
41026+ seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received_cursor));
41027+ seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received_io_cmd));
41028 seq_printf(m, "%d\n", qdev->irq_received_error);
41029 return 0;
41030 }
41031diff --git a/drivers/gpu/drm/qxl/qxl_drv.h b/drivers/gpu/drm/qxl/qxl_drv.h
41032index 36ed40b..0397633 100644
41033--- a/drivers/gpu/drm/qxl/qxl_drv.h
41034+++ b/drivers/gpu/drm/qxl/qxl_drv.h
41035@@ -290,10 +290,10 @@ struct qxl_device {
41036 unsigned int last_sent_io_cmd;
41037
41038 /* interrupt handling */
41039- atomic_t irq_received;
41040- atomic_t irq_received_display;
41041- atomic_t irq_received_cursor;
41042- atomic_t irq_received_io_cmd;
41043+ atomic_unchecked_t irq_received;
41044+ atomic_unchecked_t irq_received_display;
41045+ atomic_unchecked_t irq_received_cursor;
41046+ atomic_unchecked_t irq_received_io_cmd;
41047 unsigned irq_received_error;
41048 wait_queue_head_t display_event;
41049 wait_queue_head_t cursor_event;
41050diff --git a/drivers/gpu/drm/qxl/qxl_ioctl.c b/drivers/gpu/drm/qxl/qxl_ioctl.c
41051index 0bb86e6..d41416d 100644
41052--- a/drivers/gpu/drm/qxl/qxl_ioctl.c
41053+++ b/drivers/gpu/drm/qxl/qxl_ioctl.c
41054@@ -181,7 +181,7 @@ static int qxl_process_single_command(struct qxl_device *qdev,
41055
41056 /* TODO copy slow path code from i915 */
41057 fb_cmd = qxl_bo_kmap_atomic_page(qdev, cmd_bo, (release->release_offset & PAGE_SIZE));
41058- 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);
41059+ 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);
41060
41061 {
41062 struct qxl_drawable *draw = fb_cmd;
41063@@ -201,7 +201,7 @@ static int qxl_process_single_command(struct qxl_device *qdev,
41064 struct drm_qxl_reloc reloc;
41065
41066 if (copy_from_user(&reloc,
41067- &((struct drm_qxl_reloc *)(uintptr_t)cmd->relocs)[i],
41068+ &((struct drm_qxl_reloc __force_user *)(uintptr_t)cmd->relocs)[i],
41069 sizeof(reloc))) {
41070 ret = -EFAULT;
41071 goto out_free_bos;
41072@@ -294,10 +294,10 @@ static int qxl_execbuffer_ioctl(struct drm_device *dev, void *data,
41073
41074 for (cmd_num = 0; cmd_num < execbuffer->commands_num; ++cmd_num) {
41075
41076- struct drm_qxl_command *commands =
41077- (struct drm_qxl_command *)(uintptr_t)execbuffer->commands;
41078+ struct drm_qxl_command __user *commands =
41079+ (struct drm_qxl_command __user *)(uintptr_t)execbuffer->commands;
41080
41081- if (copy_from_user(&user_cmd, &commands[cmd_num],
41082+ if (copy_from_user(&user_cmd, (struct drm_qxl_command __force_user *)&commands[cmd_num],
41083 sizeof(user_cmd)))
41084 return -EFAULT;
41085
41086diff --git a/drivers/gpu/drm/qxl/qxl_irq.c b/drivers/gpu/drm/qxl/qxl_irq.c
41087index 28f84b4..fb3e224 100644
41088--- a/drivers/gpu/drm/qxl/qxl_irq.c
41089+++ b/drivers/gpu/drm/qxl/qxl_irq.c
41090@@ -33,19 +33,19 @@ irqreturn_t qxl_irq_handler(int irq, void *arg)
41091
41092 pending = xchg(&qdev->ram_header->int_pending, 0);
41093
41094- atomic_inc(&qdev->irq_received);
41095+ atomic_inc_unchecked(&qdev->irq_received);
41096
41097 if (pending & QXL_INTERRUPT_DISPLAY) {
41098- atomic_inc(&qdev->irq_received_display);
41099+ atomic_inc_unchecked(&qdev->irq_received_display);
41100 wake_up_all(&qdev->display_event);
41101 qxl_queue_garbage_collect(qdev, false);
41102 }
41103 if (pending & QXL_INTERRUPT_CURSOR) {
41104- atomic_inc(&qdev->irq_received_cursor);
41105+ atomic_inc_unchecked(&qdev->irq_received_cursor);
41106 wake_up_all(&qdev->cursor_event);
41107 }
41108 if (pending & QXL_INTERRUPT_IO_CMD) {
41109- atomic_inc(&qdev->irq_received_io_cmd);
41110+ atomic_inc_unchecked(&qdev->irq_received_io_cmd);
41111 wake_up_all(&qdev->io_cmd_event);
41112 }
41113 if (pending & QXL_INTERRUPT_ERROR) {
41114@@ -82,10 +82,10 @@ int qxl_irq_init(struct qxl_device *qdev)
41115 init_waitqueue_head(&qdev->io_cmd_event);
41116 INIT_WORK(&qdev->client_monitors_config_work,
41117 qxl_client_monitors_config_work_func);
41118- atomic_set(&qdev->irq_received, 0);
41119- atomic_set(&qdev->irq_received_display, 0);
41120- atomic_set(&qdev->irq_received_cursor, 0);
41121- atomic_set(&qdev->irq_received_io_cmd, 0);
41122+ atomic_set_unchecked(&qdev->irq_received, 0);
41123+ atomic_set_unchecked(&qdev->irq_received_display, 0);
41124+ atomic_set_unchecked(&qdev->irq_received_cursor, 0);
41125+ atomic_set_unchecked(&qdev->irq_received_io_cmd, 0);
41126 qdev->irq_received_error = 0;
41127 ret = drm_irq_install(qdev->ddev);
41128 qdev->ram_header->int_mask = QXL_INTERRUPT_MASK;
41129diff --git a/drivers/gpu/drm/qxl/qxl_ttm.c b/drivers/gpu/drm/qxl/qxl_ttm.c
41130index c7e7e65..7dddd4d 100644
41131--- a/drivers/gpu/drm/qxl/qxl_ttm.c
41132+++ b/drivers/gpu/drm/qxl/qxl_ttm.c
41133@@ -103,7 +103,7 @@ static void qxl_ttm_global_fini(struct qxl_device *qdev)
41134 }
41135 }
41136
41137-static struct vm_operations_struct qxl_ttm_vm_ops;
41138+static vm_operations_struct_no_const qxl_ttm_vm_ops __read_only;
41139 static const struct vm_operations_struct *ttm_vm_ops;
41140
41141 static int qxl_ttm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
41142@@ -147,8 +147,10 @@ int qxl_mmap(struct file *filp, struct vm_area_struct *vma)
41143 return r;
41144 if (unlikely(ttm_vm_ops == NULL)) {
41145 ttm_vm_ops = vma->vm_ops;
41146+ pax_open_kernel();
41147 qxl_ttm_vm_ops = *ttm_vm_ops;
41148 qxl_ttm_vm_ops.fault = &qxl_ttm_fault;
41149+ pax_close_kernel();
41150 }
41151 vma->vm_ops = &qxl_ttm_vm_ops;
41152 return 0;
41153@@ -560,25 +562,23 @@ static int qxl_mm_dump_table(struct seq_file *m, void *data)
41154 static int qxl_ttm_debugfs_init(struct qxl_device *qdev)
41155 {
41156 #if defined(CONFIG_DEBUG_FS)
41157- static struct drm_info_list qxl_mem_types_list[QXL_DEBUGFS_MEM_TYPES];
41158- static char qxl_mem_types_names[QXL_DEBUGFS_MEM_TYPES][32];
41159- unsigned i;
41160+ static struct drm_info_list qxl_mem_types_list[QXL_DEBUGFS_MEM_TYPES] = {
41161+ {
41162+ .name = "qxl_mem_mm",
41163+ .show = &qxl_mm_dump_table,
41164+ },
41165+ {
41166+ .name = "qxl_surf_mm",
41167+ .show = &qxl_mm_dump_table,
41168+ }
41169+ };
41170
41171- for (i = 0; i < QXL_DEBUGFS_MEM_TYPES; i++) {
41172- if (i == 0)
41173- sprintf(qxl_mem_types_names[i], "qxl_mem_mm");
41174- else
41175- sprintf(qxl_mem_types_names[i], "qxl_surf_mm");
41176- qxl_mem_types_list[i].name = qxl_mem_types_names[i];
41177- qxl_mem_types_list[i].show = &qxl_mm_dump_table;
41178- qxl_mem_types_list[i].driver_features = 0;
41179- if (i == 0)
41180- qxl_mem_types_list[i].data = qdev->mman.bdev.man[TTM_PL_VRAM].priv;
41181- else
41182- qxl_mem_types_list[i].data = qdev->mman.bdev.man[TTM_PL_PRIV0].priv;
41183+ pax_open_kernel();
41184+ *(void **)&qxl_mem_types_list[0].data = qdev->mman.bdev.man[TTM_PL_VRAM].priv;
41185+ *(void **)&qxl_mem_types_list[1].data = qdev->mman.bdev.man[TTM_PL_PRIV0].priv;
41186+ pax_close_kernel();
41187
41188- }
41189- return qxl_debugfs_add_files(qdev, qxl_mem_types_list, i);
41190+ return qxl_debugfs_add_files(qdev, qxl_mem_types_list, QXL_DEBUGFS_MEM_TYPES);
41191 #else
41192 return 0;
41193 #endif
41194diff --git a/drivers/gpu/drm/r128/r128_cce.c b/drivers/gpu/drm/r128/r128_cce.c
41195index 59459fe..be26b31 100644
41196--- a/drivers/gpu/drm/r128/r128_cce.c
41197+++ b/drivers/gpu/drm/r128/r128_cce.c
41198@@ -377,7 +377,7 @@ static int r128_do_init_cce(struct drm_device *dev, drm_r128_init_t *init)
41199
41200 /* GH: Simple idle check.
41201 */
41202- atomic_set(&dev_priv->idle_count, 0);
41203+ atomic_set_unchecked(&dev_priv->idle_count, 0);
41204
41205 /* We don't support anything other than bus-mastering ring mode,
41206 * but the ring can be in either AGP or PCI space for the ring
41207diff --git a/drivers/gpu/drm/r128/r128_drv.h b/drivers/gpu/drm/r128/r128_drv.h
41208index 5bf3f5f..7000661 100644
41209--- a/drivers/gpu/drm/r128/r128_drv.h
41210+++ b/drivers/gpu/drm/r128/r128_drv.h
41211@@ -90,14 +90,14 @@ typedef struct drm_r128_private {
41212 int is_pci;
41213 unsigned long cce_buffers_offset;
41214
41215- atomic_t idle_count;
41216+ atomic_unchecked_t idle_count;
41217
41218 int page_flipping;
41219 int current_page;
41220 u32 crtc_offset;
41221 u32 crtc_offset_cntl;
41222
41223- atomic_t vbl_received;
41224+ atomic_unchecked_t vbl_received;
41225
41226 u32 color_fmt;
41227 unsigned int front_offset;
41228diff --git a/drivers/gpu/drm/r128/r128_ioc32.c b/drivers/gpu/drm/r128/r128_ioc32.c
41229index b0d0fd3..a6fbbe4 100644
41230--- a/drivers/gpu/drm/r128/r128_ioc32.c
41231+++ b/drivers/gpu/drm/r128/r128_ioc32.c
41232@@ -178,7 +178,7 @@ static int compat_r128_getparam(struct file *file, unsigned int cmd,
41233 return drm_ioctl(file, DRM_IOCTL_R128_GETPARAM, (unsigned long)getparam);
41234 }
41235
41236-drm_ioctl_compat_t *r128_compat_ioctls[] = {
41237+drm_ioctl_compat_t r128_compat_ioctls[] = {
41238 [DRM_R128_INIT] = compat_r128_init,
41239 [DRM_R128_DEPTH] = compat_r128_depth,
41240 [DRM_R128_STIPPLE] = compat_r128_stipple,
41241@@ -197,18 +197,15 @@ drm_ioctl_compat_t *r128_compat_ioctls[] = {
41242 long r128_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
41243 {
41244 unsigned int nr = DRM_IOCTL_NR(cmd);
41245- drm_ioctl_compat_t *fn = NULL;
41246 int ret;
41247
41248 if (nr < DRM_COMMAND_BASE)
41249 return drm_compat_ioctl(filp, cmd, arg);
41250
41251- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(r128_compat_ioctls))
41252- fn = r128_compat_ioctls[nr - DRM_COMMAND_BASE];
41253-
41254- if (fn != NULL)
41255+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(r128_compat_ioctls)) {
41256+ drm_ioctl_compat_t fn = r128_compat_ioctls[nr - DRM_COMMAND_BASE];
41257 ret = (*fn) (filp, cmd, arg);
41258- else
41259+ } else
41260 ret = drm_ioctl(filp, cmd, arg);
41261
41262 return ret;
41263diff --git a/drivers/gpu/drm/r128/r128_irq.c b/drivers/gpu/drm/r128/r128_irq.c
41264index c2ae496..30b5993 100644
41265--- a/drivers/gpu/drm/r128/r128_irq.c
41266+++ b/drivers/gpu/drm/r128/r128_irq.c
41267@@ -41,7 +41,7 @@ u32 r128_get_vblank_counter(struct drm_device *dev, int crtc)
41268 if (crtc != 0)
41269 return 0;
41270
41271- return atomic_read(&dev_priv->vbl_received);
41272+ return atomic_read_unchecked(&dev_priv->vbl_received);
41273 }
41274
41275 irqreturn_t r128_driver_irq_handler(int irq, void *arg)
41276@@ -55,7 +55,7 @@ irqreturn_t r128_driver_irq_handler(int irq, void *arg)
41277 /* VBLANK interrupt */
41278 if (status & R128_CRTC_VBLANK_INT) {
41279 R128_WRITE(R128_GEN_INT_STATUS, R128_CRTC_VBLANK_INT_AK);
41280- atomic_inc(&dev_priv->vbl_received);
41281+ atomic_inc_unchecked(&dev_priv->vbl_received);
41282 drm_handle_vblank(dev, 0);
41283 return IRQ_HANDLED;
41284 }
41285diff --git a/drivers/gpu/drm/r128/r128_state.c b/drivers/gpu/drm/r128/r128_state.c
41286index e806dac..f81d32f 100644
41287--- a/drivers/gpu/drm/r128/r128_state.c
41288+++ b/drivers/gpu/drm/r128/r128_state.c
41289@@ -320,10 +320,10 @@ static void r128_clear_box(drm_r128_private_t *dev_priv,
41290
41291 static void r128_cce_performance_boxes(drm_r128_private_t *dev_priv)
41292 {
41293- if (atomic_read(&dev_priv->idle_count) == 0)
41294+ if (atomic_read_unchecked(&dev_priv->idle_count) == 0)
41295 r128_clear_box(dev_priv, 64, 4, 8, 8, 0, 255, 0);
41296 else
41297- atomic_set(&dev_priv->idle_count, 0);
41298+ atomic_set_unchecked(&dev_priv->idle_count, 0);
41299 }
41300
41301 #endif
41302diff --git a/drivers/gpu/drm/radeon/mkregtable.c b/drivers/gpu/drm/radeon/mkregtable.c
41303index 4a85bb6..aaea819 100644
41304--- a/drivers/gpu/drm/radeon/mkregtable.c
41305+++ b/drivers/gpu/drm/radeon/mkregtable.c
41306@@ -624,14 +624,14 @@ static int parser_auth(struct table *t, const char *filename)
41307 regex_t mask_rex;
41308 regmatch_t match[4];
41309 char buf[1024];
41310- size_t end;
41311+ long end;
41312 int len;
41313 int done = 0;
41314 int r;
41315 unsigned o;
41316 struct offset *offset;
41317 char last_reg_s[10];
41318- int last_reg;
41319+ unsigned long last_reg;
41320
41321 if (regcomp
41322 (&mask_rex, "(0x[0-9a-fA-F]*) *([_a-zA-Z0-9]*)", REG_EXTENDED)) {
41323diff --git a/drivers/gpu/drm/radeon/radeon_device.c b/drivers/gpu/drm/radeon/radeon_device.c
41324index 044bc98..50ced9b 100644
41325--- a/drivers/gpu/drm/radeon/radeon_device.c
41326+++ b/drivers/gpu/drm/radeon/radeon_device.c
41327@@ -1125,7 +1125,7 @@ static bool radeon_switcheroo_can_switch(struct pci_dev *pdev)
41328 bool can_switch;
41329
41330 spin_lock(&dev->count_lock);
41331- can_switch = (dev->open_count == 0);
41332+ can_switch = (local_read(&dev->open_count) == 0);
41333 spin_unlock(&dev->count_lock);
41334 return can_switch;
41335 }
41336diff --git a/drivers/gpu/drm/radeon/radeon_drv.h b/drivers/gpu/drm/radeon/radeon_drv.h
41337index dafd812..1bf20c7 100644
41338--- a/drivers/gpu/drm/radeon/radeon_drv.h
41339+++ b/drivers/gpu/drm/radeon/radeon_drv.h
41340@@ -262,7 +262,7 @@ typedef struct drm_radeon_private {
41341
41342 /* SW interrupt */
41343 wait_queue_head_t swi_queue;
41344- atomic_t swi_emitted;
41345+ atomic_unchecked_t swi_emitted;
41346 int vblank_crtc;
41347 uint32_t irq_enable_reg;
41348 uint32_t r500_disp_irq_reg;
41349diff --git a/drivers/gpu/drm/radeon/radeon_ioc32.c b/drivers/gpu/drm/radeon/radeon_ioc32.c
41350index bdb0f93..5ff558f 100644
41351--- a/drivers/gpu/drm/radeon/radeon_ioc32.c
41352+++ b/drivers/gpu/drm/radeon/radeon_ioc32.c
41353@@ -358,7 +358,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
41354 request = compat_alloc_user_space(sizeof(*request));
41355 if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
41356 || __put_user(req32.param, &request->param)
41357- || __put_user((void __user *)(unsigned long)req32.value,
41358+ || __put_user((unsigned long)req32.value,
41359 &request->value))
41360 return -EFAULT;
41361
41362@@ -368,7 +368,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
41363 #define compat_radeon_cp_setparam NULL
41364 #endif /* X86_64 || IA64 */
41365
41366-static drm_ioctl_compat_t *radeon_compat_ioctls[] = {
41367+static drm_ioctl_compat_t radeon_compat_ioctls[] = {
41368 [DRM_RADEON_CP_INIT] = compat_radeon_cp_init,
41369 [DRM_RADEON_CLEAR] = compat_radeon_cp_clear,
41370 [DRM_RADEON_STIPPLE] = compat_radeon_cp_stipple,
41371@@ -393,18 +393,15 @@ static drm_ioctl_compat_t *radeon_compat_ioctls[] = {
41372 long radeon_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
41373 {
41374 unsigned int nr = DRM_IOCTL_NR(cmd);
41375- drm_ioctl_compat_t *fn = NULL;
41376 int ret;
41377
41378 if (nr < DRM_COMMAND_BASE)
41379 return drm_compat_ioctl(filp, cmd, arg);
41380
41381- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(radeon_compat_ioctls))
41382- fn = radeon_compat_ioctls[nr - DRM_COMMAND_BASE];
41383-
41384- if (fn != NULL)
41385+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(radeon_compat_ioctls)) {
41386+ drm_ioctl_compat_t fn = radeon_compat_ioctls[nr - DRM_COMMAND_BASE];
41387 ret = (*fn) (filp, cmd, arg);
41388- else
41389+ } else
41390 ret = drm_ioctl(filp, cmd, arg);
41391
41392 return ret;
41393diff --git a/drivers/gpu/drm/radeon/radeon_irq.c b/drivers/gpu/drm/radeon/radeon_irq.c
41394index 244b19b..c19226d 100644
41395--- a/drivers/gpu/drm/radeon/radeon_irq.c
41396+++ b/drivers/gpu/drm/radeon/radeon_irq.c
41397@@ -226,8 +226,8 @@ static int radeon_emit_irq(struct drm_device * dev)
41398 unsigned int ret;
41399 RING_LOCALS;
41400
41401- atomic_inc(&dev_priv->swi_emitted);
41402- ret = atomic_read(&dev_priv->swi_emitted);
41403+ atomic_inc_unchecked(&dev_priv->swi_emitted);
41404+ ret = atomic_read_unchecked(&dev_priv->swi_emitted);
41405
41406 BEGIN_RING(4);
41407 OUT_RING_REG(RADEON_LAST_SWI_REG, ret);
41408@@ -353,7 +353,7 @@ int radeon_driver_irq_postinstall(struct drm_device *dev)
41409 drm_radeon_private_t *dev_priv =
41410 (drm_radeon_private_t *) dev->dev_private;
41411
41412- atomic_set(&dev_priv->swi_emitted, 0);
41413+ atomic_set_unchecked(&dev_priv->swi_emitted, 0);
41414 init_waitqueue_head(&dev_priv->swi_queue);
41415
41416 dev->max_vblank_count = 0x001fffff;
41417diff --git a/drivers/gpu/drm/radeon/radeon_state.c b/drivers/gpu/drm/radeon/radeon_state.c
41418index 956ab7f..fbd36d8 100644
41419--- a/drivers/gpu/drm/radeon/radeon_state.c
41420+++ b/drivers/gpu/drm/radeon/radeon_state.c
41421@@ -2168,7 +2168,7 @@ static int radeon_cp_clear(struct drm_device *dev, void *data, struct drm_file *
41422 if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS)
41423 sarea_priv->nbox = RADEON_NR_SAREA_CLIPRECTS;
41424
41425- if (copy_from_user(&depth_boxes, clear->depth_boxes,
41426+ if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS || copy_from_user(&depth_boxes, clear->depth_boxes,
41427 sarea_priv->nbox * sizeof(depth_boxes[0])))
41428 return -EFAULT;
41429
41430@@ -3031,7 +3031,7 @@ static int radeon_cp_getparam(struct drm_device *dev, void *data, struct drm_fil
41431 {
41432 drm_radeon_private_t *dev_priv = dev->dev_private;
41433 drm_radeon_getparam_t *param = data;
41434- int value;
41435+ int value = 0;
41436
41437 DRM_DEBUG("pid=%d\n", DRM_CURRENTPID);
41438
41439diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
41440index 040a2a1..eae4e54 100644
41441--- a/drivers/gpu/drm/radeon/radeon_ttm.c
41442+++ b/drivers/gpu/drm/radeon/radeon_ttm.c
41443@@ -790,7 +790,7 @@ void radeon_ttm_set_active_vram_size(struct radeon_device *rdev, u64 size)
41444 man->size = size >> PAGE_SHIFT;
41445 }
41446
41447-static struct vm_operations_struct radeon_ttm_vm_ops;
41448+static vm_operations_struct_no_const radeon_ttm_vm_ops __read_only;
41449 static const struct vm_operations_struct *ttm_vm_ops = NULL;
41450
41451 static int radeon_ttm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
41452@@ -831,8 +831,10 @@ int radeon_mmap(struct file *filp, struct vm_area_struct *vma)
41453 }
41454 if (unlikely(ttm_vm_ops == NULL)) {
41455 ttm_vm_ops = vma->vm_ops;
41456+ pax_open_kernel();
41457 radeon_ttm_vm_ops = *ttm_vm_ops;
41458 radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
41459+ pax_close_kernel();
41460 }
41461 vma->vm_ops = &radeon_ttm_vm_ops;
41462 return 0;
41463diff --git a/drivers/gpu/drm/tegra/dc.c b/drivers/gpu/drm/tegra/dc.c
41464index 9336006..ce78aa7 100644
41465--- a/drivers/gpu/drm/tegra/dc.c
41466+++ b/drivers/gpu/drm/tegra/dc.c
41467@@ -1057,7 +1057,7 @@ static int tegra_dc_debugfs_init(struct tegra_dc *dc, struct drm_minor *minor)
41468 }
41469
41470 for (i = 0; i < ARRAY_SIZE(debugfs_files); i++)
41471- dc->debugfs_files[i].data = dc;
41472+ *(void **)&dc->debugfs_files[i].data = dc;
41473
41474 err = drm_debugfs_create_files(dc->debugfs_files,
41475 ARRAY_SIZE(debugfs_files),
41476diff --git a/drivers/gpu/drm/tegra/dsi.c b/drivers/gpu/drm/tegra/dsi.c
41477index d452faab..f8cbc6a 100644
41478--- a/drivers/gpu/drm/tegra/dsi.c
41479+++ b/drivers/gpu/drm/tegra/dsi.c
41480@@ -53,7 +53,7 @@ struct tegra_dsi {
41481 struct clk *clk_lp;
41482 struct clk *clk;
41483
41484- struct drm_info_list *debugfs_files;
41485+ drm_info_list_no_const *debugfs_files;
41486 struct drm_minor *minor;
41487 struct dentry *debugfs;
41488
41489diff --git a/drivers/gpu/drm/tegra/hdmi.c b/drivers/gpu/drm/tegra/hdmi.c
41490index 6928015..c9853e7 100644
41491--- a/drivers/gpu/drm/tegra/hdmi.c
41492+++ b/drivers/gpu/drm/tegra/hdmi.c
41493@@ -59,7 +59,7 @@ struct tegra_hdmi {
41494 bool stereo;
41495 bool dvi;
41496
41497- struct drm_info_list *debugfs_files;
41498+ drm_info_list_no_const *debugfs_files;
41499 struct drm_minor *minor;
41500 struct dentry *debugfs;
41501 };
41502diff --git a/drivers/gpu/drm/ttm/ttm_bo_manager.c b/drivers/gpu/drm/ttm/ttm_bo_manager.c
41503index c58eba33..83c2728 100644
41504--- a/drivers/gpu/drm/ttm/ttm_bo_manager.c
41505+++ b/drivers/gpu/drm/ttm/ttm_bo_manager.c
41506@@ -141,10 +141,10 @@ static void ttm_bo_man_debug(struct ttm_mem_type_manager *man,
41507 }
41508
41509 const struct ttm_mem_type_manager_func ttm_bo_manager_func = {
41510- ttm_bo_man_init,
41511- ttm_bo_man_takedown,
41512- ttm_bo_man_get_node,
41513- ttm_bo_man_put_node,
41514- ttm_bo_man_debug
41515+ .init = ttm_bo_man_init,
41516+ .takedown = ttm_bo_man_takedown,
41517+ .get_node = ttm_bo_man_get_node,
41518+ .put_node = ttm_bo_man_put_node,
41519+ .debug = ttm_bo_man_debug
41520 };
41521 EXPORT_SYMBOL(ttm_bo_manager_func);
41522diff --git a/drivers/gpu/drm/ttm/ttm_memory.c b/drivers/gpu/drm/ttm/ttm_memory.c
41523index dbc2def..0a9f710 100644
41524--- a/drivers/gpu/drm/ttm/ttm_memory.c
41525+++ b/drivers/gpu/drm/ttm/ttm_memory.c
41526@@ -264,7 +264,7 @@ static int ttm_mem_init_kernel_zone(struct ttm_mem_global *glob,
41527 zone->glob = glob;
41528 glob->zone_kernel = zone;
41529 ret = kobject_init_and_add(
41530- &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, zone->name);
41531+ &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, "%s", zone->name);
41532 if (unlikely(ret != 0)) {
41533 kobject_put(&zone->kobj);
41534 return ret;
41535@@ -347,7 +347,7 @@ static int ttm_mem_init_dma32_zone(struct ttm_mem_global *glob,
41536 zone->glob = glob;
41537 glob->zone_dma32 = zone;
41538 ret = kobject_init_and_add(
41539- &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, zone->name);
41540+ &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, "%s", zone->name);
41541 if (unlikely(ret != 0)) {
41542 kobject_put(&zone->kobj);
41543 return ret;
41544diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc.c b/drivers/gpu/drm/ttm/ttm_page_alloc.c
41545index 863bef9..cba15cf 100644
41546--- a/drivers/gpu/drm/ttm/ttm_page_alloc.c
41547+++ b/drivers/gpu/drm/ttm/ttm_page_alloc.c
41548@@ -391,9 +391,9 @@ out:
41549 static unsigned long
41550 ttm_pool_shrink_scan(struct shrinker *shrink, struct shrink_control *sc)
41551 {
41552- static atomic_t start_pool = ATOMIC_INIT(0);
41553+ static atomic_unchecked_t start_pool = ATOMIC_INIT(0);
41554 unsigned i;
41555- unsigned pool_offset = atomic_add_return(1, &start_pool);
41556+ unsigned pool_offset = atomic_add_return_unchecked(1, &start_pool);
41557 struct ttm_page_pool *pool;
41558 int shrink_pages = sc->nr_to_scan;
41559 unsigned long freed = 0;
41560diff --git a/drivers/gpu/drm/udl/udl_fb.c b/drivers/gpu/drm/udl/udl_fb.c
41561index dbadd49..1b7457b 100644
41562--- a/drivers/gpu/drm/udl/udl_fb.c
41563+++ b/drivers/gpu/drm/udl/udl_fb.c
41564@@ -367,7 +367,6 @@ static int udl_fb_release(struct fb_info *info, int user)
41565 fb_deferred_io_cleanup(info);
41566 kfree(info->fbdefio);
41567 info->fbdefio = NULL;
41568- info->fbops->fb_mmap = udl_fb_mmap;
41569 }
41570
41571 pr_warn("released /dev/fb%d user=%d count=%d\n",
41572diff --git a/drivers/gpu/drm/via/via_drv.h b/drivers/gpu/drm/via/via_drv.h
41573index ad02732..144f5ed 100644
41574--- a/drivers/gpu/drm/via/via_drv.h
41575+++ b/drivers/gpu/drm/via/via_drv.h
41576@@ -51,7 +51,7 @@ typedef struct drm_via_ring_buffer {
41577 typedef uint32_t maskarray_t[5];
41578
41579 typedef struct drm_via_irq {
41580- atomic_t irq_received;
41581+ atomic_unchecked_t irq_received;
41582 uint32_t pending_mask;
41583 uint32_t enable_mask;
41584 wait_queue_head_t irq_queue;
41585@@ -75,7 +75,7 @@ typedef struct drm_via_private {
41586 struct timeval last_vblank;
41587 int last_vblank_valid;
41588 unsigned usec_per_vblank;
41589- atomic_t vbl_received;
41590+ atomic_unchecked_t vbl_received;
41591 drm_via_state_t hc_state;
41592 char pci_buf[VIA_PCI_BUF_SIZE];
41593 const uint32_t *fire_offsets[VIA_FIRE_BUF_SIZE];
41594diff --git a/drivers/gpu/drm/via/via_irq.c b/drivers/gpu/drm/via/via_irq.c
41595index 1319433..a993b0c 100644
41596--- a/drivers/gpu/drm/via/via_irq.c
41597+++ b/drivers/gpu/drm/via/via_irq.c
41598@@ -101,7 +101,7 @@ u32 via_get_vblank_counter(struct drm_device *dev, int crtc)
41599 if (crtc != 0)
41600 return 0;
41601
41602- return atomic_read(&dev_priv->vbl_received);
41603+ return atomic_read_unchecked(&dev_priv->vbl_received);
41604 }
41605
41606 irqreturn_t via_driver_irq_handler(int irq, void *arg)
41607@@ -116,8 +116,8 @@ irqreturn_t via_driver_irq_handler(int irq, void *arg)
41608
41609 status = VIA_READ(VIA_REG_INTERRUPT);
41610 if (status & VIA_IRQ_VBLANK_PENDING) {
41611- atomic_inc(&dev_priv->vbl_received);
41612- if (!(atomic_read(&dev_priv->vbl_received) & 0x0F)) {
41613+ atomic_inc_unchecked(&dev_priv->vbl_received);
41614+ if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0x0F)) {
41615 do_gettimeofday(&cur_vblank);
41616 if (dev_priv->last_vblank_valid) {
41617 dev_priv->usec_per_vblank =
41618@@ -127,7 +127,7 @@ irqreturn_t via_driver_irq_handler(int irq, void *arg)
41619 dev_priv->last_vblank = cur_vblank;
41620 dev_priv->last_vblank_valid = 1;
41621 }
41622- if (!(atomic_read(&dev_priv->vbl_received) & 0xFF)) {
41623+ if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0xFF)) {
41624 DRM_DEBUG("US per vblank is: %u\n",
41625 dev_priv->usec_per_vblank);
41626 }
41627@@ -137,7 +137,7 @@ irqreturn_t via_driver_irq_handler(int irq, void *arg)
41628
41629 for (i = 0; i < dev_priv->num_irqs; ++i) {
41630 if (status & cur_irq->pending_mask) {
41631- atomic_inc(&cur_irq->irq_received);
41632+ atomic_inc_unchecked(&cur_irq->irq_received);
41633 wake_up(&cur_irq->irq_queue);
41634 handled = 1;
41635 if (dev_priv->irq_map[drm_via_irq_dma0_td] == i)
41636@@ -242,11 +242,11 @@ via_driver_irq_wait(struct drm_device *dev, unsigned int irq, int force_sequence
41637 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * HZ,
41638 ((VIA_READ(masks[irq][2]) & masks[irq][3]) ==
41639 masks[irq][4]));
41640- cur_irq_sequence = atomic_read(&cur_irq->irq_received);
41641+ cur_irq_sequence = atomic_read_unchecked(&cur_irq->irq_received);
41642 } else {
41643 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * HZ,
41644 (((cur_irq_sequence =
41645- atomic_read(&cur_irq->irq_received)) -
41646+ atomic_read_unchecked(&cur_irq->irq_received)) -
41647 *sequence) <= (1 << 23)));
41648 }
41649 *sequence = cur_irq_sequence;
41650@@ -284,7 +284,7 @@ void via_driver_irq_preinstall(struct drm_device *dev)
41651 }
41652
41653 for (i = 0; i < dev_priv->num_irqs; ++i) {
41654- atomic_set(&cur_irq->irq_received, 0);
41655+ atomic_set_unchecked(&cur_irq->irq_received, 0);
41656 cur_irq->enable_mask = dev_priv->irq_masks[i][0];
41657 cur_irq->pending_mask = dev_priv->irq_masks[i][1];
41658 init_waitqueue_head(&cur_irq->irq_queue);
41659@@ -366,7 +366,7 @@ int via_wait_irq(struct drm_device *dev, void *data, struct drm_file *file_priv)
41660 switch (irqwait->request.type & ~VIA_IRQ_FLAGS_MASK) {
41661 case VIA_IRQ_RELATIVE:
41662 irqwait->request.sequence +=
41663- atomic_read(&cur_irq->irq_received);
41664+ atomic_read_unchecked(&cur_irq->irq_received);
41665 irqwait->request.type &= ~_DRM_VBLANK_RELATIVE;
41666 case VIA_IRQ_ABSOLUTE:
41667 break;
41668diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
41669index 0783155..b29e18e 100644
41670--- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
41671+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
41672@@ -437,7 +437,7 @@ struct vmw_private {
41673 * Fencing and IRQs.
41674 */
41675
41676- atomic_t marker_seq;
41677+ atomic_unchecked_t marker_seq;
41678 wait_queue_head_t fence_queue;
41679 wait_queue_head_t fifo_queue;
41680 int fence_queue_waiters; /* Protected by hw_mutex */
41681diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
41682index 6ccd993..618d592 100644
41683--- a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
41684+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
41685@@ -154,7 +154,7 @@ int vmw_fifo_init(struct vmw_private *dev_priv, struct vmw_fifo_state *fifo)
41686 (unsigned int) min,
41687 (unsigned int) fifo->capabilities);
41688
41689- atomic_set(&dev_priv->marker_seq, dev_priv->last_read_seqno);
41690+ atomic_set_unchecked(&dev_priv->marker_seq, dev_priv->last_read_seqno);
41691 iowrite32(dev_priv->last_read_seqno, fifo_mem + SVGA_FIFO_FENCE);
41692 vmw_marker_queue_init(&fifo->marker_queue);
41693 return vmw_fifo_send_fence(dev_priv, &dummy);
41694@@ -372,7 +372,7 @@ void *vmw_fifo_reserve(struct vmw_private *dev_priv, uint32_t bytes)
41695 if (reserveable)
41696 iowrite32(bytes, fifo_mem +
41697 SVGA_FIFO_RESERVED);
41698- return fifo_mem + (next_cmd >> 2);
41699+ return (__le32 __force_kernel *)fifo_mem + (next_cmd >> 2);
41700 } else {
41701 need_bounce = true;
41702 }
41703@@ -492,7 +492,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
41704
41705 fm = vmw_fifo_reserve(dev_priv, bytes);
41706 if (unlikely(fm == NULL)) {
41707- *seqno = atomic_read(&dev_priv->marker_seq);
41708+ *seqno = atomic_read_unchecked(&dev_priv->marker_seq);
41709 ret = -ENOMEM;
41710 (void)vmw_fallback_wait(dev_priv, false, true, *seqno,
41711 false, 3*HZ);
41712@@ -500,7 +500,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
41713 }
41714
41715 do {
41716- *seqno = atomic_add_return(1, &dev_priv->marker_seq);
41717+ *seqno = atomic_add_return_unchecked(1, &dev_priv->marker_seq);
41718 } while (*seqno == 0);
41719
41720 if (!(fifo_state->capabilities & SVGA_FIFO_CAP_FENCE)) {
41721diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c b/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
41722index b1273e8..9c274fd 100644
41723--- a/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
41724+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
41725@@ -164,9 +164,9 @@ static void vmw_gmrid_man_debug(struct ttm_mem_type_manager *man,
41726 }
41727
41728 const struct ttm_mem_type_manager_func vmw_gmrid_manager_func = {
41729- vmw_gmrid_man_init,
41730- vmw_gmrid_man_takedown,
41731- vmw_gmrid_man_get_node,
41732- vmw_gmrid_man_put_node,
41733- vmw_gmrid_man_debug
41734+ .init = vmw_gmrid_man_init,
41735+ .takedown = vmw_gmrid_man_takedown,
41736+ .get_node = vmw_gmrid_man_get_node,
41737+ .put_node = vmw_gmrid_man_put_node,
41738+ .debug = vmw_gmrid_man_debug
41739 };
41740diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c b/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
41741index 47b7094..698ba09 100644
41742--- a/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
41743+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
41744@@ -236,7 +236,7 @@ int vmw_present_ioctl(struct drm_device *dev, void *data,
41745 int ret;
41746
41747 num_clips = arg->num_clips;
41748- clips_ptr = (struct drm_vmw_rect *)(unsigned long)arg->clips_ptr;
41749+ clips_ptr = (struct drm_vmw_rect __user *)(unsigned long)arg->clips_ptr;
41750
41751 if (unlikely(num_clips == 0))
41752 return 0;
41753@@ -320,7 +320,7 @@ int vmw_present_readback_ioctl(struct drm_device *dev, void *data,
41754 int ret;
41755
41756 num_clips = arg->num_clips;
41757- clips_ptr = (struct drm_vmw_rect *)(unsigned long)arg->clips_ptr;
41758+ clips_ptr = (struct drm_vmw_rect __user *)(unsigned long)arg->clips_ptr;
41759
41760 if (unlikely(num_clips == 0))
41761 return 0;
41762diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
41763index 0c42376..6febe77 100644
41764--- a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
41765+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
41766@@ -107,7 +107,7 @@ bool vmw_seqno_passed(struct vmw_private *dev_priv,
41767 * emitted. Then the fence is stale and signaled.
41768 */
41769
41770- ret = ((atomic_read(&dev_priv->marker_seq) - seqno)
41771+ ret = ((atomic_read_unchecked(&dev_priv->marker_seq) - seqno)
41772 > VMW_FENCE_WRAP);
41773
41774 return ret;
41775@@ -138,7 +138,7 @@ int vmw_fallback_wait(struct vmw_private *dev_priv,
41776
41777 if (fifo_idle)
41778 down_read(&fifo_state->rwsem);
41779- signal_seq = atomic_read(&dev_priv->marker_seq);
41780+ signal_seq = atomic_read_unchecked(&dev_priv->marker_seq);
41781 ret = 0;
41782
41783 for (;;) {
41784diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
41785index 8a8725c2..afed796 100644
41786--- a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
41787+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
41788@@ -151,7 +151,7 @@ int vmw_wait_lag(struct vmw_private *dev_priv,
41789 while (!vmw_lag_lt(queue, us)) {
41790 spin_lock(&queue->lock);
41791 if (list_empty(&queue->head))
41792- seqno = atomic_read(&dev_priv->marker_seq);
41793+ seqno = atomic_read_unchecked(&dev_priv->marker_seq);
41794 else {
41795 marker = list_first_entry(&queue->head,
41796 struct vmw_marker, head);
41797diff --git a/drivers/gpu/vga/vga_switcheroo.c b/drivers/gpu/vga/vga_switcheroo.c
41798index ec0ae2d..dc0780b 100644
41799--- a/drivers/gpu/vga/vga_switcheroo.c
41800+++ b/drivers/gpu/vga/vga_switcheroo.c
41801@@ -643,7 +643,7 @@ static int vga_switcheroo_runtime_resume(struct device *dev)
41802
41803 /* this version is for the case where the power switch is separate
41804 to the device being powered down. */
41805-int vga_switcheroo_init_domain_pm_ops(struct device *dev, struct dev_pm_domain *domain)
41806+int vga_switcheroo_init_domain_pm_ops(struct device *dev, dev_pm_domain_no_const *domain)
41807 {
41808 /* copy over all the bus versions */
41809 if (dev->bus && dev->bus->pm) {
41810@@ -688,7 +688,7 @@ static int vga_switcheroo_runtime_resume_hdmi_audio(struct device *dev)
41811 return ret;
41812 }
41813
41814-int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, struct dev_pm_domain *domain)
41815+int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, dev_pm_domain_no_const *domain)
41816 {
41817 /* copy over all the bus versions */
41818 if (dev->bus && dev->bus->pm) {
41819diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
41820index cc32a6f..02a4b1c 100644
41821--- a/drivers/hid/hid-core.c
41822+++ b/drivers/hid/hid-core.c
41823@@ -2421,7 +2421,7 @@ EXPORT_SYMBOL_GPL(hid_ignore);
41824
41825 int hid_add_device(struct hid_device *hdev)
41826 {
41827- static atomic_t id = ATOMIC_INIT(0);
41828+ static atomic_unchecked_t id = ATOMIC_INIT(0);
41829 int ret;
41830
41831 if (WARN_ON(hdev->status & HID_STAT_ADDED))
41832@@ -2455,7 +2455,7 @@ int hid_add_device(struct hid_device *hdev)
41833 /* XXX hack, any other cleaner solution after the driver core
41834 * is converted to allow more than 20 bytes as the device name? */
41835 dev_set_name(&hdev->dev, "%04X:%04X:%04X.%04X", hdev->bus,
41836- hdev->vendor, hdev->product, atomic_inc_return(&id));
41837+ hdev->vendor, hdev->product, atomic_inc_return_unchecked(&id));
41838
41839 hid_debug_register(hdev, dev_name(&hdev->dev));
41840 ret = device_add(&hdev->dev);
41841diff --git a/drivers/hid/hid-wiimote-debug.c b/drivers/hid/hid-wiimote-debug.c
41842index c13fb5b..55a3802 100644
41843--- a/drivers/hid/hid-wiimote-debug.c
41844+++ b/drivers/hid/hid-wiimote-debug.c
41845@@ -66,7 +66,7 @@ static ssize_t wiidebug_eeprom_read(struct file *f, char __user *u, size_t s,
41846 else if (size == 0)
41847 return -EIO;
41848
41849- if (copy_to_user(u, buf, size))
41850+ if (size > sizeof(buf) || copy_to_user(u, buf, size))
41851 return -EFAULT;
41852
41853 *off += size;
41854diff --git a/drivers/hid/uhid.c b/drivers/hid/uhid.c
41855index cedc6da..2c3da2a 100644
41856--- a/drivers/hid/uhid.c
41857+++ b/drivers/hid/uhid.c
41858@@ -47,7 +47,7 @@ struct uhid_device {
41859 struct mutex report_lock;
41860 wait_queue_head_t report_wait;
41861 atomic_t report_done;
41862- atomic_t report_id;
41863+ atomic_unchecked_t report_id;
41864 struct uhid_event report_buf;
41865 };
41866
41867@@ -163,7 +163,7 @@ static int uhid_hid_get_raw(struct hid_device *hid, unsigned char rnum,
41868
41869 spin_lock_irqsave(&uhid->qlock, flags);
41870 ev->type = UHID_FEATURE;
41871- ev->u.feature.id = atomic_inc_return(&uhid->report_id);
41872+ ev->u.feature.id = atomic_inc_return_unchecked(&uhid->report_id);
41873 ev->u.feature.rnum = rnum;
41874 ev->u.feature.rtype = report_type;
41875
41876@@ -446,7 +446,7 @@ static int uhid_dev_feature_answer(struct uhid_device *uhid,
41877 spin_lock_irqsave(&uhid->qlock, flags);
41878
41879 /* id for old report; drop it silently */
41880- if (atomic_read(&uhid->report_id) != ev->u.feature_answer.id)
41881+ if (atomic_read_unchecked(&uhid->report_id) != ev->u.feature_answer.id)
41882 goto unlock;
41883 if (atomic_read(&uhid->report_done))
41884 goto unlock;
41885diff --git a/drivers/hv/channel.c b/drivers/hv/channel.c
41886index 69ea36f..8dbf4bb 100644
41887--- a/drivers/hv/channel.c
41888+++ b/drivers/hv/channel.c
41889@@ -364,8 +364,8 @@ int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer,
41890 int ret = 0;
41891 int t;
41892
41893- next_gpadl_handle = atomic_read(&vmbus_connection.next_gpadl_handle);
41894- atomic_inc(&vmbus_connection.next_gpadl_handle);
41895+ next_gpadl_handle = atomic_read_unchecked(&vmbus_connection.next_gpadl_handle);
41896+ atomic_inc_unchecked(&vmbus_connection.next_gpadl_handle);
41897
41898 ret = create_gpadl_header(kbuffer, size, &msginfo, &msgcount);
41899 if (ret)
41900diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c
41901index bcb4950..61dba6c 100644
41902--- a/drivers/hv/hv.c
41903+++ b/drivers/hv/hv.c
41904@@ -112,7 +112,7 @@ static u64 do_hypercall(u64 control, void *input, void *output)
41905 u64 output_address = (output) ? virt_to_phys(output) : 0;
41906 u32 output_address_hi = output_address >> 32;
41907 u32 output_address_lo = output_address & 0xFFFFFFFF;
41908- void *hypercall_page = hv_context.hypercall_page;
41909+ void *hypercall_page = ktva_ktla(hv_context.hypercall_page);
41910
41911 __asm__ __volatile__ ("call *%8" : "=d"(hv_status_hi),
41912 "=a"(hv_status_lo) : "d" (control_hi),
41913@@ -154,7 +154,7 @@ int hv_init(void)
41914 /* See if the hypercall page is already set */
41915 rdmsrl(HV_X64_MSR_HYPERCALL, hypercall_msr.as_uint64);
41916
41917- virtaddr = __vmalloc(PAGE_SIZE, GFP_KERNEL, PAGE_KERNEL_EXEC);
41918+ virtaddr = __vmalloc(PAGE_SIZE, GFP_KERNEL, PAGE_KERNEL_RX);
41919
41920 if (!virtaddr)
41921 goto cleanup;
41922diff --git a/drivers/hv/hv_balloon.c b/drivers/hv/hv_balloon.c
41923index 7e17a54..a50a33d 100644
41924--- a/drivers/hv/hv_balloon.c
41925+++ b/drivers/hv/hv_balloon.c
41926@@ -464,7 +464,7 @@ MODULE_PARM_DESC(hot_add, "If set attempt memory hot_add");
41927
41928 module_param(pressure_report_delay, uint, (S_IRUGO | S_IWUSR));
41929 MODULE_PARM_DESC(pressure_report_delay, "Delay in secs in reporting pressure");
41930-static atomic_t trans_id = ATOMIC_INIT(0);
41931+static atomic_unchecked_t trans_id = ATOMIC_INIT(0);
41932
41933 static int dm_ring_size = (5 * PAGE_SIZE);
41934
41935@@ -886,7 +886,7 @@ static void hot_add_req(struct work_struct *dummy)
41936 pr_info("Memory hot add failed\n");
41937
41938 dm->state = DM_INITIALIZED;
41939- resp.hdr.trans_id = atomic_inc_return(&trans_id);
41940+ resp.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
41941 vmbus_sendpacket(dm->dev->channel, &resp,
41942 sizeof(struct dm_hot_add_response),
41943 (unsigned long)NULL,
41944@@ -960,7 +960,7 @@ static void post_status(struct hv_dynmem_device *dm)
41945 memset(&status, 0, sizeof(struct dm_status));
41946 status.hdr.type = DM_STATUS_REPORT;
41947 status.hdr.size = sizeof(struct dm_status);
41948- status.hdr.trans_id = atomic_inc_return(&trans_id);
41949+ status.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
41950
41951 /*
41952 * The host expects the guest to report free memory.
41953@@ -980,7 +980,7 @@ static void post_status(struct hv_dynmem_device *dm)
41954 * send the status. This can happen if we were interrupted
41955 * after we picked our transaction ID.
41956 */
41957- if (status.hdr.trans_id != atomic_read(&trans_id))
41958+ if (status.hdr.trans_id != atomic_read_unchecked(&trans_id))
41959 return;
41960
41961 vmbus_sendpacket(dm->dev->channel, &status,
41962@@ -1108,7 +1108,7 @@ static void balloon_up(struct work_struct *dummy)
41963 */
41964
41965 do {
41966- bl_resp->hdr.trans_id = atomic_inc_return(&trans_id);
41967+ bl_resp->hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
41968 ret = vmbus_sendpacket(dm_device.dev->channel,
41969 bl_resp,
41970 bl_resp->hdr.size,
41971@@ -1152,7 +1152,7 @@ static void balloon_down(struct hv_dynmem_device *dm,
41972
41973 memset(&resp, 0, sizeof(struct dm_unballoon_response));
41974 resp.hdr.type = DM_UNBALLOON_RESPONSE;
41975- resp.hdr.trans_id = atomic_inc_return(&trans_id);
41976+ resp.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
41977 resp.hdr.size = sizeof(struct dm_unballoon_response);
41978
41979 vmbus_sendpacket(dm_device.dev->channel, &resp,
41980@@ -1215,7 +1215,7 @@ static void version_resp(struct hv_dynmem_device *dm,
41981 memset(&version_req, 0, sizeof(struct dm_version_request));
41982 version_req.hdr.type = DM_VERSION_REQUEST;
41983 version_req.hdr.size = sizeof(struct dm_version_request);
41984- version_req.hdr.trans_id = atomic_inc_return(&trans_id);
41985+ version_req.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
41986 version_req.version.version = DYNMEM_PROTOCOL_VERSION_WIN7;
41987 version_req.is_last_attempt = 1;
41988
41989@@ -1385,7 +1385,7 @@ static int balloon_probe(struct hv_device *dev,
41990 memset(&version_req, 0, sizeof(struct dm_version_request));
41991 version_req.hdr.type = DM_VERSION_REQUEST;
41992 version_req.hdr.size = sizeof(struct dm_version_request);
41993- version_req.hdr.trans_id = atomic_inc_return(&trans_id);
41994+ version_req.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
41995 version_req.version.version = DYNMEM_PROTOCOL_VERSION_WIN8;
41996 version_req.is_last_attempt = 0;
41997
41998@@ -1416,7 +1416,7 @@ static int balloon_probe(struct hv_device *dev,
41999 memset(&cap_msg, 0, sizeof(struct dm_capabilities));
42000 cap_msg.hdr.type = DM_CAPABILITIES_REPORT;
42001 cap_msg.hdr.size = sizeof(struct dm_capabilities);
42002- cap_msg.hdr.trans_id = atomic_inc_return(&trans_id);
42003+ cap_msg.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
42004
42005 cap_msg.caps.cap_bits.balloon = 1;
42006 cap_msg.caps.cap_bits.hot_add = 1;
42007diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h
42008index e055176..c22ff1f 100644
42009--- a/drivers/hv/hyperv_vmbus.h
42010+++ b/drivers/hv/hyperv_vmbus.h
42011@@ -602,7 +602,7 @@ enum vmbus_connect_state {
42012 struct vmbus_connection {
42013 enum vmbus_connect_state conn_state;
42014
42015- atomic_t next_gpadl_handle;
42016+ atomic_unchecked_t next_gpadl_handle;
42017
42018 /*
42019 * Represents channel interrupts. Each bit position represents a
42020diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
42021index 077bb1b..d433d74 100644
42022--- a/drivers/hv/vmbus_drv.c
42023+++ b/drivers/hv/vmbus_drv.c
42024@@ -844,10 +844,10 @@ int vmbus_device_register(struct hv_device *child_device_obj)
42025 {
42026 int ret = 0;
42027
42028- static atomic_t device_num = ATOMIC_INIT(0);
42029+ static atomic_unchecked_t device_num = ATOMIC_INIT(0);
42030
42031 dev_set_name(&child_device_obj->device, "vmbus_0_%d",
42032- atomic_inc_return(&device_num));
42033+ atomic_inc_return_unchecked(&device_num));
42034
42035 child_device_obj->device.bus = &hv_bus;
42036 child_device_obj->device.parent = &hv_acpi_dev->dev;
42037diff --git a/drivers/hwmon/acpi_power_meter.c b/drivers/hwmon/acpi_power_meter.c
42038index 579bdf9..75118b5 100644
42039--- a/drivers/hwmon/acpi_power_meter.c
42040+++ b/drivers/hwmon/acpi_power_meter.c
42041@@ -116,7 +116,7 @@ struct sensor_template {
42042 struct device_attribute *devattr,
42043 const char *buf, size_t count);
42044 int index;
42045-};
42046+} __do_const;
42047
42048 /* Averaging interval */
42049 static int update_avg_interval(struct acpi_power_meter_resource *resource)
42050@@ -631,7 +631,7 @@ static int register_attrs(struct acpi_power_meter_resource *resource,
42051 struct sensor_template *attrs)
42052 {
42053 struct device *dev = &resource->acpi_dev->dev;
42054- struct sensor_device_attribute *sensors =
42055+ sensor_device_attribute_no_const *sensors =
42056 &resource->sensors[resource->num_sensors];
42057 int res = 0;
42058
42059diff --git a/drivers/hwmon/applesmc.c b/drivers/hwmon/applesmc.c
42060index 3288f13..71cfb4e 100644
42061--- a/drivers/hwmon/applesmc.c
42062+++ b/drivers/hwmon/applesmc.c
42063@@ -1106,7 +1106,7 @@ static int applesmc_create_nodes(struct applesmc_node_group *groups, int num)
42064 {
42065 struct applesmc_node_group *grp;
42066 struct applesmc_dev_attr *node;
42067- struct attribute *attr;
42068+ attribute_no_const *attr;
42069 int ret, i;
42070
42071 for (grp = groups; grp->format; grp++) {
42072diff --git a/drivers/hwmon/asus_atk0110.c b/drivers/hwmon/asus_atk0110.c
42073index ae208f6..48b6c5b 100644
42074--- a/drivers/hwmon/asus_atk0110.c
42075+++ b/drivers/hwmon/asus_atk0110.c
42076@@ -147,10 +147,10 @@ MODULE_DEVICE_TABLE(acpi, atk_ids);
42077 struct atk_sensor_data {
42078 struct list_head list;
42079 struct atk_data *data;
42080- struct device_attribute label_attr;
42081- struct device_attribute input_attr;
42082- struct device_attribute limit1_attr;
42083- struct device_attribute limit2_attr;
42084+ device_attribute_no_const label_attr;
42085+ device_attribute_no_const input_attr;
42086+ device_attribute_no_const limit1_attr;
42087+ device_attribute_no_const limit2_attr;
42088 char label_attr_name[ATTR_NAME_SIZE];
42089 char input_attr_name[ATTR_NAME_SIZE];
42090 char limit1_attr_name[ATTR_NAME_SIZE];
42091@@ -270,7 +270,7 @@ static ssize_t atk_name_show(struct device *dev,
42092 static struct device_attribute atk_name_attr =
42093 __ATTR(name, 0444, atk_name_show, NULL);
42094
42095-static void atk_init_attribute(struct device_attribute *attr, char *name,
42096+static void atk_init_attribute(device_attribute_no_const *attr, char *name,
42097 sysfs_show_func show)
42098 {
42099 sysfs_attr_init(&attr->attr);
42100diff --git a/drivers/hwmon/coretemp.c b/drivers/hwmon/coretemp.c
42101index bbb0b0d..9fe1332 100644
42102--- a/drivers/hwmon/coretemp.c
42103+++ b/drivers/hwmon/coretemp.c
42104@@ -823,7 +823,7 @@ static int coretemp_cpu_callback(struct notifier_block *nfb,
42105 return NOTIFY_OK;
42106 }
42107
42108-static struct notifier_block coretemp_cpu_notifier __refdata = {
42109+static struct notifier_block coretemp_cpu_notifier = {
42110 .notifier_call = coretemp_cpu_callback,
42111 };
42112
42113diff --git a/drivers/hwmon/ibmaem.c b/drivers/hwmon/ibmaem.c
42114index 632f1dc..57e6a58 100644
42115--- a/drivers/hwmon/ibmaem.c
42116+++ b/drivers/hwmon/ibmaem.c
42117@@ -926,7 +926,7 @@ static int aem_register_sensors(struct aem_data *data,
42118 struct aem_rw_sensor_template *rw)
42119 {
42120 struct device *dev = &data->pdev->dev;
42121- struct sensor_device_attribute *sensors = data->sensors;
42122+ sensor_device_attribute_no_const *sensors = data->sensors;
42123 int err;
42124
42125 /* Set up read-only sensors */
42126diff --git a/drivers/hwmon/iio_hwmon.c b/drivers/hwmon/iio_hwmon.c
42127index 708081b..fe2d4ab 100644
42128--- a/drivers/hwmon/iio_hwmon.c
42129+++ b/drivers/hwmon/iio_hwmon.c
42130@@ -73,7 +73,7 @@ static int iio_hwmon_probe(struct platform_device *pdev)
42131 {
42132 struct device *dev = &pdev->dev;
42133 struct iio_hwmon_state *st;
42134- struct sensor_device_attribute *a;
42135+ sensor_device_attribute_no_const *a;
42136 int ret, i;
42137 int in_i = 1, temp_i = 1, curr_i = 1;
42138 enum iio_chan_type type;
42139diff --git a/drivers/hwmon/nct6775.c b/drivers/hwmon/nct6775.c
42140index 38d5a63..cf2c2ea 100644
42141--- a/drivers/hwmon/nct6775.c
42142+++ b/drivers/hwmon/nct6775.c
42143@@ -944,10 +944,10 @@ static struct attribute_group *
42144 nct6775_create_attr_group(struct device *dev, struct sensor_template_group *tg,
42145 int repeat)
42146 {
42147- struct attribute_group *group;
42148+ attribute_group_no_const *group;
42149 struct sensor_device_attr_u *su;
42150- struct sensor_device_attribute *a;
42151- struct sensor_device_attribute_2 *a2;
42152+ sensor_device_attribute_no_const *a;
42153+ sensor_device_attribute_2_no_const *a2;
42154 struct attribute **attrs;
42155 struct sensor_device_template **t;
42156 int i, count;
42157diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_core.c
42158index 291d11f..3f0dbbd 100644
42159--- a/drivers/hwmon/pmbus/pmbus_core.c
42160+++ b/drivers/hwmon/pmbus/pmbus_core.c
42161@@ -783,7 +783,7 @@ static int pmbus_add_attribute(struct pmbus_data *data, struct attribute *attr)
42162 return 0;
42163 }
42164
42165-static void pmbus_dev_attr_init(struct device_attribute *dev_attr,
42166+static void pmbus_dev_attr_init(device_attribute_no_const *dev_attr,
42167 const char *name,
42168 umode_t mode,
42169 ssize_t (*show)(struct device *dev,
42170@@ -800,7 +800,7 @@ static void pmbus_dev_attr_init(struct device_attribute *dev_attr,
42171 dev_attr->store = store;
42172 }
42173
42174-static void pmbus_attr_init(struct sensor_device_attribute *a,
42175+static void pmbus_attr_init(sensor_device_attribute_no_const *a,
42176 const char *name,
42177 umode_t mode,
42178 ssize_t (*show)(struct device *dev,
42179@@ -822,7 +822,7 @@ static int pmbus_add_boolean(struct pmbus_data *data,
42180 u16 reg, u8 mask)
42181 {
42182 struct pmbus_boolean *boolean;
42183- struct sensor_device_attribute *a;
42184+ sensor_device_attribute_no_const *a;
42185
42186 boolean = devm_kzalloc(data->dev, sizeof(*boolean), GFP_KERNEL);
42187 if (!boolean)
42188@@ -847,7 +847,7 @@ static struct pmbus_sensor *pmbus_add_sensor(struct pmbus_data *data,
42189 bool update, bool readonly)
42190 {
42191 struct pmbus_sensor *sensor;
42192- struct device_attribute *a;
42193+ device_attribute_no_const *a;
42194
42195 sensor = devm_kzalloc(data->dev, sizeof(*sensor), GFP_KERNEL);
42196 if (!sensor)
42197@@ -878,7 +878,7 @@ static int pmbus_add_label(struct pmbus_data *data,
42198 const char *lstring, int index)
42199 {
42200 struct pmbus_label *label;
42201- struct device_attribute *a;
42202+ device_attribute_no_const *a;
42203
42204 label = devm_kzalloc(data->dev, sizeof(*label), GFP_KERNEL);
42205 if (!label)
42206diff --git a/drivers/hwmon/sht15.c b/drivers/hwmon/sht15.c
42207index 97cd45a..ac54d8b 100644
42208--- a/drivers/hwmon/sht15.c
42209+++ b/drivers/hwmon/sht15.c
42210@@ -169,7 +169,7 @@ struct sht15_data {
42211 int supply_uv;
42212 bool supply_uv_valid;
42213 struct work_struct update_supply_work;
42214- atomic_t interrupt_handled;
42215+ atomic_unchecked_t interrupt_handled;
42216 };
42217
42218 /**
42219@@ -542,13 +542,13 @@ static int sht15_measurement(struct sht15_data *data,
42220 ret = gpio_direction_input(data->pdata->gpio_data);
42221 if (ret)
42222 return ret;
42223- atomic_set(&data->interrupt_handled, 0);
42224+ atomic_set_unchecked(&data->interrupt_handled, 0);
42225
42226 enable_irq(gpio_to_irq(data->pdata->gpio_data));
42227 if (gpio_get_value(data->pdata->gpio_data) == 0) {
42228 disable_irq_nosync(gpio_to_irq(data->pdata->gpio_data));
42229 /* Only relevant if the interrupt hasn't occurred. */
42230- if (!atomic_read(&data->interrupt_handled))
42231+ if (!atomic_read_unchecked(&data->interrupt_handled))
42232 schedule_work(&data->read_work);
42233 }
42234 ret = wait_event_timeout(data->wait_queue,
42235@@ -820,7 +820,7 @@ static irqreturn_t sht15_interrupt_fired(int irq, void *d)
42236
42237 /* First disable the interrupt */
42238 disable_irq_nosync(irq);
42239- atomic_inc(&data->interrupt_handled);
42240+ atomic_inc_unchecked(&data->interrupt_handled);
42241 /* Then schedule a reading work struct */
42242 if (data->state != SHT15_READING_NOTHING)
42243 schedule_work(&data->read_work);
42244@@ -842,11 +842,11 @@ static void sht15_bh_read_data(struct work_struct *work_s)
42245 * If not, then start the interrupt again - care here as could
42246 * have gone low in meantime so verify it hasn't!
42247 */
42248- atomic_set(&data->interrupt_handled, 0);
42249+ atomic_set_unchecked(&data->interrupt_handled, 0);
42250 enable_irq(gpio_to_irq(data->pdata->gpio_data));
42251 /* If still not occurred or another handler was scheduled */
42252 if (gpio_get_value(data->pdata->gpio_data)
42253- || atomic_read(&data->interrupt_handled))
42254+ || atomic_read_unchecked(&data->interrupt_handled))
42255 return;
42256 }
42257
42258diff --git a/drivers/hwmon/via-cputemp.c b/drivers/hwmon/via-cputemp.c
42259index 38944e9..ae9e5ed 100644
42260--- a/drivers/hwmon/via-cputemp.c
42261+++ b/drivers/hwmon/via-cputemp.c
42262@@ -296,7 +296,7 @@ static int via_cputemp_cpu_callback(struct notifier_block *nfb,
42263 return NOTIFY_OK;
42264 }
42265
42266-static struct notifier_block via_cputemp_cpu_notifier __refdata = {
42267+static struct notifier_block via_cputemp_cpu_notifier = {
42268 .notifier_call = via_cputemp_cpu_callback,
42269 };
42270
42271diff --git a/drivers/i2c/busses/i2c-amd756-s4882.c b/drivers/i2c/busses/i2c-amd756-s4882.c
42272index 41fc683..a39cfea 100644
42273--- a/drivers/i2c/busses/i2c-amd756-s4882.c
42274+++ b/drivers/i2c/busses/i2c-amd756-s4882.c
42275@@ -43,7 +43,7 @@
42276 extern struct i2c_adapter amd756_smbus;
42277
42278 static struct i2c_adapter *s4882_adapter;
42279-static struct i2c_algorithm *s4882_algo;
42280+static i2c_algorithm_no_const *s4882_algo;
42281
42282 /* Wrapper access functions for multiplexed SMBus */
42283 static DEFINE_MUTEX(amd756_lock);
42284diff --git a/drivers/i2c/busses/i2c-diolan-u2c.c b/drivers/i2c/busses/i2c-diolan-u2c.c
42285index 721f7eb..0fd2a09 100644
42286--- a/drivers/i2c/busses/i2c-diolan-u2c.c
42287+++ b/drivers/i2c/busses/i2c-diolan-u2c.c
42288@@ -98,7 +98,7 @@ MODULE_PARM_DESC(frequency, "I2C clock frequency in hertz");
42289 /* usb layer */
42290
42291 /* Send command to device, and get response. */
42292-static int diolan_usb_transfer(struct i2c_diolan_u2c *dev)
42293+static int __intentional_overflow(-1) diolan_usb_transfer(struct i2c_diolan_u2c *dev)
42294 {
42295 int ret = 0;
42296 int actual;
42297diff --git a/drivers/i2c/busses/i2c-nforce2-s4985.c b/drivers/i2c/busses/i2c-nforce2-s4985.c
42298index b170bdf..3c76427 100644
42299--- a/drivers/i2c/busses/i2c-nforce2-s4985.c
42300+++ b/drivers/i2c/busses/i2c-nforce2-s4985.c
42301@@ -41,7 +41,7 @@
42302 extern struct i2c_adapter *nforce2_smbus;
42303
42304 static struct i2c_adapter *s4985_adapter;
42305-static struct i2c_algorithm *s4985_algo;
42306+static i2c_algorithm_no_const *s4985_algo;
42307
42308 /* Wrapper access functions for multiplexed SMBus */
42309 static DEFINE_MUTEX(nforce2_lock);
42310diff --git a/drivers/i2c/i2c-dev.c b/drivers/i2c/i2c-dev.c
42311index 80b47e8..1a6040d9 100644
42312--- a/drivers/i2c/i2c-dev.c
42313+++ b/drivers/i2c/i2c-dev.c
42314@@ -277,7 +277,7 @@ static noinline int i2cdev_ioctl_rdrw(struct i2c_client *client,
42315 break;
42316 }
42317
42318- data_ptrs[i] = (u8 __user *)rdwr_pa[i].buf;
42319+ data_ptrs[i] = (u8 __force_user *)rdwr_pa[i].buf;
42320 rdwr_pa[i].buf = memdup_user(data_ptrs[i], rdwr_pa[i].len);
42321 if (IS_ERR(rdwr_pa[i].buf)) {
42322 res = PTR_ERR(rdwr_pa[i].buf);
42323diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c
42324index 0b510ba..4fbb5085 100644
42325--- a/drivers/ide/ide-cd.c
42326+++ b/drivers/ide/ide-cd.c
42327@@ -768,7 +768,7 @@ static void cdrom_do_block_pc(ide_drive_t *drive, struct request *rq)
42328 alignment = queue_dma_alignment(q) | q->dma_pad_mask;
42329 if ((unsigned long)buf & alignment
42330 || blk_rq_bytes(rq) & q->dma_pad_mask
42331- || object_is_on_stack(buf))
42332+ || object_starts_on_stack(buf))
42333 drive->dma = 0;
42334 }
42335 }
42336diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
42337index acc911a..8700c3c 100644
42338--- a/drivers/iio/industrialio-core.c
42339+++ b/drivers/iio/industrialio-core.c
42340@@ -527,7 +527,7 @@ static ssize_t iio_write_channel_info(struct device *dev,
42341 }
42342
42343 static
42344-int __iio_device_attr_init(struct device_attribute *dev_attr,
42345+int __iio_device_attr_init(device_attribute_no_const *dev_attr,
42346 const char *postfix,
42347 struct iio_chan_spec const *chan,
42348 ssize_t (*readfunc)(struct device *dev,
42349diff --git a/drivers/infiniband/core/cm.c b/drivers/infiniband/core/cm.c
42350index c323917..6ddea8b 100644
42351--- a/drivers/infiniband/core/cm.c
42352+++ b/drivers/infiniband/core/cm.c
42353@@ -115,7 +115,7 @@ static char const counter_group_names[CM_COUNTER_GROUPS]
42354
42355 struct cm_counter_group {
42356 struct kobject obj;
42357- atomic_long_t counter[CM_ATTR_COUNT];
42358+ atomic_long_unchecked_t counter[CM_ATTR_COUNT];
42359 };
42360
42361 struct cm_counter_attribute {
42362@@ -1398,7 +1398,7 @@ static void cm_dup_req_handler(struct cm_work *work,
42363 struct ib_mad_send_buf *msg = NULL;
42364 int ret;
42365
42366- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42367+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42368 counter[CM_REQ_COUNTER]);
42369
42370 /* Quick state check to discard duplicate REQs. */
42371@@ -1785,7 +1785,7 @@ static void cm_dup_rep_handler(struct cm_work *work)
42372 if (!cm_id_priv)
42373 return;
42374
42375- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42376+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42377 counter[CM_REP_COUNTER]);
42378 ret = cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg);
42379 if (ret)
42380@@ -1952,7 +1952,7 @@ static int cm_rtu_handler(struct cm_work *work)
42381 if (cm_id_priv->id.state != IB_CM_REP_SENT &&
42382 cm_id_priv->id.state != IB_CM_MRA_REP_RCVD) {
42383 spin_unlock_irq(&cm_id_priv->lock);
42384- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42385+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42386 counter[CM_RTU_COUNTER]);
42387 goto out;
42388 }
42389@@ -2135,7 +2135,7 @@ static int cm_dreq_handler(struct cm_work *work)
42390 cm_id_priv = cm_acquire_id(dreq_msg->remote_comm_id,
42391 dreq_msg->local_comm_id);
42392 if (!cm_id_priv) {
42393- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42394+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42395 counter[CM_DREQ_COUNTER]);
42396 cm_issue_drep(work->port, work->mad_recv_wc);
42397 return -EINVAL;
42398@@ -2160,7 +2160,7 @@ static int cm_dreq_handler(struct cm_work *work)
42399 case IB_CM_MRA_REP_RCVD:
42400 break;
42401 case IB_CM_TIMEWAIT:
42402- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42403+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42404 counter[CM_DREQ_COUNTER]);
42405 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
42406 goto unlock;
42407@@ -2174,7 +2174,7 @@ static int cm_dreq_handler(struct cm_work *work)
42408 cm_free_msg(msg);
42409 goto deref;
42410 case IB_CM_DREQ_RCVD:
42411- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42412+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42413 counter[CM_DREQ_COUNTER]);
42414 goto unlock;
42415 default:
42416@@ -2541,7 +2541,7 @@ static int cm_mra_handler(struct cm_work *work)
42417 ib_modify_mad(cm_id_priv->av.port->mad_agent,
42418 cm_id_priv->msg, timeout)) {
42419 if (cm_id_priv->id.lap_state == IB_CM_MRA_LAP_RCVD)
42420- atomic_long_inc(&work->port->
42421+ atomic_long_inc_unchecked(&work->port->
42422 counter_group[CM_RECV_DUPLICATES].
42423 counter[CM_MRA_COUNTER]);
42424 goto out;
42425@@ -2550,7 +2550,7 @@ static int cm_mra_handler(struct cm_work *work)
42426 break;
42427 case IB_CM_MRA_REQ_RCVD:
42428 case IB_CM_MRA_REP_RCVD:
42429- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42430+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42431 counter[CM_MRA_COUNTER]);
42432 /* fall through */
42433 default:
42434@@ -2712,7 +2712,7 @@ static int cm_lap_handler(struct cm_work *work)
42435 case IB_CM_LAP_IDLE:
42436 break;
42437 case IB_CM_MRA_LAP_SENT:
42438- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42439+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42440 counter[CM_LAP_COUNTER]);
42441 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
42442 goto unlock;
42443@@ -2728,7 +2728,7 @@ static int cm_lap_handler(struct cm_work *work)
42444 cm_free_msg(msg);
42445 goto deref;
42446 case IB_CM_LAP_RCVD:
42447- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42448+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42449 counter[CM_LAP_COUNTER]);
42450 goto unlock;
42451 default:
42452@@ -3012,7 +3012,7 @@ static int cm_sidr_req_handler(struct cm_work *work)
42453 cur_cm_id_priv = cm_insert_remote_sidr(cm_id_priv);
42454 if (cur_cm_id_priv) {
42455 spin_unlock_irq(&cm.lock);
42456- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42457+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42458 counter[CM_SIDR_REQ_COUNTER]);
42459 goto out; /* Duplicate message. */
42460 }
42461@@ -3224,10 +3224,10 @@ static void cm_send_handler(struct ib_mad_agent *mad_agent,
42462 if (!msg->context[0] && (attr_index != CM_REJ_COUNTER))
42463 msg->retries = 1;
42464
42465- atomic_long_add(1 + msg->retries,
42466+ atomic_long_add_unchecked(1 + msg->retries,
42467 &port->counter_group[CM_XMIT].counter[attr_index]);
42468 if (msg->retries)
42469- atomic_long_add(msg->retries,
42470+ atomic_long_add_unchecked(msg->retries,
42471 &port->counter_group[CM_XMIT_RETRIES].
42472 counter[attr_index]);
42473
42474@@ -3437,7 +3437,7 @@ static void cm_recv_handler(struct ib_mad_agent *mad_agent,
42475 }
42476
42477 attr_id = be16_to_cpu(mad_recv_wc->recv_buf.mad->mad_hdr.attr_id);
42478- atomic_long_inc(&port->counter_group[CM_RECV].
42479+ atomic_long_inc_unchecked(&port->counter_group[CM_RECV].
42480 counter[attr_id - CM_ATTR_ID_OFFSET]);
42481
42482 work = kmalloc(sizeof *work + sizeof(struct ib_sa_path_rec) * paths,
42483@@ -3668,7 +3668,7 @@ static ssize_t cm_show_counter(struct kobject *obj, struct attribute *attr,
42484 cm_attr = container_of(attr, struct cm_counter_attribute, attr);
42485
42486 return sprintf(buf, "%ld\n",
42487- atomic_long_read(&group->counter[cm_attr->index]));
42488+ atomic_long_read_unchecked(&group->counter[cm_attr->index]));
42489 }
42490
42491 static const struct sysfs_ops cm_counter_ops = {
42492diff --git a/drivers/infiniband/core/fmr_pool.c b/drivers/infiniband/core/fmr_pool.c
42493index 9f5ad7c..588cd84 100644
42494--- a/drivers/infiniband/core/fmr_pool.c
42495+++ b/drivers/infiniband/core/fmr_pool.c
42496@@ -98,8 +98,8 @@ struct ib_fmr_pool {
42497
42498 struct task_struct *thread;
42499
42500- atomic_t req_ser;
42501- atomic_t flush_ser;
42502+ atomic_unchecked_t req_ser;
42503+ atomic_unchecked_t flush_ser;
42504
42505 wait_queue_head_t force_wait;
42506 };
42507@@ -179,10 +179,10 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
42508 struct ib_fmr_pool *pool = pool_ptr;
42509
42510 do {
42511- if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) < 0) {
42512+ if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) < 0) {
42513 ib_fmr_batch_release(pool);
42514
42515- atomic_inc(&pool->flush_ser);
42516+ atomic_inc_unchecked(&pool->flush_ser);
42517 wake_up_interruptible(&pool->force_wait);
42518
42519 if (pool->flush_function)
42520@@ -190,7 +190,7 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
42521 }
42522
42523 set_current_state(TASK_INTERRUPTIBLE);
42524- if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) >= 0 &&
42525+ if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) >= 0 &&
42526 !kthread_should_stop())
42527 schedule();
42528 __set_current_state(TASK_RUNNING);
42529@@ -282,8 +282,8 @@ struct ib_fmr_pool *ib_create_fmr_pool(struct ib_pd *pd,
42530 pool->dirty_watermark = params->dirty_watermark;
42531 pool->dirty_len = 0;
42532 spin_lock_init(&pool->pool_lock);
42533- atomic_set(&pool->req_ser, 0);
42534- atomic_set(&pool->flush_ser, 0);
42535+ atomic_set_unchecked(&pool->req_ser, 0);
42536+ atomic_set_unchecked(&pool->flush_ser, 0);
42537 init_waitqueue_head(&pool->force_wait);
42538
42539 pool->thread = kthread_run(ib_fmr_cleanup_thread,
42540@@ -411,11 +411,11 @@ int ib_flush_fmr_pool(struct ib_fmr_pool *pool)
42541 }
42542 spin_unlock_irq(&pool->pool_lock);
42543
42544- serial = atomic_inc_return(&pool->req_ser);
42545+ serial = atomic_inc_return_unchecked(&pool->req_ser);
42546 wake_up_process(pool->thread);
42547
42548 if (wait_event_interruptible(pool->force_wait,
42549- atomic_read(&pool->flush_ser) - serial >= 0))
42550+ atomic_read_unchecked(&pool->flush_ser) - serial >= 0))
42551 return -EINTR;
42552
42553 return 0;
42554@@ -525,7 +525,7 @@ int ib_fmr_pool_unmap(struct ib_pool_fmr *fmr)
42555 } else {
42556 list_add_tail(&fmr->list, &pool->dirty_list);
42557 if (++pool->dirty_len >= pool->dirty_watermark) {
42558- atomic_inc(&pool->req_ser);
42559+ atomic_inc_unchecked(&pool->req_ser);
42560 wake_up_process(pool->thread);
42561 }
42562 }
42563diff --git a/drivers/infiniband/hw/cxgb4/mem.c b/drivers/infiniband/hw/cxgb4/mem.c
42564index 41b1195..27971a0 100644
42565--- a/drivers/infiniband/hw/cxgb4/mem.c
42566+++ b/drivers/infiniband/hw/cxgb4/mem.c
42567@@ -249,7 +249,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
42568 int err;
42569 struct fw_ri_tpte tpt;
42570 u32 stag_idx;
42571- static atomic_t key;
42572+ static atomic_unchecked_t key;
42573
42574 if (c4iw_fatal_error(rdev))
42575 return -EIO;
42576@@ -266,7 +266,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
42577 if (rdev->stats.stag.cur > rdev->stats.stag.max)
42578 rdev->stats.stag.max = rdev->stats.stag.cur;
42579 mutex_unlock(&rdev->stats.lock);
42580- *stag = (stag_idx << 8) | (atomic_inc_return(&key) & 0xff);
42581+ *stag = (stag_idx << 8) | (atomic_inc_return_unchecked(&key) & 0xff);
42582 }
42583 PDBG("%s stag_state 0x%0x type 0x%0x pdid 0x%0x, stag_idx 0x%x\n",
42584 __func__, stag_state, type, pdid, stag_idx);
42585diff --git a/drivers/infiniband/hw/ipath/ipath_dma.c b/drivers/infiniband/hw/ipath/ipath_dma.c
42586index 644c2c7..ecf0879 100644
42587--- a/drivers/infiniband/hw/ipath/ipath_dma.c
42588+++ b/drivers/infiniband/hw/ipath/ipath_dma.c
42589@@ -176,17 +176,17 @@ static void ipath_dma_free_coherent(struct ib_device *dev, size_t size,
42590 }
42591
42592 struct ib_dma_mapping_ops ipath_dma_mapping_ops = {
42593- ipath_mapping_error,
42594- ipath_dma_map_single,
42595- ipath_dma_unmap_single,
42596- ipath_dma_map_page,
42597- ipath_dma_unmap_page,
42598- ipath_map_sg,
42599- ipath_unmap_sg,
42600- ipath_sg_dma_address,
42601- ipath_sg_dma_len,
42602- ipath_sync_single_for_cpu,
42603- ipath_sync_single_for_device,
42604- ipath_dma_alloc_coherent,
42605- ipath_dma_free_coherent
42606+ .mapping_error = ipath_mapping_error,
42607+ .map_single = ipath_dma_map_single,
42608+ .unmap_single = ipath_dma_unmap_single,
42609+ .map_page = ipath_dma_map_page,
42610+ .unmap_page = ipath_dma_unmap_page,
42611+ .map_sg = ipath_map_sg,
42612+ .unmap_sg = ipath_unmap_sg,
42613+ .dma_address = ipath_sg_dma_address,
42614+ .dma_len = ipath_sg_dma_len,
42615+ .sync_single_for_cpu = ipath_sync_single_for_cpu,
42616+ .sync_single_for_device = ipath_sync_single_for_device,
42617+ .alloc_coherent = ipath_dma_alloc_coherent,
42618+ .free_coherent = ipath_dma_free_coherent
42619 };
42620diff --git a/drivers/infiniband/hw/ipath/ipath_rc.c b/drivers/infiniband/hw/ipath/ipath_rc.c
42621index 79b3dbc..96e5fcc 100644
42622--- a/drivers/infiniband/hw/ipath/ipath_rc.c
42623+++ b/drivers/infiniband/hw/ipath/ipath_rc.c
42624@@ -1868,7 +1868,7 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
42625 struct ib_atomic_eth *ateth;
42626 struct ipath_ack_entry *e;
42627 u64 vaddr;
42628- atomic64_t *maddr;
42629+ atomic64_unchecked_t *maddr;
42630 u64 sdata;
42631 u32 rkey;
42632 u8 next;
42633@@ -1903,11 +1903,11 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
42634 IB_ACCESS_REMOTE_ATOMIC)))
42635 goto nack_acc_unlck;
42636 /* Perform atomic OP and save result. */
42637- maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
42638+ maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
42639 sdata = be64_to_cpu(ateth->swap_data);
42640 e = &qp->s_ack_queue[qp->r_head_ack_queue];
42641 e->atomic_data = (opcode == OP(FETCH_ADD)) ?
42642- (u64) atomic64_add_return(sdata, maddr) - sdata :
42643+ (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
42644 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
42645 be64_to_cpu(ateth->compare_data),
42646 sdata);
42647diff --git a/drivers/infiniband/hw/ipath/ipath_ruc.c b/drivers/infiniband/hw/ipath/ipath_ruc.c
42648index 1f95bba..9530f87 100644
42649--- a/drivers/infiniband/hw/ipath/ipath_ruc.c
42650+++ b/drivers/infiniband/hw/ipath/ipath_ruc.c
42651@@ -266,7 +266,7 @@ static void ipath_ruc_loopback(struct ipath_qp *sqp)
42652 unsigned long flags;
42653 struct ib_wc wc;
42654 u64 sdata;
42655- atomic64_t *maddr;
42656+ atomic64_unchecked_t *maddr;
42657 enum ib_wc_status send_status;
42658
42659 /*
42660@@ -382,11 +382,11 @@ again:
42661 IB_ACCESS_REMOTE_ATOMIC)))
42662 goto acc_err;
42663 /* Perform atomic OP and save result. */
42664- maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
42665+ maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
42666 sdata = wqe->wr.wr.atomic.compare_add;
42667 *(u64 *) sqp->s_sge.sge.vaddr =
42668 (wqe->wr.opcode == IB_WR_ATOMIC_FETCH_AND_ADD) ?
42669- (u64) atomic64_add_return(sdata, maddr) - sdata :
42670+ (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
42671 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
42672 sdata, wqe->wr.wr.atomic.swap);
42673 goto send_comp;
42674diff --git a/drivers/infiniband/hw/mlx4/mad.c b/drivers/infiniband/hw/mlx4/mad.c
42675index f2a3f48..673ec79 100644
42676--- a/drivers/infiniband/hw/mlx4/mad.c
42677+++ b/drivers/infiniband/hw/mlx4/mad.c
42678@@ -98,7 +98,7 @@ __be64 mlx4_ib_gen_node_guid(void)
42679
42680 __be64 mlx4_ib_get_new_demux_tid(struct mlx4_ib_demux_ctx *ctx)
42681 {
42682- return cpu_to_be64(atomic_inc_return(&ctx->tid)) |
42683+ return cpu_to_be64(atomic_inc_return_unchecked(&ctx->tid)) |
42684 cpu_to_be64(0xff00000000000000LL);
42685 }
42686
42687diff --git a/drivers/infiniband/hw/mlx4/mcg.c b/drivers/infiniband/hw/mlx4/mcg.c
42688index 25b2cdf..099ff97 100644
42689--- a/drivers/infiniband/hw/mlx4/mcg.c
42690+++ b/drivers/infiniband/hw/mlx4/mcg.c
42691@@ -1040,7 +1040,7 @@ int mlx4_ib_mcg_port_init(struct mlx4_ib_demux_ctx *ctx)
42692 {
42693 char name[20];
42694
42695- atomic_set(&ctx->tid, 0);
42696+ atomic_set_unchecked(&ctx->tid, 0);
42697 sprintf(name, "mlx4_ib_mcg%d", ctx->port);
42698 ctx->mcg_wq = create_singlethread_workqueue(name);
42699 if (!ctx->mcg_wq)
42700diff --git a/drivers/infiniband/hw/mlx4/mlx4_ib.h b/drivers/infiniband/hw/mlx4/mlx4_ib.h
42701index a230683..3723f2d 100644
42702--- a/drivers/infiniband/hw/mlx4/mlx4_ib.h
42703+++ b/drivers/infiniband/hw/mlx4/mlx4_ib.h
42704@@ -408,7 +408,7 @@ struct mlx4_ib_demux_ctx {
42705 struct list_head mcg_mgid0_list;
42706 struct workqueue_struct *mcg_wq;
42707 struct mlx4_ib_demux_pv_ctx **tun;
42708- atomic_t tid;
42709+ atomic_unchecked_t tid;
42710 int flushing; /* flushing the work queue */
42711 };
42712
42713diff --git a/drivers/infiniband/hw/mthca/mthca_cmd.c b/drivers/infiniband/hw/mthca/mthca_cmd.c
42714index 9d3e5c1..6f166df 100644
42715--- a/drivers/infiniband/hw/mthca/mthca_cmd.c
42716+++ b/drivers/infiniband/hw/mthca/mthca_cmd.c
42717@@ -772,7 +772,7 @@ static void mthca_setup_cmd_doorbells(struct mthca_dev *dev, u64 base)
42718 mthca_dbg(dev, "Mapped doorbell page for posting FW commands\n");
42719 }
42720
42721-int mthca_QUERY_FW(struct mthca_dev *dev)
42722+int __intentional_overflow(-1) mthca_QUERY_FW(struct mthca_dev *dev)
42723 {
42724 struct mthca_mailbox *mailbox;
42725 u32 *outbox;
42726@@ -1612,7 +1612,7 @@ int mthca_HW2SW_MPT(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
42727 CMD_TIME_CLASS_B);
42728 }
42729
42730-int mthca_WRITE_MTT(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
42731+int __intentional_overflow(-1) mthca_WRITE_MTT(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
42732 int num_mtt)
42733 {
42734 return mthca_cmd(dev, mailbox->dma, num_mtt, 0, CMD_WRITE_MTT,
42735@@ -1634,7 +1634,7 @@ int mthca_MAP_EQ(struct mthca_dev *dev, u64 event_mask, int unmap,
42736 0, CMD_MAP_EQ, CMD_TIME_CLASS_B);
42737 }
42738
42739-int mthca_SW2HW_EQ(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
42740+int __intentional_overflow(-1) mthca_SW2HW_EQ(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
42741 int eq_num)
42742 {
42743 return mthca_cmd(dev, mailbox->dma, eq_num, 0, CMD_SW2HW_EQ,
42744@@ -1857,7 +1857,7 @@ int mthca_CONF_SPECIAL_QP(struct mthca_dev *dev, int type, u32 qpn)
42745 CMD_TIME_CLASS_B);
42746 }
42747
42748-int mthca_MAD_IFC(struct mthca_dev *dev, int ignore_mkey, int ignore_bkey,
42749+int __intentional_overflow(-1) mthca_MAD_IFC(struct mthca_dev *dev, int ignore_mkey, int ignore_bkey,
42750 int port, struct ib_wc *in_wc, struct ib_grh *in_grh,
42751 void *in_mad, void *response_mad)
42752 {
42753diff --git a/drivers/infiniband/hw/mthca/mthca_main.c b/drivers/infiniband/hw/mthca/mthca_main.c
42754index 87897b9..7e79542 100644
42755--- a/drivers/infiniband/hw/mthca/mthca_main.c
42756+++ b/drivers/infiniband/hw/mthca/mthca_main.c
42757@@ -692,7 +692,7 @@ err_close:
42758 return err;
42759 }
42760
42761-static int mthca_setup_hca(struct mthca_dev *dev)
42762+static int __intentional_overflow(-1) mthca_setup_hca(struct mthca_dev *dev)
42763 {
42764 int err;
42765
42766diff --git a/drivers/infiniband/hw/mthca/mthca_mr.c b/drivers/infiniband/hw/mthca/mthca_mr.c
42767index ed9a989..6aa5dc2 100644
42768--- a/drivers/infiniband/hw/mthca/mthca_mr.c
42769+++ b/drivers/infiniband/hw/mthca/mthca_mr.c
42770@@ -81,7 +81,7 @@ struct mthca_mpt_entry {
42771 * through the bitmaps)
42772 */
42773
42774-static u32 mthca_buddy_alloc(struct mthca_buddy *buddy, int order)
42775+static u32 __intentional_overflow(-1) mthca_buddy_alloc(struct mthca_buddy *buddy, int order)
42776 {
42777 int o;
42778 int m;
42779@@ -426,7 +426,7 @@ static inline u32 adjust_key(struct mthca_dev *dev, u32 key)
42780 return key;
42781 }
42782
42783-int mthca_mr_alloc(struct mthca_dev *dev, u32 pd, int buffer_size_shift,
42784+int __intentional_overflow(-1) mthca_mr_alloc(struct mthca_dev *dev, u32 pd, int buffer_size_shift,
42785 u64 iova, u64 total_size, u32 access, struct mthca_mr *mr)
42786 {
42787 struct mthca_mailbox *mailbox;
42788@@ -516,7 +516,7 @@ int mthca_mr_alloc_notrans(struct mthca_dev *dev, u32 pd,
42789 return mthca_mr_alloc(dev, pd, 12, 0, ~0ULL, access, mr);
42790 }
42791
42792-int mthca_mr_alloc_phys(struct mthca_dev *dev, u32 pd,
42793+int __intentional_overflow(-1) mthca_mr_alloc_phys(struct mthca_dev *dev, u32 pd,
42794 u64 *buffer_list, int buffer_size_shift,
42795 int list_len, u64 iova, u64 total_size,
42796 u32 access, struct mthca_mr *mr)
42797diff --git a/drivers/infiniband/hw/mthca/mthca_provider.c b/drivers/infiniband/hw/mthca/mthca_provider.c
42798index 42dde06..1257310 100644
42799--- a/drivers/infiniband/hw/mthca/mthca_provider.c
42800+++ b/drivers/infiniband/hw/mthca/mthca_provider.c
42801@@ -764,7 +764,7 @@ unlock:
42802 return 0;
42803 }
42804
42805-static int mthca_resize_cq(struct ib_cq *ibcq, int entries, struct ib_udata *udata)
42806+static int __intentional_overflow(-1) mthca_resize_cq(struct ib_cq *ibcq, int entries, struct ib_udata *udata)
42807 {
42808 struct mthca_dev *dev = to_mdev(ibcq->device);
42809 struct mthca_cq *cq = to_mcq(ibcq);
42810diff --git a/drivers/infiniband/hw/nes/nes.c b/drivers/infiniband/hw/nes/nes.c
42811index 353c7b0..c6ce921 100644
42812--- a/drivers/infiniband/hw/nes/nes.c
42813+++ b/drivers/infiniband/hw/nes/nes.c
42814@@ -98,7 +98,7 @@ MODULE_PARM_DESC(limit_maxrdreqsz, "Limit max read request size to 256 Bytes");
42815 LIST_HEAD(nes_adapter_list);
42816 static LIST_HEAD(nes_dev_list);
42817
42818-atomic_t qps_destroyed;
42819+atomic_unchecked_t qps_destroyed;
42820
42821 static unsigned int ee_flsh_adapter;
42822 static unsigned int sysfs_nonidx_addr;
42823@@ -269,7 +269,7 @@ static void nes_cqp_rem_ref_callback(struct nes_device *nesdev, struct nes_cqp_r
42824 struct nes_qp *nesqp = cqp_request->cqp_callback_pointer;
42825 struct nes_adapter *nesadapter = nesdev->nesadapter;
42826
42827- atomic_inc(&qps_destroyed);
42828+ atomic_inc_unchecked(&qps_destroyed);
42829
42830 /* Free the control structures */
42831
42832diff --git a/drivers/infiniband/hw/nes/nes.h b/drivers/infiniband/hw/nes/nes.h
42833index 33cc589..3bd6538 100644
42834--- a/drivers/infiniband/hw/nes/nes.h
42835+++ b/drivers/infiniband/hw/nes/nes.h
42836@@ -177,17 +177,17 @@ extern unsigned int nes_debug_level;
42837 extern unsigned int wqm_quanta;
42838 extern struct list_head nes_adapter_list;
42839
42840-extern atomic_t cm_connects;
42841-extern atomic_t cm_accepts;
42842-extern atomic_t cm_disconnects;
42843-extern atomic_t cm_closes;
42844-extern atomic_t cm_connecteds;
42845-extern atomic_t cm_connect_reqs;
42846-extern atomic_t cm_rejects;
42847-extern atomic_t mod_qp_timouts;
42848-extern atomic_t qps_created;
42849-extern atomic_t qps_destroyed;
42850-extern atomic_t sw_qps_destroyed;
42851+extern atomic_unchecked_t cm_connects;
42852+extern atomic_unchecked_t cm_accepts;
42853+extern atomic_unchecked_t cm_disconnects;
42854+extern atomic_unchecked_t cm_closes;
42855+extern atomic_unchecked_t cm_connecteds;
42856+extern atomic_unchecked_t cm_connect_reqs;
42857+extern atomic_unchecked_t cm_rejects;
42858+extern atomic_unchecked_t mod_qp_timouts;
42859+extern atomic_unchecked_t qps_created;
42860+extern atomic_unchecked_t qps_destroyed;
42861+extern atomic_unchecked_t sw_qps_destroyed;
42862 extern u32 mh_detected;
42863 extern u32 mh_pauses_sent;
42864 extern u32 cm_packets_sent;
42865@@ -196,16 +196,16 @@ extern u32 cm_packets_created;
42866 extern u32 cm_packets_received;
42867 extern u32 cm_packets_dropped;
42868 extern u32 cm_packets_retrans;
42869-extern atomic_t cm_listens_created;
42870-extern atomic_t cm_listens_destroyed;
42871+extern atomic_unchecked_t cm_listens_created;
42872+extern atomic_unchecked_t cm_listens_destroyed;
42873 extern u32 cm_backlog_drops;
42874-extern atomic_t cm_loopbacks;
42875-extern atomic_t cm_nodes_created;
42876-extern atomic_t cm_nodes_destroyed;
42877-extern atomic_t cm_accel_dropped_pkts;
42878-extern atomic_t cm_resets_recvd;
42879-extern atomic_t pau_qps_created;
42880-extern atomic_t pau_qps_destroyed;
42881+extern atomic_unchecked_t cm_loopbacks;
42882+extern atomic_unchecked_t cm_nodes_created;
42883+extern atomic_unchecked_t cm_nodes_destroyed;
42884+extern atomic_unchecked_t cm_accel_dropped_pkts;
42885+extern atomic_unchecked_t cm_resets_recvd;
42886+extern atomic_unchecked_t pau_qps_created;
42887+extern atomic_unchecked_t pau_qps_destroyed;
42888
42889 extern u32 int_mod_timer_init;
42890 extern u32 int_mod_cq_depth_256;
42891diff --git a/drivers/infiniband/hw/nes/nes_cm.c b/drivers/infiniband/hw/nes/nes_cm.c
42892index 9c9f2f5..2559190 100644
42893--- a/drivers/infiniband/hw/nes/nes_cm.c
42894+++ b/drivers/infiniband/hw/nes/nes_cm.c
42895@@ -68,14 +68,14 @@ u32 cm_packets_dropped;
42896 u32 cm_packets_retrans;
42897 u32 cm_packets_created;
42898 u32 cm_packets_received;
42899-atomic_t cm_listens_created;
42900-atomic_t cm_listens_destroyed;
42901+atomic_unchecked_t cm_listens_created;
42902+atomic_unchecked_t cm_listens_destroyed;
42903 u32 cm_backlog_drops;
42904-atomic_t cm_loopbacks;
42905-atomic_t cm_nodes_created;
42906-atomic_t cm_nodes_destroyed;
42907-atomic_t cm_accel_dropped_pkts;
42908-atomic_t cm_resets_recvd;
42909+atomic_unchecked_t cm_loopbacks;
42910+atomic_unchecked_t cm_nodes_created;
42911+atomic_unchecked_t cm_nodes_destroyed;
42912+atomic_unchecked_t cm_accel_dropped_pkts;
42913+atomic_unchecked_t cm_resets_recvd;
42914
42915 static inline int mini_cm_accelerated(struct nes_cm_core *, struct nes_cm_node *);
42916 static struct nes_cm_listener *mini_cm_listen(struct nes_cm_core *, struct nes_vnic *, struct nes_cm_info *);
42917@@ -133,28 +133,28 @@ static void print_core(struct nes_cm_core *core);
42918 /* instance of function pointers for client API */
42919 /* set address of this instance to cm_core->cm_ops at cm_core alloc */
42920 static struct nes_cm_ops nes_cm_api = {
42921- mini_cm_accelerated,
42922- mini_cm_listen,
42923- mini_cm_del_listen,
42924- mini_cm_connect,
42925- mini_cm_close,
42926- mini_cm_accept,
42927- mini_cm_reject,
42928- mini_cm_recv_pkt,
42929- mini_cm_dealloc_core,
42930- mini_cm_get,
42931- mini_cm_set
42932+ .accelerated = mini_cm_accelerated,
42933+ .listen = mini_cm_listen,
42934+ .stop_listener = mini_cm_del_listen,
42935+ .connect = mini_cm_connect,
42936+ .close = mini_cm_close,
42937+ .accept = mini_cm_accept,
42938+ .reject = mini_cm_reject,
42939+ .recv_pkt = mini_cm_recv_pkt,
42940+ .destroy_cm_core = mini_cm_dealloc_core,
42941+ .get = mini_cm_get,
42942+ .set = mini_cm_set
42943 };
42944
42945 static struct nes_cm_core *g_cm_core;
42946
42947-atomic_t cm_connects;
42948-atomic_t cm_accepts;
42949-atomic_t cm_disconnects;
42950-atomic_t cm_closes;
42951-atomic_t cm_connecteds;
42952-atomic_t cm_connect_reqs;
42953-atomic_t cm_rejects;
42954+atomic_unchecked_t cm_connects;
42955+atomic_unchecked_t cm_accepts;
42956+atomic_unchecked_t cm_disconnects;
42957+atomic_unchecked_t cm_closes;
42958+atomic_unchecked_t cm_connecteds;
42959+atomic_unchecked_t cm_connect_reqs;
42960+atomic_unchecked_t cm_rejects;
42961
42962 int nes_add_ref_cm_node(struct nes_cm_node *cm_node)
42963 {
42964@@ -1272,7 +1272,7 @@ static int mini_cm_dec_refcnt_listen(struct nes_cm_core *cm_core,
42965 kfree(listener);
42966 listener = NULL;
42967 ret = 0;
42968- atomic_inc(&cm_listens_destroyed);
42969+ atomic_inc_unchecked(&cm_listens_destroyed);
42970 } else {
42971 spin_unlock_irqrestore(&cm_core->listen_list_lock, flags);
42972 }
42973@@ -1465,7 +1465,7 @@ static struct nes_cm_node *make_cm_node(struct nes_cm_core *cm_core,
42974 cm_node->rem_mac);
42975
42976 add_hte_node(cm_core, cm_node);
42977- atomic_inc(&cm_nodes_created);
42978+ atomic_inc_unchecked(&cm_nodes_created);
42979
42980 return cm_node;
42981 }
42982@@ -1523,7 +1523,7 @@ static int rem_ref_cm_node(struct nes_cm_core *cm_core,
42983 }
42984
42985 atomic_dec(&cm_core->node_cnt);
42986- atomic_inc(&cm_nodes_destroyed);
42987+ atomic_inc_unchecked(&cm_nodes_destroyed);
42988 nesqp = cm_node->nesqp;
42989 if (nesqp) {
42990 nesqp->cm_node = NULL;
42991@@ -1587,7 +1587,7 @@ static int process_options(struct nes_cm_node *cm_node, u8 *optionsloc,
42992
42993 static void drop_packet(struct sk_buff *skb)
42994 {
42995- atomic_inc(&cm_accel_dropped_pkts);
42996+ atomic_inc_unchecked(&cm_accel_dropped_pkts);
42997 dev_kfree_skb_any(skb);
42998 }
42999
43000@@ -1650,7 +1650,7 @@ static void handle_rst_pkt(struct nes_cm_node *cm_node, struct sk_buff *skb,
43001 {
43002
43003 int reset = 0; /* whether to send reset in case of err.. */
43004- atomic_inc(&cm_resets_recvd);
43005+ atomic_inc_unchecked(&cm_resets_recvd);
43006 nes_debug(NES_DBG_CM, "Received Reset, cm_node = %p, state = %u."
43007 " refcnt=%d\n", cm_node, cm_node->state,
43008 atomic_read(&cm_node->ref_count));
43009@@ -2291,7 +2291,7 @@ static struct nes_cm_node *mini_cm_connect(struct nes_cm_core *cm_core,
43010 rem_ref_cm_node(cm_node->cm_core, cm_node);
43011 return NULL;
43012 }
43013- atomic_inc(&cm_loopbacks);
43014+ atomic_inc_unchecked(&cm_loopbacks);
43015 loopbackremotenode->loopbackpartner = cm_node;
43016 loopbackremotenode->tcp_cntxt.rcv_wscale =
43017 NES_CM_DEFAULT_RCV_WND_SCALE;
43018@@ -2566,7 +2566,7 @@ static int mini_cm_recv_pkt(struct nes_cm_core *cm_core,
43019 nes_queue_mgt_skbs(skb, nesvnic, cm_node->nesqp);
43020 else {
43021 rem_ref_cm_node(cm_core, cm_node);
43022- atomic_inc(&cm_accel_dropped_pkts);
43023+ atomic_inc_unchecked(&cm_accel_dropped_pkts);
43024 dev_kfree_skb_any(skb);
43025 }
43026 break;
43027@@ -2874,7 +2874,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
43028
43029 if ((cm_id) && (cm_id->event_handler)) {
43030 if (issue_disconn) {
43031- atomic_inc(&cm_disconnects);
43032+ atomic_inc_unchecked(&cm_disconnects);
43033 cm_event.event = IW_CM_EVENT_DISCONNECT;
43034 cm_event.status = disconn_status;
43035 cm_event.local_addr = cm_id->local_addr;
43036@@ -2896,7 +2896,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
43037 }
43038
43039 if (issue_close) {
43040- atomic_inc(&cm_closes);
43041+ atomic_inc_unchecked(&cm_closes);
43042 nes_disconnect(nesqp, 1);
43043
43044 cm_id->provider_data = nesqp;
43045@@ -3034,7 +3034,7 @@ int nes_accept(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
43046
43047 nes_debug(NES_DBG_CM, "QP%u, cm_node=%p, jiffies = %lu listener = %p\n",
43048 nesqp->hwqp.qp_id, cm_node, jiffies, cm_node->listener);
43049- atomic_inc(&cm_accepts);
43050+ atomic_inc_unchecked(&cm_accepts);
43051
43052 nes_debug(NES_DBG_CM, "netdev refcnt = %u.\n",
43053 netdev_refcnt_read(nesvnic->netdev));
43054@@ -3223,7 +3223,7 @@ int nes_reject(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
43055 struct nes_cm_core *cm_core;
43056 u8 *start_buff;
43057
43058- atomic_inc(&cm_rejects);
43059+ atomic_inc_unchecked(&cm_rejects);
43060 cm_node = (struct nes_cm_node *)cm_id->provider_data;
43061 loopback = cm_node->loopbackpartner;
43062 cm_core = cm_node->cm_core;
43063@@ -3285,7 +3285,7 @@ int nes_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
43064 ntohs(raddr->sin_port), ntohl(laddr->sin_addr.s_addr),
43065 ntohs(laddr->sin_port));
43066
43067- atomic_inc(&cm_connects);
43068+ atomic_inc_unchecked(&cm_connects);
43069 nesqp->active_conn = 1;
43070
43071 /* cache the cm_id in the qp */
43072@@ -3397,7 +3397,7 @@ int nes_create_listen(struct iw_cm_id *cm_id, int backlog)
43073 g_cm_core->api->stop_listener(g_cm_core, (void *)cm_node);
43074 return err;
43075 }
43076- atomic_inc(&cm_listens_created);
43077+ atomic_inc_unchecked(&cm_listens_created);
43078 }
43079
43080 cm_id->add_ref(cm_id);
43081@@ -3504,7 +3504,7 @@ static void cm_event_connected(struct nes_cm_event *event)
43082
43083 if (nesqp->destroyed)
43084 return;
43085- atomic_inc(&cm_connecteds);
43086+ atomic_inc_unchecked(&cm_connecteds);
43087 nes_debug(NES_DBG_CM, "QP%u attempting to connect to 0x%08X:0x%04X on"
43088 " local port 0x%04X. jiffies = %lu.\n",
43089 nesqp->hwqp.qp_id, ntohl(raddr->sin_addr.s_addr),
43090@@ -3685,7 +3685,7 @@ static void cm_event_reset(struct nes_cm_event *event)
43091
43092 cm_id->add_ref(cm_id);
43093 ret = cm_id->event_handler(cm_id, &cm_event);
43094- atomic_inc(&cm_closes);
43095+ atomic_inc_unchecked(&cm_closes);
43096 cm_event.event = IW_CM_EVENT_CLOSE;
43097 cm_event.status = 0;
43098 cm_event.provider_data = cm_id->provider_data;
43099@@ -3725,7 +3725,7 @@ static void cm_event_mpa_req(struct nes_cm_event *event)
43100 return;
43101 cm_id = cm_node->cm_id;
43102
43103- atomic_inc(&cm_connect_reqs);
43104+ atomic_inc_unchecked(&cm_connect_reqs);
43105 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
43106 cm_node, cm_id, jiffies);
43107
43108@@ -3769,7 +3769,7 @@ static void cm_event_mpa_reject(struct nes_cm_event *event)
43109 return;
43110 cm_id = cm_node->cm_id;
43111
43112- atomic_inc(&cm_connect_reqs);
43113+ atomic_inc_unchecked(&cm_connect_reqs);
43114 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
43115 cm_node, cm_id, jiffies);
43116
43117diff --git a/drivers/infiniband/hw/nes/nes_mgt.c b/drivers/infiniband/hw/nes/nes_mgt.c
43118index 4166452..fc952c3 100644
43119--- a/drivers/infiniband/hw/nes/nes_mgt.c
43120+++ b/drivers/infiniband/hw/nes/nes_mgt.c
43121@@ -40,8 +40,8 @@
43122 #include "nes.h"
43123 #include "nes_mgt.h"
43124
43125-atomic_t pau_qps_created;
43126-atomic_t pau_qps_destroyed;
43127+atomic_unchecked_t pau_qps_created;
43128+atomic_unchecked_t pau_qps_destroyed;
43129
43130 static void nes_replenish_mgt_rq(struct nes_vnic_mgt *mgtvnic)
43131 {
43132@@ -621,7 +621,7 @@ void nes_destroy_pau_qp(struct nes_device *nesdev, struct nes_qp *nesqp)
43133 {
43134 struct sk_buff *skb;
43135 unsigned long flags;
43136- atomic_inc(&pau_qps_destroyed);
43137+ atomic_inc_unchecked(&pau_qps_destroyed);
43138
43139 /* Free packets that have not yet been forwarded */
43140 /* Lock is acquired by skb_dequeue when removing the skb */
43141@@ -810,7 +810,7 @@ static void nes_mgt_ce_handler(struct nes_device *nesdev, struct nes_hw_nic_cq *
43142 cq->cq_vbase[head].cqe_words[NES_NIC_CQE_HASH_RCVNXT]);
43143 skb_queue_head_init(&nesqp->pau_list);
43144 spin_lock_init(&nesqp->pau_lock);
43145- atomic_inc(&pau_qps_created);
43146+ atomic_inc_unchecked(&pau_qps_created);
43147 nes_change_quad_hash(nesdev, mgtvnic->nesvnic, nesqp);
43148 }
43149
43150diff --git a/drivers/infiniband/hw/nes/nes_nic.c b/drivers/infiniband/hw/nes/nes_nic.c
43151index 49eb511..a774366 100644
43152--- a/drivers/infiniband/hw/nes/nes_nic.c
43153+++ b/drivers/infiniband/hw/nes/nes_nic.c
43154@@ -1273,39 +1273,39 @@ static void nes_netdev_get_ethtool_stats(struct net_device *netdev,
43155 target_stat_values[++index] = mh_detected;
43156 target_stat_values[++index] = mh_pauses_sent;
43157 target_stat_values[++index] = nesvnic->endnode_ipv4_tcp_retransmits;
43158- target_stat_values[++index] = atomic_read(&cm_connects);
43159- target_stat_values[++index] = atomic_read(&cm_accepts);
43160- target_stat_values[++index] = atomic_read(&cm_disconnects);
43161- target_stat_values[++index] = atomic_read(&cm_connecteds);
43162- target_stat_values[++index] = atomic_read(&cm_connect_reqs);
43163- target_stat_values[++index] = atomic_read(&cm_rejects);
43164- target_stat_values[++index] = atomic_read(&mod_qp_timouts);
43165- target_stat_values[++index] = atomic_read(&qps_created);
43166- target_stat_values[++index] = atomic_read(&sw_qps_destroyed);
43167- target_stat_values[++index] = atomic_read(&qps_destroyed);
43168- target_stat_values[++index] = atomic_read(&cm_closes);
43169+ target_stat_values[++index] = atomic_read_unchecked(&cm_connects);
43170+ target_stat_values[++index] = atomic_read_unchecked(&cm_accepts);
43171+ target_stat_values[++index] = atomic_read_unchecked(&cm_disconnects);
43172+ target_stat_values[++index] = atomic_read_unchecked(&cm_connecteds);
43173+ target_stat_values[++index] = atomic_read_unchecked(&cm_connect_reqs);
43174+ target_stat_values[++index] = atomic_read_unchecked(&cm_rejects);
43175+ target_stat_values[++index] = atomic_read_unchecked(&mod_qp_timouts);
43176+ target_stat_values[++index] = atomic_read_unchecked(&qps_created);
43177+ target_stat_values[++index] = atomic_read_unchecked(&sw_qps_destroyed);
43178+ target_stat_values[++index] = atomic_read_unchecked(&qps_destroyed);
43179+ target_stat_values[++index] = atomic_read_unchecked(&cm_closes);
43180 target_stat_values[++index] = cm_packets_sent;
43181 target_stat_values[++index] = cm_packets_bounced;
43182 target_stat_values[++index] = cm_packets_created;
43183 target_stat_values[++index] = cm_packets_received;
43184 target_stat_values[++index] = cm_packets_dropped;
43185 target_stat_values[++index] = cm_packets_retrans;
43186- target_stat_values[++index] = atomic_read(&cm_listens_created);
43187- target_stat_values[++index] = atomic_read(&cm_listens_destroyed);
43188+ target_stat_values[++index] = atomic_read_unchecked(&cm_listens_created);
43189+ target_stat_values[++index] = atomic_read_unchecked(&cm_listens_destroyed);
43190 target_stat_values[++index] = cm_backlog_drops;
43191- target_stat_values[++index] = atomic_read(&cm_loopbacks);
43192- target_stat_values[++index] = atomic_read(&cm_nodes_created);
43193- target_stat_values[++index] = atomic_read(&cm_nodes_destroyed);
43194- target_stat_values[++index] = atomic_read(&cm_accel_dropped_pkts);
43195- target_stat_values[++index] = atomic_read(&cm_resets_recvd);
43196+ target_stat_values[++index] = atomic_read_unchecked(&cm_loopbacks);
43197+ target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_created);
43198+ target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_destroyed);
43199+ target_stat_values[++index] = atomic_read_unchecked(&cm_accel_dropped_pkts);
43200+ target_stat_values[++index] = atomic_read_unchecked(&cm_resets_recvd);
43201 target_stat_values[++index] = nesadapter->free_4kpbl;
43202 target_stat_values[++index] = nesadapter->free_256pbl;
43203 target_stat_values[++index] = int_mod_timer_init;
43204 target_stat_values[++index] = nesvnic->lro_mgr.stats.aggregated;
43205 target_stat_values[++index] = nesvnic->lro_mgr.stats.flushed;
43206 target_stat_values[++index] = nesvnic->lro_mgr.stats.no_desc;
43207- target_stat_values[++index] = atomic_read(&pau_qps_created);
43208- target_stat_values[++index] = atomic_read(&pau_qps_destroyed);
43209+ target_stat_values[++index] = atomic_read_unchecked(&pau_qps_created);
43210+ target_stat_values[++index] = atomic_read_unchecked(&pau_qps_destroyed);
43211 }
43212
43213 /**
43214diff --git a/drivers/infiniband/hw/nes/nes_verbs.c b/drivers/infiniband/hw/nes/nes_verbs.c
43215index eb62461..2b7fc71 100644
43216--- a/drivers/infiniband/hw/nes/nes_verbs.c
43217+++ b/drivers/infiniband/hw/nes/nes_verbs.c
43218@@ -46,9 +46,9 @@
43219
43220 #include <rdma/ib_umem.h>
43221
43222-atomic_t mod_qp_timouts;
43223-atomic_t qps_created;
43224-atomic_t sw_qps_destroyed;
43225+atomic_unchecked_t mod_qp_timouts;
43226+atomic_unchecked_t qps_created;
43227+atomic_unchecked_t sw_qps_destroyed;
43228
43229 static void nes_unregister_ofa_device(struct nes_ib_device *nesibdev);
43230
43231@@ -1134,7 +1134,7 @@ static struct ib_qp *nes_create_qp(struct ib_pd *ibpd,
43232 if (init_attr->create_flags)
43233 return ERR_PTR(-EINVAL);
43234
43235- atomic_inc(&qps_created);
43236+ atomic_inc_unchecked(&qps_created);
43237 switch (init_attr->qp_type) {
43238 case IB_QPT_RC:
43239 if (nes_drv_opt & NES_DRV_OPT_NO_INLINE_DATA) {
43240@@ -1466,7 +1466,7 @@ static int nes_destroy_qp(struct ib_qp *ibqp)
43241 struct iw_cm_event cm_event;
43242 int ret = 0;
43243
43244- atomic_inc(&sw_qps_destroyed);
43245+ atomic_inc_unchecked(&sw_qps_destroyed);
43246 nesqp->destroyed = 1;
43247
43248 /* Blow away the connection if it exists. */
43249diff --git a/drivers/infiniband/hw/qib/qib.h b/drivers/infiniband/hw/qib/qib.h
43250index 1946101..09766d2 100644
43251--- a/drivers/infiniband/hw/qib/qib.h
43252+++ b/drivers/infiniband/hw/qib/qib.h
43253@@ -52,6 +52,7 @@
43254 #include <linux/kref.h>
43255 #include <linux/sched.h>
43256 #include <linux/kthread.h>
43257+#include <linux/slab.h>
43258
43259 #include "qib_common.h"
43260 #include "qib_verbs.h"
43261diff --git a/drivers/input/gameport/gameport.c b/drivers/input/gameport/gameport.c
43262index 24c41ba..102d71f 100644
43263--- a/drivers/input/gameport/gameport.c
43264+++ b/drivers/input/gameport/gameport.c
43265@@ -490,14 +490,14 @@ EXPORT_SYMBOL(gameport_set_phys);
43266 */
43267 static void gameport_init_port(struct gameport *gameport)
43268 {
43269- static atomic_t gameport_no = ATOMIC_INIT(0);
43270+ static atomic_unchecked_t gameport_no = ATOMIC_INIT(0);
43271
43272 __module_get(THIS_MODULE);
43273
43274 mutex_init(&gameport->drv_mutex);
43275 device_initialize(&gameport->dev);
43276 dev_set_name(&gameport->dev, "gameport%lu",
43277- (unsigned long)atomic_inc_return(&gameport_no) - 1);
43278+ (unsigned long)atomic_inc_return_unchecked(&gameport_no) - 1);
43279 gameport->dev.bus = &gameport_bus;
43280 gameport->dev.release = gameport_release_port;
43281 if (gameport->parent)
43282diff --git a/drivers/input/input.c b/drivers/input/input.c
43283index 1c4c0db..6f7abe3 100644
43284--- a/drivers/input/input.c
43285+++ b/drivers/input/input.c
43286@@ -1772,7 +1772,7 @@ EXPORT_SYMBOL_GPL(input_class);
43287 */
43288 struct input_dev *input_allocate_device(void)
43289 {
43290- static atomic_t input_no = ATOMIC_INIT(0);
43291+ static atomic_unchecked_t input_no = ATOMIC_INIT(0);
43292 struct input_dev *dev;
43293
43294 dev = kzalloc(sizeof(struct input_dev), GFP_KERNEL);
43295@@ -1787,7 +1787,7 @@ struct input_dev *input_allocate_device(void)
43296 INIT_LIST_HEAD(&dev->node);
43297
43298 dev_set_name(&dev->dev, "input%ld",
43299- (unsigned long) atomic_inc_return(&input_no) - 1);
43300+ (unsigned long) atomic_inc_return_unchecked(&input_no) - 1);
43301
43302 __module_get(THIS_MODULE);
43303 }
43304diff --git a/drivers/input/joystick/sidewinder.c b/drivers/input/joystick/sidewinder.c
43305index 4a95b22..874c182 100644
43306--- a/drivers/input/joystick/sidewinder.c
43307+++ b/drivers/input/joystick/sidewinder.c
43308@@ -30,6 +30,7 @@
43309 #include <linux/kernel.h>
43310 #include <linux/module.h>
43311 #include <linux/slab.h>
43312+#include <linux/sched.h>
43313 #include <linux/input.h>
43314 #include <linux/gameport.h>
43315 #include <linux/jiffies.h>
43316diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c
43317index 603fe0d..f63decc 100644
43318--- a/drivers/input/joystick/xpad.c
43319+++ b/drivers/input/joystick/xpad.c
43320@@ -737,7 +737,7 @@ static void xpad_led_set(struct led_classdev *led_cdev,
43321
43322 static int xpad_led_probe(struct usb_xpad *xpad)
43323 {
43324- static atomic_t led_seq = ATOMIC_INIT(0);
43325+ static atomic_unchecked_t led_seq = ATOMIC_INIT(0);
43326 long led_no;
43327 struct xpad_led *led;
43328 struct led_classdev *led_cdev;
43329@@ -750,7 +750,7 @@ static int xpad_led_probe(struct usb_xpad *xpad)
43330 if (!led)
43331 return -ENOMEM;
43332
43333- led_no = (long)atomic_inc_return(&led_seq) - 1;
43334+ led_no = (long)atomic_inc_return_unchecked(&led_seq) - 1;
43335
43336 snprintf(led->name, sizeof(led->name), "xpad%ld", led_no);
43337 led->xpad = xpad;
43338diff --git a/drivers/input/misc/ims-pcu.c b/drivers/input/misc/ims-pcu.c
43339index e204f26..8459f15 100644
43340--- a/drivers/input/misc/ims-pcu.c
43341+++ b/drivers/input/misc/ims-pcu.c
43342@@ -1621,7 +1621,7 @@ static int ims_pcu_identify_type(struct ims_pcu *pcu, u8 *device_id)
43343
43344 static int ims_pcu_init_application_mode(struct ims_pcu *pcu)
43345 {
43346- static atomic_t device_no = ATOMIC_INIT(0);
43347+ static atomic_unchecked_t device_no = ATOMIC_INIT(0);
43348
43349 const struct ims_pcu_device_info *info;
43350 u8 device_id;
43351@@ -1653,7 +1653,7 @@ static int ims_pcu_init_application_mode(struct ims_pcu *pcu)
43352 }
43353
43354 /* Device appears to be operable, complete initialization */
43355- pcu->device_no = atomic_inc_return(&device_no) - 1;
43356+ pcu->device_no = atomic_inc_return_unchecked(&device_no) - 1;
43357
43358 error = ims_pcu_setup_backlight(pcu);
43359 if (error)
43360diff --git a/drivers/input/mouse/psmouse.h b/drivers/input/mouse/psmouse.h
43361index 2f0b39d..7370f13 100644
43362--- a/drivers/input/mouse/psmouse.h
43363+++ b/drivers/input/mouse/psmouse.h
43364@@ -116,7 +116,7 @@ struct psmouse_attribute {
43365 ssize_t (*set)(struct psmouse *psmouse, void *data,
43366 const char *buf, size_t count);
43367 bool protect;
43368-};
43369+} __do_const;
43370 #define to_psmouse_attr(a) container_of((a), struct psmouse_attribute, dattr)
43371
43372 ssize_t psmouse_attr_show_helper(struct device *dev, struct device_attribute *attr,
43373diff --git a/drivers/input/mousedev.c b/drivers/input/mousedev.c
43374index b604564..3f14ae4 100644
43375--- a/drivers/input/mousedev.c
43376+++ b/drivers/input/mousedev.c
43377@@ -744,7 +744,7 @@ static ssize_t mousedev_read(struct file *file, char __user *buffer,
43378
43379 spin_unlock_irq(&client->packet_lock);
43380
43381- if (copy_to_user(buffer, data, count))
43382+ if (count > sizeof(data) || copy_to_user(buffer, data, count))
43383 return -EFAULT;
43384
43385 return count;
43386diff --git a/drivers/input/serio/serio.c b/drivers/input/serio/serio.c
43387index 8f4c4ab..5fc8a45 100644
43388--- a/drivers/input/serio/serio.c
43389+++ b/drivers/input/serio/serio.c
43390@@ -505,7 +505,7 @@ static void serio_release_port(struct device *dev)
43391 */
43392 static void serio_init_port(struct serio *serio)
43393 {
43394- static atomic_t serio_no = ATOMIC_INIT(0);
43395+ static atomic_unchecked_t serio_no = ATOMIC_INIT(0);
43396
43397 __module_get(THIS_MODULE);
43398
43399@@ -516,7 +516,7 @@ static void serio_init_port(struct serio *serio)
43400 mutex_init(&serio->drv_mutex);
43401 device_initialize(&serio->dev);
43402 dev_set_name(&serio->dev, "serio%ld",
43403- (long)atomic_inc_return(&serio_no) - 1);
43404+ (long)atomic_inc_return_unchecked(&serio_no) - 1);
43405 serio->dev.bus = &serio_bus;
43406 serio->dev.release = serio_release_port;
43407 serio->dev.groups = serio_device_attr_groups;
43408diff --git a/drivers/input/serio/serio_raw.c b/drivers/input/serio/serio_raw.c
43409index c9a02fe..0debc75 100644
43410--- a/drivers/input/serio/serio_raw.c
43411+++ b/drivers/input/serio/serio_raw.c
43412@@ -292,7 +292,7 @@ static irqreturn_t serio_raw_interrupt(struct serio *serio, unsigned char data,
43413
43414 static int serio_raw_connect(struct serio *serio, struct serio_driver *drv)
43415 {
43416- static atomic_t serio_raw_no = ATOMIC_INIT(0);
43417+ static atomic_unchecked_t serio_raw_no = ATOMIC_INIT(0);
43418 struct serio_raw *serio_raw;
43419 int err;
43420
43421@@ -303,7 +303,7 @@ static int serio_raw_connect(struct serio *serio, struct serio_driver *drv)
43422 }
43423
43424 snprintf(serio_raw->name, sizeof(serio_raw->name),
43425- "serio_raw%ld", (long)atomic_inc_return(&serio_raw_no) - 1);
43426+ "serio_raw%ld", (long)atomic_inc_return_unchecked(&serio_raw_no) - 1);
43427 kref_init(&serio_raw->kref);
43428 INIT_LIST_HEAD(&serio_raw->client_list);
43429 init_waitqueue_head(&serio_raw->wait);
43430diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
43431index e5555fc..937986d 100644
43432--- a/drivers/iommu/iommu.c
43433+++ b/drivers/iommu/iommu.c
43434@@ -588,7 +588,7 @@ static struct notifier_block iommu_bus_nb = {
43435 static void iommu_bus_init(struct bus_type *bus, struct iommu_ops *ops)
43436 {
43437 bus_register_notifier(bus, &iommu_bus_nb);
43438- bus_for_each_dev(bus, NULL, ops, add_iommu_group);
43439+ bus_for_each_dev(bus, NULL, (void *)ops, add_iommu_group);
43440 }
43441
43442 /**
43443diff --git a/drivers/iommu/irq_remapping.c b/drivers/iommu/irq_remapping.c
43444index 228632c9..edfe331 100644
43445--- a/drivers/iommu/irq_remapping.c
43446+++ b/drivers/iommu/irq_remapping.c
43447@@ -356,7 +356,7 @@ int setup_hpet_msi_remapped(unsigned int irq, unsigned int id)
43448 void panic_if_irq_remap(const char *msg)
43449 {
43450 if (irq_remapping_enabled)
43451- panic(msg);
43452+ panic("%s", msg);
43453 }
43454
43455 static void ir_ack_apic_edge(struct irq_data *data)
43456@@ -377,10 +377,12 @@ static void ir_print_prefix(struct irq_data *data, struct seq_file *p)
43457
43458 void irq_remap_modify_chip_defaults(struct irq_chip *chip)
43459 {
43460- chip->irq_print_chip = ir_print_prefix;
43461- chip->irq_ack = ir_ack_apic_edge;
43462- chip->irq_eoi = ir_ack_apic_level;
43463- chip->irq_set_affinity = x86_io_apic_ops.set_affinity;
43464+ pax_open_kernel();
43465+ *(void **)&chip->irq_print_chip = ir_print_prefix;
43466+ *(void **)&chip->irq_ack = ir_ack_apic_edge;
43467+ *(void **)&chip->irq_eoi = ir_ack_apic_level;
43468+ *(void **)&chip->irq_set_affinity = x86_io_apic_ops.set_affinity;
43469+ pax_close_kernel();
43470 }
43471
43472 bool setup_remapped_irq(int irq, struct irq_cfg *cfg, struct irq_chip *chip)
43473diff --git a/drivers/irqchip/irq-gic.c b/drivers/irqchip/irq-gic.c
43474index 341c601..e5f407e 100644
43475--- a/drivers/irqchip/irq-gic.c
43476+++ b/drivers/irqchip/irq-gic.c
43477@@ -84,7 +84,7 @@ static u8 gic_cpu_map[NR_GIC_CPU_IF] __read_mostly;
43478 * Supported arch specific GIC irq extension.
43479 * Default make them NULL.
43480 */
43481-struct irq_chip gic_arch_extn = {
43482+irq_chip_no_const gic_arch_extn = {
43483 .irq_eoi = NULL,
43484 .irq_mask = NULL,
43485 .irq_unmask = NULL,
43486@@ -332,7 +332,7 @@ static void gic_handle_cascade_irq(unsigned int irq, struct irq_desc *desc)
43487 chained_irq_exit(chip, desc);
43488 }
43489
43490-static struct irq_chip gic_chip = {
43491+static irq_chip_no_const gic_chip __read_only = {
43492 .name = "GIC",
43493 .irq_mask = gic_mask_irq,
43494 .irq_unmask = gic_unmask_irq,
43495diff --git a/drivers/irqchip/irq-renesas-irqc.c b/drivers/irqchip/irq-renesas-irqc.c
43496index 8777065..a4a9967 100644
43497--- a/drivers/irqchip/irq-renesas-irqc.c
43498+++ b/drivers/irqchip/irq-renesas-irqc.c
43499@@ -151,7 +151,7 @@ static int irqc_probe(struct platform_device *pdev)
43500 struct irqc_priv *p;
43501 struct resource *io;
43502 struct resource *irq;
43503- struct irq_chip *irq_chip;
43504+ irq_chip_no_const *irq_chip;
43505 const char *name = dev_name(&pdev->dev);
43506 int ret;
43507 int k;
43508diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c
43509index ac6f72b..81150f2 100644
43510--- a/drivers/isdn/capi/capi.c
43511+++ b/drivers/isdn/capi/capi.c
43512@@ -81,8 +81,8 @@ struct capiminor {
43513
43514 struct capi20_appl *ap;
43515 u32 ncci;
43516- atomic_t datahandle;
43517- atomic_t msgid;
43518+ atomic_unchecked_t datahandle;
43519+ atomic_unchecked_t msgid;
43520
43521 struct tty_port port;
43522 int ttyinstop;
43523@@ -391,7 +391,7 @@ gen_data_b3_resp_for(struct capiminor *mp, struct sk_buff *skb)
43524 capimsg_setu16(s, 2, mp->ap->applid);
43525 capimsg_setu8 (s, 4, CAPI_DATA_B3);
43526 capimsg_setu8 (s, 5, CAPI_RESP);
43527- capimsg_setu16(s, 6, atomic_inc_return(&mp->msgid));
43528+ capimsg_setu16(s, 6, atomic_inc_return_unchecked(&mp->msgid));
43529 capimsg_setu32(s, 8, mp->ncci);
43530 capimsg_setu16(s, 12, datahandle);
43531 }
43532@@ -512,14 +512,14 @@ static void handle_minor_send(struct capiminor *mp)
43533 mp->outbytes -= len;
43534 spin_unlock_bh(&mp->outlock);
43535
43536- datahandle = atomic_inc_return(&mp->datahandle);
43537+ datahandle = atomic_inc_return_unchecked(&mp->datahandle);
43538 skb_push(skb, CAPI_DATA_B3_REQ_LEN);
43539 memset(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
43540 capimsg_setu16(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
43541 capimsg_setu16(skb->data, 2, mp->ap->applid);
43542 capimsg_setu8 (skb->data, 4, CAPI_DATA_B3);
43543 capimsg_setu8 (skb->data, 5, CAPI_REQ);
43544- capimsg_setu16(skb->data, 6, atomic_inc_return(&mp->msgid));
43545+ capimsg_setu16(skb->data, 6, atomic_inc_return_unchecked(&mp->msgid));
43546 capimsg_setu32(skb->data, 8, mp->ncci); /* NCCI */
43547 capimsg_setu32(skb->data, 12, (u32)(long)skb->data);/* Data32 */
43548 capimsg_setu16(skb->data, 16, len); /* Data length */
43549diff --git a/drivers/isdn/gigaset/bas-gigaset.c b/drivers/isdn/gigaset/bas-gigaset.c
43550index c44950d..10ac276 100644
43551--- a/drivers/isdn/gigaset/bas-gigaset.c
43552+++ b/drivers/isdn/gigaset/bas-gigaset.c
43553@@ -2564,22 +2564,22 @@ static int gigaset_post_reset(struct usb_interface *intf)
43554
43555
43556 static const struct gigaset_ops gigops = {
43557- gigaset_write_cmd,
43558- gigaset_write_room,
43559- gigaset_chars_in_buffer,
43560- gigaset_brkchars,
43561- gigaset_init_bchannel,
43562- gigaset_close_bchannel,
43563- gigaset_initbcshw,
43564- gigaset_freebcshw,
43565- gigaset_reinitbcshw,
43566- gigaset_initcshw,
43567- gigaset_freecshw,
43568- gigaset_set_modem_ctrl,
43569- gigaset_baud_rate,
43570- gigaset_set_line_ctrl,
43571- gigaset_isoc_send_skb,
43572- gigaset_isoc_input,
43573+ .write_cmd = gigaset_write_cmd,
43574+ .write_room = gigaset_write_room,
43575+ .chars_in_buffer = gigaset_chars_in_buffer,
43576+ .brkchars = gigaset_brkchars,
43577+ .init_bchannel = gigaset_init_bchannel,
43578+ .close_bchannel = gigaset_close_bchannel,
43579+ .initbcshw = gigaset_initbcshw,
43580+ .freebcshw = gigaset_freebcshw,
43581+ .reinitbcshw = gigaset_reinitbcshw,
43582+ .initcshw = gigaset_initcshw,
43583+ .freecshw = gigaset_freecshw,
43584+ .set_modem_ctrl = gigaset_set_modem_ctrl,
43585+ .baud_rate = gigaset_baud_rate,
43586+ .set_line_ctrl = gigaset_set_line_ctrl,
43587+ .send_skb = gigaset_isoc_send_skb,
43588+ .handle_input = gigaset_isoc_input,
43589 };
43590
43591 /* bas_gigaset_init
43592diff --git a/drivers/isdn/gigaset/interface.c b/drivers/isdn/gigaset/interface.c
43593index 600c79b..3752bab 100644
43594--- a/drivers/isdn/gigaset/interface.c
43595+++ b/drivers/isdn/gigaset/interface.c
43596@@ -130,9 +130,9 @@ static int if_open(struct tty_struct *tty, struct file *filp)
43597 }
43598 tty->driver_data = cs;
43599
43600- ++cs->port.count;
43601+ atomic_inc(&cs->port.count);
43602
43603- if (cs->port.count == 1) {
43604+ if (atomic_read(&cs->port.count) == 1) {
43605 tty_port_tty_set(&cs->port, tty);
43606 cs->port.low_latency = 1;
43607 }
43608@@ -156,9 +156,9 @@ static void if_close(struct tty_struct *tty, struct file *filp)
43609
43610 if (!cs->connected)
43611 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
43612- else if (!cs->port.count)
43613+ else if (!atomic_read(&cs->port.count))
43614 dev_warn(cs->dev, "%s: device not opened\n", __func__);
43615- else if (!--cs->port.count)
43616+ else if (!atomic_dec_return(&cs->port.count))
43617 tty_port_tty_set(&cs->port, NULL);
43618
43619 mutex_unlock(&cs->mutex);
43620diff --git a/drivers/isdn/gigaset/ser-gigaset.c b/drivers/isdn/gigaset/ser-gigaset.c
43621index 8c91fd5..14f13ce 100644
43622--- a/drivers/isdn/gigaset/ser-gigaset.c
43623+++ b/drivers/isdn/gigaset/ser-gigaset.c
43624@@ -453,22 +453,22 @@ static int gigaset_set_line_ctrl(struct cardstate *cs, unsigned cflag)
43625 }
43626
43627 static const struct gigaset_ops ops = {
43628- gigaset_write_cmd,
43629- gigaset_write_room,
43630- gigaset_chars_in_buffer,
43631- gigaset_brkchars,
43632- gigaset_init_bchannel,
43633- gigaset_close_bchannel,
43634- gigaset_initbcshw,
43635- gigaset_freebcshw,
43636- gigaset_reinitbcshw,
43637- gigaset_initcshw,
43638- gigaset_freecshw,
43639- gigaset_set_modem_ctrl,
43640- gigaset_baud_rate,
43641- gigaset_set_line_ctrl,
43642- gigaset_m10x_send_skb, /* asyncdata.c */
43643- gigaset_m10x_input, /* asyncdata.c */
43644+ .write_cmd = gigaset_write_cmd,
43645+ .write_room = gigaset_write_room,
43646+ .chars_in_buffer = gigaset_chars_in_buffer,
43647+ .brkchars = gigaset_brkchars,
43648+ .init_bchannel = gigaset_init_bchannel,
43649+ .close_bchannel = gigaset_close_bchannel,
43650+ .initbcshw = gigaset_initbcshw,
43651+ .freebcshw = gigaset_freebcshw,
43652+ .reinitbcshw = gigaset_reinitbcshw,
43653+ .initcshw = gigaset_initcshw,
43654+ .freecshw = gigaset_freecshw,
43655+ .set_modem_ctrl = gigaset_set_modem_ctrl,
43656+ .baud_rate = gigaset_baud_rate,
43657+ .set_line_ctrl = gigaset_set_line_ctrl,
43658+ .send_skb = gigaset_m10x_send_skb, /* asyncdata.c */
43659+ .handle_input = gigaset_m10x_input, /* asyncdata.c */
43660 };
43661
43662
43663diff --git a/drivers/isdn/gigaset/usb-gigaset.c b/drivers/isdn/gigaset/usb-gigaset.c
43664index d0a41cb..b953e50 100644
43665--- a/drivers/isdn/gigaset/usb-gigaset.c
43666+++ b/drivers/isdn/gigaset/usb-gigaset.c
43667@@ -547,7 +547,7 @@ static int gigaset_brkchars(struct cardstate *cs, const unsigned char buf[6])
43668 gigaset_dbg_buffer(DEBUG_USBREQ, "brkchars", 6, buf);
43669 memcpy(cs->hw.usb->bchars, buf, 6);
43670 return usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 0x19, 0x41,
43671- 0, 0, &buf, 6, 2000);
43672+ 0, 0, buf, 6, 2000);
43673 }
43674
43675 static void gigaset_freebcshw(struct bc_state *bcs)
43676@@ -869,22 +869,22 @@ static int gigaset_pre_reset(struct usb_interface *intf)
43677 }
43678
43679 static const struct gigaset_ops ops = {
43680- gigaset_write_cmd,
43681- gigaset_write_room,
43682- gigaset_chars_in_buffer,
43683- gigaset_brkchars,
43684- gigaset_init_bchannel,
43685- gigaset_close_bchannel,
43686- gigaset_initbcshw,
43687- gigaset_freebcshw,
43688- gigaset_reinitbcshw,
43689- gigaset_initcshw,
43690- gigaset_freecshw,
43691- gigaset_set_modem_ctrl,
43692- gigaset_baud_rate,
43693- gigaset_set_line_ctrl,
43694- gigaset_m10x_send_skb,
43695- gigaset_m10x_input,
43696+ .write_cmd = gigaset_write_cmd,
43697+ .write_room = gigaset_write_room,
43698+ .chars_in_buffer = gigaset_chars_in_buffer,
43699+ .brkchars = gigaset_brkchars,
43700+ .init_bchannel = gigaset_init_bchannel,
43701+ .close_bchannel = gigaset_close_bchannel,
43702+ .initbcshw = gigaset_initbcshw,
43703+ .freebcshw = gigaset_freebcshw,
43704+ .reinitbcshw = gigaset_reinitbcshw,
43705+ .initcshw = gigaset_initcshw,
43706+ .freecshw = gigaset_freecshw,
43707+ .set_modem_ctrl = gigaset_set_modem_ctrl,
43708+ .baud_rate = gigaset_baud_rate,
43709+ .set_line_ctrl = gigaset_set_line_ctrl,
43710+ .send_skb = gigaset_m10x_send_skb,
43711+ .handle_input = gigaset_m10x_input,
43712 };
43713
43714 /*
43715diff --git a/drivers/isdn/hardware/avm/b1.c b/drivers/isdn/hardware/avm/b1.c
43716index 4d9b195..455075c 100644
43717--- a/drivers/isdn/hardware/avm/b1.c
43718+++ b/drivers/isdn/hardware/avm/b1.c
43719@@ -176,7 +176,7 @@ int b1_load_t4file(avmcard *card, capiloaddatapart *t4file)
43720 }
43721 if (left) {
43722 if (t4file->user) {
43723- if (copy_from_user(buf, dp, left))
43724+ if (left > sizeof buf || copy_from_user(buf, dp, left))
43725 return -EFAULT;
43726 } else {
43727 memcpy(buf, dp, left);
43728@@ -224,7 +224,7 @@ int b1_load_config(avmcard *card, capiloaddatapart *config)
43729 }
43730 if (left) {
43731 if (config->user) {
43732- if (copy_from_user(buf, dp, left))
43733+ if (left > sizeof buf || copy_from_user(buf, dp, left))
43734 return -EFAULT;
43735 } else {
43736 memcpy(buf, dp, left);
43737diff --git a/drivers/isdn/i4l/isdn_common.c b/drivers/isdn/i4l/isdn_common.c
43738index 9bb12ba..d4262f7 100644
43739--- a/drivers/isdn/i4l/isdn_common.c
43740+++ b/drivers/isdn/i4l/isdn_common.c
43741@@ -1651,6 +1651,8 @@ isdn_ioctl(struct file *file, uint cmd, ulong arg)
43742 } else
43743 return -EINVAL;
43744 case IIOCDBGVAR:
43745+ if (!capable(CAP_SYS_RAWIO))
43746+ return -EPERM;
43747 if (arg) {
43748 if (copy_to_user(argp, &dev, sizeof(ulong)))
43749 return -EFAULT;
43750diff --git a/drivers/isdn/i4l/isdn_concap.c b/drivers/isdn/i4l/isdn_concap.c
43751index 91d5730..336523e 100644
43752--- a/drivers/isdn/i4l/isdn_concap.c
43753+++ b/drivers/isdn/i4l/isdn_concap.c
43754@@ -80,9 +80,9 @@ static int isdn_concap_dl_disconn_req(struct concap_proto *concap)
43755 }
43756
43757 struct concap_device_ops isdn_concap_reliable_dl_dops = {
43758- &isdn_concap_dl_data_req,
43759- &isdn_concap_dl_connect_req,
43760- &isdn_concap_dl_disconn_req
43761+ .data_req = &isdn_concap_dl_data_req,
43762+ .connect_req = &isdn_concap_dl_connect_req,
43763+ .disconn_req = &isdn_concap_dl_disconn_req
43764 };
43765
43766 /* The following should better go into a dedicated source file such that
43767diff --git a/drivers/isdn/i4l/isdn_tty.c b/drivers/isdn/i4l/isdn_tty.c
43768index 3c5f249..5fac4d0 100644
43769--- a/drivers/isdn/i4l/isdn_tty.c
43770+++ b/drivers/isdn/i4l/isdn_tty.c
43771@@ -1508,9 +1508,9 @@ isdn_tty_open(struct tty_struct *tty, struct file *filp)
43772
43773 #ifdef ISDN_DEBUG_MODEM_OPEN
43774 printk(KERN_DEBUG "isdn_tty_open %s, count = %d\n", tty->name,
43775- port->count);
43776+ atomic_read(&port->count));
43777 #endif
43778- port->count++;
43779+ atomic_inc(&port->count);
43780 port->tty = tty;
43781 /*
43782 * Start up serial port
43783@@ -1554,7 +1554,7 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
43784 #endif
43785 return;
43786 }
43787- if ((tty->count == 1) && (port->count != 1)) {
43788+ if ((tty->count == 1) && (atomic_read(&port->count) != 1)) {
43789 /*
43790 * Uh, oh. tty->count is 1, which means that the tty
43791 * structure will be freed. Info->count should always
43792@@ -1563,15 +1563,15 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
43793 * serial port won't be shutdown.
43794 */
43795 printk(KERN_ERR "isdn_tty_close: bad port count; tty->count is 1, "
43796- "info->count is %d\n", port->count);
43797- port->count = 1;
43798+ "info->count is %d\n", atomic_read(&port->count));
43799+ atomic_set(&port->count, 1);
43800 }
43801- if (--port->count < 0) {
43802+ if (atomic_dec_return(&port->count) < 0) {
43803 printk(KERN_ERR "isdn_tty_close: bad port count for ttyi%d: %d\n",
43804- info->line, port->count);
43805- port->count = 0;
43806+ info->line, atomic_read(&port->count));
43807+ atomic_set(&port->count, 0);
43808 }
43809- if (port->count) {
43810+ if (atomic_read(&port->count)) {
43811 #ifdef ISDN_DEBUG_MODEM_OPEN
43812 printk(KERN_DEBUG "isdn_tty_close after info->count != 0\n");
43813 #endif
43814@@ -1625,7 +1625,7 @@ isdn_tty_hangup(struct tty_struct *tty)
43815 if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_hangup"))
43816 return;
43817 isdn_tty_shutdown(info);
43818- port->count = 0;
43819+ atomic_set(&port->count, 0);
43820 port->flags &= ~ASYNC_NORMAL_ACTIVE;
43821 port->tty = NULL;
43822 wake_up_interruptible(&port->open_wait);
43823@@ -1970,7 +1970,7 @@ isdn_tty_find_icall(int di, int ch, setup_parm *setup)
43824 for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
43825 modem_info *info = &dev->mdm.info[i];
43826
43827- if (info->port.count == 0)
43828+ if (atomic_read(&info->port.count) == 0)
43829 continue;
43830 if ((info->emu.mdmreg[REG_SI1] & si2bit[si1]) && /* SI1 is matching */
43831 (info->emu.mdmreg[REG_SI2] == si2)) { /* SI2 is matching */
43832diff --git a/drivers/isdn/i4l/isdn_x25iface.c b/drivers/isdn/i4l/isdn_x25iface.c
43833index e2d4e58..40cd045 100644
43834--- a/drivers/isdn/i4l/isdn_x25iface.c
43835+++ b/drivers/isdn/i4l/isdn_x25iface.c
43836@@ -53,14 +53,14 @@ static int isdn_x25iface_disconn_ind(struct concap_proto *);
43837
43838
43839 static struct concap_proto_ops ix25_pops = {
43840- &isdn_x25iface_proto_new,
43841- &isdn_x25iface_proto_del,
43842- &isdn_x25iface_proto_restart,
43843- &isdn_x25iface_proto_close,
43844- &isdn_x25iface_xmit,
43845- &isdn_x25iface_receive,
43846- &isdn_x25iface_connect_ind,
43847- &isdn_x25iface_disconn_ind
43848+ .proto_new = &isdn_x25iface_proto_new,
43849+ .proto_del = &isdn_x25iface_proto_del,
43850+ .restart = &isdn_x25iface_proto_restart,
43851+ .close = &isdn_x25iface_proto_close,
43852+ .encap_and_xmit = &isdn_x25iface_xmit,
43853+ .data_ind = &isdn_x25iface_receive,
43854+ .connect_ind = &isdn_x25iface_connect_ind,
43855+ .disconn_ind = &isdn_x25iface_disconn_ind
43856 };
43857
43858 /* error message helper function */
43859diff --git a/drivers/isdn/icn/icn.c b/drivers/isdn/icn/icn.c
43860index 53d487f..cae33fe 100644
43861--- a/drivers/isdn/icn/icn.c
43862+++ b/drivers/isdn/icn/icn.c
43863@@ -1045,7 +1045,7 @@ icn_writecmd(const u_char *buf, int len, int user, icn_card *card)
43864 if (count > len)
43865 count = len;
43866 if (user) {
43867- if (copy_from_user(msg, buf, count))
43868+ if (count > sizeof msg || copy_from_user(msg, buf, count))
43869 return -EFAULT;
43870 } else
43871 memcpy(msg, buf, count);
43872@@ -1155,7 +1155,7 @@ icn_command(isdn_ctrl *c, icn_card *card)
43873 ulong a;
43874 ulong flags;
43875 int i;
43876- char cbuf[60];
43877+ char cbuf[80];
43878 isdn_ctrl cmd;
43879 icn_cdef cdef;
43880 char __user *arg;
43881@@ -1309,7 +1309,6 @@ icn_command(isdn_ctrl *c, icn_card *card)
43882 break;
43883 if ((c->arg & 255) < ICN_BCH) {
43884 char *p;
43885- char dial[50];
43886 char dcode[4];
43887
43888 a = c->arg;
43889@@ -1321,10 +1320,10 @@ icn_command(isdn_ctrl *c, icn_card *card)
43890 } else
43891 /* Normal Dial */
43892 strcpy(dcode, "CAL");
43893- strcpy(dial, p);
43894- sprintf(cbuf, "%02d;D%s_R%s,%02d,%02d,%s\n", (int) (a + 1),
43895- dcode, dial, c->parm.setup.si1,
43896- c->parm.setup.si2, c->parm.setup.eazmsn);
43897+ snprintf(cbuf, sizeof(cbuf),
43898+ "%02d;D%s_R%s,%02d,%02d,%s\n", (int) (a + 1),
43899+ dcode, p, c->parm.setup.si1,
43900+ c->parm.setup.si2, c->parm.setup.eazmsn);
43901 i = icn_writecmd(cbuf, strlen(cbuf), 0, card);
43902 }
43903 break;
43904diff --git a/drivers/isdn/mISDN/dsp_cmx.c b/drivers/isdn/mISDN/dsp_cmx.c
43905index a4f05c5..1433bc5 100644
43906--- a/drivers/isdn/mISDN/dsp_cmx.c
43907+++ b/drivers/isdn/mISDN/dsp_cmx.c
43908@@ -1628,7 +1628,7 @@ unsigned long dsp_spl_jiffies; /* calculate the next time to fire */
43909 static u16 dsp_count; /* last sample count */
43910 static int dsp_count_valid; /* if we have last sample count */
43911
43912-void
43913+void __intentional_overflow(-1)
43914 dsp_cmx_send(void *arg)
43915 {
43916 struct dsp_conf *conf;
43917diff --git a/drivers/leds/leds-clevo-mail.c b/drivers/leds/leds-clevo-mail.c
43918index d93e245..e7ece6b 100644
43919--- a/drivers/leds/leds-clevo-mail.c
43920+++ b/drivers/leds/leds-clevo-mail.c
43921@@ -40,7 +40,7 @@ static int __init clevo_mail_led_dmi_callback(const struct dmi_system_id *id)
43922 * detected as working, but in reality it is not) as low as
43923 * possible.
43924 */
43925-static struct dmi_system_id clevo_mail_led_dmi_table[] __initdata = {
43926+static struct dmi_system_id clevo_mail_led_dmi_table[] __initconst = {
43927 {
43928 .callback = clevo_mail_led_dmi_callback,
43929 .ident = "Clevo D410J",
43930diff --git a/drivers/leds/leds-ss4200.c b/drivers/leds/leds-ss4200.c
43931index 5b8f938..b73d657 100644
43932--- a/drivers/leds/leds-ss4200.c
43933+++ b/drivers/leds/leds-ss4200.c
43934@@ -91,7 +91,7 @@ MODULE_PARM_DESC(nodetect, "Skip DMI-based hardware detection");
43935 * detected as working, but in reality it is not) as low as
43936 * possible.
43937 */
43938-static struct dmi_system_id nas_led_whitelist[] __initdata = {
43939+static struct dmi_system_id nas_led_whitelist[] __initconst = {
43940 {
43941 .callback = ss4200_led_dmi_callback,
43942 .ident = "Intel SS4200-E",
43943diff --git a/drivers/lguest/core.c b/drivers/lguest/core.c
43944index 0bf1e4e..b4bf44e 100644
43945--- a/drivers/lguest/core.c
43946+++ b/drivers/lguest/core.c
43947@@ -97,9 +97,17 @@ static __init int map_switcher(void)
43948 * The end address needs +1 because __get_vm_area allocates an
43949 * extra guard page, so we need space for that.
43950 */
43951+
43952+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
43953+ switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
43954+ VM_ALLOC | VM_KERNEXEC, switcher_addr, switcher_addr
43955+ + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
43956+#else
43957 switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
43958 VM_ALLOC, switcher_addr, switcher_addr
43959 + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
43960+#endif
43961+
43962 if (!switcher_vma) {
43963 err = -ENOMEM;
43964 printk("lguest: could not map switcher pages high\n");
43965@@ -124,7 +132,7 @@ static __init int map_switcher(void)
43966 * Now the Switcher is mapped at the right address, we can't fail!
43967 * Copy in the compiled-in Switcher code (from x86/switcher_32.S).
43968 */
43969- memcpy(switcher_vma->addr, start_switcher_text,
43970+ memcpy(switcher_vma->addr, ktla_ktva(start_switcher_text),
43971 end_switcher_text - start_switcher_text);
43972
43973 printk(KERN_INFO "lguest: mapped switcher at %p\n",
43974diff --git a/drivers/lguest/page_tables.c b/drivers/lguest/page_tables.c
43975index bfb39bb..08a603b 100644
43976--- a/drivers/lguest/page_tables.c
43977+++ b/drivers/lguest/page_tables.c
43978@@ -559,7 +559,7 @@ void pin_page(struct lg_cpu *cpu, unsigned long vaddr)
43979 /*:*/
43980
43981 #ifdef CONFIG_X86_PAE
43982-static void release_pmd(pmd_t *spmd)
43983+static void __intentional_overflow(-1) release_pmd(pmd_t *spmd)
43984 {
43985 /* If the entry's not present, there's nothing to release. */
43986 if (pmd_flags(*spmd) & _PAGE_PRESENT) {
43987diff --git a/drivers/lguest/x86/core.c b/drivers/lguest/x86/core.c
43988index 922a1ac..9dd0c2a 100644
43989--- a/drivers/lguest/x86/core.c
43990+++ b/drivers/lguest/x86/core.c
43991@@ -59,7 +59,7 @@ static struct {
43992 /* Offset from where switcher.S was compiled to where we've copied it */
43993 static unsigned long switcher_offset(void)
43994 {
43995- return switcher_addr - (unsigned long)start_switcher_text;
43996+ return switcher_addr - (unsigned long)ktla_ktva(start_switcher_text);
43997 }
43998
43999 /* This cpu's struct lguest_pages (after the Switcher text page) */
44000@@ -99,7 +99,13 @@ static void copy_in_guest_info(struct lg_cpu *cpu, struct lguest_pages *pages)
44001 * These copies are pretty cheap, so we do them unconditionally: */
44002 /* Save the current Host top-level page directory.
44003 */
44004+
44005+#ifdef CONFIG_PAX_PER_CPU_PGD
44006+ pages->state.host_cr3 = read_cr3();
44007+#else
44008 pages->state.host_cr3 = __pa(current->mm->pgd);
44009+#endif
44010+
44011 /*
44012 * Set up the Guest's page tables to see this CPU's pages (and no
44013 * other CPU's pages).
44014@@ -477,7 +483,7 @@ void __init lguest_arch_host_init(void)
44015 * compiled-in switcher code and the high-mapped copy we just made.
44016 */
44017 for (i = 0; i < IDT_ENTRIES; i++)
44018- default_idt_entries[i] += switcher_offset();
44019+ default_idt_entries[i] = ktla_ktva(default_idt_entries[i]) + switcher_offset();
44020
44021 /*
44022 * Set up the Switcher's per-cpu areas.
44023@@ -560,7 +566,7 @@ void __init lguest_arch_host_init(void)
44024 * it will be undisturbed when we switch. To change %cs and jump we
44025 * need this structure to feed to Intel's "lcall" instruction.
44026 */
44027- lguest_entry.offset = (long)switch_to_guest + switcher_offset();
44028+ lguest_entry.offset = (long)ktla_ktva(switch_to_guest) + switcher_offset();
44029 lguest_entry.segment = LGUEST_CS;
44030
44031 /*
44032diff --git a/drivers/lguest/x86/switcher_32.S b/drivers/lguest/x86/switcher_32.S
44033index 40634b0..4f5855e 100644
44034--- a/drivers/lguest/x86/switcher_32.S
44035+++ b/drivers/lguest/x86/switcher_32.S
44036@@ -87,6 +87,7 @@
44037 #include <asm/page.h>
44038 #include <asm/segment.h>
44039 #include <asm/lguest.h>
44040+#include <asm/processor-flags.h>
44041
44042 // We mark the start of the code to copy
44043 // It's placed in .text tho it's never run here
44044@@ -149,6 +150,13 @@ ENTRY(switch_to_guest)
44045 // Changes type when we load it: damn Intel!
44046 // For after we switch over our page tables
44047 // That entry will be read-only: we'd crash.
44048+
44049+#ifdef CONFIG_PAX_KERNEXEC
44050+ mov %cr0, %edx
44051+ xor $X86_CR0_WP, %edx
44052+ mov %edx, %cr0
44053+#endif
44054+
44055 movl $(GDT_ENTRY_TSS*8), %edx
44056 ltr %dx
44057
44058@@ -157,9 +165,15 @@ ENTRY(switch_to_guest)
44059 // Let's clear it again for our return.
44060 // The GDT descriptor of the Host
44061 // Points to the table after two "size" bytes
44062- movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %edx
44063+ movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %eax
44064 // Clear "used" from type field (byte 5, bit 2)
44065- andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%edx)
44066+ andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%eax)
44067+
44068+#ifdef CONFIG_PAX_KERNEXEC
44069+ mov %cr0, %eax
44070+ xor $X86_CR0_WP, %eax
44071+ mov %eax, %cr0
44072+#endif
44073
44074 // Once our page table's switched, the Guest is live!
44075 // The Host fades as we run this final step.
44076@@ -295,13 +309,12 @@ deliver_to_host:
44077 // I consulted gcc, and it gave
44078 // These instructions, which I gladly credit:
44079 leal (%edx,%ebx,8), %eax
44080- movzwl (%eax),%edx
44081- movl 4(%eax), %eax
44082- xorw %ax, %ax
44083- orl %eax, %edx
44084+ movl 4(%eax), %edx
44085+ movw (%eax), %dx
44086 // Now the address of the handler's in %edx
44087 // We call it now: its "iret" drops us home.
44088- jmp *%edx
44089+ ljmp $__KERNEL_CS, $1f
44090+1: jmp *%edx
44091
44092 // Every interrupt can come to us here
44093 // But we must truly tell each apart.
44094diff --git a/drivers/md/bcache/closure.h b/drivers/md/bcache/closure.h
44095index 7ef7461..5a09dac 100644
44096--- a/drivers/md/bcache/closure.h
44097+++ b/drivers/md/bcache/closure.h
44098@@ -238,7 +238,7 @@ static inline void closure_set_stopped(struct closure *cl)
44099 static inline void set_closure_fn(struct closure *cl, closure_fn *fn,
44100 struct workqueue_struct *wq)
44101 {
44102- BUG_ON(object_is_on_stack(cl));
44103+ BUG_ON(object_starts_on_stack(cl));
44104 closure_set_ip(cl);
44105 cl->fn = fn;
44106 cl->wq = wq;
44107diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c
44108index 4195a01..42527ac 100644
44109--- a/drivers/md/bitmap.c
44110+++ b/drivers/md/bitmap.c
44111@@ -1779,7 +1779,7 @@ void bitmap_status(struct seq_file *seq, struct bitmap *bitmap)
44112 chunk_kb ? "KB" : "B");
44113 if (bitmap->storage.file) {
44114 seq_printf(seq, ", file: ");
44115- seq_path(seq, &bitmap->storage.file->f_path, " \t\n");
44116+ seq_path(seq, &bitmap->storage.file->f_path, " \t\n\\");
44117 }
44118
44119 seq_printf(seq, "\n");
44120diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c
44121index 5152142..623d141 100644
44122--- a/drivers/md/dm-ioctl.c
44123+++ b/drivers/md/dm-ioctl.c
44124@@ -1769,7 +1769,7 @@ static int validate_params(uint cmd, struct dm_ioctl *param)
44125 cmd == DM_LIST_VERSIONS_CMD)
44126 return 0;
44127
44128- if ((cmd == DM_DEV_CREATE_CMD)) {
44129+ if (cmd == DM_DEV_CREATE_CMD) {
44130 if (!*param->name) {
44131 DMWARN("name not supplied when creating device");
44132 return -EINVAL;
44133diff --git a/drivers/md/dm-raid1.c b/drivers/md/dm-raid1.c
44134index 7dfdb5c..4caada6 100644
44135--- a/drivers/md/dm-raid1.c
44136+++ b/drivers/md/dm-raid1.c
44137@@ -40,7 +40,7 @@ enum dm_raid1_error {
44138
44139 struct mirror {
44140 struct mirror_set *ms;
44141- atomic_t error_count;
44142+ atomic_unchecked_t error_count;
44143 unsigned long error_type;
44144 struct dm_dev *dev;
44145 sector_t offset;
44146@@ -186,7 +186,7 @@ static struct mirror *get_valid_mirror(struct mirror_set *ms)
44147 struct mirror *m;
44148
44149 for (m = ms->mirror; m < ms->mirror + ms->nr_mirrors; m++)
44150- if (!atomic_read(&m->error_count))
44151+ if (!atomic_read_unchecked(&m->error_count))
44152 return m;
44153
44154 return NULL;
44155@@ -218,7 +218,7 @@ static void fail_mirror(struct mirror *m, enum dm_raid1_error error_type)
44156 * simple way to tell if a device has encountered
44157 * errors.
44158 */
44159- atomic_inc(&m->error_count);
44160+ atomic_inc_unchecked(&m->error_count);
44161
44162 if (test_and_set_bit(error_type, &m->error_type))
44163 return;
44164@@ -409,7 +409,7 @@ static struct mirror *choose_mirror(struct mirror_set *ms, sector_t sector)
44165 struct mirror *m = get_default_mirror(ms);
44166
44167 do {
44168- if (likely(!atomic_read(&m->error_count)))
44169+ if (likely(!atomic_read_unchecked(&m->error_count)))
44170 return m;
44171
44172 if (m-- == ms->mirror)
44173@@ -423,7 +423,7 @@ static int default_ok(struct mirror *m)
44174 {
44175 struct mirror *default_mirror = get_default_mirror(m->ms);
44176
44177- return !atomic_read(&default_mirror->error_count);
44178+ return !atomic_read_unchecked(&default_mirror->error_count);
44179 }
44180
44181 static int mirror_available(struct mirror_set *ms, struct bio *bio)
44182@@ -560,7 +560,7 @@ static void do_reads(struct mirror_set *ms, struct bio_list *reads)
44183 */
44184 if (likely(region_in_sync(ms, region, 1)))
44185 m = choose_mirror(ms, bio->bi_iter.bi_sector);
44186- else if (m && atomic_read(&m->error_count))
44187+ else if (m && atomic_read_unchecked(&m->error_count))
44188 m = NULL;
44189
44190 if (likely(m))
44191@@ -927,7 +927,7 @@ static int get_mirror(struct mirror_set *ms, struct dm_target *ti,
44192 }
44193
44194 ms->mirror[mirror].ms = ms;
44195- atomic_set(&(ms->mirror[mirror].error_count), 0);
44196+ atomic_set_unchecked(&(ms->mirror[mirror].error_count), 0);
44197 ms->mirror[mirror].error_type = 0;
44198 ms->mirror[mirror].offset = offset;
44199
44200@@ -1342,7 +1342,7 @@ static void mirror_resume(struct dm_target *ti)
44201 */
44202 static char device_status_char(struct mirror *m)
44203 {
44204- if (!atomic_read(&(m->error_count)))
44205+ if (!atomic_read_unchecked(&(m->error_count)))
44206 return 'A';
44207
44208 return (test_bit(DM_RAID1_FLUSH_ERROR, &(m->error_type))) ? 'F' :
44209diff --git a/drivers/md/dm-stats.c b/drivers/md/dm-stats.c
44210index 28a9012..9c0f6a5 100644
44211--- a/drivers/md/dm-stats.c
44212+++ b/drivers/md/dm-stats.c
44213@@ -382,7 +382,7 @@ do_sync_free:
44214 synchronize_rcu_expedited();
44215 dm_stat_free(&s->rcu_head);
44216 } else {
44217- ACCESS_ONCE(dm_stat_need_rcu_barrier) = 1;
44218+ ACCESS_ONCE_RW(dm_stat_need_rcu_barrier) = 1;
44219 call_rcu(&s->rcu_head, dm_stat_free);
44220 }
44221 return 0;
44222@@ -554,8 +554,8 @@ void dm_stats_account_io(struct dm_stats *stats, unsigned long bi_rw,
44223 ((bi_rw & (REQ_WRITE | REQ_DISCARD)) ==
44224 (ACCESS_ONCE(last->last_rw) & (REQ_WRITE | REQ_DISCARD)))
44225 ));
44226- ACCESS_ONCE(last->last_sector) = end_sector;
44227- ACCESS_ONCE(last->last_rw) = bi_rw;
44228+ ACCESS_ONCE_RW(last->last_sector) = end_sector;
44229+ ACCESS_ONCE_RW(last->last_rw) = bi_rw;
44230 }
44231
44232 rcu_read_lock();
44233diff --git a/drivers/md/dm-stripe.c b/drivers/md/dm-stripe.c
44234index d1600d2..4c3af3a 100644
44235--- a/drivers/md/dm-stripe.c
44236+++ b/drivers/md/dm-stripe.c
44237@@ -21,7 +21,7 @@ struct stripe {
44238 struct dm_dev *dev;
44239 sector_t physical_start;
44240
44241- atomic_t error_count;
44242+ atomic_unchecked_t error_count;
44243 };
44244
44245 struct stripe_c {
44246@@ -186,7 +186,7 @@ static int stripe_ctr(struct dm_target *ti, unsigned int argc, char **argv)
44247 kfree(sc);
44248 return r;
44249 }
44250- atomic_set(&(sc->stripe[i].error_count), 0);
44251+ atomic_set_unchecked(&(sc->stripe[i].error_count), 0);
44252 }
44253
44254 ti->private = sc;
44255@@ -330,7 +330,7 @@ static void stripe_status(struct dm_target *ti, status_type_t type,
44256 DMEMIT("%d ", sc->stripes);
44257 for (i = 0; i < sc->stripes; i++) {
44258 DMEMIT("%s ", sc->stripe[i].dev->name);
44259- buffer[i] = atomic_read(&(sc->stripe[i].error_count)) ?
44260+ buffer[i] = atomic_read_unchecked(&(sc->stripe[i].error_count)) ?
44261 'D' : 'A';
44262 }
44263 buffer[i] = '\0';
44264@@ -375,8 +375,8 @@ static int stripe_end_io(struct dm_target *ti, struct bio *bio, int error)
44265 */
44266 for (i = 0; i < sc->stripes; i++)
44267 if (!strcmp(sc->stripe[i].dev->name, major_minor)) {
44268- atomic_inc(&(sc->stripe[i].error_count));
44269- if (atomic_read(&(sc->stripe[i].error_count)) <
44270+ atomic_inc_unchecked(&(sc->stripe[i].error_count));
44271+ if (atomic_read_unchecked(&(sc->stripe[i].error_count)) <
44272 DM_IO_ERROR_THRESHOLD)
44273 schedule_work(&sc->trigger_event);
44274 }
44275diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
44276index 6a7f2b8..fea0bde 100644
44277--- a/drivers/md/dm-table.c
44278+++ b/drivers/md/dm-table.c
44279@@ -274,7 +274,7 @@ static struct dm_dev_internal *find_device(struct list_head *l, dev_t dev)
44280 static int open_dev(struct dm_dev_internal *d, dev_t dev,
44281 struct mapped_device *md)
44282 {
44283- static char *_claim_ptr = "I belong to device-mapper";
44284+ static char _claim_ptr[] = "I belong to device-mapper";
44285 struct block_device *bdev;
44286
44287 int r;
44288@@ -342,7 +342,7 @@ static int device_area_is_invalid(struct dm_target *ti, struct dm_dev *dev,
44289 if (!dev_size)
44290 return 0;
44291
44292- if ((start >= dev_size) || (start + len > dev_size)) {
44293+ if ((start >= dev_size) || (len > dev_size - start)) {
44294 DMWARN("%s: %s too small for target: "
44295 "start=%llu, len=%llu, dev_size=%llu",
44296 dm_device_name(ti->table->md), bdevname(bdev, b),
44297diff --git a/drivers/md/dm-thin-metadata.c b/drivers/md/dm-thin-metadata.c
44298index b086a94..74cb67e 100644
44299--- a/drivers/md/dm-thin-metadata.c
44300+++ b/drivers/md/dm-thin-metadata.c
44301@@ -404,7 +404,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
44302 {
44303 pmd->info.tm = pmd->tm;
44304 pmd->info.levels = 2;
44305- pmd->info.value_type.context = pmd->data_sm;
44306+ pmd->info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
44307 pmd->info.value_type.size = sizeof(__le64);
44308 pmd->info.value_type.inc = data_block_inc;
44309 pmd->info.value_type.dec = data_block_dec;
44310@@ -423,7 +423,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
44311
44312 pmd->bl_info.tm = pmd->tm;
44313 pmd->bl_info.levels = 1;
44314- pmd->bl_info.value_type.context = pmd->data_sm;
44315+ pmd->bl_info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
44316 pmd->bl_info.value_type.size = sizeof(__le64);
44317 pmd->bl_info.value_type.inc = data_block_inc;
44318 pmd->bl_info.value_type.dec = data_block_dec;
44319diff --git a/drivers/md/dm.c b/drivers/md/dm.c
44320index 8c53b09..f1fb2b0 100644
44321--- a/drivers/md/dm.c
44322+++ b/drivers/md/dm.c
44323@@ -185,9 +185,9 @@ struct mapped_device {
44324 /*
44325 * Event handling.
44326 */
44327- atomic_t event_nr;
44328+ atomic_unchecked_t event_nr;
44329 wait_queue_head_t eventq;
44330- atomic_t uevent_seq;
44331+ atomic_unchecked_t uevent_seq;
44332 struct list_head uevent_list;
44333 spinlock_t uevent_lock; /* Protect access to uevent_list */
44334
44335@@ -1888,8 +1888,8 @@ static struct mapped_device *alloc_dev(int minor)
44336 spin_lock_init(&md->deferred_lock);
44337 atomic_set(&md->holders, 1);
44338 atomic_set(&md->open_count, 0);
44339- atomic_set(&md->event_nr, 0);
44340- atomic_set(&md->uevent_seq, 0);
44341+ atomic_set_unchecked(&md->event_nr, 0);
44342+ atomic_set_unchecked(&md->uevent_seq, 0);
44343 INIT_LIST_HEAD(&md->uevent_list);
44344 spin_lock_init(&md->uevent_lock);
44345
44346@@ -2043,7 +2043,7 @@ static void event_callback(void *context)
44347
44348 dm_send_uevents(&uevents, &disk_to_dev(md->disk)->kobj);
44349
44350- atomic_inc(&md->event_nr);
44351+ atomic_inc_unchecked(&md->event_nr);
44352 wake_up(&md->eventq);
44353 }
44354
44355@@ -2736,18 +2736,18 @@ int dm_kobject_uevent(struct mapped_device *md, enum kobject_action action,
44356
44357 uint32_t dm_next_uevent_seq(struct mapped_device *md)
44358 {
44359- return atomic_add_return(1, &md->uevent_seq);
44360+ return atomic_add_return_unchecked(1, &md->uevent_seq);
44361 }
44362
44363 uint32_t dm_get_event_nr(struct mapped_device *md)
44364 {
44365- return atomic_read(&md->event_nr);
44366+ return atomic_read_unchecked(&md->event_nr);
44367 }
44368
44369 int dm_wait_event(struct mapped_device *md, int event_nr)
44370 {
44371 return wait_event_interruptible(md->eventq,
44372- (event_nr != atomic_read(&md->event_nr)));
44373+ (event_nr != atomic_read_unchecked(&md->event_nr)));
44374 }
44375
44376 void dm_uevent_add(struct mapped_device *md, struct list_head *elist)
44377diff --git a/drivers/md/md.c b/drivers/md/md.c
44378index 4ad5cc4..0f19664 100644
44379--- a/drivers/md/md.c
44380+++ b/drivers/md/md.c
44381@@ -194,10 +194,10 @@ EXPORT_SYMBOL_GPL(bio_clone_mddev);
44382 * start build, activate spare
44383 */
44384 static DECLARE_WAIT_QUEUE_HEAD(md_event_waiters);
44385-static atomic_t md_event_count;
44386+static atomic_unchecked_t md_event_count;
44387 void md_new_event(struct mddev *mddev)
44388 {
44389- atomic_inc(&md_event_count);
44390+ atomic_inc_unchecked(&md_event_count);
44391 wake_up(&md_event_waiters);
44392 }
44393 EXPORT_SYMBOL_GPL(md_new_event);
44394@@ -207,7 +207,7 @@ EXPORT_SYMBOL_GPL(md_new_event);
44395 */
44396 static void md_new_event_inintr(struct mddev *mddev)
44397 {
44398- atomic_inc(&md_event_count);
44399+ atomic_inc_unchecked(&md_event_count);
44400 wake_up(&md_event_waiters);
44401 }
44402
44403@@ -1462,7 +1462,7 @@ static int super_1_load(struct md_rdev *rdev, struct md_rdev *refdev, int minor_
44404 if ((le32_to_cpu(sb->feature_map) & MD_FEATURE_RESHAPE_ACTIVE) &&
44405 (le32_to_cpu(sb->feature_map) & MD_FEATURE_NEW_OFFSET))
44406 rdev->new_data_offset += (s32)le32_to_cpu(sb->new_offset);
44407- atomic_set(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
44408+ atomic_set_unchecked(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
44409
44410 rdev->sb_size = le32_to_cpu(sb->max_dev) * 2 + 256;
44411 bmask = queue_logical_block_size(rdev->bdev->bd_disk->queue)-1;
44412@@ -1713,7 +1713,7 @@ static void super_1_sync(struct mddev *mddev, struct md_rdev *rdev)
44413 else
44414 sb->resync_offset = cpu_to_le64(0);
44415
44416- sb->cnt_corrected_read = cpu_to_le32(atomic_read(&rdev->corrected_errors));
44417+ sb->cnt_corrected_read = cpu_to_le32(atomic_read_unchecked(&rdev->corrected_errors));
44418
44419 sb->raid_disks = cpu_to_le32(mddev->raid_disks);
44420 sb->size = cpu_to_le64(mddev->dev_sectors);
44421@@ -2725,7 +2725,7 @@ __ATTR(state, S_IRUGO|S_IWUSR, state_show, state_store);
44422 static ssize_t
44423 errors_show(struct md_rdev *rdev, char *page)
44424 {
44425- return sprintf(page, "%d\n", atomic_read(&rdev->corrected_errors));
44426+ return sprintf(page, "%d\n", atomic_read_unchecked(&rdev->corrected_errors));
44427 }
44428
44429 static ssize_t
44430@@ -2734,7 +2734,7 @@ errors_store(struct md_rdev *rdev, const char *buf, size_t len)
44431 char *e;
44432 unsigned long n = simple_strtoul(buf, &e, 10);
44433 if (*buf && (*e == 0 || *e == '\n')) {
44434- atomic_set(&rdev->corrected_errors, n);
44435+ atomic_set_unchecked(&rdev->corrected_errors, n);
44436 return len;
44437 }
44438 return -EINVAL;
44439@@ -3183,8 +3183,8 @@ int md_rdev_init(struct md_rdev *rdev)
44440 rdev->sb_loaded = 0;
44441 rdev->bb_page = NULL;
44442 atomic_set(&rdev->nr_pending, 0);
44443- atomic_set(&rdev->read_errors, 0);
44444- atomic_set(&rdev->corrected_errors, 0);
44445+ atomic_set_unchecked(&rdev->read_errors, 0);
44446+ atomic_set_unchecked(&rdev->corrected_errors, 0);
44447
44448 INIT_LIST_HEAD(&rdev->same_set);
44449 init_waitqueue_head(&rdev->blocked_wait);
44450@@ -7075,7 +7075,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
44451
44452 spin_unlock(&pers_lock);
44453 seq_printf(seq, "\n");
44454- seq->poll_event = atomic_read(&md_event_count);
44455+ seq->poll_event = atomic_read_unchecked(&md_event_count);
44456 return 0;
44457 }
44458 if (v == (void*)2) {
44459@@ -7178,7 +7178,7 @@ static int md_seq_open(struct inode *inode, struct file *file)
44460 return error;
44461
44462 seq = file->private_data;
44463- seq->poll_event = atomic_read(&md_event_count);
44464+ seq->poll_event = atomic_read_unchecked(&md_event_count);
44465 return error;
44466 }
44467
44468@@ -7192,7 +7192,7 @@ static unsigned int mdstat_poll(struct file *filp, poll_table *wait)
44469 /* always allow read */
44470 mask = POLLIN | POLLRDNORM;
44471
44472- if (seq->poll_event != atomic_read(&md_event_count))
44473+ if (seq->poll_event != atomic_read_unchecked(&md_event_count))
44474 mask |= POLLERR | POLLPRI;
44475 return mask;
44476 }
44477@@ -7236,7 +7236,7 @@ static int is_mddev_idle(struct mddev *mddev, int init)
44478 struct gendisk *disk = rdev->bdev->bd_contains->bd_disk;
44479 curr_events = (int)part_stat_read(&disk->part0, sectors[0]) +
44480 (int)part_stat_read(&disk->part0, sectors[1]) -
44481- atomic_read(&disk->sync_io);
44482+ atomic_read_unchecked(&disk->sync_io);
44483 /* sync IO will cause sync_io to increase before the disk_stats
44484 * as sync_io is counted when a request starts, and
44485 * disk_stats is counted when it completes.
44486diff --git a/drivers/md/md.h b/drivers/md/md.h
44487index 07bba96..2d6788c 100644
44488--- a/drivers/md/md.h
44489+++ b/drivers/md/md.h
44490@@ -94,13 +94,13 @@ struct md_rdev {
44491 * only maintained for arrays that
44492 * support hot removal
44493 */
44494- atomic_t read_errors; /* number of consecutive read errors that
44495+ atomic_unchecked_t read_errors; /* number of consecutive read errors that
44496 * we have tried to ignore.
44497 */
44498 struct timespec last_read_error; /* monotonic time since our
44499 * last read error
44500 */
44501- atomic_t corrected_errors; /* number of corrected read errors,
44502+ atomic_unchecked_t corrected_errors; /* number of corrected read errors,
44503 * for reporting to userspace and storing
44504 * in superblock.
44505 */
44506@@ -449,7 +449,7 @@ static inline void rdev_dec_pending(struct md_rdev *rdev, struct mddev *mddev)
44507
44508 static inline void md_sync_acct(struct block_device *bdev, unsigned long nr_sectors)
44509 {
44510- atomic_add(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
44511+ atomic_add_unchecked(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
44512 }
44513
44514 struct md_personality
44515diff --git a/drivers/md/persistent-data/dm-space-map-metadata.c b/drivers/md/persistent-data/dm-space-map-metadata.c
44516index 786b689..ea8c956 100644
44517--- a/drivers/md/persistent-data/dm-space-map-metadata.c
44518+++ b/drivers/md/persistent-data/dm-space-map-metadata.c
44519@@ -679,7 +679,7 @@ static int sm_metadata_extend(struct dm_space_map *sm, dm_block_t extra_blocks)
44520 * Flick into a mode where all blocks get allocated in the new area.
44521 */
44522 smm->begin = old_len;
44523- memcpy(sm, &bootstrap_ops, sizeof(*sm));
44524+ memcpy((void *)sm, &bootstrap_ops, sizeof(*sm));
44525
44526 /*
44527 * Extend.
44528@@ -710,7 +710,7 @@ out:
44529 /*
44530 * Switch back to normal behaviour.
44531 */
44532- memcpy(sm, &ops, sizeof(*sm));
44533+ memcpy((void *)sm, &ops, sizeof(*sm));
44534 return r;
44535 }
44536
44537diff --git a/drivers/md/persistent-data/dm-space-map.h b/drivers/md/persistent-data/dm-space-map.h
44538index 3e6d115..ffecdeb 100644
44539--- a/drivers/md/persistent-data/dm-space-map.h
44540+++ b/drivers/md/persistent-data/dm-space-map.h
44541@@ -71,6 +71,7 @@ struct dm_space_map {
44542 dm_sm_threshold_fn fn,
44543 void *context);
44544 };
44545+typedef struct dm_space_map __no_const dm_space_map_no_const;
44546
44547 /*----------------------------------------------------------------*/
44548
44549diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
44550index 4a6ca1c..e952750 100644
44551--- a/drivers/md/raid1.c
44552+++ b/drivers/md/raid1.c
44553@@ -1922,7 +1922,7 @@ static int fix_sync_read_error(struct r1bio *r1_bio)
44554 if (r1_sync_page_io(rdev, sect, s,
44555 bio->bi_io_vec[idx].bv_page,
44556 READ) != 0)
44557- atomic_add(s, &rdev->corrected_errors);
44558+ atomic_add_unchecked(s, &rdev->corrected_errors);
44559 }
44560 sectors -= s;
44561 sect += s;
44562@@ -2156,7 +2156,7 @@ static void fix_read_error(struct r1conf *conf, int read_disk,
44563 test_bit(In_sync, &rdev->flags)) {
44564 if (r1_sync_page_io(rdev, sect, s,
44565 conf->tmppage, READ)) {
44566- atomic_add(s, &rdev->corrected_errors);
44567+ atomic_add_unchecked(s, &rdev->corrected_errors);
44568 printk(KERN_INFO
44569 "md/raid1:%s: read error corrected "
44570 "(%d sectors at %llu on %s)\n",
44571diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
44572index 33fc408..fc61709 100644
44573--- a/drivers/md/raid10.c
44574+++ b/drivers/md/raid10.c
44575@@ -1948,7 +1948,7 @@ static void end_sync_read(struct bio *bio, int error)
44576 /* The write handler will notice the lack of
44577 * R10BIO_Uptodate and record any errors etc
44578 */
44579- atomic_add(r10_bio->sectors,
44580+ atomic_add_unchecked(r10_bio->sectors,
44581 &conf->mirrors[d].rdev->corrected_errors);
44582
44583 /* for reconstruct, we always reschedule after a read.
44584@@ -2306,7 +2306,7 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
44585 {
44586 struct timespec cur_time_mon;
44587 unsigned long hours_since_last;
44588- unsigned int read_errors = atomic_read(&rdev->read_errors);
44589+ unsigned int read_errors = atomic_read_unchecked(&rdev->read_errors);
44590
44591 ktime_get_ts(&cur_time_mon);
44592
44593@@ -2328,9 +2328,9 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
44594 * overflowing the shift of read_errors by hours_since_last.
44595 */
44596 if (hours_since_last >= 8 * sizeof(read_errors))
44597- atomic_set(&rdev->read_errors, 0);
44598+ atomic_set_unchecked(&rdev->read_errors, 0);
44599 else
44600- atomic_set(&rdev->read_errors, read_errors >> hours_since_last);
44601+ atomic_set_unchecked(&rdev->read_errors, read_errors >> hours_since_last);
44602 }
44603
44604 static int r10_sync_page_io(struct md_rdev *rdev, sector_t sector,
44605@@ -2384,8 +2384,8 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
44606 return;
44607
44608 check_decay_read_errors(mddev, rdev);
44609- atomic_inc(&rdev->read_errors);
44610- if (atomic_read(&rdev->read_errors) > max_read_errors) {
44611+ atomic_inc_unchecked(&rdev->read_errors);
44612+ if (atomic_read_unchecked(&rdev->read_errors) > max_read_errors) {
44613 char b[BDEVNAME_SIZE];
44614 bdevname(rdev->bdev, b);
44615
44616@@ -2393,7 +2393,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
44617 "md/raid10:%s: %s: Raid device exceeded "
44618 "read_error threshold [cur %d:max %d]\n",
44619 mdname(mddev), b,
44620- atomic_read(&rdev->read_errors), max_read_errors);
44621+ atomic_read_unchecked(&rdev->read_errors), max_read_errors);
44622 printk(KERN_NOTICE
44623 "md/raid10:%s: %s: Failing raid device\n",
44624 mdname(mddev), b);
44625@@ -2548,7 +2548,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
44626 sect +
44627 choose_data_offset(r10_bio, rdev)),
44628 bdevname(rdev->bdev, b));
44629- atomic_add(s, &rdev->corrected_errors);
44630+ atomic_add_unchecked(s, &rdev->corrected_errors);
44631 }
44632
44633 rdev_dec_pending(rdev, mddev);
44634diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
44635index 16f5c21..4df20dc 100644
44636--- a/drivers/md/raid5.c
44637+++ b/drivers/md/raid5.c
44638@@ -1991,21 +1991,21 @@ static void raid5_end_read_request(struct bio * bi, int error)
44639 mdname(conf->mddev), STRIPE_SECTORS,
44640 (unsigned long long)s,
44641 bdevname(rdev->bdev, b));
44642- atomic_add(STRIPE_SECTORS, &rdev->corrected_errors);
44643+ atomic_add_unchecked(STRIPE_SECTORS, &rdev->corrected_errors);
44644 clear_bit(R5_ReadError, &sh->dev[i].flags);
44645 clear_bit(R5_ReWrite, &sh->dev[i].flags);
44646 } else if (test_bit(R5_ReadNoMerge, &sh->dev[i].flags))
44647 clear_bit(R5_ReadNoMerge, &sh->dev[i].flags);
44648
44649- if (atomic_read(&rdev->read_errors))
44650- atomic_set(&rdev->read_errors, 0);
44651+ if (atomic_read_unchecked(&rdev->read_errors))
44652+ atomic_set_unchecked(&rdev->read_errors, 0);
44653 } else {
44654 const char *bdn = bdevname(rdev->bdev, b);
44655 int retry = 0;
44656 int set_bad = 0;
44657
44658 clear_bit(R5_UPTODATE, &sh->dev[i].flags);
44659- atomic_inc(&rdev->read_errors);
44660+ atomic_inc_unchecked(&rdev->read_errors);
44661 if (test_bit(R5_ReadRepl, &sh->dev[i].flags))
44662 printk_ratelimited(
44663 KERN_WARNING
44664@@ -2033,7 +2033,7 @@ static void raid5_end_read_request(struct bio * bi, int error)
44665 mdname(conf->mddev),
44666 (unsigned long long)s,
44667 bdn);
44668- } else if (atomic_read(&rdev->read_errors)
44669+ } else if (atomic_read_unchecked(&rdev->read_errors)
44670 > conf->max_nr_stripes)
44671 printk(KERN_WARNING
44672 "md/raid:%s: Too many read errors, failing device %s.\n",
44673diff --git a/drivers/media/dvb-core/dvbdev.c b/drivers/media/dvb-core/dvbdev.c
44674index 983db75..ef9248c 100644
44675--- a/drivers/media/dvb-core/dvbdev.c
44676+++ b/drivers/media/dvb-core/dvbdev.c
44677@@ -185,7 +185,7 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,
44678 const struct dvb_device *template, void *priv, int type)
44679 {
44680 struct dvb_device *dvbdev;
44681- struct file_operations *dvbdevfops;
44682+ file_operations_no_const *dvbdevfops;
44683 struct device *clsdev;
44684 int minor;
44685 int id;
44686diff --git a/drivers/media/dvb-frontends/dib3000.h b/drivers/media/dvb-frontends/dib3000.h
44687index 9b6c3bb..baeb5c7 100644
44688--- a/drivers/media/dvb-frontends/dib3000.h
44689+++ b/drivers/media/dvb-frontends/dib3000.h
44690@@ -39,7 +39,7 @@ struct dib_fe_xfer_ops
44691 int (*fifo_ctrl)(struct dvb_frontend *fe, int onoff);
44692 int (*pid_ctrl)(struct dvb_frontend *fe, int index, int pid, int onoff);
44693 int (*tuner_pass_ctrl)(struct dvb_frontend *fe, int onoff, u8 pll_ctrl);
44694-};
44695+} __no_const;
44696
44697 #if IS_ENABLED(CONFIG_DVB_DIB3000MB)
44698 extern struct dvb_frontend* dib3000mb_attach(const struct dib3000_config* config,
44699diff --git a/drivers/media/media-device.c b/drivers/media/media-device.c
44700index d5a7a13..703560f 100644
44701--- a/drivers/media/media-device.c
44702+++ b/drivers/media/media-device.c
44703@@ -93,6 +93,7 @@ static long media_device_enum_entities(struct media_device *mdev,
44704 struct media_entity *ent;
44705 struct media_entity_desc u_ent;
44706
44707+ memset(&u_ent, 0, sizeof(u_ent));
44708 if (copy_from_user(&u_ent.id, &uent->id, sizeof(u_ent.id)))
44709 return -EFAULT;
44710
44711diff --git a/drivers/media/pci/cx88/cx88-video.c b/drivers/media/pci/cx88/cx88-video.c
44712index ed8cb90..5ef7f79 100644
44713--- a/drivers/media/pci/cx88/cx88-video.c
44714+++ b/drivers/media/pci/cx88/cx88-video.c
44715@@ -50,9 +50,9 @@ MODULE_VERSION(CX88_VERSION);
44716
44717 /* ------------------------------------------------------------------ */
44718
44719-static unsigned int video_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
44720-static unsigned int vbi_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
44721-static unsigned int radio_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
44722+static int video_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
44723+static int vbi_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
44724+static int radio_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
44725
44726 module_param_array(video_nr, int, NULL, 0444);
44727 module_param_array(vbi_nr, int, NULL, 0444);
44728diff --git a/drivers/media/pci/ivtv/ivtv-driver.c b/drivers/media/pci/ivtv/ivtv-driver.c
44729index 802642d..5534900 100644
44730--- a/drivers/media/pci/ivtv/ivtv-driver.c
44731+++ b/drivers/media/pci/ivtv/ivtv-driver.c
44732@@ -83,7 +83,7 @@ static struct pci_device_id ivtv_pci_tbl[] = {
44733 MODULE_DEVICE_TABLE(pci,ivtv_pci_tbl);
44734
44735 /* ivtv instance counter */
44736-static atomic_t ivtv_instance = ATOMIC_INIT(0);
44737+static atomic_unchecked_t ivtv_instance = ATOMIC_INIT(0);
44738
44739 /* Parameter declarations */
44740 static int cardtype[IVTV_MAX_CARDS];
44741diff --git a/drivers/media/platform/omap/omap_vout.c b/drivers/media/platform/omap/omap_vout.c
44742index dfd0a21..6bbb465 100644
44743--- a/drivers/media/platform/omap/omap_vout.c
44744+++ b/drivers/media/platform/omap/omap_vout.c
44745@@ -63,7 +63,6 @@ enum omap_vout_channels {
44746 OMAP_VIDEO2,
44747 };
44748
44749-static struct videobuf_queue_ops video_vbq_ops;
44750 /* Variables configurable through module params*/
44751 static u32 video1_numbuffers = 3;
44752 static u32 video2_numbuffers = 3;
44753@@ -1014,6 +1013,12 @@ static int omap_vout_open(struct file *file)
44754 {
44755 struct videobuf_queue *q;
44756 struct omap_vout_device *vout = NULL;
44757+ static struct videobuf_queue_ops video_vbq_ops = {
44758+ .buf_setup = omap_vout_buffer_setup,
44759+ .buf_prepare = omap_vout_buffer_prepare,
44760+ .buf_release = omap_vout_buffer_release,
44761+ .buf_queue = omap_vout_buffer_queue,
44762+ };
44763
44764 vout = video_drvdata(file);
44765 v4l2_dbg(1, debug, &vout->vid_dev->v4l2_dev, "Entering %s\n", __func__);
44766@@ -1031,10 +1036,6 @@ static int omap_vout_open(struct file *file)
44767 vout->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
44768
44769 q = &vout->vbq;
44770- video_vbq_ops.buf_setup = omap_vout_buffer_setup;
44771- video_vbq_ops.buf_prepare = omap_vout_buffer_prepare;
44772- video_vbq_ops.buf_release = omap_vout_buffer_release;
44773- video_vbq_ops.buf_queue = omap_vout_buffer_queue;
44774 spin_lock_init(&vout->vbq_lock);
44775
44776 videobuf_queue_dma_contig_init(q, &video_vbq_ops, q->dev,
44777diff --git a/drivers/media/platform/s5p-tv/mixer.h b/drivers/media/platform/s5p-tv/mixer.h
44778index fb2acc5..a2fcbdc4 100644
44779--- a/drivers/media/platform/s5p-tv/mixer.h
44780+++ b/drivers/media/platform/s5p-tv/mixer.h
44781@@ -156,7 +156,7 @@ struct mxr_layer {
44782 /** layer index (unique identifier) */
44783 int idx;
44784 /** callbacks for layer methods */
44785- struct mxr_layer_ops ops;
44786+ struct mxr_layer_ops *ops;
44787 /** format array */
44788 const struct mxr_format **fmt_array;
44789 /** size of format array */
44790diff --git a/drivers/media/platform/s5p-tv/mixer_grp_layer.c b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
44791index 74344c7..a39e70e 100644
44792--- a/drivers/media/platform/s5p-tv/mixer_grp_layer.c
44793+++ b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
44794@@ -235,7 +235,7 @@ struct mxr_layer *mxr_graph_layer_create(struct mxr_device *mdev, int idx)
44795 {
44796 struct mxr_layer *layer;
44797 int ret;
44798- struct mxr_layer_ops ops = {
44799+ static struct mxr_layer_ops ops = {
44800 .release = mxr_graph_layer_release,
44801 .buffer_set = mxr_graph_buffer_set,
44802 .stream_set = mxr_graph_stream_set,
44803diff --git a/drivers/media/platform/s5p-tv/mixer_reg.c b/drivers/media/platform/s5p-tv/mixer_reg.c
44804index b713403..53cb5ad 100644
44805--- a/drivers/media/platform/s5p-tv/mixer_reg.c
44806+++ b/drivers/media/platform/s5p-tv/mixer_reg.c
44807@@ -276,7 +276,7 @@ static void mxr_irq_layer_handle(struct mxr_layer *layer)
44808 layer->update_buf = next;
44809 }
44810
44811- layer->ops.buffer_set(layer, layer->update_buf);
44812+ layer->ops->buffer_set(layer, layer->update_buf);
44813
44814 if (done && done != layer->shadow_buf)
44815 vb2_buffer_done(&done->vb, VB2_BUF_STATE_DONE);
44816diff --git a/drivers/media/platform/s5p-tv/mixer_video.c b/drivers/media/platform/s5p-tv/mixer_video.c
44817index c5059ba..2649f28 100644
44818--- a/drivers/media/platform/s5p-tv/mixer_video.c
44819+++ b/drivers/media/platform/s5p-tv/mixer_video.c
44820@@ -210,7 +210,7 @@ static void mxr_layer_default_geo(struct mxr_layer *layer)
44821 layer->geo.src.height = layer->geo.src.full_height;
44822
44823 mxr_geometry_dump(mdev, &layer->geo);
44824- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
44825+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
44826 mxr_geometry_dump(mdev, &layer->geo);
44827 }
44828
44829@@ -228,7 +228,7 @@ static void mxr_layer_update_output(struct mxr_layer *layer)
44830 layer->geo.dst.full_width = mbus_fmt.width;
44831 layer->geo.dst.full_height = mbus_fmt.height;
44832 layer->geo.dst.field = mbus_fmt.field;
44833- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
44834+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
44835
44836 mxr_geometry_dump(mdev, &layer->geo);
44837 }
44838@@ -334,7 +334,7 @@ static int mxr_s_fmt(struct file *file, void *priv,
44839 /* set source size to highest accepted value */
44840 geo->src.full_width = max(geo->dst.full_width, pix->width);
44841 geo->src.full_height = max(geo->dst.full_height, pix->height);
44842- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
44843+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
44844 mxr_geometry_dump(mdev, &layer->geo);
44845 /* set cropping to total visible screen */
44846 geo->src.width = pix->width;
44847@@ -342,12 +342,12 @@ static int mxr_s_fmt(struct file *file, void *priv,
44848 geo->src.x_offset = 0;
44849 geo->src.y_offset = 0;
44850 /* assure consistency of geometry */
44851- layer->ops.fix_geometry(layer, MXR_GEOMETRY_CROP, MXR_NO_OFFSET);
44852+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_CROP, MXR_NO_OFFSET);
44853 mxr_geometry_dump(mdev, &layer->geo);
44854 /* set full size to lowest possible value */
44855 geo->src.full_width = 0;
44856 geo->src.full_height = 0;
44857- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
44858+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
44859 mxr_geometry_dump(mdev, &layer->geo);
44860
44861 /* returning results */
44862@@ -474,7 +474,7 @@ static int mxr_s_selection(struct file *file, void *fh,
44863 target->width = s->r.width;
44864 target->height = s->r.height;
44865
44866- layer->ops.fix_geometry(layer, stage, s->flags);
44867+ layer->ops->fix_geometry(layer, stage, s->flags);
44868
44869 /* retrieve update selection rectangle */
44870 res.left = target->x_offset;
44871@@ -955,13 +955,13 @@ static int start_streaming(struct vb2_queue *vq, unsigned int count)
44872 mxr_output_get(mdev);
44873
44874 mxr_layer_update_output(layer);
44875- layer->ops.format_set(layer);
44876+ layer->ops->format_set(layer);
44877 /* enabling layer in hardware */
44878 spin_lock_irqsave(&layer->enq_slock, flags);
44879 layer->state = MXR_LAYER_STREAMING;
44880 spin_unlock_irqrestore(&layer->enq_slock, flags);
44881
44882- layer->ops.stream_set(layer, MXR_ENABLE);
44883+ layer->ops->stream_set(layer, MXR_ENABLE);
44884 mxr_streamer_get(mdev);
44885
44886 return 0;
44887@@ -1031,7 +1031,7 @@ static int stop_streaming(struct vb2_queue *vq)
44888 spin_unlock_irqrestore(&layer->enq_slock, flags);
44889
44890 /* disabling layer in hardware */
44891- layer->ops.stream_set(layer, MXR_DISABLE);
44892+ layer->ops->stream_set(layer, MXR_DISABLE);
44893 /* remove one streamer */
44894 mxr_streamer_put(mdev);
44895 /* allow changes in output configuration */
44896@@ -1070,8 +1070,8 @@ void mxr_base_layer_unregister(struct mxr_layer *layer)
44897
44898 void mxr_layer_release(struct mxr_layer *layer)
44899 {
44900- if (layer->ops.release)
44901- layer->ops.release(layer);
44902+ if (layer->ops->release)
44903+ layer->ops->release(layer);
44904 }
44905
44906 void mxr_base_layer_release(struct mxr_layer *layer)
44907@@ -1097,7 +1097,7 @@ struct mxr_layer *mxr_base_layer_create(struct mxr_device *mdev,
44908
44909 layer->mdev = mdev;
44910 layer->idx = idx;
44911- layer->ops = *ops;
44912+ layer->ops = ops;
44913
44914 spin_lock_init(&layer->enq_slock);
44915 INIT_LIST_HEAD(&layer->enq_list);
44916diff --git a/drivers/media/platform/s5p-tv/mixer_vp_layer.c b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
44917index c9388c4..ce71ece 100644
44918--- a/drivers/media/platform/s5p-tv/mixer_vp_layer.c
44919+++ b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
44920@@ -206,7 +206,7 @@ struct mxr_layer *mxr_vp_layer_create(struct mxr_device *mdev, int idx)
44921 {
44922 struct mxr_layer *layer;
44923 int ret;
44924- struct mxr_layer_ops ops = {
44925+ static struct mxr_layer_ops ops = {
44926 .release = mxr_vp_layer_release,
44927 .buffer_set = mxr_vp_buffer_set,
44928 .stream_set = mxr_vp_stream_set,
44929diff --git a/drivers/media/platform/vivi.c b/drivers/media/platform/vivi.c
44930index 2d4e73b..8b4d5b6 100644
44931--- a/drivers/media/platform/vivi.c
44932+++ b/drivers/media/platform/vivi.c
44933@@ -58,8 +58,8 @@ MODULE_AUTHOR("Mauro Carvalho Chehab, Ted Walther and John Sokol");
44934 MODULE_LICENSE("Dual BSD/GPL");
44935 MODULE_VERSION(VIVI_VERSION);
44936
44937-static unsigned video_nr = -1;
44938-module_param(video_nr, uint, 0644);
44939+static int video_nr = -1;
44940+module_param(video_nr, int, 0644);
44941 MODULE_PARM_DESC(video_nr, "videoX start number, -1 is autodetect");
44942
44943 static unsigned n_devs = 1;
44944diff --git a/drivers/media/radio/radio-cadet.c b/drivers/media/radio/radio-cadet.c
44945index 545c04c..a14bded 100644
44946--- a/drivers/media/radio/radio-cadet.c
44947+++ b/drivers/media/radio/radio-cadet.c
44948@@ -324,6 +324,8 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
44949 unsigned char readbuf[RDS_BUFFER];
44950 int i = 0;
44951
44952+ if (count > RDS_BUFFER)
44953+ return -EFAULT;
44954 mutex_lock(&dev->lock);
44955 if (dev->rdsstat == 0)
44956 cadet_start_rds(dev);
44957@@ -339,7 +341,7 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
44958 while (i < count && dev->rdsin != dev->rdsout)
44959 readbuf[i++] = dev->rdsbuf[dev->rdsout++];
44960
44961- if (i && copy_to_user(data, readbuf, i))
44962+ if (i > sizeof(readbuf) || copy_to_user(data, readbuf, i))
44963 i = -EFAULT;
44964 unlock:
44965 mutex_unlock(&dev->lock);
44966diff --git a/drivers/media/radio/radio-maxiradio.c b/drivers/media/radio/radio-maxiradio.c
44967index 5236035..c622c74 100644
44968--- a/drivers/media/radio/radio-maxiradio.c
44969+++ b/drivers/media/radio/radio-maxiradio.c
44970@@ -61,7 +61,7 @@ MODULE_PARM_DESC(radio_nr, "Radio device number");
44971 /* TEA5757 pin mappings */
44972 static const int clk = 1, data = 2, wren = 4, mo_st = 8, power = 16;
44973
44974-static atomic_t maxiradio_instance = ATOMIC_INIT(0);
44975+static atomic_unchecked_t maxiradio_instance = ATOMIC_INIT(0);
44976
44977 #define PCI_VENDOR_ID_GUILLEMOT 0x5046
44978 #define PCI_DEVICE_ID_GUILLEMOT_MAXIRADIO 0x1001
44979diff --git a/drivers/media/radio/radio-shark.c b/drivers/media/radio/radio-shark.c
44980index 050b3bb..79f62b9 100644
44981--- a/drivers/media/radio/radio-shark.c
44982+++ b/drivers/media/radio/radio-shark.c
44983@@ -79,7 +79,7 @@ struct shark_device {
44984 u32 last_val;
44985 };
44986
44987-static atomic_t shark_instance = ATOMIC_INIT(0);
44988+static atomic_unchecked_t shark_instance = ATOMIC_INIT(0);
44989
44990 static void shark_write_val(struct snd_tea575x *tea, u32 val)
44991 {
44992diff --git a/drivers/media/radio/radio-shark2.c b/drivers/media/radio/radio-shark2.c
44993index 8654e0d..0608a64 100644
44994--- a/drivers/media/radio/radio-shark2.c
44995+++ b/drivers/media/radio/radio-shark2.c
44996@@ -74,7 +74,7 @@ struct shark_device {
44997 u8 *transfer_buffer;
44998 };
44999
45000-static atomic_t shark_instance = ATOMIC_INIT(0);
45001+static atomic_unchecked_t shark_instance = ATOMIC_INIT(0);
45002
45003 static int shark_write_reg(struct radio_tea5777 *tea, u64 reg)
45004 {
45005diff --git a/drivers/media/radio/radio-si476x.c b/drivers/media/radio/radio-si476x.c
45006index 2fd9009..278cc1e 100644
45007--- a/drivers/media/radio/radio-si476x.c
45008+++ b/drivers/media/radio/radio-si476x.c
45009@@ -1445,7 +1445,7 @@ static int si476x_radio_probe(struct platform_device *pdev)
45010 struct si476x_radio *radio;
45011 struct v4l2_ctrl *ctrl;
45012
45013- static atomic_t instance = ATOMIC_INIT(0);
45014+ static atomic_unchecked_t instance = ATOMIC_INIT(0);
45015
45016 radio = devm_kzalloc(&pdev->dev, sizeof(*radio), GFP_KERNEL);
45017 if (!radio)
45018diff --git a/drivers/media/usb/dvb-usb/cxusb.c b/drivers/media/usb/dvb-usb/cxusb.c
45019index a1c641e..3007da9 100644
45020--- a/drivers/media/usb/dvb-usb/cxusb.c
45021+++ b/drivers/media/usb/dvb-usb/cxusb.c
45022@@ -1112,7 +1112,7 @@ static struct dib0070_config dib7070p_dib0070_config = {
45023
45024 struct dib0700_adapter_state {
45025 int (*set_param_save) (struct dvb_frontend *);
45026-};
45027+} __no_const;
45028
45029 static int dib7070_set_param_override(struct dvb_frontend *fe)
45030 {
45031diff --git a/drivers/media/usb/dvb-usb/dw2102.c b/drivers/media/usb/dvb-usb/dw2102.c
45032index ae0f56a..ec71784 100644
45033--- a/drivers/media/usb/dvb-usb/dw2102.c
45034+++ b/drivers/media/usb/dvb-usb/dw2102.c
45035@@ -118,7 +118,7 @@ struct su3000_state {
45036
45037 struct s6x0_state {
45038 int (*old_set_voltage)(struct dvb_frontend *f, fe_sec_voltage_t v);
45039-};
45040+} __no_const;
45041
45042 /* debug */
45043 static int dvb_usb_dw2102_debug;
45044diff --git a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
45045index b63a5e5..b16a062 100644
45046--- a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
45047+++ b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
45048@@ -326,7 +326,7 @@ struct v4l2_buffer32 {
45049 __u32 reserved;
45050 };
45051
45052-static int get_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
45053+static int get_v4l2_plane32(struct v4l2_plane __user *up, struct v4l2_plane32 __user *up32,
45054 enum v4l2_memory memory)
45055 {
45056 void __user *up_pln;
45057@@ -355,7 +355,7 @@ static int get_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
45058 return 0;
45059 }
45060
45061-static int put_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
45062+static int put_v4l2_plane32(struct v4l2_plane __user *up, struct v4l2_plane32 __user *up32,
45063 enum v4l2_memory memory)
45064 {
45065 if (copy_in_user(up32, up, 2 * sizeof(__u32)) ||
45066@@ -425,7 +425,7 @@ static int get_v4l2_buffer32(struct v4l2_buffer *kp, struct v4l2_buffer32 __user
45067 * by passing a very big num_planes value */
45068 uplane = compat_alloc_user_space(num_planes *
45069 sizeof(struct v4l2_plane));
45070- kp->m.planes = uplane;
45071+ kp->m.planes = (struct v4l2_plane __force_kernel *)uplane;
45072
45073 while (--num_planes >= 0) {
45074 ret = get_v4l2_plane32(uplane, uplane32, kp->memory);
45075@@ -496,7 +496,7 @@ static int put_v4l2_buffer32(struct v4l2_buffer *kp, struct v4l2_buffer32 __user
45076 if (num_planes == 0)
45077 return 0;
45078
45079- uplane = kp->m.planes;
45080+ uplane = (struct v4l2_plane __force_user *)kp->m.planes;
45081 if (get_user(p, &up->m.planes))
45082 return -EFAULT;
45083 uplane32 = compat_ptr(p);
45084@@ -550,7 +550,7 @@ static int get_v4l2_framebuffer32(struct v4l2_framebuffer *kp, struct v4l2_frame
45085 get_user(kp->capability, &up->capability) ||
45086 get_user(kp->flags, &up->flags))
45087 return -EFAULT;
45088- kp->base = compat_ptr(tmp);
45089+ kp->base = (void __force_kernel *)compat_ptr(tmp);
45090 get_v4l2_pix_format(&kp->fmt, &up->fmt);
45091 return 0;
45092 }
45093@@ -656,7 +656,7 @@ static int get_v4l2_ext_controls32(struct v4l2_ext_controls *kp, struct v4l2_ext
45094 n * sizeof(struct v4l2_ext_control32)))
45095 return -EFAULT;
45096 kcontrols = compat_alloc_user_space(n * sizeof(struct v4l2_ext_control));
45097- kp->controls = kcontrols;
45098+ kp->controls = (struct v4l2_ext_control __force_kernel *)kcontrols;
45099 while (--n >= 0) {
45100 if (copy_in_user(kcontrols, ucontrols, sizeof(*ucontrols)))
45101 return -EFAULT;
45102@@ -678,7 +678,7 @@ static int get_v4l2_ext_controls32(struct v4l2_ext_controls *kp, struct v4l2_ext
45103 static int put_v4l2_ext_controls32(struct v4l2_ext_controls *kp, struct v4l2_ext_controls32 __user *up)
45104 {
45105 struct v4l2_ext_control32 __user *ucontrols;
45106- struct v4l2_ext_control __user *kcontrols = kp->controls;
45107+ struct v4l2_ext_control __user *kcontrols = (struct v4l2_ext_control __force_user *)kp->controls;
45108 int n = kp->count;
45109 compat_caddr_t p;
45110
45111@@ -772,7 +772,7 @@ static int put_v4l2_subdev_edid32(struct v4l2_subdev_edid *kp, struct v4l2_subde
45112 put_user(kp->start_block, &up->start_block) ||
45113 put_user(kp->blocks, &up->blocks) ||
45114 put_user(tmp, &up->edid) ||
45115- copy_to_user(kp->reserved, up->reserved, sizeof(kp->reserved)))
45116+ copy_to_user(up->reserved, kp->reserved, sizeof(kp->reserved)))
45117 return -EFAULT;
45118 return 0;
45119 }
45120diff --git a/drivers/media/v4l2-core/v4l2-ctrls.c b/drivers/media/v4l2-core/v4l2-ctrls.c
45121index 6ff002b..6b9316b 100644
45122--- a/drivers/media/v4l2-core/v4l2-ctrls.c
45123+++ b/drivers/media/v4l2-core/v4l2-ctrls.c
45124@@ -1401,8 +1401,8 @@ static int validate_new(const struct v4l2_ctrl *ctrl,
45125 return 0;
45126
45127 case V4L2_CTRL_TYPE_STRING:
45128- len = strlen(c->string);
45129- if (len < ctrl->minimum)
45130+ len = strlen_user(c->string);
45131+ if (!len || len < ctrl->minimum)
45132 return -ERANGE;
45133 if ((len - ctrl->minimum) % ctrl->step)
45134 return -ERANGE;
45135diff --git a/drivers/media/v4l2-core/v4l2-device.c b/drivers/media/v4l2-core/v4l2-device.c
45136index 02d1b63..5fd6b16 100644
45137--- a/drivers/media/v4l2-core/v4l2-device.c
45138+++ b/drivers/media/v4l2-core/v4l2-device.c
45139@@ -75,9 +75,9 @@ int v4l2_device_put(struct v4l2_device *v4l2_dev)
45140 EXPORT_SYMBOL_GPL(v4l2_device_put);
45141
45142 int v4l2_device_set_name(struct v4l2_device *v4l2_dev, const char *basename,
45143- atomic_t *instance)
45144+ atomic_unchecked_t *instance)
45145 {
45146- int num = atomic_inc_return(instance) - 1;
45147+ int num = atomic_inc_return_unchecked(instance) - 1;
45148 int len = strlen(basename);
45149
45150 if (basename[len - 1] >= '0' && basename[len - 1] <= '9')
45151diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c b/drivers/media/v4l2-core/v4l2-ioctl.c
45152index 707aef7..93b8ac0 100644
45153--- a/drivers/media/v4l2-core/v4l2-ioctl.c
45154+++ b/drivers/media/v4l2-core/v4l2-ioctl.c
45155@@ -1942,7 +1942,8 @@ struct v4l2_ioctl_info {
45156 struct file *file, void *fh, void *p);
45157 } u;
45158 void (*debug)(const void *arg, bool write_only);
45159-};
45160+} __do_const;
45161+typedef struct v4l2_ioctl_info __no_const v4l2_ioctl_info_no_const;
45162
45163 /* This control needs a priority check */
45164 #define INFO_FL_PRIO (1 << 0)
45165@@ -2123,7 +2124,7 @@ static long __video_do_ioctl(struct file *file,
45166 struct video_device *vfd = video_devdata(file);
45167 const struct v4l2_ioctl_ops *ops = vfd->ioctl_ops;
45168 bool write_only = false;
45169- struct v4l2_ioctl_info default_info;
45170+ v4l2_ioctl_info_no_const default_info;
45171 const struct v4l2_ioctl_info *info;
45172 void *fh = file->private_data;
45173 struct v4l2_fh *vfh = NULL;
45174@@ -2197,7 +2198,7 @@ done:
45175 }
45176
45177 static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
45178- void * __user *user_ptr, void ***kernel_ptr)
45179+ void __user **user_ptr, void ***kernel_ptr)
45180 {
45181 int ret = 0;
45182
45183@@ -2213,7 +2214,7 @@ static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
45184 ret = -EINVAL;
45185 break;
45186 }
45187- *user_ptr = (void __user *)buf->m.planes;
45188+ *user_ptr = (void __force_user *)buf->m.planes;
45189 *kernel_ptr = (void *)&buf->m.planes;
45190 *array_size = sizeof(struct v4l2_plane) * buf->length;
45191 ret = 1;
45192@@ -2248,7 +2249,7 @@ static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
45193 ret = -EINVAL;
45194 break;
45195 }
45196- *user_ptr = (void __user *)ctrls->controls;
45197+ *user_ptr = (void __force_user *)ctrls->controls;
45198 *kernel_ptr = (void *)&ctrls->controls;
45199 *array_size = sizeof(struct v4l2_ext_control)
45200 * ctrls->count;
45201@@ -2349,7 +2350,7 @@ video_usercopy(struct file *file, unsigned int cmd, unsigned long arg,
45202 }
45203
45204 if (has_array_args) {
45205- *kernel_ptr = user_ptr;
45206+ *kernel_ptr = (void __force_kernel *)user_ptr;
45207 if (copy_to_user(user_ptr, mbuf, array_size))
45208 err = -EFAULT;
45209 goto out_array_args;
45210diff --git a/drivers/message/fusion/mptbase.c b/drivers/message/fusion/mptbase.c
45211index 570b18a..f880314 100644
45212--- a/drivers/message/fusion/mptbase.c
45213+++ b/drivers/message/fusion/mptbase.c
45214@@ -6755,8 +6755,13 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
45215 seq_printf(m, " MaxChainDepth = 0x%02x frames\n", ioc->facts.MaxChainDepth);
45216 seq_printf(m, " MinBlockSize = 0x%02x bytes\n", 4*ioc->facts.BlockSize);
45217
45218+#ifdef CONFIG_GRKERNSEC_HIDESYM
45219+ seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n", NULL, NULL);
45220+#else
45221 seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n",
45222 (void *)ioc->req_frames, (void *)(ulong)ioc->req_frames_dma);
45223+#endif
45224+
45225 /*
45226 * Rounding UP to nearest 4-kB boundary here...
45227 */
45228@@ -6769,7 +6774,11 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
45229 ioc->facts.GlobalCredits);
45230
45231 seq_printf(m, " Frames @ 0x%p (Dma @ 0x%p)\n",
45232+#ifdef CONFIG_GRKERNSEC_HIDESYM
45233+ NULL, NULL);
45234+#else
45235 (void *)ioc->alloc, (void *)(ulong)ioc->alloc_dma);
45236+#endif
45237 sz = (ioc->reply_sz * ioc->reply_depth) + 128;
45238 seq_printf(m, " {CurRepSz=%d} x {CurRepDepth=%d} = %d bytes ^= 0x%x\n",
45239 ioc->reply_sz, ioc->reply_depth, ioc->reply_sz*ioc->reply_depth, sz);
45240diff --git a/drivers/message/fusion/mptsas.c b/drivers/message/fusion/mptsas.c
45241index 00d339c..2ea899d 100644
45242--- a/drivers/message/fusion/mptsas.c
45243+++ b/drivers/message/fusion/mptsas.c
45244@@ -446,6 +446,23 @@ mptsas_is_end_device(struct mptsas_devinfo * attached)
45245 return 0;
45246 }
45247
45248+static inline void
45249+mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
45250+{
45251+ if (phy_info->port_details) {
45252+ phy_info->port_details->rphy = rphy;
45253+ dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
45254+ ioc->name, rphy));
45255+ }
45256+
45257+ if (rphy) {
45258+ dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
45259+ &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
45260+ dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
45261+ ioc->name, rphy, rphy->dev.release));
45262+ }
45263+}
45264+
45265 /* no mutex */
45266 static void
45267 mptsas_port_delete(MPT_ADAPTER *ioc, struct mptsas_portinfo_details * port_details)
45268@@ -484,23 +501,6 @@ mptsas_get_rphy(struct mptsas_phyinfo *phy_info)
45269 return NULL;
45270 }
45271
45272-static inline void
45273-mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
45274-{
45275- if (phy_info->port_details) {
45276- phy_info->port_details->rphy = rphy;
45277- dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
45278- ioc->name, rphy));
45279- }
45280-
45281- if (rphy) {
45282- dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
45283- &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
45284- dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
45285- ioc->name, rphy, rphy->dev.release));
45286- }
45287-}
45288-
45289 static inline struct sas_port *
45290 mptsas_get_port(struct mptsas_phyinfo *phy_info)
45291 {
45292diff --git a/drivers/message/fusion/mptscsih.c b/drivers/message/fusion/mptscsih.c
45293index 727819c..ad74694 100644
45294--- a/drivers/message/fusion/mptscsih.c
45295+++ b/drivers/message/fusion/mptscsih.c
45296@@ -1271,15 +1271,16 @@ mptscsih_info(struct Scsi_Host *SChost)
45297
45298 h = shost_priv(SChost);
45299
45300- if (h) {
45301- if (h->info_kbuf == NULL)
45302- if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
45303- return h->info_kbuf;
45304- h->info_kbuf[0] = '\0';
45305+ if (!h)
45306+ return NULL;
45307
45308- mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
45309- h->info_kbuf[size-1] = '\0';
45310- }
45311+ if (h->info_kbuf == NULL)
45312+ if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
45313+ return h->info_kbuf;
45314+ h->info_kbuf[0] = '\0';
45315+
45316+ mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
45317+ h->info_kbuf[size-1] = '\0';
45318
45319 return h->info_kbuf;
45320 }
45321diff --git a/drivers/message/i2o/i2o_proc.c b/drivers/message/i2o/i2o_proc.c
45322index b7d87cd..3fb36da 100644
45323--- a/drivers/message/i2o/i2o_proc.c
45324+++ b/drivers/message/i2o/i2o_proc.c
45325@@ -255,12 +255,6 @@ static char *scsi_devices[] = {
45326 "Array Controller Device"
45327 };
45328
45329-static char *chtostr(char *tmp, u8 *chars, int n)
45330-{
45331- tmp[0] = 0;
45332- return strncat(tmp, (char *)chars, n);
45333-}
45334-
45335 static int i2o_report_query_status(struct seq_file *seq, int block_status,
45336 char *group)
45337 {
45338@@ -707,9 +701,9 @@ static int i2o_seq_show_status(struct seq_file *seq, void *v)
45339 static int i2o_seq_show_hw(struct seq_file *seq, void *v)
45340 {
45341 struct i2o_controller *c = (struct i2o_controller *)seq->private;
45342- static u32 work32[5];
45343- static u8 *work8 = (u8 *) work32;
45344- static u16 *work16 = (u16 *) work32;
45345+ u32 work32[5];
45346+ u8 *work8 = (u8 *) work32;
45347+ u16 *work16 = (u16 *) work32;
45348 int token;
45349 u32 hwcap;
45350
45351@@ -790,7 +784,6 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
45352 } *result;
45353
45354 i2o_exec_execute_ddm_table ddm_table;
45355- char tmp[28 + 1];
45356
45357 result = kmalloc(sizeof(*result), GFP_KERNEL);
45358 if (!result)
45359@@ -825,8 +818,7 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
45360
45361 seq_printf(seq, "%-#7x", ddm_table.i2o_vendor_id);
45362 seq_printf(seq, "%-#8x", ddm_table.module_id);
45363- seq_printf(seq, "%-29s",
45364- chtostr(tmp, ddm_table.module_name_version, 28));
45365+ seq_printf(seq, "%-.28s", ddm_table.module_name_version);
45366 seq_printf(seq, "%9d ", ddm_table.data_size);
45367 seq_printf(seq, "%8d", ddm_table.code_size);
45368
45369@@ -893,7 +885,6 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
45370
45371 i2o_driver_result_table *result;
45372 i2o_driver_store_table *dst;
45373- char tmp[28 + 1];
45374
45375 result = kmalloc(sizeof(i2o_driver_result_table), GFP_KERNEL);
45376 if (result == NULL)
45377@@ -928,9 +919,8 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
45378
45379 seq_printf(seq, "%-#7x", dst->i2o_vendor_id);
45380 seq_printf(seq, "%-#8x", dst->module_id);
45381- seq_printf(seq, "%-29s",
45382- chtostr(tmp, dst->module_name_version, 28));
45383- seq_printf(seq, "%-9s", chtostr(tmp, dst->date, 8));
45384+ seq_printf(seq, "%-.28s", dst->module_name_version);
45385+ seq_printf(seq, "%-.8s", dst->date);
45386 seq_printf(seq, "%8d ", dst->module_size);
45387 seq_printf(seq, "%8d ", dst->mpb_size);
45388 seq_printf(seq, "0x%04x", dst->module_flags);
45389@@ -1246,11 +1236,10 @@ static int i2o_seq_show_authorized_users(struct seq_file *seq, void *v)
45390 static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
45391 {
45392 struct i2o_device *d = (struct i2o_device *)seq->private;
45393- static u32 work32[128]; // allow for "stuff" + up to 256 byte (max) serial number
45394+ u32 work32[128]; // allow for "stuff" + up to 256 byte (max) serial number
45395 // == (allow) 512d bytes (max)
45396- static u16 *work16 = (u16 *) work32;
45397+ u16 *work16 = (u16 *) work32;
45398 int token;
45399- char tmp[16 + 1];
45400
45401 token = i2o_parm_field_get(d, 0xF100, -1, &work32, sizeof(work32));
45402
45403@@ -1262,14 +1251,10 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
45404 seq_printf(seq, "Device Class : %s\n", i2o_get_class_name(work16[0]));
45405 seq_printf(seq, "Owner TID : %0#5x\n", work16[2]);
45406 seq_printf(seq, "Parent TID : %0#5x\n", work16[3]);
45407- seq_printf(seq, "Vendor info : %s\n",
45408- chtostr(tmp, (u8 *) (work32 + 2), 16));
45409- seq_printf(seq, "Product info : %s\n",
45410- chtostr(tmp, (u8 *) (work32 + 6), 16));
45411- seq_printf(seq, "Description : %s\n",
45412- chtostr(tmp, (u8 *) (work32 + 10), 16));
45413- seq_printf(seq, "Product rev. : %s\n",
45414- chtostr(tmp, (u8 *) (work32 + 14), 8));
45415+ seq_printf(seq, "Vendor info : %.16s\n", (u8 *) (work32 + 2));
45416+ seq_printf(seq, "Product info : %.16s\n", (u8 *) (work32 + 6));
45417+ seq_printf(seq, "Description : %.16s\n", (u8 *) (work32 + 10));
45418+ seq_printf(seq, "Product rev. : %.8s\n", (u8 *) (work32 + 14));
45419
45420 seq_printf(seq, "Serial number : ");
45421 print_serial_number(seq, (u8 *) (work32 + 16),
45422@@ -1306,8 +1291,6 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
45423 u8 pad[256]; // allow up to 256 byte (max) serial number
45424 } result;
45425
45426- char tmp[24 + 1];
45427-
45428 token = i2o_parm_field_get(d, 0xF101, -1, &result, sizeof(result));
45429
45430 if (token < 0) {
45431@@ -1316,10 +1299,8 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
45432 }
45433
45434 seq_printf(seq, "Registering DDM TID : 0x%03x\n", result.ddm_tid);
45435- seq_printf(seq, "Module name : %s\n",
45436- chtostr(tmp, result.module_name, 24));
45437- seq_printf(seq, "Module revision : %s\n",
45438- chtostr(tmp, result.module_rev, 8));
45439+ seq_printf(seq, "Module name : %.24s\n", result.module_name);
45440+ seq_printf(seq, "Module revision : %.8s\n", result.module_rev);
45441
45442 seq_printf(seq, "Serial number : ");
45443 print_serial_number(seq, result.serial_number, sizeof(result) - 36);
45444@@ -1343,8 +1324,6 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
45445 u8 instance_number[4];
45446 } result;
45447
45448- char tmp[64 + 1];
45449-
45450 token = i2o_parm_field_get(d, 0xF102, -1, &result, sizeof(result));
45451
45452 if (token < 0) {
45453@@ -1352,14 +1331,10 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
45454 return 0;
45455 }
45456
45457- seq_printf(seq, "Device name : %s\n",
45458- chtostr(tmp, result.device_name, 64));
45459- seq_printf(seq, "Service name : %s\n",
45460- chtostr(tmp, result.service_name, 64));
45461- seq_printf(seq, "Physical name : %s\n",
45462- chtostr(tmp, result.physical_location, 64));
45463- seq_printf(seq, "Instance number : %s\n",
45464- chtostr(tmp, result.instance_number, 4));
45465+ seq_printf(seq, "Device name : %.64s\n", result.device_name);
45466+ seq_printf(seq, "Service name : %.64s\n", result.service_name);
45467+ seq_printf(seq, "Physical name : %.64s\n", result.physical_location);
45468+ seq_printf(seq, "Instance number : %.4s\n", result.instance_number);
45469
45470 return 0;
45471 }
45472@@ -1368,9 +1343,9 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
45473 static int i2o_seq_show_sgl_limits(struct seq_file *seq, void *v)
45474 {
45475 struct i2o_device *d = (struct i2o_device *)seq->private;
45476- static u32 work32[12];
45477- static u16 *work16 = (u16 *) work32;
45478- static u8 *work8 = (u8 *) work32;
45479+ u32 work32[12];
45480+ u16 *work16 = (u16 *) work32;
45481+ u8 *work8 = (u8 *) work32;
45482 int token;
45483
45484 token = i2o_parm_field_get(d, 0xF103, -1, &work32, sizeof(work32));
45485diff --git a/drivers/message/i2o/iop.c b/drivers/message/i2o/iop.c
45486index a8c08f3..155fe3d 100644
45487--- a/drivers/message/i2o/iop.c
45488+++ b/drivers/message/i2o/iop.c
45489@@ -111,10 +111,10 @@ u32 i2o_cntxt_list_add(struct i2o_controller * c, void *ptr)
45490
45491 spin_lock_irqsave(&c->context_list_lock, flags);
45492
45493- if (unlikely(atomic_inc_and_test(&c->context_list_counter)))
45494- atomic_inc(&c->context_list_counter);
45495+ if (unlikely(atomic_inc_and_test_unchecked(&c->context_list_counter)))
45496+ atomic_inc_unchecked(&c->context_list_counter);
45497
45498- entry->context = atomic_read(&c->context_list_counter);
45499+ entry->context = atomic_read_unchecked(&c->context_list_counter);
45500
45501 list_add(&entry->list, &c->context_list);
45502
45503@@ -1077,7 +1077,7 @@ struct i2o_controller *i2o_iop_alloc(void)
45504
45505 #if BITS_PER_LONG == 64
45506 spin_lock_init(&c->context_list_lock);
45507- atomic_set(&c->context_list_counter, 0);
45508+ atomic_set_unchecked(&c->context_list_counter, 0);
45509 INIT_LIST_HEAD(&c->context_list);
45510 #endif
45511
45512diff --git a/drivers/mfd/ab8500-debugfs.c b/drivers/mfd/ab8500-debugfs.c
45513index d1a22aa..d0f7bf7 100644
45514--- a/drivers/mfd/ab8500-debugfs.c
45515+++ b/drivers/mfd/ab8500-debugfs.c
45516@@ -100,7 +100,7 @@ static int irq_last;
45517 static u32 *irq_count;
45518 static int num_irqs;
45519
45520-static struct device_attribute **dev_attr;
45521+static device_attribute_no_const **dev_attr;
45522 static char **event_name;
45523
45524 static u8 avg_sample = SAMPLE_16;
45525diff --git a/drivers/mfd/janz-cmodio.c b/drivers/mfd/janz-cmodio.c
45526index 81b7d88..95ae998 100644
45527--- a/drivers/mfd/janz-cmodio.c
45528+++ b/drivers/mfd/janz-cmodio.c
45529@@ -13,6 +13,7 @@
45530
45531 #include <linux/kernel.h>
45532 #include <linux/module.h>
45533+#include <linux/slab.h>
45534 #include <linux/init.h>
45535 #include <linux/pci.h>
45536 #include <linux/interrupt.h>
45537diff --git a/drivers/mfd/max8925-i2c.c b/drivers/mfd/max8925-i2c.c
45538index a83eed5..62a58a9 100644
45539--- a/drivers/mfd/max8925-i2c.c
45540+++ b/drivers/mfd/max8925-i2c.c
45541@@ -152,7 +152,7 @@ static int max8925_probe(struct i2c_client *client,
45542 const struct i2c_device_id *id)
45543 {
45544 struct max8925_platform_data *pdata = dev_get_platdata(&client->dev);
45545- static struct max8925_chip *chip;
45546+ struct max8925_chip *chip;
45547 struct device_node *node = client->dev.of_node;
45548
45549 if (node && !pdata) {
45550diff --git a/drivers/mfd/tps65910.c b/drivers/mfd/tps65910.c
45551index d657331..0d9a80f 100644
45552--- a/drivers/mfd/tps65910.c
45553+++ b/drivers/mfd/tps65910.c
45554@@ -230,7 +230,7 @@ static int tps65910_irq_init(struct tps65910 *tps65910, int irq,
45555 struct tps65910_platform_data *pdata)
45556 {
45557 int ret = 0;
45558- static struct regmap_irq_chip *tps6591x_irqs_chip;
45559+ struct regmap_irq_chip *tps6591x_irqs_chip;
45560
45561 if (!irq) {
45562 dev_warn(tps65910->dev, "No interrupt support, no core IRQ\n");
45563diff --git a/drivers/mfd/twl4030-irq.c b/drivers/mfd/twl4030-irq.c
45564index 9aa6d1e..1631bfc 100644
45565--- a/drivers/mfd/twl4030-irq.c
45566+++ b/drivers/mfd/twl4030-irq.c
45567@@ -35,6 +35,7 @@
45568 #include <linux/of.h>
45569 #include <linux/irqdomain.h>
45570 #include <linux/i2c/twl.h>
45571+#include <asm/pgtable.h>
45572
45573 #include "twl-core.h"
45574
45575@@ -726,10 +727,12 @@ int twl4030_init_irq(struct device *dev, int irq_num)
45576 * Install an irq handler for each of the SIH modules;
45577 * clone dummy irq_chip since PIH can't *do* anything
45578 */
45579- twl4030_irq_chip = dummy_irq_chip;
45580- twl4030_irq_chip.name = "twl4030";
45581+ pax_open_kernel();
45582+ memcpy((void *)&twl4030_irq_chip, &dummy_irq_chip, sizeof twl4030_irq_chip);
45583+ *(const char **)&twl4030_irq_chip.name = "twl4030";
45584
45585- twl4030_sih_irq_chip.irq_ack = dummy_irq_chip.irq_ack;
45586+ *(void **)&twl4030_sih_irq_chip.irq_ack = dummy_irq_chip.irq_ack;
45587+ pax_close_kernel();
45588
45589 for (i = irq_base; i < irq_end; i++) {
45590 irq_set_chip_and_handler(i, &twl4030_irq_chip,
45591diff --git a/drivers/misc/c2port/core.c b/drivers/misc/c2port/core.c
45592index 464419b..64bae8d 100644
45593--- a/drivers/misc/c2port/core.c
45594+++ b/drivers/misc/c2port/core.c
45595@@ -922,7 +922,9 @@ struct c2port_device *c2port_device_register(char *name,
45596 goto error_idr_alloc;
45597 c2dev->id = ret;
45598
45599- bin_attr_flash_data.size = ops->blocks_num * ops->block_size;
45600+ pax_open_kernel();
45601+ *(size_t *)&bin_attr_flash_data.size = ops->blocks_num * ops->block_size;
45602+ pax_close_kernel();
45603
45604 c2dev->dev = device_create(c2port_class, NULL, 0, c2dev,
45605 "c2port%d", c2dev->id);
45606diff --git a/drivers/misc/eeprom/sunxi_sid.c b/drivers/misc/eeprom/sunxi_sid.c
45607index 9c34e57..b981cda 100644
45608--- a/drivers/misc/eeprom/sunxi_sid.c
45609+++ b/drivers/misc/eeprom/sunxi_sid.c
45610@@ -127,7 +127,9 @@ static int sunxi_sid_probe(struct platform_device *pdev)
45611
45612 platform_set_drvdata(pdev, sid_data);
45613
45614- sid_bin_attr.size = sid_data->keysize;
45615+ pax_open_kernel();
45616+ *(size_t *)&sid_bin_attr.size = sid_data->keysize;
45617+ pax_close_kernel();
45618 if (device_create_bin_file(&pdev->dev, &sid_bin_attr))
45619 return -ENODEV;
45620
45621diff --git a/drivers/misc/kgdbts.c b/drivers/misc/kgdbts.c
45622index 36f5d52..32311c3 100644
45623--- a/drivers/misc/kgdbts.c
45624+++ b/drivers/misc/kgdbts.c
45625@@ -834,7 +834,7 @@ static void run_plant_and_detach_test(int is_early)
45626 char before[BREAK_INSTR_SIZE];
45627 char after[BREAK_INSTR_SIZE];
45628
45629- probe_kernel_read(before, (char *)kgdbts_break_test,
45630+ probe_kernel_read(before, ktla_ktva((char *)kgdbts_break_test),
45631 BREAK_INSTR_SIZE);
45632 init_simple_test();
45633 ts.tst = plant_and_detach_test;
45634@@ -842,7 +842,7 @@ static void run_plant_and_detach_test(int is_early)
45635 /* Activate test with initial breakpoint */
45636 if (!is_early)
45637 kgdb_breakpoint();
45638- probe_kernel_read(after, (char *)kgdbts_break_test,
45639+ probe_kernel_read(after, ktla_ktva((char *)kgdbts_break_test),
45640 BREAK_INSTR_SIZE);
45641 if (memcmp(before, after, BREAK_INSTR_SIZE)) {
45642 printk(KERN_CRIT "kgdbts: ERROR kgdb corrupted memory\n");
45643diff --git a/drivers/misc/lis3lv02d/lis3lv02d.c b/drivers/misc/lis3lv02d/lis3lv02d.c
45644index 036effe..b3a6336 100644
45645--- a/drivers/misc/lis3lv02d/lis3lv02d.c
45646+++ b/drivers/misc/lis3lv02d/lis3lv02d.c
45647@@ -498,7 +498,7 @@ static irqreturn_t lis302dl_interrupt(int irq, void *data)
45648 * the lid is closed. This leads to interrupts as soon as a little move
45649 * is done.
45650 */
45651- atomic_inc(&lis3->count);
45652+ atomic_inc_unchecked(&lis3->count);
45653
45654 wake_up_interruptible(&lis3->misc_wait);
45655 kill_fasync(&lis3->async_queue, SIGIO, POLL_IN);
45656@@ -584,7 +584,7 @@ static int lis3lv02d_misc_open(struct inode *inode, struct file *file)
45657 if (lis3->pm_dev)
45658 pm_runtime_get_sync(lis3->pm_dev);
45659
45660- atomic_set(&lis3->count, 0);
45661+ atomic_set_unchecked(&lis3->count, 0);
45662 return 0;
45663 }
45664
45665@@ -616,7 +616,7 @@ static ssize_t lis3lv02d_misc_read(struct file *file, char __user *buf,
45666 add_wait_queue(&lis3->misc_wait, &wait);
45667 while (true) {
45668 set_current_state(TASK_INTERRUPTIBLE);
45669- data = atomic_xchg(&lis3->count, 0);
45670+ data = atomic_xchg_unchecked(&lis3->count, 0);
45671 if (data)
45672 break;
45673
45674@@ -657,7 +657,7 @@ static unsigned int lis3lv02d_misc_poll(struct file *file, poll_table *wait)
45675 struct lis3lv02d, miscdev);
45676
45677 poll_wait(file, &lis3->misc_wait, wait);
45678- if (atomic_read(&lis3->count))
45679+ if (atomic_read_unchecked(&lis3->count))
45680 return POLLIN | POLLRDNORM;
45681 return 0;
45682 }
45683diff --git a/drivers/misc/lis3lv02d/lis3lv02d.h b/drivers/misc/lis3lv02d/lis3lv02d.h
45684index c439c82..1f20f57 100644
45685--- a/drivers/misc/lis3lv02d/lis3lv02d.h
45686+++ b/drivers/misc/lis3lv02d/lis3lv02d.h
45687@@ -297,7 +297,7 @@ struct lis3lv02d {
45688 struct input_polled_dev *idev; /* input device */
45689 struct platform_device *pdev; /* platform device */
45690 struct regulator_bulk_data regulators[2];
45691- atomic_t count; /* interrupt count after last read */
45692+ atomic_unchecked_t count; /* interrupt count after last read */
45693 union axis_conversion ac; /* hw -> logical axis */
45694 int mapped_btns[3];
45695
45696diff --git a/drivers/misc/sgi-gru/gruhandles.c b/drivers/misc/sgi-gru/gruhandles.c
45697index 2f30bad..c4c13d0 100644
45698--- a/drivers/misc/sgi-gru/gruhandles.c
45699+++ b/drivers/misc/sgi-gru/gruhandles.c
45700@@ -44,8 +44,8 @@ static void update_mcs_stats(enum mcs_op op, unsigned long clks)
45701 unsigned long nsec;
45702
45703 nsec = CLKS2NSEC(clks);
45704- atomic_long_inc(&mcs_op_statistics[op].count);
45705- atomic_long_add(nsec, &mcs_op_statistics[op].total);
45706+ atomic_long_inc_unchecked(&mcs_op_statistics[op].count);
45707+ atomic_long_add_unchecked(nsec, &mcs_op_statistics[op].total);
45708 if (mcs_op_statistics[op].max < nsec)
45709 mcs_op_statistics[op].max = nsec;
45710 }
45711diff --git a/drivers/misc/sgi-gru/gruprocfs.c b/drivers/misc/sgi-gru/gruprocfs.c
45712index 4f76359..cdfcb2e 100644
45713--- a/drivers/misc/sgi-gru/gruprocfs.c
45714+++ b/drivers/misc/sgi-gru/gruprocfs.c
45715@@ -32,9 +32,9 @@
45716
45717 #define printstat(s, f) printstat_val(s, &gru_stats.f, #f)
45718
45719-static void printstat_val(struct seq_file *s, atomic_long_t *v, char *id)
45720+static void printstat_val(struct seq_file *s, atomic_long_unchecked_t *v, char *id)
45721 {
45722- unsigned long val = atomic_long_read(v);
45723+ unsigned long val = atomic_long_read_unchecked(v);
45724
45725 seq_printf(s, "%16lu %s\n", val, id);
45726 }
45727@@ -134,8 +134,8 @@ static int mcs_statistics_show(struct seq_file *s, void *p)
45728
45729 seq_printf(s, "%-20s%12s%12s%12s\n", "#id", "count", "aver-clks", "max-clks");
45730 for (op = 0; op < mcsop_last; op++) {
45731- count = atomic_long_read(&mcs_op_statistics[op].count);
45732- total = atomic_long_read(&mcs_op_statistics[op].total);
45733+ count = atomic_long_read_unchecked(&mcs_op_statistics[op].count);
45734+ total = atomic_long_read_unchecked(&mcs_op_statistics[op].total);
45735 max = mcs_op_statistics[op].max;
45736 seq_printf(s, "%-20s%12ld%12ld%12ld\n", id[op], count,
45737 count ? total / count : 0, max);
45738diff --git a/drivers/misc/sgi-gru/grutables.h b/drivers/misc/sgi-gru/grutables.h
45739index 5c3ce24..4915ccb 100644
45740--- a/drivers/misc/sgi-gru/grutables.h
45741+++ b/drivers/misc/sgi-gru/grutables.h
45742@@ -167,82 +167,82 @@ extern unsigned int gru_max_gids;
45743 * GRU statistics.
45744 */
45745 struct gru_stats_s {
45746- atomic_long_t vdata_alloc;
45747- atomic_long_t vdata_free;
45748- atomic_long_t gts_alloc;
45749- atomic_long_t gts_free;
45750- atomic_long_t gms_alloc;
45751- atomic_long_t gms_free;
45752- atomic_long_t gts_double_allocate;
45753- atomic_long_t assign_context;
45754- atomic_long_t assign_context_failed;
45755- atomic_long_t free_context;
45756- atomic_long_t load_user_context;
45757- atomic_long_t load_kernel_context;
45758- atomic_long_t lock_kernel_context;
45759- atomic_long_t unlock_kernel_context;
45760- atomic_long_t steal_user_context;
45761- atomic_long_t steal_kernel_context;
45762- atomic_long_t steal_context_failed;
45763- atomic_long_t nopfn;
45764- atomic_long_t asid_new;
45765- atomic_long_t asid_next;
45766- atomic_long_t asid_wrap;
45767- atomic_long_t asid_reuse;
45768- atomic_long_t intr;
45769- atomic_long_t intr_cbr;
45770- atomic_long_t intr_tfh;
45771- atomic_long_t intr_spurious;
45772- atomic_long_t intr_mm_lock_failed;
45773- atomic_long_t call_os;
45774- atomic_long_t call_os_wait_queue;
45775- atomic_long_t user_flush_tlb;
45776- atomic_long_t user_unload_context;
45777- atomic_long_t user_exception;
45778- atomic_long_t set_context_option;
45779- atomic_long_t check_context_retarget_intr;
45780- atomic_long_t check_context_unload;
45781- atomic_long_t tlb_dropin;
45782- atomic_long_t tlb_preload_page;
45783- atomic_long_t tlb_dropin_fail_no_asid;
45784- atomic_long_t tlb_dropin_fail_upm;
45785- atomic_long_t tlb_dropin_fail_invalid;
45786- atomic_long_t tlb_dropin_fail_range_active;
45787- atomic_long_t tlb_dropin_fail_idle;
45788- atomic_long_t tlb_dropin_fail_fmm;
45789- atomic_long_t tlb_dropin_fail_no_exception;
45790- atomic_long_t tfh_stale_on_fault;
45791- atomic_long_t mmu_invalidate_range;
45792- atomic_long_t mmu_invalidate_page;
45793- atomic_long_t flush_tlb;
45794- atomic_long_t flush_tlb_gru;
45795- atomic_long_t flush_tlb_gru_tgh;
45796- atomic_long_t flush_tlb_gru_zero_asid;
45797+ atomic_long_unchecked_t vdata_alloc;
45798+ atomic_long_unchecked_t vdata_free;
45799+ atomic_long_unchecked_t gts_alloc;
45800+ atomic_long_unchecked_t gts_free;
45801+ atomic_long_unchecked_t gms_alloc;
45802+ atomic_long_unchecked_t gms_free;
45803+ atomic_long_unchecked_t gts_double_allocate;
45804+ atomic_long_unchecked_t assign_context;
45805+ atomic_long_unchecked_t assign_context_failed;
45806+ atomic_long_unchecked_t free_context;
45807+ atomic_long_unchecked_t load_user_context;
45808+ atomic_long_unchecked_t load_kernel_context;
45809+ atomic_long_unchecked_t lock_kernel_context;
45810+ atomic_long_unchecked_t unlock_kernel_context;
45811+ atomic_long_unchecked_t steal_user_context;
45812+ atomic_long_unchecked_t steal_kernel_context;
45813+ atomic_long_unchecked_t steal_context_failed;
45814+ atomic_long_unchecked_t nopfn;
45815+ atomic_long_unchecked_t asid_new;
45816+ atomic_long_unchecked_t asid_next;
45817+ atomic_long_unchecked_t asid_wrap;
45818+ atomic_long_unchecked_t asid_reuse;
45819+ atomic_long_unchecked_t intr;
45820+ atomic_long_unchecked_t intr_cbr;
45821+ atomic_long_unchecked_t intr_tfh;
45822+ atomic_long_unchecked_t intr_spurious;
45823+ atomic_long_unchecked_t intr_mm_lock_failed;
45824+ atomic_long_unchecked_t call_os;
45825+ atomic_long_unchecked_t call_os_wait_queue;
45826+ atomic_long_unchecked_t user_flush_tlb;
45827+ atomic_long_unchecked_t user_unload_context;
45828+ atomic_long_unchecked_t user_exception;
45829+ atomic_long_unchecked_t set_context_option;
45830+ atomic_long_unchecked_t check_context_retarget_intr;
45831+ atomic_long_unchecked_t check_context_unload;
45832+ atomic_long_unchecked_t tlb_dropin;
45833+ atomic_long_unchecked_t tlb_preload_page;
45834+ atomic_long_unchecked_t tlb_dropin_fail_no_asid;
45835+ atomic_long_unchecked_t tlb_dropin_fail_upm;
45836+ atomic_long_unchecked_t tlb_dropin_fail_invalid;
45837+ atomic_long_unchecked_t tlb_dropin_fail_range_active;
45838+ atomic_long_unchecked_t tlb_dropin_fail_idle;
45839+ atomic_long_unchecked_t tlb_dropin_fail_fmm;
45840+ atomic_long_unchecked_t tlb_dropin_fail_no_exception;
45841+ atomic_long_unchecked_t tfh_stale_on_fault;
45842+ atomic_long_unchecked_t mmu_invalidate_range;
45843+ atomic_long_unchecked_t mmu_invalidate_page;
45844+ atomic_long_unchecked_t flush_tlb;
45845+ atomic_long_unchecked_t flush_tlb_gru;
45846+ atomic_long_unchecked_t flush_tlb_gru_tgh;
45847+ atomic_long_unchecked_t flush_tlb_gru_zero_asid;
45848
45849- atomic_long_t copy_gpa;
45850- atomic_long_t read_gpa;
45851+ atomic_long_unchecked_t copy_gpa;
45852+ atomic_long_unchecked_t read_gpa;
45853
45854- atomic_long_t mesq_receive;
45855- atomic_long_t mesq_receive_none;
45856- atomic_long_t mesq_send;
45857- atomic_long_t mesq_send_failed;
45858- atomic_long_t mesq_noop;
45859- atomic_long_t mesq_send_unexpected_error;
45860- atomic_long_t mesq_send_lb_overflow;
45861- atomic_long_t mesq_send_qlimit_reached;
45862- atomic_long_t mesq_send_amo_nacked;
45863- atomic_long_t mesq_send_put_nacked;
45864- atomic_long_t mesq_page_overflow;
45865- atomic_long_t mesq_qf_locked;
45866- atomic_long_t mesq_qf_noop_not_full;
45867- atomic_long_t mesq_qf_switch_head_failed;
45868- atomic_long_t mesq_qf_unexpected_error;
45869- atomic_long_t mesq_noop_unexpected_error;
45870- atomic_long_t mesq_noop_lb_overflow;
45871- atomic_long_t mesq_noop_qlimit_reached;
45872- atomic_long_t mesq_noop_amo_nacked;
45873- atomic_long_t mesq_noop_put_nacked;
45874- atomic_long_t mesq_noop_page_overflow;
45875+ atomic_long_unchecked_t mesq_receive;
45876+ atomic_long_unchecked_t mesq_receive_none;
45877+ atomic_long_unchecked_t mesq_send;
45878+ atomic_long_unchecked_t mesq_send_failed;
45879+ atomic_long_unchecked_t mesq_noop;
45880+ atomic_long_unchecked_t mesq_send_unexpected_error;
45881+ atomic_long_unchecked_t mesq_send_lb_overflow;
45882+ atomic_long_unchecked_t mesq_send_qlimit_reached;
45883+ atomic_long_unchecked_t mesq_send_amo_nacked;
45884+ atomic_long_unchecked_t mesq_send_put_nacked;
45885+ atomic_long_unchecked_t mesq_page_overflow;
45886+ atomic_long_unchecked_t mesq_qf_locked;
45887+ atomic_long_unchecked_t mesq_qf_noop_not_full;
45888+ atomic_long_unchecked_t mesq_qf_switch_head_failed;
45889+ atomic_long_unchecked_t mesq_qf_unexpected_error;
45890+ atomic_long_unchecked_t mesq_noop_unexpected_error;
45891+ atomic_long_unchecked_t mesq_noop_lb_overflow;
45892+ atomic_long_unchecked_t mesq_noop_qlimit_reached;
45893+ atomic_long_unchecked_t mesq_noop_amo_nacked;
45894+ atomic_long_unchecked_t mesq_noop_put_nacked;
45895+ atomic_long_unchecked_t mesq_noop_page_overflow;
45896
45897 };
45898
45899@@ -251,8 +251,8 @@ enum mcs_op {cchop_allocate, cchop_start, cchop_interrupt, cchop_interrupt_sync,
45900 tghop_invalidate, mcsop_last};
45901
45902 struct mcs_op_statistic {
45903- atomic_long_t count;
45904- atomic_long_t total;
45905+ atomic_long_unchecked_t count;
45906+ atomic_long_unchecked_t total;
45907 unsigned long max;
45908 };
45909
45910@@ -275,7 +275,7 @@ extern struct mcs_op_statistic mcs_op_statistics[mcsop_last];
45911
45912 #define STAT(id) do { \
45913 if (gru_options & OPT_STATS) \
45914- atomic_long_inc(&gru_stats.id); \
45915+ atomic_long_inc_unchecked(&gru_stats.id); \
45916 } while (0)
45917
45918 #ifdef CONFIG_SGI_GRU_DEBUG
45919diff --git a/drivers/misc/sgi-xp/xp.h b/drivers/misc/sgi-xp/xp.h
45920index c862cd4..0d176fe 100644
45921--- a/drivers/misc/sgi-xp/xp.h
45922+++ b/drivers/misc/sgi-xp/xp.h
45923@@ -288,7 +288,7 @@ struct xpc_interface {
45924 xpc_notify_func, void *);
45925 void (*received) (short, int, void *);
45926 enum xp_retval (*partid_to_nasids) (short, void *);
45927-};
45928+} __no_const;
45929
45930 extern struct xpc_interface xpc_interface;
45931
45932diff --git a/drivers/misc/sgi-xp/xp_main.c b/drivers/misc/sgi-xp/xp_main.c
45933index 01be66d..e3a0c7e 100644
45934--- a/drivers/misc/sgi-xp/xp_main.c
45935+++ b/drivers/misc/sgi-xp/xp_main.c
45936@@ -78,13 +78,13 @@ xpc_notloaded(void)
45937 }
45938
45939 struct xpc_interface xpc_interface = {
45940- (void (*)(int))xpc_notloaded,
45941- (void (*)(int))xpc_notloaded,
45942- (enum xp_retval(*)(short, int, u32, void *, u16))xpc_notloaded,
45943- (enum xp_retval(*)(short, int, u32, void *, u16, xpc_notify_func,
45944+ .connect = (void (*)(int))xpc_notloaded,
45945+ .disconnect = (void (*)(int))xpc_notloaded,
45946+ .send = (enum xp_retval(*)(short, int, u32, void *, u16))xpc_notloaded,
45947+ .send_notify = (enum xp_retval(*)(short, int, u32, void *, u16, xpc_notify_func,
45948 void *))xpc_notloaded,
45949- (void (*)(short, int, void *))xpc_notloaded,
45950- (enum xp_retval(*)(short, void *))xpc_notloaded
45951+ .received = (void (*)(short, int, void *))xpc_notloaded,
45952+ .partid_to_nasids = (enum xp_retval(*)(short, void *))xpc_notloaded
45953 };
45954 EXPORT_SYMBOL_GPL(xpc_interface);
45955
45956diff --git a/drivers/misc/sgi-xp/xpc.h b/drivers/misc/sgi-xp/xpc.h
45957index b94d5f7..7f494c5 100644
45958--- a/drivers/misc/sgi-xp/xpc.h
45959+++ b/drivers/misc/sgi-xp/xpc.h
45960@@ -835,6 +835,7 @@ struct xpc_arch_operations {
45961 void (*received_payload) (struct xpc_channel *, void *);
45962 void (*notify_senders_of_disconnect) (struct xpc_channel *);
45963 };
45964+typedef struct xpc_arch_operations __no_const xpc_arch_operations_no_const;
45965
45966 /* struct xpc_partition act_state values (for XPC HB) */
45967
45968@@ -876,7 +877,7 @@ extern struct xpc_registration xpc_registrations[];
45969 /* found in xpc_main.c */
45970 extern struct device *xpc_part;
45971 extern struct device *xpc_chan;
45972-extern struct xpc_arch_operations xpc_arch_ops;
45973+extern xpc_arch_operations_no_const xpc_arch_ops;
45974 extern int xpc_disengage_timelimit;
45975 extern int xpc_disengage_timedout;
45976 extern int xpc_activate_IRQ_rcvd;
45977diff --git a/drivers/misc/sgi-xp/xpc_main.c b/drivers/misc/sgi-xp/xpc_main.c
45978index 82dc574..8539ab2 100644
45979--- a/drivers/misc/sgi-xp/xpc_main.c
45980+++ b/drivers/misc/sgi-xp/xpc_main.c
45981@@ -166,7 +166,7 @@ static struct notifier_block xpc_die_notifier = {
45982 .notifier_call = xpc_system_die,
45983 };
45984
45985-struct xpc_arch_operations xpc_arch_ops;
45986+xpc_arch_operations_no_const xpc_arch_ops;
45987
45988 /*
45989 * Timer function to enforce the timelimit on the partition disengage.
45990@@ -1210,7 +1210,7 @@ xpc_system_die(struct notifier_block *nb, unsigned long event, void *_die_args)
45991
45992 if (((die_args->trapnr == X86_TRAP_MF) ||
45993 (die_args->trapnr == X86_TRAP_XF)) &&
45994- !user_mode_vm(die_args->regs))
45995+ !user_mode(die_args->regs))
45996 xpc_die_deactivate();
45997
45998 break;
45999diff --git a/drivers/mmc/card/block.c b/drivers/mmc/card/block.c
46000index 7b5424f..ed1d6ac 100644
46001--- a/drivers/mmc/card/block.c
46002+++ b/drivers/mmc/card/block.c
46003@@ -575,7 +575,7 @@ static int mmc_blk_ioctl_cmd(struct block_device *bdev,
46004 if (idata->ic.postsleep_min_us)
46005 usleep_range(idata->ic.postsleep_min_us, idata->ic.postsleep_max_us);
46006
46007- if (copy_to_user(&(ic_ptr->response), cmd.resp, sizeof(cmd.resp))) {
46008+ if (copy_to_user(ic_ptr->response, cmd.resp, sizeof(cmd.resp))) {
46009 err = -EFAULT;
46010 goto cmd_rel_host;
46011 }
46012diff --git a/drivers/mmc/core/mmc_ops.c b/drivers/mmc/core/mmc_ops.c
46013index e5b5eeb..7bf2212 100644
46014--- a/drivers/mmc/core/mmc_ops.c
46015+++ b/drivers/mmc/core/mmc_ops.c
46016@@ -247,7 +247,7 @@ mmc_send_cxd_data(struct mmc_card *card, struct mmc_host *host,
46017 void *data_buf;
46018 int is_on_stack;
46019
46020- is_on_stack = object_is_on_stack(buf);
46021+ is_on_stack = object_starts_on_stack(buf);
46022 if (is_on_stack) {
46023 /*
46024 * dma onto stack is unsafe/nonportable, but callers to this
46025diff --git a/drivers/mmc/host/dw_mmc.h b/drivers/mmc/host/dw_mmc.h
46026index 6bf24ab..13d0293b 100644
46027--- a/drivers/mmc/host/dw_mmc.h
46028+++ b/drivers/mmc/host/dw_mmc.h
46029@@ -258,5 +258,5 @@ struct dw_mci_drv_data {
46030 int (*parse_dt)(struct dw_mci *host);
46031 int (*execute_tuning)(struct dw_mci_slot *slot, u32 opcode,
46032 struct dw_mci_tuning_data *tuning_data);
46033-};
46034+} __do_const;
46035 #endif /* _DW_MMC_H_ */
46036diff --git a/drivers/mmc/host/mmci.c b/drivers/mmc/host/mmci.c
46037index b931226..df6a085 100644
46038--- a/drivers/mmc/host/mmci.c
46039+++ b/drivers/mmc/host/mmci.c
46040@@ -1504,7 +1504,9 @@ static int mmci_probe(struct amba_device *dev,
46041 }
46042
46043 if (variant->busy_detect) {
46044- mmci_ops.card_busy = mmci_card_busy;
46045+ pax_open_kernel();
46046+ *(void **)&mmci_ops.card_busy = mmci_card_busy;
46047+ pax_close_kernel();
46048 mmci_write_datactrlreg(host, MCI_ST_DPSM_BUSYMODE);
46049 }
46050
46051diff --git a/drivers/mmc/host/sdhci-esdhc-imx.c b/drivers/mmc/host/sdhci-esdhc-imx.c
46052index b841bb7..d82712f5 100644
46053--- a/drivers/mmc/host/sdhci-esdhc-imx.c
46054+++ b/drivers/mmc/host/sdhci-esdhc-imx.c
46055@@ -1031,9 +1031,12 @@ static int sdhci_esdhc_imx_probe(struct platform_device *pdev)
46056 host->mmc->caps |= MMC_CAP_1_8V_DDR;
46057 }
46058
46059- if (imx_data->socdata->flags & ESDHC_FLAG_MAN_TUNING)
46060- sdhci_esdhc_ops.platform_execute_tuning =
46061+ if (imx_data->socdata->flags & ESDHC_FLAG_MAN_TUNING) {
46062+ pax_open_kernel();
46063+ *(void **)&sdhci_esdhc_ops.platform_execute_tuning =
46064 esdhc_executing_tuning;
46065+ pax_close_kernel();
46066+ }
46067
46068 if (imx_data->socdata->flags & ESDHC_FLAG_STD_TUNING)
46069 writel(readl(host->ioaddr + ESDHC_TUNING_CTRL) |
46070diff --git a/drivers/mmc/host/sdhci-s3c.c b/drivers/mmc/host/sdhci-s3c.c
46071index 6debda9..2ba7427 100644
46072--- a/drivers/mmc/host/sdhci-s3c.c
46073+++ b/drivers/mmc/host/sdhci-s3c.c
46074@@ -668,9 +668,11 @@ static int sdhci_s3c_probe(struct platform_device *pdev)
46075 * we can use overriding functions instead of default.
46076 */
46077 if (host->quirks & SDHCI_QUIRK_NONSTANDARD_CLOCK) {
46078- sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
46079- sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
46080- sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
46081+ pax_open_kernel();
46082+ *(void **)&sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
46083+ *(void **)&sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
46084+ *(void **)&sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
46085+ pax_close_kernel();
46086 }
46087
46088 /* It supports additional host capabilities if needed */
46089diff --git a/drivers/mtd/chips/cfi_cmdset_0020.c b/drivers/mtd/chips/cfi_cmdset_0020.c
46090index 096993f..f02c23b 100644
46091--- a/drivers/mtd/chips/cfi_cmdset_0020.c
46092+++ b/drivers/mtd/chips/cfi_cmdset_0020.c
46093@@ -669,7 +669,7 @@ cfi_staa_writev(struct mtd_info *mtd, const struct kvec *vecs,
46094 size_t totlen = 0, thislen;
46095 int ret = 0;
46096 size_t buflen = 0;
46097- static char *buffer;
46098+ char *buffer;
46099
46100 if (!ECCBUF_SIZE) {
46101 /* We should fall back to a general writev implementation.
46102diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
46103index c07cd57..61c4fbd 100644
46104--- a/drivers/mtd/nand/denali.c
46105+++ b/drivers/mtd/nand/denali.c
46106@@ -24,6 +24,7 @@
46107 #include <linux/slab.h>
46108 #include <linux/mtd/mtd.h>
46109 #include <linux/module.h>
46110+#include <linux/slab.h>
46111
46112 #include "denali.h"
46113
46114diff --git a/drivers/mtd/nand/gpmi-nand/gpmi-nand.c b/drivers/mtd/nand/gpmi-nand/gpmi-nand.c
46115index ca6369f..0ce9fed 100644
46116--- a/drivers/mtd/nand/gpmi-nand/gpmi-nand.c
46117+++ b/drivers/mtd/nand/gpmi-nand/gpmi-nand.c
46118@@ -369,7 +369,7 @@ void prepare_data_dma(struct gpmi_nand_data *this, enum dma_data_direction dr)
46119
46120 /* first try to map the upper buffer directly */
46121 if (virt_addr_valid(this->upper_buf) &&
46122- !object_is_on_stack(this->upper_buf)) {
46123+ !object_starts_on_stack(this->upper_buf)) {
46124 sg_init_one(sgl, this->upper_buf, this->upper_len);
46125 ret = dma_map_sg(this->dev, sgl, 1, dr);
46126 if (ret == 0)
46127diff --git a/drivers/mtd/nftlmount.c b/drivers/mtd/nftlmount.c
46128index 51b9d6a..52af9a7 100644
46129--- a/drivers/mtd/nftlmount.c
46130+++ b/drivers/mtd/nftlmount.c
46131@@ -24,6 +24,7 @@
46132 #include <asm/errno.h>
46133 #include <linux/delay.h>
46134 #include <linux/slab.h>
46135+#include <linux/sched.h>
46136 #include <linux/mtd/mtd.h>
46137 #include <linux/mtd/nand.h>
46138 #include <linux/mtd/nftl.h>
46139diff --git a/drivers/mtd/sm_ftl.c b/drivers/mtd/sm_ftl.c
46140index cf49c22..971b133 100644
46141--- a/drivers/mtd/sm_ftl.c
46142+++ b/drivers/mtd/sm_ftl.c
46143@@ -56,7 +56,7 @@ static ssize_t sm_attr_show(struct device *dev, struct device_attribute *attr,
46144 #define SM_CIS_VENDOR_OFFSET 0x59
46145 static struct attribute_group *sm_create_sysfs_attributes(struct sm_ftl *ftl)
46146 {
46147- struct attribute_group *attr_group;
46148+ attribute_group_no_const *attr_group;
46149 struct attribute **attributes;
46150 struct sm_sysfs_attribute *vendor_attribute;
46151 char *vendor;
46152diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
46153index e5628fc..ffe54d1 100644
46154--- a/drivers/net/bonding/bond_main.c
46155+++ b/drivers/net/bonding/bond_main.c
46156@@ -4551,6 +4551,7 @@ static void __exit bonding_exit(void)
46157
46158 bond_netlink_fini();
46159 unregister_pernet_subsys(&bond_net_ops);
46160+ rtnl_link_unregister(&bond_link_ops);
46161
46162 #ifdef CONFIG_NET_POLL_CONTROLLER
46163 /*
46164diff --git a/drivers/net/bonding/bond_netlink.c b/drivers/net/bonding/bond_netlink.c
46165index 70651f8..7eb1bdf 100644
46166--- a/drivers/net/bonding/bond_netlink.c
46167+++ b/drivers/net/bonding/bond_netlink.c
46168@@ -542,7 +542,7 @@ nla_put_failure:
46169 return -EMSGSIZE;
46170 }
46171
46172-struct rtnl_link_ops bond_link_ops __read_mostly = {
46173+struct rtnl_link_ops bond_link_ops = {
46174 .kind = "bond",
46175 .priv_size = sizeof(struct bonding),
46176 .setup = bond_setup,
46177diff --git a/drivers/net/can/Kconfig b/drivers/net/can/Kconfig
46178index 9e7d95d..d447b88 100644
46179--- a/drivers/net/can/Kconfig
46180+++ b/drivers/net/can/Kconfig
46181@@ -104,7 +104,7 @@ config CAN_JANZ_ICAN3
46182
46183 config CAN_FLEXCAN
46184 tristate "Support for Freescale FLEXCAN based chips"
46185- depends on ARM || PPC
46186+ depends on (ARM && CPU_LITTLE_ENDIAN) || PPC
46187 ---help---
46188 Say Y here if you want to support for Freescale FlexCAN.
46189
46190diff --git a/drivers/net/ethernet/8390/ax88796.c b/drivers/net/ethernet/8390/ax88796.c
46191index 455d4c3..3353ee7 100644
46192--- a/drivers/net/ethernet/8390/ax88796.c
46193+++ b/drivers/net/ethernet/8390/ax88796.c
46194@@ -889,9 +889,11 @@ static int ax_probe(struct platform_device *pdev)
46195 if (ax->plat->reg_offsets)
46196 ei_local->reg_offset = ax->plat->reg_offsets;
46197 else {
46198+ resource_size_t _mem_size = mem_size;
46199+ do_div(_mem_size, 0x18);
46200 ei_local->reg_offset = ax->reg_offsets;
46201 for (ret = 0; ret < 0x18; ret++)
46202- ax->reg_offsets[ret] = (mem_size / 0x18) * ret;
46203+ ax->reg_offsets[ret] = _mem_size * ret;
46204 }
46205
46206 if (!request_mem_region(mem->start, mem_size, pdev->name)) {
46207diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
46208index a89a40f..5a8a2ac 100644
46209--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
46210+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
46211@@ -1062,7 +1062,7 @@ static inline u8 bnx2x_get_path_func_num(struct bnx2x *bp)
46212 static inline void bnx2x_init_bp_objs(struct bnx2x *bp)
46213 {
46214 /* RX_MODE controlling object */
46215- bnx2x_init_rx_mode_obj(bp, &bp->rx_mode_obj);
46216+ bnx2x_init_rx_mode_obj(bp);
46217
46218 /* multicast configuration controlling object */
46219 bnx2x_init_mcast_obj(bp, &bp->mcast_obj, bp->fp->cl_id, bp->fp->cid,
46220diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
46221index 0fb6ff2..78fd55c 100644
46222--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
46223+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
46224@@ -2329,15 +2329,14 @@ int bnx2x_config_rx_mode(struct bnx2x *bp,
46225 return rc;
46226 }
46227
46228-void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
46229- struct bnx2x_rx_mode_obj *o)
46230+void bnx2x_init_rx_mode_obj(struct bnx2x *bp)
46231 {
46232 if (CHIP_IS_E1x(bp)) {
46233- o->wait_comp = bnx2x_empty_rx_mode_wait;
46234- o->config_rx_mode = bnx2x_set_rx_mode_e1x;
46235+ bp->rx_mode_obj.wait_comp = bnx2x_empty_rx_mode_wait;
46236+ bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e1x;
46237 } else {
46238- o->wait_comp = bnx2x_wait_rx_mode_comp_e2;
46239- o->config_rx_mode = bnx2x_set_rx_mode_e2;
46240+ bp->rx_mode_obj.wait_comp = bnx2x_wait_rx_mode_comp_e2;
46241+ bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e2;
46242 }
46243 }
46244
46245diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
46246index 00d7f21..2cddec4 100644
46247--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
46248+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
46249@@ -1321,8 +1321,7 @@ int bnx2x_vlan_mac_move(struct bnx2x *bp,
46250
46251 /********************* RX MODE ****************/
46252
46253-void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
46254- struct bnx2x_rx_mode_obj *o);
46255+void bnx2x_init_rx_mode_obj(struct bnx2x *bp);
46256
46257 /**
46258 * bnx2x_config_rx_mode - Send and RX_MODE ramrod according to the provided parameters.
46259diff --git a/drivers/net/ethernet/broadcom/tg3.h b/drivers/net/ethernet/broadcom/tg3.h
46260index 04321e5..b51cdc4 100644
46261--- a/drivers/net/ethernet/broadcom/tg3.h
46262+++ b/drivers/net/ethernet/broadcom/tg3.h
46263@@ -150,6 +150,7 @@
46264 #define CHIPREV_ID_5750_A0 0x4000
46265 #define CHIPREV_ID_5750_A1 0x4001
46266 #define CHIPREV_ID_5750_A3 0x4003
46267+#define CHIPREV_ID_5750_C1 0x4201
46268 #define CHIPREV_ID_5750_C2 0x4202
46269 #define CHIPREV_ID_5752_A0_HW 0x5000
46270 #define CHIPREV_ID_5752_A0 0x6000
46271diff --git a/drivers/net/ethernet/brocade/bna/bna_enet.c b/drivers/net/ethernet/brocade/bna/bna_enet.c
46272index 13f9636..228040f 100644
46273--- a/drivers/net/ethernet/brocade/bna/bna_enet.c
46274+++ b/drivers/net/ethernet/brocade/bna/bna_enet.c
46275@@ -1690,10 +1690,10 @@ bna_cb_ioceth_reset(void *arg)
46276 }
46277
46278 static struct bfa_ioc_cbfn bna_ioceth_cbfn = {
46279- bna_cb_ioceth_enable,
46280- bna_cb_ioceth_disable,
46281- bna_cb_ioceth_hbfail,
46282- bna_cb_ioceth_reset
46283+ .enable_cbfn = bna_cb_ioceth_enable,
46284+ .disable_cbfn = bna_cb_ioceth_disable,
46285+ .hbfail_cbfn = bna_cb_ioceth_hbfail,
46286+ .reset_cbfn = bna_cb_ioceth_reset
46287 };
46288
46289 static void bna_attr_init(struct bna_ioceth *ioceth)
46290diff --git a/drivers/net/ethernet/chelsio/cxgb3/l2t.h b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
46291index 8cffcdf..aadf043 100644
46292--- a/drivers/net/ethernet/chelsio/cxgb3/l2t.h
46293+++ b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
46294@@ -87,7 +87,7 @@ typedef void (*arp_failure_handler_func)(struct t3cdev * dev,
46295 */
46296 struct l2t_skb_cb {
46297 arp_failure_handler_func arp_failure_handler;
46298-};
46299+} __no_const;
46300
46301 #define L2T_SKB_CB(skb) ((struct l2t_skb_cb *)(skb)->cb)
46302
46303diff --git a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
46304index 34e2488..07e2079 100644
46305--- a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
46306+++ b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
46307@@ -2120,7 +2120,7 @@ static void get_regs(struct net_device *dev, struct ethtool_regs *regs,
46308
46309 int i;
46310 struct adapter *ap = netdev2adap(dev);
46311- static const unsigned int *reg_ranges;
46312+ const unsigned int *reg_ranges;
46313 int arr_size = 0, buf_size = 0;
46314
46315 if (is_t4(ap->params.chip)) {
46316diff --git a/drivers/net/ethernet/dec/tulip/de4x5.c b/drivers/net/ethernet/dec/tulip/de4x5.c
46317index c05b66d..ed69872 100644
46318--- a/drivers/net/ethernet/dec/tulip/de4x5.c
46319+++ b/drivers/net/ethernet/dec/tulip/de4x5.c
46320@@ -5388,7 +5388,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
46321 for (i=0; i<ETH_ALEN; i++) {
46322 tmp.addr[i] = dev->dev_addr[i];
46323 }
46324- if (copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
46325+ if (ioc->len > sizeof tmp.addr || copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
46326 break;
46327
46328 case DE4X5_SET_HWADDR: /* Set the hardware address */
46329@@ -5428,7 +5428,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
46330 spin_lock_irqsave(&lp->lock, flags);
46331 memcpy(&statbuf, &lp->pktStats, ioc->len);
46332 spin_unlock_irqrestore(&lp->lock, flags);
46333- if (copy_to_user(ioc->data, &statbuf, ioc->len))
46334+ if (ioc->len > sizeof statbuf || copy_to_user(ioc->data, &statbuf, ioc->len))
46335 return -EFAULT;
46336 break;
46337 }
46338diff --git a/drivers/net/ethernet/emulex/benet/be_main.c b/drivers/net/ethernet/emulex/benet/be_main.c
46339index 36c8061..ca5e1e0 100644
46340--- a/drivers/net/ethernet/emulex/benet/be_main.c
46341+++ b/drivers/net/ethernet/emulex/benet/be_main.c
46342@@ -534,7 +534,7 @@ static void accumulate_16bit_val(u32 *acc, u16 val)
46343
46344 if (wrapped)
46345 newacc += 65536;
46346- ACCESS_ONCE(*acc) = newacc;
46347+ ACCESS_ONCE_RW(*acc) = newacc;
46348 }
46349
46350 static void populate_erx_stats(struct be_adapter *adapter,
46351diff --git a/drivers/net/ethernet/faraday/ftgmac100.c b/drivers/net/ethernet/faraday/ftgmac100.c
46352index c11ecbc..13bb299 100644
46353--- a/drivers/net/ethernet/faraday/ftgmac100.c
46354+++ b/drivers/net/ethernet/faraday/ftgmac100.c
46355@@ -30,6 +30,8 @@
46356 #include <linux/netdevice.h>
46357 #include <linux/phy.h>
46358 #include <linux/platform_device.h>
46359+#include <linux/interrupt.h>
46360+#include <linux/irqreturn.h>
46361 #include <net/ip.h>
46362
46363 #include "ftgmac100.h"
46364diff --git a/drivers/net/ethernet/faraday/ftmac100.c b/drivers/net/ethernet/faraday/ftmac100.c
46365index 8be5b40..081bc1b 100644
46366--- a/drivers/net/ethernet/faraday/ftmac100.c
46367+++ b/drivers/net/ethernet/faraday/ftmac100.c
46368@@ -31,6 +31,8 @@
46369 #include <linux/module.h>
46370 #include <linux/netdevice.h>
46371 #include <linux/platform_device.h>
46372+#include <linux/interrupt.h>
46373+#include <linux/irqreturn.h>
46374
46375 #include "ftmac100.h"
46376
46377diff --git a/drivers/net/ethernet/intel/i40e/i40e_ptp.c b/drivers/net/ethernet/intel/i40e/i40e_ptp.c
46378index e33ec6c..f54cfe7 100644
46379--- a/drivers/net/ethernet/intel/i40e/i40e_ptp.c
46380+++ b/drivers/net/ethernet/intel/i40e/i40e_ptp.c
46381@@ -436,7 +436,7 @@ void i40e_ptp_set_increment(struct i40e_pf *pf)
46382 wr32(hw, I40E_PRTTSYN_INC_H, incval >> 32);
46383
46384 /* Update the base adjustement value. */
46385- ACCESS_ONCE(pf->ptp_base_adj) = incval;
46386+ ACCESS_ONCE_RW(pf->ptp_base_adj) = incval;
46387 smp_mb(); /* Force the above update. */
46388 }
46389
46390diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
46391index 5184e2a..acb28c3 100644
46392--- a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
46393+++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
46394@@ -776,7 +776,7 @@ void ixgbe_ptp_start_cyclecounter(struct ixgbe_adapter *adapter)
46395 }
46396
46397 /* update the base incval used to calculate frequency adjustment */
46398- ACCESS_ONCE(adapter->base_incval) = incval;
46399+ ACCESS_ONCE_RW(adapter->base_incval) = incval;
46400 smp_mb();
46401
46402 /* need lock to prevent incorrect read while modifying cyclecounter */
46403diff --git a/drivers/net/ethernet/neterion/vxge/vxge-config.c b/drivers/net/ethernet/neterion/vxge/vxge-config.c
46404index 089b713..28d87ae 100644
46405--- a/drivers/net/ethernet/neterion/vxge/vxge-config.c
46406+++ b/drivers/net/ethernet/neterion/vxge/vxge-config.c
46407@@ -3461,7 +3461,10 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
46408 struct __vxge_hw_fifo *fifo;
46409 struct vxge_hw_fifo_config *config;
46410 u32 txdl_size, txdl_per_memblock;
46411- struct vxge_hw_mempool_cbs fifo_mp_callback;
46412+ static struct vxge_hw_mempool_cbs fifo_mp_callback = {
46413+ .item_func_alloc = __vxge_hw_fifo_mempool_item_alloc,
46414+ };
46415+
46416 struct __vxge_hw_virtualpath *vpath;
46417
46418 if ((vp == NULL) || (attr == NULL)) {
46419@@ -3544,8 +3547,6 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
46420 goto exit;
46421 }
46422
46423- fifo_mp_callback.item_func_alloc = __vxge_hw_fifo_mempool_item_alloc;
46424-
46425 fifo->mempool =
46426 __vxge_hw_mempool_create(vpath->hldev,
46427 fifo->config->memblock_size,
46428diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
46429index 90a2dda..47e620e 100644
46430--- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
46431+++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
46432@@ -2088,7 +2088,9 @@ int qlcnic_83xx_configure_opmode(struct qlcnic_adapter *adapter)
46433 adapter->max_tx_rings = QLCNIC_MAX_VNIC_TX_RINGS;
46434 } else if (ret == QLC_83XX_DEFAULT_OPMODE) {
46435 ahw->nic_mode = QLCNIC_DEFAULT_MODE;
46436- adapter->nic_ops->init_driver = qlcnic_83xx_init_default_driver;
46437+ pax_open_kernel();
46438+ *(void **)&adapter->nic_ops->init_driver = qlcnic_83xx_init_default_driver;
46439+ pax_close_kernel();
46440 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
46441 adapter->max_sds_rings = QLCNIC_MAX_SDS_RINGS;
46442 adapter->max_tx_rings = QLCNIC_MAX_TX_RINGS;
46443diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
46444index be7d7a6..a8983f8 100644
46445--- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
46446+++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
46447@@ -207,17 +207,23 @@ int qlcnic_83xx_config_vnic_opmode(struct qlcnic_adapter *adapter)
46448 case QLCNIC_NON_PRIV_FUNC:
46449 ahw->op_mode = QLCNIC_NON_PRIV_FUNC;
46450 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
46451- nic_ops->init_driver = qlcnic_83xx_init_non_privileged_vnic;
46452+ pax_open_kernel();
46453+ *(void **)&nic_ops->init_driver = qlcnic_83xx_init_non_privileged_vnic;
46454+ pax_close_kernel();
46455 break;
46456 case QLCNIC_PRIV_FUNC:
46457 ahw->op_mode = QLCNIC_PRIV_FUNC;
46458 ahw->idc.state_entry = qlcnic_83xx_idc_vnic_pf_entry;
46459- nic_ops->init_driver = qlcnic_83xx_init_privileged_vnic;
46460+ pax_open_kernel();
46461+ *(void **)&nic_ops->init_driver = qlcnic_83xx_init_privileged_vnic;
46462+ pax_close_kernel();
46463 break;
46464 case QLCNIC_MGMT_FUNC:
46465 ahw->op_mode = QLCNIC_MGMT_FUNC;
46466 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
46467- nic_ops->init_driver = qlcnic_83xx_init_mgmt_vnic;
46468+ pax_open_kernel();
46469+ *(void **)&nic_ops->init_driver = qlcnic_83xx_init_mgmt_vnic;
46470+ pax_close_kernel();
46471 break;
46472 default:
46473 dev_err(&adapter->pdev->dev, "Invalid Virtual NIC opmode\n");
46474diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c
46475index 7763962..c3499a7 100644
46476--- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c
46477+++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c
46478@@ -1108,7 +1108,7 @@ int qlcnic_dump_fw(struct qlcnic_adapter *adapter)
46479 struct qlcnic_dump_entry *entry;
46480 struct qlcnic_fw_dump *fw_dump = &adapter->ahw->fw_dump;
46481 struct qlcnic_dump_template_hdr *tmpl_hdr = fw_dump->tmpl_hdr;
46482- static const struct qlcnic_dump_operations *fw_dump_ops;
46483+ const struct qlcnic_dump_operations *fw_dump_ops;
46484 struct device *dev = &adapter->pdev->dev;
46485 struct qlcnic_hardware_context *ahw;
46486 void *temp_buffer;
46487diff --git a/drivers/net/ethernet/realtek/r8169.c b/drivers/net/ethernet/realtek/r8169.c
46488index 3ff7bc3..366091b 100644
46489--- a/drivers/net/ethernet/realtek/r8169.c
46490+++ b/drivers/net/ethernet/realtek/r8169.c
46491@@ -758,22 +758,22 @@ struct rtl8169_private {
46492 struct mdio_ops {
46493 void (*write)(struct rtl8169_private *, int, int);
46494 int (*read)(struct rtl8169_private *, int);
46495- } mdio_ops;
46496+ } __no_const mdio_ops;
46497
46498 struct pll_power_ops {
46499 void (*down)(struct rtl8169_private *);
46500 void (*up)(struct rtl8169_private *);
46501- } pll_power_ops;
46502+ } __no_const pll_power_ops;
46503
46504 struct jumbo_ops {
46505 void (*enable)(struct rtl8169_private *);
46506 void (*disable)(struct rtl8169_private *);
46507- } jumbo_ops;
46508+ } __no_const jumbo_ops;
46509
46510 struct csi_ops {
46511 void (*write)(struct rtl8169_private *, int, int);
46512 u32 (*read)(struct rtl8169_private *, int);
46513- } csi_ops;
46514+ } __no_const csi_ops;
46515
46516 int (*set_speed)(struct net_device *, u8 aneg, u16 sp, u8 dpx, u32 adv);
46517 int (*get_settings)(struct net_device *, struct ethtool_cmd *);
46518diff --git a/drivers/net/ethernet/sfc/ptp.c b/drivers/net/ethernet/sfc/ptp.c
46519index d7a3682..9ce272a 100644
46520--- a/drivers/net/ethernet/sfc/ptp.c
46521+++ b/drivers/net/ethernet/sfc/ptp.c
46522@@ -825,7 +825,7 @@ static int efx_ptp_synchronize(struct efx_nic *efx, unsigned int num_readings)
46523 ptp->start.dma_addr);
46524
46525 /* Clear flag that signals MC ready */
46526- ACCESS_ONCE(*start) = 0;
46527+ ACCESS_ONCE_RW(*start) = 0;
46528 rc = efx_mcdi_rpc_start(efx, MC_CMD_PTP, synch_buf,
46529 MC_CMD_PTP_IN_SYNCHRONIZE_LEN);
46530 EFX_BUG_ON_PARANOID(rc);
46531diff --git a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
46532index 50617c5..b13724c 100644
46533--- a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
46534+++ b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
46535@@ -140,8 +140,8 @@ void dwmac_mmc_ctrl(void __iomem *ioaddr, unsigned int mode)
46536
46537 writel(value, ioaddr + MMC_CNTRL);
46538
46539- pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
46540- MMC_CNTRL, value);
46541+// pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
46542+// MMC_CNTRL, value);
46543 }
46544
46545 /* To mask all all interrupts.*/
46546diff --git a/drivers/net/hyperv/hyperv_net.h b/drivers/net/hyperv/hyperv_net.h
46547index 7b594ce..1f6c5708 100644
46548--- a/drivers/net/hyperv/hyperv_net.h
46549+++ b/drivers/net/hyperv/hyperv_net.h
46550@@ -100,7 +100,7 @@ struct rndis_device {
46551
46552 enum rndis_device_state state;
46553 bool link_state;
46554- atomic_t new_req_id;
46555+ atomic_unchecked_t new_req_id;
46556
46557 spinlock_t request_lock;
46558 struct list_head req_list;
46559diff --git a/drivers/net/hyperv/rndis_filter.c b/drivers/net/hyperv/rndis_filter.c
46560index b54fd25..9bd2bae 100644
46561--- a/drivers/net/hyperv/rndis_filter.c
46562+++ b/drivers/net/hyperv/rndis_filter.c
46563@@ -103,7 +103,7 @@ static struct rndis_request *get_rndis_request(struct rndis_device *dev,
46564 * template
46565 */
46566 set = &rndis_msg->msg.set_req;
46567- set->req_id = atomic_inc_return(&dev->new_req_id);
46568+ set->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
46569
46570 /* Add to the request list */
46571 spin_lock_irqsave(&dev->request_lock, flags);
46572@@ -770,7 +770,7 @@ static void rndis_filter_halt_device(struct rndis_device *dev)
46573
46574 /* Setup the rndis set */
46575 halt = &request->request_msg.msg.halt_req;
46576- halt->req_id = atomic_inc_return(&dev->new_req_id);
46577+ halt->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
46578
46579 /* Ignore return since this msg is optional. */
46580 rndis_filter_send_request(dev, request);
46581diff --git a/drivers/net/ieee802154/fakehard.c b/drivers/net/ieee802154/fakehard.c
46582index bf0d55e..82bcfbd1 100644
46583--- a/drivers/net/ieee802154/fakehard.c
46584+++ b/drivers/net/ieee802154/fakehard.c
46585@@ -364,7 +364,7 @@ static int ieee802154fake_probe(struct platform_device *pdev)
46586 phy->transmit_power = 0xbf;
46587
46588 dev->netdev_ops = &fake_ops;
46589- dev->ml_priv = &fake_mlme;
46590+ dev->ml_priv = (void *)&fake_mlme;
46591
46592 priv = netdev_priv(dev);
46593 priv->phy = phy;
46594diff --git a/drivers/net/macvlan.c b/drivers/net/macvlan.c
46595index 1831fb7..9c24bca 100644
46596--- a/drivers/net/macvlan.c
46597+++ b/drivers/net/macvlan.c
46598@@ -984,13 +984,15 @@ static const struct nla_policy macvlan_policy[IFLA_MACVLAN_MAX + 1] = {
46599 int macvlan_link_register(struct rtnl_link_ops *ops)
46600 {
46601 /* common fields */
46602- ops->priv_size = sizeof(struct macvlan_dev);
46603- ops->validate = macvlan_validate;
46604- ops->maxtype = IFLA_MACVLAN_MAX;
46605- ops->policy = macvlan_policy;
46606- ops->changelink = macvlan_changelink;
46607- ops->get_size = macvlan_get_size;
46608- ops->fill_info = macvlan_fill_info;
46609+ pax_open_kernel();
46610+ *(size_t *)&ops->priv_size = sizeof(struct macvlan_dev);
46611+ *(void **)&ops->validate = macvlan_validate;
46612+ *(int *)&ops->maxtype = IFLA_MACVLAN_MAX;
46613+ *(const void **)&ops->policy = macvlan_policy;
46614+ *(void **)&ops->changelink = macvlan_changelink;
46615+ *(void **)&ops->get_size = macvlan_get_size;
46616+ *(void **)&ops->fill_info = macvlan_fill_info;
46617+ pax_close_kernel();
46618
46619 return rtnl_link_register(ops);
46620 };
46621@@ -1045,7 +1047,7 @@ static int macvlan_device_event(struct notifier_block *unused,
46622 return NOTIFY_DONE;
46623 }
46624
46625-static struct notifier_block macvlan_notifier_block __read_mostly = {
46626+static struct notifier_block macvlan_notifier_block = {
46627 .notifier_call = macvlan_device_event,
46628 };
46629
46630diff --git a/drivers/net/macvtap.c b/drivers/net/macvtap.c
46631index ff111a8..c4c3ac4 100644
46632--- a/drivers/net/macvtap.c
46633+++ b/drivers/net/macvtap.c
46634@@ -1011,7 +1011,7 @@ static long macvtap_ioctl(struct file *file, unsigned int cmd,
46635 }
46636
46637 ret = 0;
46638- if (copy_to_user(&ifr->ifr_name, vlan->dev->name, IFNAMSIZ) ||
46639+ if (copy_to_user(ifr->ifr_name, vlan->dev->name, IFNAMSIZ) ||
46640 put_user(q->flags, &ifr->ifr_flags))
46641 ret = -EFAULT;
46642 macvtap_put_vlan(vlan);
46643@@ -1181,7 +1181,7 @@ static int macvtap_device_event(struct notifier_block *unused,
46644 return NOTIFY_DONE;
46645 }
46646
46647-static struct notifier_block macvtap_notifier_block __read_mostly = {
46648+static struct notifier_block macvtap_notifier_block = {
46649 .notifier_call = macvtap_device_event,
46650 };
46651
46652diff --git a/drivers/net/phy/mdio-bitbang.c b/drivers/net/phy/mdio-bitbang.c
46653index daec9b0..6428fcb 100644
46654--- a/drivers/net/phy/mdio-bitbang.c
46655+++ b/drivers/net/phy/mdio-bitbang.c
46656@@ -234,6 +234,7 @@ void free_mdio_bitbang(struct mii_bus *bus)
46657 struct mdiobb_ctrl *ctrl = bus->priv;
46658
46659 module_put(ctrl->ops->owner);
46660+ mdiobus_unregister(bus);
46661 mdiobus_free(bus);
46662 }
46663 EXPORT_SYMBOL(free_mdio_bitbang);
46664diff --git a/drivers/net/ppp/ppp_generic.c b/drivers/net/ppp/ppp_generic.c
46665index 72ff14b..11d442d 100644
46666--- a/drivers/net/ppp/ppp_generic.c
46667+++ b/drivers/net/ppp/ppp_generic.c
46668@@ -999,7 +999,6 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
46669 void __user *addr = (void __user *) ifr->ifr_ifru.ifru_data;
46670 struct ppp_stats stats;
46671 struct ppp_comp_stats cstats;
46672- char *vers;
46673
46674 switch (cmd) {
46675 case SIOCGPPPSTATS:
46676@@ -1021,8 +1020,7 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
46677 break;
46678
46679 case SIOCGPPPVER:
46680- vers = PPP_VERSION;
46681- if (copy_to_user(addr, vers, strlen(vers) + 1))
46682+ if (copy_to_user(addr, PPP_VERSION, sizeof(PPP_VERSION)))
46683 break;
46684 err = 0;
46685 break;
46686diff --git a/drivers/net/slip/slhc.c b/drivers/net/slip/slhc.c
46687index 1252d9c..80e660b 100644
46688--- a/drivers/net/slip/slhc.c
46689+++ b/drivers/net/slip/slhc.c
46690@@ -488,7 +488,7 @@ slhc_uncompress(struct slcompress *comp, unsigned char *icp, int isize)
46691 register struct tcphdr *thp;
46692 register struct iphdr *ip;
46693 register struct cstate *cs;
46694- int len, hdrlen;
46695+ long len, hdrlen;
46696 unsigned char *cp = icp;
46697
46698 /* We've got a compressed packet; read the change byte */
46699diff --git a/drivers/net/team/team.c b/drivers/net/team/team.c
46700index c8624a8..f0a4f6a 100644
46701--- a/drivers/net/team/team.c
46702+++ b/drivers/net/team/team.c
46703@@ -2869,7 +2869,7 @@ static int team_device_event(struct notifier_block *unused,
46704 return NOTIFY_DONE;
46705 }
46706
46707-static struct notifier_block team_notifier_block __read_mostly = {
46708+static struct notifier_block team_notifier_block = {
46709 .notifier_call = team_device_event,
46710 };
46711
46712diff --git a/drivers/net/tun.c b/drivers/net/tun.c
46713index 26f8635..c237839 100644
46714--- a/drivers/net/tun.c
46715+++ b/drivers/net/tun.c
46716@@ -1876,7 +1876,7 @@ unlock:
46717 }
46718
46719 static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
46720- unsigned long arg, int ifreq_len)
46721+ unsigned long arg, size_t ifreq_len)
46722 {
46723 struct tun_file *tfile = file->private_data;
46724 struct tun_struct *tun;
46725@@ -1889,6 +1889,9 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
46726 unsigned int ifindex;
46727 int ret;
46728
46729+ if (ifreq_len > sizeof ifr)
46730+ return -EFAULT;
46731+
46732 if (cmd == TUNSETIFF || cmd == TUNSETQUEUE || _IOC_TYPE(cmd) == 0x89) {
46733 if (copy_from_user(&ifr, argp, ifreq_len))
46734 return -EFAULT;
46735diff --git a/drivers/net/usb/cdc_ncm.c b/drivers/net/usb/cdc_ncm.c
46736index d350d27..75d7d9d 100644
46737--- a/drivers/net/usb/cdc_ncm.c
46738+++ b/drivers/net/usb/cdc_ncm.c
46739@@ -768,7 +768,7 @@ cdc_ncm_fill_tx_frame(struct usbnet *dev, struct sk_buff *skb, __le32 sign)
46740 skb_out->len > CDC_NCM_MIN_TX_PKT)
46741 memset(skb_put(skb_out, ctx->tx_max - skb_out->len), 0,
46742 ctx->tx_max - skb_out->len);
46743- else if ((skb_out->len % dev->maxpacket) == 0)
46744+ else if (skb_out->len < ctx->tx_max && (skb_out->len % dev->maxpacket) == 0)
46745 *skb_put(skb_out, 1) = 0; /* force short packet */
46746
46747 /* set final frame length */
46748diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c
46749index 660bd5e..ac59452 100644
46750--- a/drivers/net/usb/hso.c
46751+++ b/drivers/net/usb/hso.c
46752@@ -71,7 +71,7 @@
46753 #include <asm/byteorder.h>
46754 #include <linux/serial_core.h>
46755 #include <linux/serial.h>
46756-
46757+#include <asm/local.h>
46758
46759 #define MOD_AUTHOR "Option Wireless"
46760 #define MOD_DESCRIPTION "USB High Speed Option driver"
46761@@ -1179,7 +1179,7 @@ static void put_rxbuf_data_and_resubmit_ctrl_urb(struct hso_serial *serial)
46762 struct urb *urb;
46763
46764 urb = serial->rx_urb[0];
46765- if (serial->port.count > 0) {
46766+ if (atomic_read(&serial->port.count) > 0) {
46767 count = put_rxbuf_data(urb, serial);
46768 if (count == -1)
46769 return;
46770@@ -1217,7 +1217,7 @@ static void hso_std_serial_read_bulk_callback(struct urb *urb)
46771 DUMP1(urb->transfer_buffer, urb->actual_length);
46772
46773 /* Anyone listening? */
46774- if (serial->port.count == 0)
46775+ if (atomic_read(&serial->port.count) == 0)
46776 return;
46777
46778 if (serial->parent->port_spec & HSO_INFO_CRC_BUG)
46779@@ -1287,8 +1287,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
46780 tty_port_tty_set(&serial->port, tty);
46781
46782 /* check for port already opened, if not set the termios */
46783- serial->port.count++;
46784- if (serial->port.count == 1) {
46785+ if (atomic_inc_return(&serial->port.count) == 1) {
46786 serial->rx_state = RX_IDLE;
46787 /* Force default termio settings */
46788 _hso_serial_set_termios(tty, NULL);
46789@@ -1300,7 +1299,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
46790 result = hso_start_serial_device(serial->parent, GFP_KERNEL);
46791 if (result) {
46792 hso_stop_serial_device(serial->parent);
46793- serial->port.count--;
46794+ atomic_dec(&serial->port.count);
46795 kref_put(&serial->parent->ref, hso_serial_ref_free);
46796 }
46797 } else {
46798@@ -1337,10 +1336,10 @@ static void hso_serial_close(struct tty_struct *tty, struct file *filp)
46799
46800 /* reset the rts and dtr */
46801 /* do the actual close */
46802- serial->port.count--;
46803+ atomic_dec(&serial->port.count);
46804
46805- if (serial->port.count <= 0) {
46806- serial->port.count = 0;
46807+ if (atomic_read(&serial->port.count) <= 0) {
46808+ atomic_set(&serial->port.count, 0);
46809 tty_port_tty_set(&serial->port, NULL);
46810 if (!usb_gone)
46811 hso_stop_serial_device(serial->parent);
46812@@ -1416,7 +1415,7 @@ static void hso_serial_set_termios(struct tty_struct *tty, struct ktermios *old)
46813
46814 /* the actual setup */
46815 spin_lock_irqsave(&serial->serial_lock, flags);
46816- if (serial->port.count)
46817+ if (atomic_read(&serial->port.count))
46818 _hso_serial_set_termios(tty, old);
46819 else
46820 tty->termios = *old;
46821@@ -1885,7 +1884,7 @@ static void intr_callback(struct urb *urb)
46822 D1("Pending read interrupt on port %d\n", i);
46823 spin_lock(&serial->serial_lock);
46824 if (serial->rx_state == RX_IDLE &&
46825- serial->port.count > 0) {
46826+ atomic_read(&serial->port.count) > 0) {
46827 /* Setup and send a ctrl req read on
46828 * port i */
46829 if (!serial->rx_urb_filled[0]) {
46830@@ -3061,7 +3060,7 @@ static int hso_resume(struct usb_interface *iface)
46831 /* Start all serial ports */
46832 for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) {
46833 if (serial_table[i] && (serial_table[i]->interface == iface)) {
46834- if (dev2ser(serial_table[i])->port.count) {
46835+ if (atomic_read(&dev2ser(serial_table[i])->port.count)) {
46836 result =
46837 hso_start_serial_device(serial_table[i], GFP_NOIO);
46838 hso_kick_transmit(dev2ser(serial_table[i]));
46839diff --git a/drivers/net/usb/r8152.c b/drivers/net/usb/r8152.c
46840index adb12f3..48005ab 100644
46841--- a/drivers/net/usb/r8152.c
46842+++ b/drivers/net/usb/r8152.c
46843@@ -513,7 +513,7 @@ struct r8152 {
46844 void (*disable)(struct r8152 *);
46845 void (*down)(struct r8152 *);
46846 void (*unload)(struct r8152 *);
46847- } rtl_ops;
46848+ } __no_const rtl_ops;
46849
46850 int intr_interval;
46851 u32 msg_enable;
46852diff --git a/drivers/net/usb/sierra_net.c b/drivers/net/usb/sierra_net.c
46853index a2515887..6d13233 100644
46854--- a/drivers/net/usb/sierra_net.c
46855+++ b/drivers/net/usb/sierra_net.c
46856@@ -51,7 +51,7 @@ static const char driver_name[] = "sierra_net";
46857 /* atomic counter partially included in MAC address to make sure 2 devices
46858 * do not end up with the same MAC - concept breaks in case of > 255 ifaces
46859 */
46860-static atomic_t iface_counter = ATOMIC_INIT(0);
46861+static atomic_unchecked_t iface_counter = ATOMIC_INIT(0);
46862
46863 /*
46864 * SYNC Timer Delay definition used to set the expiry time
46865@@ -697,7 +697,7 @@ static int sierra_net_bind(struct usbnet *dev, struct usb_interface *intf)
46866 dev->net->netdev_ops = &sierra_net_device_ops;
46867
46868 /* change MAC addr to include, ifacenum, and to be unique */
46869- dev->net->dev_addr[ETH_ALEN-2] = atomic_inc_return(&iface_counter);
46870+ dev->net->dev_addr[ETH_ALEN-2] = atomic_inc_return_unchecked(&iface_counter);
46871 dev->net->dev_addr[ETH_ALEN-1] = ifacenum;
46872
46873 /* we will have to manufacture ethernet headers, prepare template */
46874diff --git a/drivers/net/vxlan.c b/drivers/net/vxlan.c
46875index d091e52..568bb179 100644
46876--- a/drivers/net/vxlan.c
46877+++ b/drivers/net/vxlan.c
46878@@ -2847,7 +2847,7 @@ nla_put_failure:
46879 return -EMSGSIZE;
46880 }
46881
46882-static struct rtnl_link_ops vxlan_link_ops __read_mostly = {
46883+static struct rtnl_link_ops vxlan_link_ops = {
46884 .kind = "vxlan",
46885 .maxtype = IFLA_VXLAN_MAX,
46886 .policy = vxlan_policy,
46887@@ -2894,7 +2894,7 @@ static int vxlan_lowerdev_event(struct notifier_block *unused,
46888 return NOTIFY_DONE;
46889 }
46890
46891-static struct notifier_block vxlan_notifier_block __read_mostly = {
46892+static struct notifier_block vxlan_notifier_block = {
46893 .notifier_call = vxlan_lowerdev_event,
46894 };
46895
46896diff --git a/drivers/net/wan/lmc/lmc_media.c b/drivers/net/wan/lmc/lmc_media.c
46897index 5920c99..ff2e4a5 100644
46898--- a/drivers/net/wan/lmc/lmc_media.c
46899+++ b/drivers/net/wan/lmc/lmc_media.c
46900@@ -95,62 +95,63 @@ static inline void write_av9110_bit (lmc_softc_t *, int);
46901 static void write_av9110(lmc_softc_t *, u32, u32, u32, u32, u32);
46902
46903 lmc_media_t lmc_ds3_media = {
46904- lmc_ds3_init, /* special media init stuff */
46905- lmc_ds3_default, /* reset to default state */
46906- lmc_ds3_set_status, /* reset status to state provided */
46907- lmc_dummy_set_1, /* set clock source */
46908- lmc_dummy_set2_1, /* set line speed */
46909- lmc_ds3_set_100ft, /* set cable length */
46910- lmc_ds3_set_scram, /* set scrambler */
46911- lmc_ds3_get_link_status, /* get link status */
46912- lmc_dummy_set_1, /* set link status */
46913- lmc_ds3_set_crc_length, /* set CRC length */
46914- lmc_dummy_set_1, /* set T1 or E1 circuit type */
46915- lmc_ds3_watchdog
46916+ .init = lmc_ds3_init, /* special media init stuff */
46917+ .defaults = lmc_ds3_default, /* reset to default state */
46918+ .set_status = lmc_ds3_set_status, /* reset status to state provided */
46919+ .set_clock_source = lmc_dummy_set_1, /* set clock source */
46920+ .set_speed = lmc_dummy_set2_1, /* set line speed */
46921+ .set_cable_length = lmc_ds3_set_100ft, /* set cable length */
46922+ .set_scrambler = lmc_ds3_set_scram, /* set scrambler */
46923+ .get_link_status = lmc_ds3_get_link_status, /* get link status */
46924+ .set_link_status = lmc_dummy_set_1, /* set link status */
46925+ .set_crc_length = lmc_ds3_set_crc_length, /* set CRC length */
46926+ .set_circuit_type = lmc_dummy_set_1, /* set T1 or E1 circuit type */
46927+ .watchdog = lmc_ds3_watchdog
46928 };
46929
46930 lmc_media_t lmc_hssi_media = {
46931- lmc_hssi_init, /* special media init stuff */
46932- lmc_hssi_default, /* reset to default state */
46933- lmc_hssi_set_status, /* reset status to state provided */
46934- lmc_hssi_set_clock, /* set clock source */
46935- lmc_dummy_set2_1, /* set line speed */
46936- lmc_dummy_set_1, /* set cable length */
46937- lmc_dummy_set_1, /* set scrambler */
46938- lmc_hssi_get_link_status, /* get link status */
46939- lmc_hssi_set_link_status, /* set link status */
46940- lmc_hssi_set_crc_length, /* set CRC length */
46941- lmc_dummy_set_1, /* set T1 or E1 circuit type */
46942- lmc_hssi_watchdog
46943+ .init = lmc_hssi_init, /* special media init stuff */
46944+ .defaults = lmc_hssi_default, /* reset to default state */
46945+ .set_status = lmc_hssi_set_status, /* reset status to state provided */
46946+ .set_clock_source = lmc_hssi_set_clock, /* set clock source */
46947+ .set_speed = lmc_dummy_set2_1, /* set line speed */
46948+ .set_cable_length = lmc_dummy_set_1, /* set cable length */
46949+ .set_scrambler = lmc_dummy_set_1, /* set scrambler */
46950+ .get_link_status = lmc_hssi_get_link_status, /* get link status */
46951+ .set_link_status = lmc_hssi_set_link_status, /* set link status */
46952+ .set_crc_length = lmc_hssi_set_crc_length, /* set CRC length */
46953+ .set_circuit_type = lmc_dummy_set_1, /* set T1 or E1 circuit type */
46954+ .watchdog = lmc_hssi_watchdog
46955 };
46956
46957-lmc_media_t lmc_ssi_media = { lmc_ssi_init, /* special media init stuff */
46958- lmc_ssi_default, /* reset to default state */
46959- lmc_ssi_set_status, /* reset status to state provided */
46960- lmc_ssi_set_clock, /* set clock source */
46961- lmc_ssi_set_speed, /* set line speed */
46962- lmc_dummy_set_1, /* set cable length */
46963- lmc_dummy_set_1, /* set scrambler */
46964- lmc_ssi_get_link_status, /* get link status */
46965- lmc_ssi_set_link_status, /* set link status */
46966- lmc_ssi_set_crc_length, /* set CRC length */
46967- lmc_dummy_set_1, /* set T1 or E1 circuit type */
46968- lmc_ssi_watchdog
46969+lmc_media_t lmc_ssi_media = {
46970+ .init = lmc_ssi_init, /* special media init stuff */
46971+ .defaults = lmc_ssi_default, /* reset to default state */
46972+ .set_status = lmc_ssi_set_status, /* reset status to state provided */
46973+ .set_clock_source = lmc_ssi_set_clock, /* set clock source */
46974+ .set_speed = lmc_ssi_set_speed, /* set line speed */
46975+ .set_cable_length = lmc_dummy_set_1, /* set cable length */
46976+ .set_scrambler = lmc_dummy_set_1, /* set scrambler */
46977+ .get_link_status = lmc_ssi_get_link_status, /* get link status */
46978+ .set_link_status = lmc_ssi_set_link_status, /* set link status */
46979+ .set_crc_length = lmc_ssi_set_crc_length, /* set CRC length */
46980+ .set_circuit_type = lmc_dummy_set_1, /* set T1 or E1 circuit type */
46981+ .watchdog = lmc_ssi_watchdog
46982 };
46983
46984 lmc_media_t lmc_t1_media = {
46985- lmc_t1_init, /* special media init stuff */
46986- lmc_t1_default, /* reset to default state */
46987- lmc_t1_set_status, /* reset status to state provided */
46988- lmc_t1_set_clock, /* set clock source */
46989- lmc_dummy_set2_1, /* set line speed */
46990- lmc_dummy_set_1, /* set cable length */
46991- lmc_dummy_set_1, /* set scrambler */
46992- lmc_t1_get_link_status, /* get link status */
46993- lmc_dummy_set_1, /* set link status */
46994- lmc_t1_set_crc_length, /* set CRC length */
46995- lmc_t1_set_circuit_type, /* set T1 or E1 circuit type */
46996- lmc_t1_watchdog
46997+ .init = lmc_t1_init, /* special media init stuff */
46998+ .defaults = lmc_t1_default, /* reset to default state */
46999+ .set_status = lmc_t1_set_status, /* reset status to state provided */
47000+ .set_clock_source = lmc_t1_set_clock, /* set clock source */
47001+ .set_speed = lmc_dummy_set2_1, /* set line speed */
47002+ .set_cable_length = lmc_dummy_set_1, /* set cable length */
47003+ .set_scrambler = lmc_dummy_set_1, /* set scrambler */
47004+ .get_link_status = lmc_t1_get_link_status, /* get link status */
47005+ .set_link_status = lmc_dummy_set_1, /* set link status */
47006+ .set_crc_length = lmc_t1_set_crc_length, /* set CRC length */
47007+ .set_circuit_type = lmc_t1_set_circuit_type, /* set T1 or E1 circuit type */
47008+ .watchdog = lmc_t1_watchdog
47009 };
47010
47011 static void
47012diff --git a/drivers/net/wan/z85230.c b/drivers/net/wan/z85230.c
47013index feacc3b..5bac0de 100644
47014--- a/drivers/net/wan/z85230.c
47015+++ b/drivers/net/wan/z85230.c
47016@@ -485,9 +485,9 @@ static void z8530_status(struct z8530_channel *chan)
47017
47018 struct z8530_irqhandler z8530_sync =
47019 {
47020- z8530_rx,
47021- z8530_tx,
47022- z8530_status
47023+ .rx = z8530_rx,
47024+ .tx = z8530_tx,
47025+ .status = z8530_status
47026 };
47027
47028 EXPORT_SYMBOL(z8530_sync);
47029@@ -605,15 +605,15 @@ static void z8530_dma_status(struct z8530_channel *chan)
47030 }
47031
47032 static struct z8530_irqhandler z8530_dma_sync = {
47033- z8530_dma_rx,
47034- z8530_dma_tx,
47035- z8530_dma_status
47036+ .rx = z8530_dma_rx,
47037+ .tx = z8530_dma_tx,
47038+ .status = z8530_dma_status
47039 };
47040
47041 static struct z8530_irqhandler z8530_txdma_sync = {
47042- z8530_rx,
47043- z8530_dma_tx,
47044- z8530_dma_status
47045+ .rx = z8530_rx,
47046+ .tx = z8530_dma_tx,
47047+ .status = z8530_dma_status
47048 };
47049
47050 /**
47051@@ -680,9 +680,9 @@ static void z8530_status_clear(struct z8530_channel *chan)
47052
47053 struct z8530_irqhandler z8530_nop=
47054 {
47055- z8530_rx_clear,
47056- z8530_tx_clear,
47057- z8530_status_clear
47058+ .rx = z8530_rx_clear,
47059+ .tx = z8530_tx_clear,
47060+ .status = z8530_status_clear
47061 };
47062
47063
47064diff --git a/drivers/net/wimax/i2400m/rx.c b/drivers/net/wimax/i2400m/rx.c
47065index 0b60295..b8bfa5b 100644
47066--- a/drivers/net/wimax/i2400m/rx.c
47067+++ b/drivers/net/wimax/i2400m/rx.c
47068@@ -1359,7 +1359,7 @@ int i2400m_rx_setup(struct i2400m *i2400m)
47069 if (i2400m->rx_roq == NULL)
47070 goto error_roq_alloc;
47071
47072- rd = kcalloc(I2400M_RO_CIN + 1, sizeof(*i2400m->rx_roq[0].log),
47073+ rd = kcalloc(sizeof(*i2400m->rx_roq[0].log), I2400M_RO_CIN + 1,
47074 GFP_KERNEL);
47075 if (rd == NULL) {
47076 result = -ENOMEM;
47077diff --git a/drivers/net/wireless/airo.c b/drivers/net/wireless/airo.c
47078index edf4b57..68b51c0 100644
47079--- a/drivers/net/wireless/airo.c
47080+++ b/drivers/net/wireless/airo.c
47081@@ -7843,7 +7843,7 @@ static int writerids(struct net_device *dev, aironet_ioctl *comp) {
47082 struct airo_info *ai = dev->ml_priv;
47083 int ridcode;
47084 int enabled;
47085- static int (* writer)(struct airo_info *, u16 rid, const void *, int, int);
47086+ int (* writer)(struct airo_info *, u16 rid, const void *, int, int);
47087 unsigned char *iobuf;
47088
47089 /* Only super-user can write RIDs */
47090diff --git a/drivers/net/wireless/at76c50x-usb.c b/drivers/net/wireless/at76c50x-usb.c
47091index 99b3bfa..9559372 100644
47092--- a/drivers/net/wireless/at76c50x-usb.c
47093+++ b/drivers/net/wireless/at76c50x-usb.c
47094@@ -353,7 +353,7 @@ static int at76_dfu_get_state(struct usb_device *udev, u8 *state)
47095 }
47096
47097 /* Convert timeout from the DFU status to jiffies */
47098-static inline unsigned long at76_get_timeout(struct dfu_status *s)
47099+static inline unsigned long __intentional_overflow(-1) at76_get_timeout(struct dfu_status *s)
47100 {
47101 return msecs_to_jiffies((s->poll_timeout[2] << 16)
47102 | (s->poll_timeout[1] << 8)
47103diff --git a/drivers/net/wireless/ath/ath10k/htc.c b/drivers/net/wireless/ath/ath10k/htc.c
47104index edc57ab..ff49e0a 100644
47105--- a/drivers/net/wireless/ath/ath10k/htc.c
47106+++ b/drivers/net/wireless/ath/ath10k/htc.c
47107@@ -831,7 +831,10 @@ void ath10k_htc_stop(struct ath10k_htc *htc)
47108 /* registered target arrival callback from the HIF layer */
47109 int ath10k_htc_init(struct ath10k *ar)
47110 {
47111- struct ath10k_hif_cb htc_callbacks;
47112+ static struct ath10k_hif_cb htc_callbacks = {
47113+ .rx_completion = ath10k_htc_rx_completion_handler,
47114+ .tx_completion = ath10k_htc_tx_completion_handler,
47115+ };
47116 struct ath10k_htc_ep *ep = NULL;
47117 struct ath10k_htc *htc = &ar->htc;
47118
47119@@ -841,8 +844,6 @@ int ath10k_htc_init(struct ath10k *ar)
47120 ath10k_htc_reset_endpoint_states(htc);
47121
47122 /* setup HIF layer callbacks */
47123- htc_callbacks.rx_completion = ath10k_htc_rx_completion_handler;
47124- htc_callbacks.tx_completion = ath10k_htc_tx_completion_handler;
47125 htc->ar = ar;
47126
47127 /* Get HIF default pipe for HTC message exchange */
47128diff --git a/drivers/net/wireless/ath/ath10k/htc.h b/drivers/net/wireless/ath/ath10k/htc.h
47129index 4716d33..a688310 100644
47130--- a/drivers/net/wireless/ath/ath10k/htc.h
47131+++ b/drivers/net/wireless/ath/ath10k/htc.h
47132@@ -271,13 +271,13 @@ enum ath10k_htc_ep_id {
47133
47134 struct ath10k_htc_ops {
47135 void (*target_send_suspend_complete)(struct ath10k *ar);
47136-};
47137+} __no_const;
47138
47139 struct ath10k_htc_ep_ops {
47140 void (*ep_tx_complete)(struct ath10k *, struct sk_buff *);
47141 void (*ep_rx_complete)(struct ath10k *, struct sk_buff *);
47142 void (*ep_tx_credits)(struct ath10k *);
47143-};
47144+} __no_const;
47145
47146 /* service connection information */
47147 struct ath10k_htc_svc_conn_req {
47148diff --git a/drivers/net/wireless/ath/ath9k/ar9002_mac.c b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
47149index 741b38d..b7ae41b 100644
47150--- a/drivers/net/wireless/ath/ath9k/ar9002_mac.c
47151+++ b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
47152@@ -220,8 +220,8 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
47153 ads->ds_txstatus6 = ads->ds_txstatus7 = 0;
47154 ads->ds_txstatus8 = ads->ds_txstatus9 = 0;
47155
47156- ACCESS_ONCE(ads->ds_link) = i->link;
47157- ACCESS_ONCE(ads->ds_data) = i->buf_addr[0];
47158+ ACCESS_ONCE_RW(ads->ds_link) = i->link;
47159+ ACCESS_ONCE_RW(ads->ds_data) = i->buf_addr[0];
47160
47161 ctl1 = i->buf_len[0] | (i->is_last ? 0 : AR_TxMore);
47162 ctl6 = SM(i->keytype, AR_EncrType);
47163@@ -235,26 +235,26 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
47164
47165 if ((i->is_first || i->is_last) &&
47166 i->aggr != AGGR_BUF_MIDDLE && i->aggr != AGGR_BUF_LAST) {
47167- ACCESS_ONCE(ads->ds_ctl2) = set11nTries(i->rates, 0)
47168+ ACCESS_ONCE_RW(ads->ds_ctl2) = set11nTries(i->rates, 0)
47169 | set11nTries(i->rates, 1)
47170 | set11nTries(i->rates, 2)
47171 | set11nTries(i->rates, 3)
47172 | (i->dur_update ? AR_DurUpdateEna : 0)
47173 | SM(0, AR_BurstDur);
47174
47175- ACCESS_ONCE(ads->ds_ctl3) = set11nRate(i->rates, 0)
47176+ ACCESS_ONCE_RW(ads->ds_ctl3) = set11nRate(i->rates, 0)
47177 | set11nRate(i->rates, 1)
47178 | set11nRate(i->rates, 2)
47179 | set11nRate(i->rates, 3);
47180 } else {
47181- ACCESS_ONCE(ads->ds_ctl2) = 0;
47182- ACCESS_ONCE(ads->ds_ctl3) = 0;
47183+ ACCESS_ONCE_RW(ads->ds_ctl2) = 0;
47184+ ACCESS_ONCE_RW(ads->ds_ctl3) = 0;
47185 }
47186
47187 if (!i->is_first) {
47188- ACCESS_ONCE(ads->ds_ctl0) = 0;
47189- ACCESS_ONCE(ads->ds_ctl1) = ctl1;
47190- ACCESS_ONCE(ads->ds_ctl6) = ctl6;
47191+ ACCESS_ONCE_RW(ads->ds_ctl0) = 0;
47192+ ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
47193+ ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
47194 return;
47195 }
47196
47197@@ -279,7 +279,7 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
47198 break;
47199 }
47200
47201- ACCESS_ONCE(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
47202+ ACCESS_ONCE_RW(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
47203 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
47204 | SM(i->txpower, AR_XmitPower)
47205 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
47206@@ -289,19 +289,19 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
47207 | (i->flags & ATH9K_TXDESC_RTSENA ? AR_RTSEnable :
47208 (i->flags & ATH9K_TXDESC_CTSENA ? AR_CTSEnable : 0));
47209
47210- ACCESS_ONCE(ads->ds_ctl1) = ctl1;
47211- ACCESS_ONCE(ads->ds_ctl6) = ctl6;
47212+ ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
47213+ ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
47214
47215 if (i->aggr == AGGR_BUF_MIDDLE || i->aggr == AGGR_BUF_LAST)
47216 return;
47217
47218- ACCESS_ONCE(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
47219+ ACCESS_ONCE_RW(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
47220 | set11nPktDurRTSCTS(i->rates, 1);
47221
47222- ACCESS_ONCE(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
47223+ ACCESS_ONCE_RW(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
47224 | set11nPktDurRTSCTS(i->rates, 3);
47225
47226- ACCESS_ONCE(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
47227+ ACCESS_ONCE_RW(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
47228 | set11nRateFlags(i->rates, 1)
47229 | set11nRateFlags(i->rates, 2)
47230 | set11nRateFlags(i->rates, 3)
47231diff --git a/drivers/net/wireless/ath/ath9k/ar9003_mac.c b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
47232index 729ffbf..49f50e3 100644
47233--- a/drivers/net/wireless/ath/ath9k/ar9003_mac.c
47234+++ b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
47235@@ -39,47 +39,47 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
47236 (i->qcu << AR_TxQcuNum_S) | desc_len;
47237
47238 checksum += val;
47239- ACCESS_ONCE(ads->info) = val;
47240+ ACCESS_ONCE_RW(ads->info) = val;
47241
47242 checksum += i->link;
47243- ACCESS_ONCE(ads->link) = i->link;
47244+ ACCESS_ONCE_RW(ads->link) = i->link;
47245
47246 checksum += i->buf_addr[0];
47247- ACCESS_ONCE(ads->data0) = i->buf_addr[0];
47248+ ACCESS_ONCE_RW(ads->data0) = i->buf_addr[0];
47249 checksum += i->buf_addr[1];
47250- ACCESS_ONCE(ads->data1) = i->buf_addr[1];
47251+ ACCESS_ONCE_RW(ads->data1) = i->buf_addr[1];
47252 checksum += i->buf_addr[2];
47253- ACCESS_ONCE(ads->data2) = i->buf_addr[2];
47254+ ACCESS_ONCE_RW(ads->data2) = i->buf_addr[2];
47255 checksum += i->buf_addr[3];
47256- ACCESS_ONCE(ads->data3) = i->buf_addr[3];
47257+ ACCESS_ONCE_RW(ads->data3) = i->buf_addr[3];
47258
47259 checksum += (val = (i->buf_len[0] << AR_BufLen_S) & AR_BufLen);
47260- ACCESS_ONCE(ads->ctl3) = val;
47261+ ACCESS_ONCE_RW(ads->ctl3) = val;
47262 checksum += (val = (i->buf_len[1] << AR_BufLen_S) & AR_BufLen);
47263- ACCESS_ONCE(ads->ctl5) = val;
47264+ ACCESS_ONCE_RW(ads->ctl5) = val;
47265 checksum += (val = (i->buf_len[2] << AR_BufLen_S) & AR_BufLen);
47266- ACCESS_ONCE(ads->ctl7) = val;
47267+ ACCESS_ONCE_RW(ads->ctl7) = val;
47268 checksum += (val = (i->buf_len[3] << AR_BufLen_S) & AR_BufLen);
47269- ACCESS_ONCE(ads->ctl9) = val;
47270+ ACCESS_ONCE_RW(ads->ctl9) = val;
47271
47272 checksum = (u16) (((checksum & 0xffff) + (checksum >> 16)) & 0xffff);
47273- ACCESS_ONCE(ads->ctl10) = checksum;
47274+ ACCESS_ONCE_RW(ads->ctl10) = checksum;
47275
47276 if (i->is_first || i->is_last) {
47277- ACCESS_ONCE(ads->ctl13) = set11nTries(i->rates, 0)
47278+ ACCESS_ONCE_RW(ads->ctl13) = set11nTries(i->rates, 0)
47279 | set11nTries(i->rates, 1)
47280 | set11nTries(i->rates, 2)
47281 | set11nTries(i->rates, 3)
47282 | (i->dur_update ? AR_DurUpdateEna : 0)
47283 | SM(0, AR_BurstDur);
47284
47285- ACCESS_ONCE(ads->ctl14) = set11nRate(i->rates, 0)
47286+ ACCESS_ONCE_RW(ads->ctl14) = set11nRate(i->rates, 0)
47287 | set11nRate(i->rates, 1)
47288 | set11nRate(i->rates, 2)
47289 | set11nRate(i->rates, 3);
47290 } else {
47291- ACCESS_ONCE(ads->ctl13) = 0;
47292- ACCESS_ONCE(ads->ctl14) = 0;
47293+ ACCESS_ONCE_RW(ads->ctl13) = 0;
47294+ ACCESS_ONCE_RW(ads->ctl14) = 0;
47295 }
47296
47297 ads->ctl20 = 0;
47298@@ -89,17 +89,17 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
47299
47300 ctl17 = SM(i->keytype, AR_EncrType);
47301 if (!i->is_first) {
47302- ACCESS_ONCE(ads->ctl11) = 0;
47303- ACCESS_ONCE(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
47304- ACCESS_ONCE(ads->ctl15) = 0;
47305- ACCESS_ONCE(ads->ctl16) = 0;
47306- ACCESS_ONCE(ads->ctl17) = ctl17;
47307- ACCESS_ONCE(ads->ctl18) = 0;
47308- ACCESS_ONCE(ads->ctl19) = 0;
47309+ ACCESS_ONCE_RW(ads->ctl11) = 0;
47310+ ACCESS_ONCE_RW(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
47311+ ACCESS_ONCE_RW(ads->ctl15) = 0;
47312+ ACCESS_ONCE_RW(ads->ctl16) = 0;
47313+ ACCESS_ONCE_RW(ads->ctl17) = ctl17;
47314+ ACCESS_ONCE_RW(ads->ctl18) = 0;
47315+ ACCESS_ONCE_RW(ads->ctl19) = 0;
47316 return;
47317 }
47318
47319- ACCESS_ONCE(ads->ctl11) = (i->pkt_len & AR_FrameLen)
47320+ ACCESS_ONCE_RW(ads->ctl11) = (i->pkt_len & AR_FrameLen)
47321 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
47322 | SM(i->txpower, AR_XmitPower)
47323 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
47324@@ -135,22 +135,22 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
47325 val = (i->flags & ATH9K_TXDESC_PAPRD) >> ATH9K_TXDESC_PAPRD_S;
47326 ctl12 |= SM(val, AR_PAPRDChainMask);
47327
47328- ACCESS_ONCE(ads->ctl12) = ctl12;
47329- ACCESS_ONCE(ads->ctl17) = ctl17;
47330+ ACCESS_ONCE_RW(ads->ctl12) = ctl12;
47331+ ACCESS_ONCE_RW(ads->ctl17) = ctl17;
47332
47333- ACCESS_ONCE(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
47334+ ACCESS_ONCE_RW(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
47335 | set11nPktDurRTSCTS(i->rates, 1);
47336
47337- ACCESS_ONCE(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
47338+ ACCESS_ONCE_RW(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
47339 | set11nPktDurRTSCTS(i->rates, 3);
47340
47341- ACCESS_ONCE(ads->ctl18) = set11nRateFlags(i->rates, 0)
47342+ ACCESS_ONCE_RW(ads->ctl18) = set11nRateFlags(i->rates, 0)
47343 | set11nRateFlags(i->rates, 1)
47344 | set11nRateFlags(i->rates, 2)
47345 | set11nRateFlags(i->rates, 3)
47346 | SM(i->rtscts_rate, AR_RTSCTSRate);
47347
47348- ACCESS_ONCE(ads->ctl19) = AR_Not_Sounding;
47349+ ACCESS_ONCE_RW(ads->ctl19) = AR_Not_Sounding;
47350 }
47351
47352 static u16 ar9003_calc_ptr_chksum(struct ar9003_txc *ads)
47353diff --git a/drivers/net/wireless/ath/ath9k/hw.h b/drivers/net/wireless/ath/ath9k/hw.h
47354index 0acd4b5..0591c91 100644
47355--- a/drivers/net/wireless/ath/ath9k/hw.h
47356+++ b/drivers/net/wireless/ath/ath9k/hw.h
47357@@ -629,7 +629,7 @@ struct ath_hw_private_ops {
47358
47359 /* ANI */
47360 void (*ani_cache_ini_regs)(struct ath_hw *ah);
47361-};
47362+} __no_const;
47363
47364 /**
47365 * struct ath_spec_scan - parameters for Atheros spectral scan
47366@@ -706,7 +706,7 @@ struct ath_hw_ops {
47367 #ifdef CONFIG_ATH9K_BTCOEX_SUPPORT
47368 void (*set_bt_ant_diversity)(struct ath_hw *hw, bool enable);
47369 #endif
47370-};
47371+} __no_const;
47372
47373 struct ath_nf_limits {
47374 s16 max;
47375diff --git a/drivers/net/wireless/b43/phy_lp.c b/drivers/net/wireless/b43/phy_lp.c
47376index 92190da..f3a4c4c 100644
47377--- a/drivers/net/wireless/b43/phy_lp.c
47378+++ b/drivers/net/wireless/b43/phy_lp.c
47379@@ -2514,7 +2514,7 @@ static int lpphy_b2063_tune(struct b43_wldev *dev,
47380 {
47381 struct ssb_bus *bus = dev->dev->sdev->bus;
47382
47383- static const struct b206x_channel *chandata = NULL;
47384+ const struct b206x_channel *chandata = NULL;
47385 u32 crystal_freq = bus->chipco.pmu.crystalfreq * 1000;
47386 u32 freqref, vco_freq, val1, val2, val3, timeout, timeoutref, count;
47387 u16 old_comm15, scale;
47388diff --git a/drivers/net/wireless/iwlegacy/3945-mac.c b/drivers/net/wireless/iwlegacy/3945-mac.c
47389index 0487461..fd9e84a 100644
47390--- a/drivers/net/wireless/iwlegacy/3945-mac.c
47391+++ b/drivers/net/wireless/iwlegacy/3945-mac.c
47392@@ -3638,7 +3638,9 @@ il3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
47393 */
47394 if (il3945_mod_params.disable_hw_scan) {
47395 D_INFO("Disabling hw_scan\n");
47396- il3945_mac_ops.hw_scan = NULL;
47397+ pax_open_kernel();
47398+ *(void **)&il3945_mac_ops.hw_scan = NULL;
47399+ pax_close_kernel();
47400 }
47401
47402 D_INFO("*** LOAD DRIVER ***\n");
47403diff --git a/drivers/net/wireless/iwlwifi/dvm/debugfs.c b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
47404index d2fe259..0c4c682 100644
47405--- a/drivers/net/wireless/iwlwifi/dvm/debugfs.c
47406+++ b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
47407@@ -188,7 +188,7 @@ static ssize_t iwl_dbgfs_sram_write(struct file *file,
47408 {
47409 struct iwl_priv *priv = file->private_data;
47410 char buf[64];
47411- int buf_size;
47412+ size_t buf_size;
47413 u32 offset, len;
47414
47415 memset(buf, 0, sizeof(buf));
47416@@ -458,7 +458,7 @@ static ssize_t iwl_dbgfs_rx_handlers_write(struct file *file,
47417 struct iwl_priv *priv = file->private_data;
47418
47419 char buf[8];
47420- int buf_size;
47421+ size_t buf_size;
47422 u32 reset_flag;
47423
47424 memset(buf, 0, sizeof(buf));
47425@@ -539,7 +539,7 @@ static ssize_t iwl_dbgfs_disable_ht40_write(struct file *file,
47426 {
47427 struct iwl_priv *priv = file->private_data;
47428 char buf[8];
47429- int buf_size;
47430+ size_t buf_size;
47431 int ht40;
47432
47433 memset(buf, 0, sizeof(buf));
47434@@ -591,7 +591,7 @@ static ssize_t iwl_dbgfs_sleep_level_override_write(struct file *file,
47435 {
47436 struct iwl_priv *priv = file->private_data;
47437 char buf[8];
47438- int buf_size;
47439+ size_t buf_size;
47440 int value;
47441
47442 memset(buf, 0, sizeof(buf));
47443@@ -683,10 +683,10 @@ DEBUGFS_READ_FILE_OPS(temperature);
47444 DEBUGFS_READ_WRITE_FILE_OPS(sleep_level_override);
47445 DEBUGFS_READ_FILE_OPS(current_sleep_command);
47446
47447-static const char *fmt_value = " %-30s %10u\n";
47448-static const char *fmt_hex = " %-30s 0x%02X\n";
47449-static const char *fmt_table = " %-30s %10u %10u %10u %10u\n";
47450-static const char *fmt_header =
47451+static const char fmt_value[] = " %-30s %10u\n";
47452+static const char fmt_hex[] = " %-30s 0x%02X\n";
47453+static const char fmt_table[] = " %-30s %10u %10u %10u %10u\n";
47454+static const char fmt_header[] =
47455 "%-32s current cumulative delta max\n";
47456
47457 static int iwl_statistics_flag(struct iwl_priv *priv, char *buf, int bufsz)
47458@@ -1856,7 +1856,7 @@ static ssize_t iwl_dbgfs_clear_ucode_statistics_write(struct file *file,
47459 {
47460 struct iwl_priv *priv = file->private_data;
47461 char buf[8];
47462- int buf_size;
47463+ size_t buf_size;
47464 int clear;
47465
47466 memset(buf, 0, sizeof(buf));
47467@@ -1901,7 +1901,7 @@ static ssize_t iwl_dbgfs_ucode_tracing_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 trace;
47474
47475 memset(buf, 0, sizeof(buf));
47476@@ -1972,7 +1972,7 @@ static ssize_t iwl_dbgfs_missed_beacon_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 missed;
47483
47484 memset(buf, 0, sizeof(buf));
47485@@ -2013,7 +2013,7 @@ static ssize_t iwl_dbgfs_plcp_delta_write(struct file *file,
47486
47487 struct iwl_priv *priv = file->private_data;
47488 char buf[8];
47489- int buf_size;
47490+ size_t buf_size;
47491 int plcp;
47492
47493 memset(buf, 0, sizeof(buf));
47494@@ -2073,7 +2073,7 @@ static ssize_t iwl_dbgfs_txfifo_flush_write(struct file *file,
47495
47496 struct iwl_priv *priv = file->private_data;
47497 char buf[8];
47498- int buf_size;
47499+ size_t buf_size;
47500 int flush;
47501
47502 memset(buf, 0, sizeof(buf));
47503@@ -2163,7 +2163,7 @@ static ssize_t iwl_dbgfs_protection_mode_write(struct file *file,
47504
47505 struct iwl_priv *priv = file->private_data;
47506 char buf[8];
47507- int buf_size;
47508+ size_t buf_size;
47509 int rts;
47510
47511 if (!priv->cfg->ht_params)
47512@@ -2205,7 +2205,7 @@ static ssize_t iwl_dbgfs_echo_test_write(struct file *file,
47513 {
47514 struct iwl_priv *priv = file->private_data;
47515 char buf[8];
47516- int buf_size;
47517+ size_t buf_size;
47518
47519 memset(buf, 0, sizeof(buf));
47520 buf_size = min(count, sizeof(buf) - 1);
47521@@ -2239,7 +2239,7 @@ static ssize_t iwl_dbgfs_log_event_write(struct file *file,
47522 struct iwl_priv *priv = file->private_data;
47523 u32 event_log_flag;
47524 char buf[8];
47525- int buf_size;
47526+ size_t buf_size;
47527
47528 /* check that the interface is up */
47529 if (!iwl_is_ready(priv))
47530@@ -2293,7 +2293,7 @@ static ssize_t iwl_dbgfs_calib_disabled_write(struct file *file,
47531 struct iwl_priv *priv = file->private_data;
47532 char buf[8];
47533 u32 calib_disabled;
47534- int buf_size;
47535+ size_t buf_size;
47536
47537 memset(buf, 0, sizeof(buf));
47538 buf_size = min(count, sizeof(buf) - 1);
47539diff --git a/drivers/net/wireless/iwlwifi/dvm/main.c b/drivers/net/wireless/iwlwifi/dvm/main.c
47540index ea7e70c..bc0c45f 100644
47541--- a/drivers/net/wireless/iwlwifi/dvm/main.c
47542+++ b/drivers/net/wireless/iwlwifi/dvm/main.c
47543@@ -1127,7 +1127,7 @@ static void iwl_option_config(struct iwl_priv *priv)
47544 static int iwl_eeprom_init_hw_params(struct iwl_priv *priv)
47545 {
47546 struct iwl_nvm_data *data = priv->nvm_data;
47547- char *debug_msg;
47548+ static const char debug_msg[] = "Device SKU: 24GHz %s %s, 52GHz %s %s, 11.n %s %s\n";
47549
47550 if (data->sku_cap_11n_enable &&
47551 !priv->cfg->ht_params) {
47552@@ -1141,7 +1141,6 @@ static int iwl_eeprom_init_hw_params(struct iwl_priv *priv)
47553 return -EINVAL;
47554 }
47555
47556- debug_msg = "Device SKU: 24GHz %s %s, 52GHz %s %s, 11.n %s %s\n";
47557 IWL_DEBUG_INFO(priv, debug_msg,
47558 data->sku_cap_band_24GHz_enable ? "" : "NOT", "enabled",
47559 data->sku_cap_band_52GHz_enable ? "" : "NOT", "enabled",
47560diff --git a/drivers/net/wireless/iwlwifi/pcie/trans.c b/drivers/net/wireless/iwlwifi/pcie/trans.c
47561index f950780..be9df93 100644
47562--- a/drivers/net/wireless/iwlwifi/pcie/trans.c
47563+++ b/drivers/net/wireless/iwlwifi/pcie/trans.c
47564@@ -1365,7 +1365,7 @@ static ssize_t iwl_dbgfs_interrupt_write(struct file *file,
47565 struct isr_statistics *isr_stats = &trans_pcie->isr_stats;
47566
47567 char buf[8];
47568- int buf_size;
47569+ size_t buf_size;
47570 u32 reset_flag;
47571
47572 memset(buf, 0, sizeof(buf));
47573@@ -1386,7 +1386,7 @@ static ssize_t iwl_dbgfs_csr_write(struct file *file,
47574 {
47575 struct iwl_trans *trans = file->private_data;
47576 char buf[8];
47577- int buf_size;
47578+ size_t buf_size;
47579 int csr;
47580
47581 memset(buf, 0, sizeof(buf));
47582diff --git a/drivers/net/wireless/mac80211_hwsim.c b/drivers/net/wireless/mac80211_hwsim.c
47583index 69d4c31..bd0b316 100644
47584--- a/drivers/net/wireless/mac80211_hwsim.c
47585+++ b/drivers/net/wireless/mac80211_hwsim.c
47586@@ -2541,20 +2541,20 @@ static int __init init_mac80211_hwsim(void)
47587 if (channels < 1)
47588 return -EINVAL;
47589
47590- mac80211_hwsim_mchan_ops = mac80211_hwsim_ops;
47591- mac80211_hwsim_mchan_ops.hw_scan = mac80211_hwsim_hw_scan;
47592- mac80211_hwsim_mchan_ops.cancel_hw_scan = mac80211_hwsim_cancel_hw_scan;
47593- mac80211_hwsim_mchan_ops.sw_scan_start = NULL;
47594- mac80211_hwsim_mchan_ops.sw_scan_complete = NULL;
47595- mac80211_hwsim_mchan_ops.remain_on_channel = mac80211_hwsim_roc;
47596- mac80211_hwsim_mchan_ops.cancel_remain_on_channel = mac80211_hwsim_croc;
47597- mac80211_hwsim_mchan_ops.add_chanctx = mac80211_hwsim_add_chanctx;
47598- mac80211_hwsim_mchan_ops.remove_chanctx = mac80211_hwsim_remove_chanctx;
47599- mac80211_hwsim_mchan_ops.change_chanctx = mac80211_hwsim_change_chanctx;
47600- mac80211_hwsim_mchan_ops.assign_vif_chanctx =
47601- mac80211_hwsim_assign_vif_chanctx;
47602- mac80211_hwsim_mchan_ops.unassign_vif_chanctx =
47603- mac80211_hwsim_unassign_vif_chanctx;
47604+ pax_open_kernel();
47605+ memcpy((void *)&mac80211_hwsim_mchan_ops, &mac80211_hwsim_ops, sizeof mac80211_hwsim_mchan_ops);
47606+ *(void **)&mac80211_hwsim_mchan_ops.hw_scan = mac80211_hwsim_hw_scan;
47607+ *(void **)&mac80211_hwsim_mchan_ops.cancel_hw_scan = mac80211_hwsim_cancel_hw_scan;
47608+ *(void **)&mac80211_hwsim_mchan_ops.sw_scan_start = NULL;
47609+ *(void **)&mac80211_hwsim_mchan_ops.sw_scan_complete = NULL;
47610+ *(void **)&mac80211_hwsim_mchan_ops.remain_on_channel = mac80211_hwsim_roc;
47611+ *(void **)&mac80211_hwsim_mchan_ops.cancel_remain_on_channel = mac80211_hwsim_croc;
47612+ *(void **)&mac80211_hwsim_mchan_ops.add_chanctx = mac80211_hwsim_add_chanctx;
47613+ *(void **)&mac80211_hwsim_mchan_ops.remove_chanctx = mac80211_hwsim_remove_chanctx;
47614+ *(void **)&mac80211_hwsim_mchan_ops.change_chanctx = mac80211_hwsim_change_chanctx;
47615+ *(void **)&mac80211_hwsim_mchan_ops.assign_vif_chanctx = mac80211_hwsim_assign_vif_chanctx;
47616+ *(void **)&mac80211_hwsim_mchan_ops.unassign_vif_chanctx = mac80211_hwsim_unassign_vif_chanctx;
47617+ pax_close_kernel();
47618
47619 spin_lock_init(&hwsim_radio_lock);
47620 INIT_LIST_HEAD(&hwsim_radios);
47621diff --git a/drivers/net/wireless/rndis_wlan.c b/drivers/net/wireless/rndis_wlan.c
47622index 5028557..91cf394 100644
47623--- a/drivers/net/wireless/rndis_wlan.c
47624+++ b/drivers/net/wireless/rndis_wlan.c
47625@@ -1236,7 +1236,7 @@ static int set_rts_threshold(struct usbnet *usbdev, u32 rts_threshold)
47626
47627 netdev_dbg(usbdev->net, "%s(): %i\n", __func__, rts_threshold);
47628
47629- if (rts_threshold < 0 || rts_threshold > 2347)
47630+ if (rts_threshold > 2347)
47631 rts_threshold = 2347;
47632
47633 tmp = cpu_to_le32(rts_threshold);
47634diff --git a/drivers/net/wireless/rt2x00/rt2x00.h b/drivers/net/wireless/rt2x00/rt2x00.h
47635index e3b885d..7a7de2f 100644
47636--- a/drivers/net/wireless/rt2x00/rt2x00.h
47637+++ b/drivers/net/wireless/rt2x00/rt2x00.h
47638@@ -375,7 +375,7 @@ struct rt2x00_intf {
47639 * for hardware which doesn't support hardware
47640 * sequence counting.
47641 */
47642- atomic_t seqno;
47643+ atomic_unchecked_t seqno;
47644 };
47645
47646 static inline struct rt2x00_intf* vif_to_intf(struct ieee80211_vif *vif)
47647diff --git a/drivers/net/wireless/rt2x00/rt2x00queue.c b/drivers/net/wireless/rt2x00/rt2x00queue.c
47648index 5642ccc..01f03eb 100644
47649--- a/drivers/net/wireless/rt2x00/rt2x00queue.c
47650+++ b/drivers/net/wireless/rt2x00/rt2x00queue.c
47651@@ -250,9 +250,9 @@ static void rt2x00queue_create_tx_descriptor_seq(struct rt2x00_dev *rt2x00dev,
47652 * sequence counter given by mac80211.
47653 */
47654 if (test_bit(ENTRY_TXD_FIRST_FRAGMENT, &txdesc->flags))
47655- seqno = atomic_add_return(0x10, &intf->seqno);
47656+ seqno = atomic_add_return_unchecked(0x10, &intf->seqno);
47657 else
47658- seqno = atomic_read(&intf->seqno);
47659+ seqno = atomic_read_unchecked(&intf->seqno);
47660
47661 hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
47662 hdr->seq_ctrl |= cpu_to_le16(seqno);
47663diff --git a/drivers/net/wireless/ti/wl1251/sdio.c b/drivers/net/wireless/ti/wl1251/sdio.c
47664index e2b3d9c..67a5184 100644
47665--- a/drivers/net/wireless/ti/wl1251/sdio.c
47666+++ b/drivers/net/wireless/ti/wl1251/sdio.c
47667@@ -271,13 +271,17 @@ static int wl1251_sdio_probe(struct sdio_func *func,
47668
47669 irq_set_irq_type(wl->irq, IRQ_TYPE_EDGE_RISING);
47670
47671- wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
47672- wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
47673+ pax_open_kernel();
47674+ *(void **)&wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
47675+ *(void **)&wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
47676+ pax_close_kernel();
47677
47678 wl1251_info("using dedicated interrupt line");
47679 } else {
47680- wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
47681- wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
47682+ pax_open_kernel();
47683+ *(void **)&wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
47684+ *(void **)&wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
47685+ pax_close_kernel();
47686
47687 wl1251_info("using SDIO interrupt");
47688 }
47689diff --git a/drivers/net/wireless/ti/wl12xx/main.c b/drivers/net/wireless/ti/wl12xx/main.c
47690index be7129b..4161356 100644
47691--- a/drivers/net/wireless/ti/wl12xx/main.c
47692+++ b/drivers/net/wireless/ti/wl12xx/main.c
47693@@ -656,7 +656,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
47694 sizeof(wl->conf.mem));
47695
47696 /* read data preparation is only needed by wl127x */
47697- wl->ops->prepare_read = wl127x_prepare_read;
47698+ pax_open_kernel();
47699+ *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
47700+ pax_close_kernel();
47701
47702 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER,
47703 WL127X_IFTYPE_SR_VER, WL127X_MAJOR_SR_VER,
47704@@ -681,7 +683,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
47705 sizeof(wl->conf.mem));
47706
47707 /* read data preparation is only needed by wl127x */
47708- wl->ops->prepare_read = wl127x_prepare_read;
47709+ pax_open_kernel();
47710+ *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
47711+ pax_close_kernel();
47712
47713 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER,
47714 WL127X_IFTYPE_SR_VER, WL127X_MAJOR_SR_VER,
47715diff --git a/drivers/net/wireless/ti/wl18xx/main.c b/drivers/net/wireless/ti/wl18xx/main.c
47716index ec37b16..7e34d66 100644
47717--- a/drivers/net/wireless/ti/wl18xx/main.c
47718+++ b/drivers/net/wireless/ti/wl18xx/main.c
47719@@ -1823,8 +1823,10 @@ static int wl18xx_setup(struct wl1271 *wl)
47720 }
47721
47722 if (!checksum_param) {
47723- wl18xx_ops.set_rx_csum = NULL;
47724- wl18xx_ops.init_vif = NULL;
47725+ pax_open_kernel();
47726+ *(void **)&wl18xx_ops.set_rx_csum = NULL;
47727+ *(void **)&wl18xx_ops.init_vif = NULL;
47728+ pax_close_kernel();
47729 }
47730
47731 /* Enable 11a Band only if we have 5G antennas */
47732diff --git a/drivers/net/wireless/zd1211rw/zd_usb.c b/drivers/net/wireless/zd1211rw/zd_usb.c
47733index a912dc0..a8225ba 100644
47734--- a/drivers/net/wireless/zd1211rw/zd_usb.c
47735+++ b/drivers/net/wireless/zd1211rw/zd_usb.c
47736@@ -385,7 +385,7 @@ static inline void handle_regs_int(struct urb *urb)
47737 {
47738 struct zd_usb *usb = urb->context;
47739 struct zd_usb_interrupt *intr = &usb->intr;
47740- int len;
47741+ unsigned int len;
47742 u16 int_num;
47743
47744 ZD_ASSERT(in_interrupt());
47745diff --git a/drivers/nfc/nfcwilink.c b/drivers/nfc/nfcwilink.c
47746index 683671a..4519fc2 100644
47747--- a/drivers/nfc/nfcwilink.c
47748+++ b/drivers/nfc/nfcwilink.c
47749@@ -497,7 +497,7 @@ static struct nci_ops nfcwilink_ops = {
47750
47751 static int nfcwilink_probe(struct platform_device *pdev)
47752 {
47753- static struct nfcwilink *drv;
47754+ struct nfcwilink *drv;
47755 int rc;
47756 __u32 protocols;
47757
47758diff --git a/drivers/oprofile/buffer_sync.c b/drivers/oprofile/buffer_sync.c
47759index d93b2b6..ae50401 100644
47760--- a/drivers/oprofile/buffer_sync.c
47761+++ b/drivers/oprofile/buffer_sync.c
47762@@ -332,7 +332,7 @@ static void add_data(struct op_entry *entry, struct mm_struct *mm)
47763 if (cookie == NO_COOKIE)
47764 offset = pc;
47765 if (cookie == INVALID_COOKIE) {
47766- atomic_inc(&oprofile_stats.sample_lost_no_mapping);
47767+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
47768 offset = pc;
47769 }
47770 if (cookie != last_cookie) {
47771@@ -376,14 +376,14 @@ add_sample(struct mm_struct *mm, struct op_sample *s, int in_kernel)
47772 /* add userspace sample */
47773
47774 if (!mm) {
47775- atomic_inc(&oprofile_stats.sample_lost_no_mm);
47776+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mm);
47777 return 0;
47778 }
47779
47780 cookie = lookup_dcookie(mm, s->eip, &offset);
47781
47782 if (cookie == INVALID_COOKIE) {
47783- atomic_inc(&oprofile_stats.sample_lost_no_mapping);
47784+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
47785 return 0;
47786 }
47787
47788@@ -552,7 +552,7 @@ void sync_buffer(int cpu)
47789 /* ignore backtraces if failed to add a sample */
47790 if (state == sb_bt_start) {
47791 state = sb_bt_ignore;
47792- atomic_inc(&oprofile_stats.bt_lost_no_mapping);
47793+ atomic_inc_unchecked(&oprofile_stats.bt_lost_no_mapping);
47794 }
47795 }
47796 release_mm(mm);
47797diff --git a/drivers/oprofile/event_buffer.c b/drivers/oprofile/event_buffer.c
47798index c0cc4e7..44d4e54 100644
47799--- a/drivers/oprofile/event_buffer.c
47800+++ b/drivers/oprofile/event_buffer.c
47801@@ -53,7 +53,7 @@ void add_event_entry(unsigned long value)
47802 }
47803
47804 if (buffer_pos == buffer_size) {
47805- atomic_inc(&oprofile_stats.event_lost_overflow);
47806+ atomic_inc_unchecked(&oprofile_stats.event_lost_overflow);
47807 return;
47808 }
47809
47810diff --git a/drivers/oprofile/oprof.c b/drivers/oprofile/oprof.c
47811index ed2c3ec..deda85a 100644
47812--- a/drivers/oprofile/oprof.c
47813+++ b/drivers/oprofile/oprof.c
47814@@ -110,7 +110,7 @@ static void switch_worker(struct work_struct *work)
47815 if (oprofile_ops.switch_events())
47816 return;
47817
47818- atomic_inc(&oprofile_stats.multiplex_counter);
47819+ atomic_inc_unchecked(&oprofile_stats.multiplex_counter);
47820 start_switch_worker();
47821 }
47822
47823diff --git a/drivers/oprofile/oprofile_files.c b/drivers/oprofile/oprofile_files.c
47824index ee2cfce..7f8f699 100644
47825--- a/drivers/oprofile/oprofile_files.c
47826+++ b/drivers/oprofile/oprofile_files.c
47827@@ -27,7 +27,7 @@ unsigned long oprofile_time_slice;
47828
47829 #ifdef CONFIG_OPROFILE_EVENT_MULTIPLEX
47830
47831-static ssize_t timeout_read(struct file *file, char __user *buf,
47832+static ssize_t __intentional_overflow(-1) timeout_read(struct file *file, char __user *buf,
47833 size_t count, loff_t *offset)
47834 {
47835 return oprofilefs_ulong_to_user(jiffies_to_msecs(oprofile_time_slice),
47836diff --git a/drivers/oprofile/oprofile_stats.c b/drivers/oprofile/oprofile_stats.c
47837index 59659ce..6c860a0 100644
47838--- a/drivers/oprofile/oprofile_stats.c
47839+++ b/drivers/oprofile/oprofile_stats.c
47840@@ -30,11 +30,11 @@ void oprofile_reset_stats(void)
47841 cpu_buf->sample_invalid_eip = 0;
47842 }
47843
47844- atomic_set(&oprofile_stats.sample_lost_no_mm, 0);
47845- atomic_set(&oprofile_stats.sample_lost_no_mapping, 0);
47846- atomic_set(&oprofile_stats.event_lost_overflow, 0);
47847- atomic_set(&oprofile_stats.bt_lost_no_mapping, 0);
47848- atomic_set(&oprofile_stats.multiplex_counter, 0);
47849+ atomic_set_unchecked(&oprofile_stats.sample_lost_no_mm, 0);
47850+ atomic_set_unchecked(&oprofile_stats.sample_lost_no_mapping, 0);
47851+ atomic_set_unchecked(&oprofile_stats.event_lost_overflow, 0);
47852+ atomic_set_unchecked(&oprofile_stats.bt_lost_no_mapping, 0);
47853+ atomic_set_unchecked(&oprofile_stats.multiplex_counter, 0);
47854 }
47855
47856
47857diff --git a/drivers/oprofile/oprofile_stats.h b/drivers/oprofile/oprofile_stats.h
47858index 1fc622b..8c48fc3 100644
47859--- a/drivers/oprofile/oprofile_stats.h
47860+++ b/drivers/oprofile/oprofile_stats.h
47861@@ -13,11 +13,11 @@
47862 #include <linux/atomic.h>
47863
47864 struct oprofile_stat_struct {
47865- atomic_t sample_lost_no_mm;
47866- atomic_t sample_lost_no_mapping;
47867- atomic_t bt_lost_no_mapping;
47868- atomic_t event_lost_overflow;
47869- atomic_t multiplex_counter;
47870+ atomic_unchecked_t sample_lost_no_mm;
47871+ atomic_unchecked_t sample_lost_no_mapping;
47872+ atomic_unchecked_t bt_lost_no_mapping;
47873+ atomic_unchecked_t event_lost_overflow;
47874+ atomic_unchecked_t multiplex_counter;
47875 };
47876
47877 extern struct oprofile_stat_struct oprofile_stats;
47878diff --git a/drivers/oprofile/oprofilefs.c b/drivers/oprofile/oprofilefs.c
47879index 3f49345..c750d0b 100644
47880--- a/drivers/oprofile/oprofilefs.c
47881+++ b/drivers/oprofile/oprofilefs.c
47882@@ -176,8 +176,8 @@ int oprofilefs_create_ro_ulong(struct dentry *root,
47883
47884 static ssize_t atomic_read_file(struct file *file, char __user *buf, size_t count, loff_t *offset)
47885 {
47886- atomic_t *val = file->private_data;
47887- return oprofilefs_ulong_to_user(atomic_read(val), buf, count, offset);
47888+ atomic_unchecked_t *val = file->private_data;
47889+ return oprofilefs_ulong_to_user(atomic_read_unchecked(val), buf, count, offset);
47890 }
47891
47892
47893@@ -189,7 +189,7 @@ static const struct file_operations atomic_ro_fops = {
47894
47895
47896 int oprofilefs_create_ro_atomic(struct dentry *root,
47897- char const *name, atomic_t *val)
47898+ char const *name, atomic_unchecked_t *val)
47899 {
47900 return __oprofilefs_create_file(root, name,
47901 &atomic_ro_fops, 0444, val);
47902diff --git a/drivers/oprofile/timer_int.c b/drivers/oprofile/timer_int.c
47903index 61be1d9..dec05d7 100644
47904--- a/drivers/oprofile/timer_int.c
47905+++ b/drivers/oprofile/timer_int.c
47906@@ -93,7 +93,7 @@ static int oprofile_cpu_notify(struct notifier_block *self,
47907 return NOTIFY_OK;
47908 }
47909
47910-static struct notifier_block __refdata oprofile_cpu_notifier = {
47911+static struct notifier_block oprofile_cpu_notifier = {
47912 .notifier_call = oprofile_cpu_notify,
47913 };
47914
47915diff --git a/drivers/parport/procfs.c b/drivers/parport/procfs.c
47916index 92ed045..62d39bd7 100644
47917--- a/drivers/parport/procfs.c
47918+++ b/drivers/parport/procfs.c
47919@@ -64,7 +64,7 @@ static int do_active_device(ctl_table *table, int write,
47920
47921 *ppos += len;
47922
47923- return copy_to_user(result, buffer, len) ? -EFAULT : 0;
47924+ return (len > sizeof buffer || copy_to_user(result, buffer, len)) ? -EFAULT : 0;
47925 }
47926
47927 #ifdef CONFIG_PARPORT_1284
47928@@ -106,7 +106,7 @@ static int do_autoprobe(ctl_table *table, int write,
47929
47930 *ppos += len;
47931
47932- return copy_to_user (result, buffer, len) ? -EFAULT : 0;
47933+ return (len > sizeof buffer || copy_to_user (result, buffer, len)) ? -EFAULT : 0;
47934 }
47935 #endif /* IEEE1284.3 support. */
47936
47937diff --git a/drivers/pci/hotplug/acpiphp_ibm.c b/drivers/pci/hotplug/acpiphp_ibm.c
47938index 8dcccff..35d701d 100644
47939--- a/drivers/pci/hotplug/acpiphp_ibm.c
47940+++ b/drivers/pci/hotplug/acpiphp_ibm.c
47941@@ -452,7 +452,9 @@ static int __init ibm_acpiphp_init(void)
47942 goto init_cleanup;
47943 }
47944
47945- ibm_apci_table_attr.size = ibm_get_table_from_acpi(NULL);
47946+ pax_open_kernel();
47947+ *(size_t *)&ibm_apci_table_attr.size = ibm_get_table_from_acpi(NULL);
47948+ pax_close_kernel();
47949 retval = sysfs_create_bin_file(sysdir, &ibm_apci_table_attr);
47950
47951 return retval;
47952diff --git a/drivers/pci/hotplug/cpcihp_generic.c b/drivers/pci/hotplug/cpcihp_generic.c
47953index 7536eef..52dc8fa 100644
47954--- a/drivers/pci/hotplug/cpcihp_generic.c
47955+++ b/drivers/pci/hotplug/cpcihp_generic.c
47956@@ -73,7 +73,6 @@ static u16 port;
47957 static unsigned int enum_bit;
47958 static u8 enum_mask;
47959
47960-static struct cpci_hp_controller_ops generic_hpc_ops;
47961 static struct cpci_hp_controller generic_hpc;
47962
47963 static int __init validate_parameters(void)
47964@@ -139,6 +138,10 @@ static int query_enum(void)
47965 return ((value & enum_mask) == enum_mask);
47966 }
47967
47968+static struct cpci_hp_controller_ops generic_hpc_ops = {
47969+ .query_enum = query_enum,
47970+};
47971+
47972 static int __init cpcihp_generic_init(void)
47973 {
47974 int status;
47975@@ -165,7 +168,6 @@ static int __init cpcihp_generic_init(void)
47976 pci_dev_put(dev);
47977
47978 memset(&generic_hpc, 0, sizeof (struct cpci_hp_controller));
47979- generic_hpc_ops.query_enum = query_enum;
47980 generic_hpc.ops = &generic_hpc_ops;
47981
47982 status = cpci_hp_register_controller(&generic_hpc);
47983diff --git a/drivers/pci/hotplug/cpcihp_zt5550.c b/drivers/pci/hotplug/cpcihp_zt5550.c
47984index e8c4a7c..7046f5c 100644
47985--- a/drivers/pci/hotplug/cpcihp_zt5550.c
47986+++ b/drivers/pci/hotplug/cpcihp_zt5550.c
47987@@ -59,7 +59,6 @@
47988 /* local variables */
47989 static bool debug;
47990 static bool poll;
47991-static struct cpci_hp_controller_ops zt5550_hpc_ops;
47992 static struct cpci_hp_controller zt5550_hpc;
47993
47994 /* Primary cPCI bus bridge device */
47995@@ -205,6 +204,10 @@ static int zt5550_hc_disable_irq(void)
47996 return 0;
47997 }
47998
47999+static struct cpci_hp_controller_ops zt5550_hpc_ops = {
48000+ .query_enum = zt5550_hc_query_enum,
48001+};
48002+
48003 static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
48004 {
48005 int status;
48006@@ -216,16 +219,17 @@ static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id
48007 dbg("returned from zt5550_hc_config");
48008
48009 memset(&zt5550_hpc, 0, sizeof (struct cpci_hp_controller));
48010- zt5550_hpc_ops.query_enum = zt5550_hc_query_enum;
48011 zt5550_hpc.ops = &zt5550_hpc_ops;
48012 if(!poll) {
48013 zt5550_hpc.irq = hc_dev->irq;
48014 zt5550_hpc.irq_flags = IRQF_SHARED;
48015 zt5550_hpc.dev_id = hc_dev;
48016
48017- zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
48018- zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
48019- zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
48020+ pax_open_kernel();
48021+ *(void **)&zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
48022+ *(void **)&zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
48023+ *(void **)&zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
48024+ pax_open_kernel();
48025 } else {
48026 info("using ENUM# polling mode");
48027 }
48028diff --git a/drivers/pci/hotplug/cpqphp_nvram.c b/drivers/pci/hotplug/cpqphp_nvram.c
48029index 76ba8a1..20ca857 100644
48030--- a/drivers/pci/hotplug/cpqphp_nvram.c
48031+++ b/drivers/pci/hotplug/cpqphp_nvram.c
48032@@ -428,9 +428,13 @@ static u32 store_HRT (void __iomem *rom_start)
48033
48034 void compaq_nvram_init (void __iomem *rom_start)
48035 {
48036+
48037+#ifndef CONFIG_PAX_KERNEXEC
48038 if (rom_start) {
48039 compaq_int15_entry_point = (rom_start + ROM_INT15_PHY_ADDR - ROM_PHY_ADDR);
48040 }
48041+#endif
48042+
48043 dbg("int15 entry = %p\n", compaq_int15_entry_point);
48044
48045 /* initialize our int15 lock */
48046diff --git a/drivers/pci/hotplug/pci_hotplug_core.c b/drivers/pci/hotplug/pci_hotplug_core.c
48047index cfa92a9..29539c5 100644
48048--- a/drivers/pci/hotplug/pci_hotplug_core.c
48049+++ b/drivers/pci/hotplug/pci_hotplug_core.c
48050@@ -441,8 +441,10 @@ int __pci_hp_register(struct hotplug_slot *slot, struct pci_bus *bus,
48051 return -EINVAL;
48052 }
48053
48054- slot->ops->owner = owner;
48055- slot->ops->mod_name = mod_name;
48056+ pax_open_kernel();
48057+ *(struct module **)&slot->ops->owner = owner;
48058+ *(const char **)&slot->ops->mod_name = mod_name;
48059+ pax_close_kernel();
48060
48061 mutex_lock(&pci_hp_mutex);
48062 /*
48063diff --git a/drivers/pci/hotplug/pciehp_core.c b/drivers/pci/hotplug/pciehp_core.c
48064index 53b58de..4479896 100644
48065--- a/drivers/pci/hotplug/pciehp_core.c
48066+++ b/drivers/pci/hotplug/pciehp_core.c
48067@@ -92,7 +92,7 @@ static int init_slot(struct controller *ctrl)
48068 struct slot *slot = ctrl->slot;
48069 struct hotplug_slot *hotplug = NULL;
48070 struct hotplug_slot_info *info = NULL;
48071- struct hotplug_slot_ops *ops = NULL;
48072+ hotplug_slot_ops_no_const *ops = NULL;
48073 char name[SLOT_NAME_SIZE];
48074 int retval = -ENOMEM;
48075
48076diff --git a/drivers/pci/msi.c b/drivers/pci/msi.c
48077index 955ab79..d1df9c7 100644
48078--- a/drivers/pci/msi.c
48079+++ b/drivers/pci/msi.c
48080@@ -524,8 +524,8 @@ static int populate_msi_sysfs(struct pci_dev *pdev)
48081 {
48082 struct attribute **msi_attrs;
48083 struct attribute *msi_attr;
48084- struct device_attribute *msi_dev_attr;
48085- struct attribute_group *msi_irq_group;
48086+ device_attribute_no_const *msi_dev_attr;
48087+ attribute_group_no_const *msi_irq_group;
48088 const struct attribute_group **msi_irq_groups;
48089 struct msi_desc *entry;
48090 int ret = -ENOMEM;
48091@@ -589,7 +589,7 @@ error_attrs:
48092 count = 0;
48093 msi_attr = msi_attrs[count];
48094 while (msi_attr) {
48095- msi_dev_attr = container_of(msi_attr, struct device_attribute, attr);
48096+ msi_dev_attr = container_of(msi_attr, device_attribute_no_const, attr);
48097 kfree(msi_attr->name);
48098 kfree(msi_dev_attr);
48099 ++count;
48100diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c
48101index 276ef9c..1d33a36 100644
48102--- a/drivers/pci/pci-sysfs.c
48103+++ b/drivers/pci/pci-sysfs.c
48104@@ -1112,7 +1112,7 @@ static int pci_create_attr(struct pci_dev *pdev, int num, int write_combine)
48105 {
48106 /* allocate attribute structure, piggyback attribute name */
48107 int name_len = write_combine ? 13 : 10;
48108- struct bin_attribute *res_attr;
48109+ bin_attribute_no_const *res_attr;
48110 int retval;
48111
48112 res_attr = kzalloc(sizeof(*res_attr) + name_len, GFP_ATOMIC);
48113@@ -1297,7 +1297,7 @@ static struct device_attribute reset_attr = __ATTR(reset, 0200, NULL, reset_stor
48114 static int pci_create_capabilities_sysfs(struct pci_dev *dev)
48115 {
48116 int retval;
48117- struct bin_attribute *attr;
48118+ bin_attribute_no_const *attr;
48119
48120 /* If the device has VPD, try to expose it in sysfs. */
48121 if (dev->vpd) {
48122@@ -1344,7 +1344,7 @@ int __must_check pci_create_sysfs_dev_files (struct pci_dev *pdev)
48123 {
48124 int retval;
48125 int rom_size = 0;
48126- struct bin_attribute *attr;
48127+ bin_attribute_no_const *attr;
48128
48129 if (!sysfs_initialized)
48130 return -EACCES;
48131diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h
48132index 4df38df..b6bb7fe 100644
48133--- a/drivers/pci/pci.h
48134+++ b/drivers/pci/pci.h
48135@@ -93,7 +93,7 @@ struct pci_vpd_ops {
48136 struct pci_vpd {
48137 unsigned int len;
48138 const struct pci_vpd_ops *ops;
48139- struct bin_attribute *attr; /* descriptor for sysfs VPD entry */
48140+ bin_attribute_no_const *attr; /* descriptor for sysfs VPD entry */
48141 };
48142
48143 int pci_vpd_pci22_init(struct pci_dev *dev);
48144diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
48145index e1e7026..d28dd33 100644
48146--- a/drivers/pci/pcie/aspm.c
48147+++ b/drivers/pci/pcie/aspm.c
48148@@ -27,9 +27,9 @@
48149 #define MODULE_PARAM_PREFIX "pcie_aspm."
48150
48151 /* Note: those are not register definitions */
48152-#define ASPM_STATE_L0S_UP (1) /* Upstream direction L0s state */
48153-#define ASPM_STATE_L0S_DW (2) /* Downstream direction L0s state */
48154-#define ASPM_STATE_L1 (4) /* L1 state */
48155+#define ASPM_STATE_L0S_UP (1U) /* Upstream direction L0s state */
48156+#define ASPM_STATE_L0S_DW (2U) /* Downstream direction L0s state */
48157+#define ASPM_STATE_L1 (4U) /* L1 state */
48158 #define ASPM_STATE_L0S (ASPM_STATE_L0S_UP | ASPM_STATE_L0S_DW)
48159 #define ASPM_STATE_ALL (ASPM_STATE_L0S | ASPM_STATE_L1)
48160
48161diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
48162index 6e34498..9911975 100644
48163--- a/drivers/pci/probe.c
48164+++ b/drivers/pci/probe.c
48165@@ -175,7 +175,7 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
48166 struct pci_bus_region region, inverted_region;
48167 bool bar_too_big = false, bar_disabled = false;
48168
48169- mask = type ? PCI_ROM_ADDRESS_MASK : ~0;
48170+ mask = type ? (u32)PCI_ROM_ADDRESS_MASK : ~0;
48171
48172 /* No printks while decoding is disabled! */
48173 if (!dev->mmio_always_on) {
48174diff --git a/drivers/pci/proc.c b/drivers/pci/proc.c
48175index 46d1378..30e452b 100644
48176--- a/drivers/pci/proc.c
48177+++ b/drivers/pci/proc.c
48178@@ -434,7 +434,16 @@ static const struct file_operations proc_bus_pci_dev_operations = {
48179 static int __init pci_proc_init(void)
48180 {
48181 struct pci_dev *dev = NULL;
48182+
48183+#ifdef CONFIG_GRKERNSEC_PROC_ADD
48184+#ifdef CONFIG_GRKERNSEC_PROC_USER
48185+ proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR, NULL);
48186+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
48187+ proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
48188+#endif
48189+#else
48190 proc_bus_pci_dir = proc_mkdir("bus/pci", NULL);
48191+#endif
48192 proc_create("devices", 0, proc_bus_pci_dir,
48193 &proc_bus_pci_dev_operations);
48194 proc_initialized = 1;
48195diff --git a/drivers/platform/chrome/chromeos_laptop.c b/drivers/platform/chrome/chromeos_laptop.c
48196index 7f3aad0..7d604bb 100644
48197--- a/drivers/platform/chrome/chromeos_laptop.c
48198+++ b/drivers/platform/chrome/chromeos_laptop.c
48199@@ -406,7 +406,7 @@ static struct chromeos_laptop cr48 = {
48200 .callback = chromeos_laptop_dmi_matched, \
48201 .driver_data = (void *)&board_
48202
48203-static struct dmi_system_id chromeos_laptop_dmi_table[] __initdata = {
48204+static struct dmi_system_id chromeos_laptop_dmi_table[] __initconst = {
48205 {
48206 .ident = "Samsung Series 5 550",
48207 .matches = {
48208diff --git a/drivers/platform/x86/asus-wmi.c b/drivers/platform/x86/asus-wmi.c
48209index c5e082f..d6307a0 100644
48210--- a/drivers/platform/x86/asus-wmi.c
48211+++ b/drivers/platform/x86/asus-wmi.c
48212@@ -1595,6 +1595,10 @@ static int show_dsts(struct seq_file *m, void *data)
48213 int err;
48214 u32 retval = -1;
48215
48216+#ifdef CONFIG_GRKERNSEC_KMEM
48217+ return -EPERM;
48218+#endif
48219+
48220 err = asus_wmi_get_devstate(asus, asus->debug.dev_id, &retval);
48221
48222 if (err < 0)
48223@@ -1611,6 +1615,10 @@ static int show_devs(struct seq_file *m, void *data)
48224 int err;
48225 u32 retval = -1;
48226
48227+#ifdef CONFIG_GRKERNSEC_KMEM
48228+ return -EPERM;
48229+#endif
48230+
48231 err = asus_wmi_set_devstate(asus->debug.dev_id, asus->debug.ctrl_param,
48232 &retval);
48233
48234@@ -1635,6 +1643,10 @@ static int show_call(struct seq_file *m, void *data)
48235 union acpi_object *obj;
48236 acpi_status status;
48237
48238+#ifdef CONFIG_GRKERNSEC_KMEM
48239+ return -EPERM;
48240+#endif
48241+
48242 status = wmi_evaluate_method(ASUS_WMI_MGMT_GUID,
48243 1, asus->debug.method_id,
48244 &input, &output);
48245diff --git a/drivers/platform/x86/msi-laptop.c b/drivers/platform/x86/msi-laptop.c
48246index 62f8030..c7f2a45 100644
48247--- a/drivers/platform/x86/msi-laptop.c
48248+++ b/drivers/platform/x86/msi-laptop.c
48249@@ -1000,12 +1000,14 @@ static int __init load_scm_model_init(struct platform_device *sdev)
48250
48251 if (!quirks->ec_read_only) {
48252 /* allow userland write sysfs file */
48253- dev_attr_bluetooth.store = store_bluetooth;
48254- dev_attr_wlan.store = store_wlan;
48255- dev_attr_threeg.store = store_threeg;
48256- dev_attr_bluetooth.attr.mode |= S_IWUSR;
48257- dev_attr_wlan.attr.mode |= S_IWUSR;
48258- dev_attr_threeg.attr.mode |= S_IWUSR;
48259+ pax_open_kernel();
48260+ *(void **)&dev_attr_bluetooth.store = store_bluetooth;
48261+ *(void **)&dev_attr_wlan.store = store_wlan;
48262+ *(void **)&dev_attr_threeg.store = store_threeg;
48263+ *(umode_t *)&dev_attr_bluetooth.attr.mode |= S_IWUSR;
48264+ *(umode_t *)&dev_attr_wlan.attr.mode |= S_IWUSR;
48265+ *(umode_t *)&dev_attr_threeg.attr.mode |= S_IWUSR;
48266+ pax_close_kernel();
48267 }
48268
48269 /* disable hardware control by fn key */
48270diff --git a/drivers/platform/x86/msi-wmi.c b/drivers/platform/x86/msi-wmi.c
48271index 70222f2..8c8ce66 100644
48272--- a/drivers/platform/x86/msi-wmi.c
48273+++ b/drivers/platform/x86/msi-wmi.c
48274@@ -183,7 +183,7 @@ static const struct backlight_ops msi_backlight_ops = {
48275 static void msi_wmi_notify(u32 value, void *context)
48276 {
48277 struct acpi_buffer response = { ACPI_ALLOCATE_BUFFER, NULL };
48278- static struct key_entry *key;
48279+ struct key_entry *key;
48280 union acpi_object *obj;
48281 acpi_status status;
48282
48283diff --git a/drivers/platform/x86/sony-laptop.c b/drivers/platform/x86/sony-laptop.c
48284index 8f8551a..3ace3ca 100644
48285--- a/drivers/platform/x86/sony-laptop.c
48286+++ b/drivers/platform/x86/sony-laptop.c
48287@@ -2451,7 +2451,7 @@ static void sony_nc_gfx_switch_cleanup(struct platform_device *pd)
48288 }
48289
48290 /* High speed charging function */
48291-static struct device_attribute *hsc_handle;
48292+static device_attribute_no_const *hsc_handle;
48293
48294 static ssize_t sony_nc_highspeed_charging_store(struct device *dev,
48295 struct device_attribute *attr,
48296diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
48297index e2a91c8..986cc9f 100644
48298--- a/drivers/platform/x86/thinkpad_acpi.c
48299+++ b/drivers/platform/x86/thinkpad_acpi.c
48300@@ -2094,7 +2094,7 @@ static int hotkey_mask_get(void)
48301 return 0;
48302 }
48303
48304-void static hotkey_mask_warn_incomplete_mask(void)
48305+static void hotkey_mask_warn_incomplete_mask(void)
48306 {
48307 /* log only what the user can fix... */
48308 const u32 wantedmask = hotkey_driver_mask &
48309@@ -2321,11 +2321,6 @@ static void hotkey_read_nvram(struct tp_nvram_state *n, const u32 m)
48310 }
48311 }
48312
48313-static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
48314- struct tp_nvram_state *newn,
48315- const u32 event_mask)
48316-{
48317-
48318 #define TPACPI_COMPARE_KEY(__scancode, __member) \
48319 do { \
48320 if ((event_mask & (1 << __scancode)) && \
48321@@ -2339,36 +2334,42 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
48322 tpacpi_hotkey_send_key(__scancode); \
48323 } while (0)
48324
48325- void issue_volchange(const unsigned int oldvol,
48326- const unsigned int newvol)
48327- {
48328- unsigned int i = oldvol;
48329+static void issue_volchange(const unsigned int oldvol,
48330+ const unsigned int newvol,
48331+ const u32 event_mask)
48332+{
48333+ unsigned int i = oldvol;
48334
48335- while (i > newvol) {
48336- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
48337- i--;
48338- }
48339- while (i < newvol) {
48340- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
48341- i++;
48342- }
48343+ while (i > newvol) {
48344+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
48345+ i--;
48346 }
48347+ while (i < newvol) {
48348+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
48349+ i++;
48350+ }
48351+}
48352
48353- void issue_brightnesschange(const unsigned int oldbrt,
48354- const unsigned int newbrt)
48355- {
48356- unsigned int i = oldbrt;
48357+static void issue_brightnesschange(const unsigned int oldbrt,
48358+ const unsigned int newbrt,
48359+ const u32 event_mask)
48360+{
48361+ unsigned int i = oldbrt;
48362
48363- while (i > newbrt) {
48364- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
48365- i--;
48366- }
48367- while (i < newbrt) {
48368- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
48369- i++;
48370- }
48371+ while (i > newbrt) {
48372+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
48373+ i--;
48374+ }
48375+ while (i < newbrt) {
48376+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
48377+ i++;
48378 }
48379+}
48380
48381+static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
48382+ struct tp_nvram_state *newn,
48383+ const u32 event_mask)
48384+{
48385 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_THINKPAD, thinkpad_toggle);
48386 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNSPACE, zoom_toggle);
48387 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF7, display_toggle);
48388@@ -2402,7 +2403,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
48389 oldn->volume_level != newn->volume_level) {
48390 /* recently muted, or repeated mute keypress, or
48391 * multiple presses ending in mute */
48392- issue_volchange(oldn->volume_level, newn->volume_level);
48393+ issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
48394 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE);
48395 }
48396 } else {
48397@@ -2412,7 +2413,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
48398 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
48399 }
48400 if (oldn->volume_level != newn->volume_level) {
48401- issue_volchange(oldn->volume_level, newn->volume_level);
48402+ issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
48403 } else if (oldn->volume_toggle != newn->volume_toggle) {
48404 /* repeated vol up/down keypress at end of scale ? */
48405 if (newn->volume_level == 0)
48406@@ -2425,7 +2426,8 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
48407 /* handle brightness */
48408 if (oldn->brightness_level != newn->brightness_level) {
48409 issue_brightnesschange(oldn->brightness_level,
48410- newn->brightness_level);
48411+ newn->brightness_level,
48412+ event_mask);
48413 } else if (oldn->brightness_toggle != newn->brightness_toggle) {
48414 /* repeated key presses that didn't change state */
48415 if (newn->brightness_level == 0)
48416@@ -2434,10 +2436,10 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
48417 && !tp_features.bright_unkfw)
48418 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
48419 }
48420+}
48421
48422 #undef TPACPI_COMPARE_KEY
48423 #undef TPACPI_MAY_SEND_KEY
48424-}
48425
48426 /*
48427 * Polling driver
48428diff --git a/drivers/pnp/pnpbios/bioscalls.c b/drivers/pnp/pnpbios/bioscalls.c
48429index 769d265..a3a05ca 100644
48430--- a/drivers/pnp/pnpbios/bioscalls.c
48431+++ b/drivers/pnp/pnpbios/bioscalls.c
48432@@ -58,7 +58,7 @@ do { \
48433 set_desc_limit(&gdt[(selname) >> 3], (size) - 1); \
48434 } while(0)
48435
48436-static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
48437+static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
48438 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
48439
48440 /*
48441@@ -95,7 +95,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
48442
48443 cpu = get_cpu();
48444 save_desc_40 = get_cpu_gdt_table(cpu)[0x40 / 8];
48445+
48446+ pax_open_kernel();
48447 get_cpu_gdt_table(cpu)[0x40 / 8] = bad_bios_desc;
48448+ pax_close_kernel();
48449
48450 /* On some boxes IRQ's during PnP BIOS calls are deadly. */
48451 spin_lock_irqsave(&pnp_bios_lock, flags);
48452@@ -133,7 +136,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
48453 :"memory");
48454 spin_unlock_irqrestore(&pnp_bios_lock, flags);
48455
48456+ pax_open_kernel();
48457 get_cpu_gdt_table(cpu)[0x40 / 8] = save_desc_40;
48458+ pax_close_kernel();
48459+
48460 put_cpu();
48461
48462 /* If we get here and this is set then the PnP BIOS faulted on us. */
48463@@ -467,7 +473,7 @@ int pnp_bios_read_escd(char *data, u32 nvram_base)
48464 return status;
48465 }
48466
48467-void pnpbios_calls_init(union pnp_bios_install_struct *header)
48468+void __init pnpbios_calls_init(union pnp_bios_install_struct *header)
48469 {
48470 int i;
48471
48472@@ -475,6 +481,8 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
48473 pnp_bios_callpoint.offset = header->fields.pm16offset;
48474 pnp_bios_callpoint.segment = PNP_CS16;
48475
48476+ pax_open_kernel();
48477+
48478 for_each_possible_cpu(i) {
48479 struct desc_struct *gdt = get_cpu_gdt_table(i);
48480 if (!gdt)
48481@@ -486,4 +494,6 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
48482 set_desc_base(&gdt[GDT_ENTRY_PNPBIOS_DS],
48483 (unsigned long)__va(header->fields.pm16dseg));
48484 }
48485+
48486+ pax_close_kernel();
48487 }
48488diff --git a/drivers/pnp/resource.c b/drivers/pnp/resource.c
48489index bacddd1..65ea100 100644
48490--- a/drivers/pnp/resource.c
48491+++ b/drivers/pnp/resource.c
48492@@ -360,7 +360,7 @@ int pnp_check_irq(struct pnp_dev *dev, struct resource *res)
48493 return 1;
48494
48495 /* check if the resource is valid */
48496- if (*irq < 0 || *irq > 15)
48497+ if (*irq > 15)
48498 return 0;
48499
48500 /* check if the resource is reserved */
48501@@ -424,7 +424,7 @@ int pnp_check_dma(struct pnp_dev *dev, struct resource *res)
48502 return 1;
48503
48504 /* check if the resource is valid */
48505- if (*dma < 0 || *dma == 4 || *dma > 7)
48506+ if (*dma == 4 || *dma > 7)
48507 return 0;
48508
48509 /* check if the resource is reserved */
48510diff --git a/drivers/power/pda_power.c b/drivers/power/pda_power.c
48511index 0c52e2a..3421ab7 100644
48512--- a/drivers/power/pda_power.c
48513+++ b/drivers/power/pda_power.c
48514@@ -37,7 +37,11 @@ static int polling;
48515
48516 #if IS_ENABLED(CONFIG_USB_PHY)
48517 static struct usb_phy *transceiver;
48518-static struct notifier_block otg_nb;
48519+static int otg_handle_notification(struct notifier_block *nb,
48520+ unsigned long event, void *unused);
48521+static struct notifier_block otg_nb = {
48522+ .notifier_call = otg_handle_notification
48523+};
48524 #endif
48525
48526 static struct regulator *ac_draw;
48527@@ -369,7 +373,6 @@ static int pda_power_probe(struct platform_device *pdev)
48528
48529 #if IS_ENABLED(CONFIG_USB_PHY)
48530 if (!IS_ERR_OR_NULL(transceiver) && pdata->use_otg_notifier) {
48531- otg_nb.notifier_call = otg_handle_notification;
48532 ret = usb_register_notifier(transceiver, &otg_nb);
48533 if (ret) {
48534 dev_err(dev, "failure to register otg notifier\n");
48535diff --git a/drivers/power/power_supply.h b/drivers/power/power_supply.h
48536index cc439fd..8fa30df 100644
48537--- a/drivers/power/power_supply.h
48538+++ b/drivers/power/power_supply.h
48539@@ -16,12 +16,12 @@ struct power_supply;
48540
48541 #ifdef CONFIG_SYSFS
48542
48543-extern void power_supply_init_attrs(struct device_type *dev_type);
48544+extern void power_supply_init_attrs(void);
48545 extern int power_supply_uevent(struct device *dev, struct kobj_uevent_env *env);
48546
48547 #else
48548
48549-static inline void power_supply_init_attrs(struct device_type *dev_type) {}
48550+static inline void power_supply_init_attrs(void) {}
48551 #define power_supply_uevent NULL
48552
48553 #endif /* CONFIG_SYSFS */
48554diff --git a/drivers/power/power_supply_core.c b/drivers/power/power_supply_core.c
48555index 2660664..75fcb04 100644
48556--- a/drivers/power/power_supply_core.c
48557+++ b/drivers/power/power_supply_core.c
48558@@ -28,7 +28,10 @@ EXPORT_SYMBOL_GPL(power_supply_class);
48559 ATOMIC_NOTIFIER_HEAD(power_supply_notifier);
48560 EXPORT_SYMBOL_GPL(power_supply_notifier);
48561
48562-static struct device_type power_supply_dev_type;
48563+extern const struct attribute_group *power_supply_attr_groups[];
48564+static struct device_type power_supply_dev_type = {
48565+ .groups = power_supply_attr_groups,
48566+};
48567
48568 static bool __power_supply_is_supplied_by(struct power_supply *supplier,
48569 struct power_supply *supply)
48570@@ -628,7 +631,7 @@ static int __init power_supply_class_init(void)
48571 return PTR_ERR(power_supply_class);
48572
48573 power_supply_class->dev_uevent = power_supply_uevent;
48574- power_supply_init_attrs(&power_supply_dev_type);
48575+ power_supply_init_attrs();
48576
48577 return 0;
48578 }
48579diff --git a/drivers/power/power_supply_sysfs.c b/drivers/power/power_supply_sysfs.c
48580index 44420d1..967126e 100644
48581--- a/drivers/power/power_supply_sysfs.c
48582+++ b/drivers/power/power_supply_sysfs.c
48583@@ -230,17 +230,15 @@ static struct attribute_group power_supply_attr_group = {
48584 .is_visible = power_supply_attr_is_visible,
48585 };
48586
48587-static const struct attribute_group *power_supply_attr_groups[] = {
48588+const struct attribute_group *power_supply_attr_groups[] = {
48589 &power_supply_attr_group,
48590 NULL,
48591 };
48592
48593-void power_supply_init_attrs(struct device_type *dev_type)
48594+void power_supply_init_attrs(void)
48595 {
48596 int i;
48597
48598- dev_type->groups = power_supply_attr_groups;
48599-
48600 for (i = 0; i < ARRAY_SIZE(power_supply_attrs); i++)
48601 __power_supply_attrs[i] = &power_supply_attrs[i].attr;
48602 }
48603diff --git a/drivers/powercap/powercap_sys.c b/drivers/powercap/powercap_sys.c
48604index 84419af..268ede8 100644
48605--- a/drivers/powercap/powercap_sys.c
48606+++ b/drivers/powercap/powercap_sys.c
48607@@ -154,8 +154,77 @@ struct powercap_constraint_attr {
48608 struct device_attribute name_attr;
48609 };
48610
48611+static ssize_t show_constraint_name(struct device *dev,
48612+ struct device_attribute *dev_attr,
48613+ char *buf);
48614+
48615 static struct powercap_constraint_attr
48616- constraint_attrs[MAX_CONSTRAINTS_PER_ZONE];
48617+ constraint_attrs[MAX_CONSTRAINTS_PER_ZONE] = {
48618+ [0 ... MAX_CONSTRAINTS_PER_ZONE - 1] = {
48619+ .power_limit_attr = {
48620+ .attr = {
48621+ .name = NULL,
48622+ .mode = S_IWUSR | S_IRUGO
48623+ },
48624+ .show = show_constraint_power_limit_uw,
48625+ .store = store_constraint_power_limit_uw
48626+ },
48627+
48628+ .time_window_attr = {
48629+ .attr = {
48630+ .name = NULL,
48631+ .mode = S_IWUSR | S_IRUGO
48632+ },
48633+ .show = show_constraint_time_window_us,
48634+ .store = store_constraint_time_window_us
48635+ },
48636+
48637+ .max_power_attr = {
48638+ .attr = {
48639+ .name = NULL,
48640+ .mode = S_IRUGO
48641+ },
48642+ .show = show_constraint_max_power_uw,
48643+ .store = NULL
48644+ },
48645+
48646+ .min_power_attr = {
48647+ .attr = {
48648+ .name = NULL,
48649+ .mode = S_IRUGO
48650+ },
48651+ .show = show_constraint_min_power_uw,
48652+ .store = NULL
48653+ },
48654+
48655+ .max_time_window_attr = {
48656+ .attr = {
48657+ .name = NULL,
48658+ .mode = S_IRUGO
48659+ },
48660+ .show = show_constraint_max_time_window_us,
48661+ .store = NULL
48662+ },
48663+
48664+ .min_time_window_attr = {
48665+ .attr = {
48666+ .name = NULL,
48667+ .mode = S_IRUGO
48668+ },
48669+ .show = show_constraint_min_time_window_us,
48670+ .store = NULL
48671+ },
48672+
48673+ .name_attr = {
48674+ .attr = {
48675+ .name = NULL,
48676+ .mode = S_IRUGO
48677+ },
48678+ .show = show_constraint_name,
48679+ .store = NULL
48680+ }
48681+ }
48682+};
48683
48684 /* A list of powercap control_types */
48685 static LIST_HEAD(powercap_cntrl_list);
48686@@ -193,23 +262,16 @@ static ssize_t show_constraint_name(struct device *dev,
48687 }
48688
48689 static int create_constraint_attribute(int id, const char *name,
48690- int mode,
48691- struct device_attribute *dev_attr,
48692- ssize_t (*show)(struct device *,
48693- struct device_attribute *, char *),
48694- ssize_t (*store)(struct device *,
48695- struct device_attribute *,
48696- const char *, size_t)
48697- )
48698+ struct device_attribute *dev_attr)
48699 {
48700+ name = kasprintf(GFP_KERNEL, "constraint_%d_%s", id, name);
48701
48702- dev_attr->attr.name = kasprintf(GFP_KERNEL, "constraint_%d_%s",
48703- id, name);
48704- if (!dev_attr->attr.name)
48705+ if (!name)
48706 return -ENOMEM;
48707- dev_attr->attr.mode = mode;
48708- dev_attr->show = show;
48709- dev_attr->store = store;
48710+
48711+ pax_open_kernel();
48712+ *(const char **)&dev_attr->attr.name = name;
48713+ pax_close_kernel();
48714
48715 return 0;
48716 }
48717@@ -236,49 +298,31 @@ static int seed_constraint_attributes(void)
48718
48719 for (i = 0; i < MAX_CONSTRAINTS_PER_ZONE; ++i) {
48720 ret = create_constraint_attribute(i, "power_limit_uw",
48721- S_IWUSR | S_IRUGO,
48722- &constraint_attrs[i].power_limit_attr,
48723- show_constraint_power_limit_uw,
48724- store_constraint_power_limit_uw);
48725+ &constraint_attrs[i].power_limit_attr);
48726 if (ret)
48727 goto err_alloc;
48728 ret = create_constraint_attribute(i, "time_window_us",
48729- S_IWUSR | S_IRUGO,
48730- &constraint_attrs[i].time_window_attr,
48731- show_constraint_time_window_us,
48732- store_constraint_time_window_us);
48733+ &constraint_attrs[i].time_window_attr);
48734 if (ret)
48735 goto err_alloc;
48736- ret = create_constraint_attribute(i, "name", S_IRUGO,
48737- &constraint_attrs[i].name_attr,
48738- show_constraint_name,
48739- NULL);
48740+ ret = create_constraint_attribute(i, "name",
48741+ &constraint_attrs[i].name_attr);
48742 if (ret)
48743 goto err_alloc;
48744- ret = create_constraint_attribute(i, "max_power_uw", S_IRUGO,
48745- &constraint_attrs[i].max_power_attr,
48746- show_constraint_max_power_uw,
48747- NULL);
48748+ ret = create_constraint_attribute(i, "max_power_uw",
48749+ &constraint_attrs[i].max_power_attr);
48750 if (ret)
48751 goto err_alloc;
48752- ret = create_constraint_attribute(i, "min_power_uw", S_IRUGO,
48753- &constraint_attrs[i].min_power_attr,
48754- show_constraint_min_power_uw,
48755- NULL);
48756+ ret = create_constraint_attribute(i, "min_power_uw",
48757+ &constraint_attrs[i].min_power_attr);
48758 if (ret)
48759 goto err_alloc;
48760 ret = create_constraint_attribute(i, "max_time_window_us",
48761- S_IRUGO,
48762- &constraint_attrs[i].max_time_window_attr,
48763- show_constraint_max_time_window_us,
48764- NULL);
48765+ &constraint_attrs[i].max_time_window_attr);
48766 if (ret)
48767 goto err_alloc;
48768 ret = create_constraint_attribute(i, "min_time_window_us",
48769- S_IRUGO,
48770- &constraint_attrs[i].min_time_window_attr,
48771- show_constraint_min_time_window_us,
48772- NULL);
48773+ &constraint_attrs[i].min_time_window_attr);
48774 if (ret)
48775 goto err_alloc;
48776
48777@@ -378,10 +422,12 @@ static void create_power_zone_common_attributes(
48778 power_zone->zone_dev_attrs[count++] =
48779 &dev_attr_max_energy_range_uj.attr;
48780 if (power_zone->ops->get_energy_uj) {
48781+ pax_open_kernel();
48782 if (power_zone->ops->reset_energy_uj)
48783- dev_attr_energy_uj.attr.mode = S_IWUSR | S_IRUGO;
48784+ *(umode_t *)&dev_attr_energy_uj.attr.mode = S_IWUSR | S_IRUGO;
48785 else
48786- dev_attr_energy_uj.attr.mode = S_IRUGO;
48787+ *(umode_t *)&dev_attr_energy_uj.attr.mode = S_IRUGO;
48788+ pax_close_kernel();
48789 power_zone->zone_dev_attrs[count++] =
48790 &dev_attr_energy_uj.attr;
48791 }
48792diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
48793index afca1bc..86840b8 100644
48794--- a/drivers/regulator/core.c
48795+++ b/drivers/regulator/core.c
48796@@ -3366,7 +3366,7 @@ regulator_register(const struct regulator_desc *regulator_desc,
48797 {
48798 const struct regulation_constraints *constraints = NULL;
48799 const struct regulator_init_data *init_data;
48800- static atomic_t regulator_no = ATOMIC_INIT(0);
48801+ static atomic_unchecked_t regulator_no = ATOMIC_INIT(0);
48802 struct regulator_dev *rdev;
48803 struct device *dev;
48804 int ret, i;
48805@@ -3436,7 +3436,7 @@ regulator_register(const struct regulator_desc *regulator_desc,
48806 rdev->dev.of_node = config->of_node;
48807 rdev->dev.parent = dev;
48808 dev_set_name(&rdev->dev, "regulator.%d",
48809- atomic_inc_return(&regulator_no) - 1);
48810+ atomic_inc_return_unchecked(&regulator_no) - 1);
48811 ret = device_register(&rdev->dev);
48812 if (ret != 0) {
48813 put_device(&rdev->dev);
48814diff --git a/drivers/regulator/max8660.c b/drivers/regulator/max8660.c
48815index 8d94d3d..653b623 100644
48816--- a/drivers/regulator/max8660.c
48817+++ b/drivers/regulator/max8660.c
48818@@ -420,8 +420,10 @@ static int max8660_probe(struct i2c_client *client,
48819 max8660->shadow_regs[MAX8660_OVER1] = 5;
48820 } else {
48821 /* Otherwise devices can be toggled via software */
48822- max8660_dcdc_ops.enable = max8660_dcdc_enable;
48823- max8660_dcdc_ops.disable = max8660_dcdc_disable;
48824+ pax_open_kernel();
48825+ *(void **)&max8660_dcdc_ops.enable = max8660_dcdc_enable;
48826+ *(void **)&max8660_dcdc_ops.disable = max8660_dcdc_disable;
48827+ pax_close_kernel();
48828 }
48829
48830 /*
48831diff --git a/drivers/regulator/max8973-regulator.c b/drivers/regulator/max8973-regulator.c
48832index 892aa1e..ebd1b9c 100644
48833--- a/drivers/regulator/max8973-regulator.c
48834+++ b/drivers/regulator/max8973-regulator.c
48835@@ -406,9 +406,11 @@ static int max8973_probe(struct i2c_client *client,
48836 if (!pdata || !pdata->enable_ext_control) {
48837 max->desc.enable_reg = MAX8973_VOUT;
48838 max->desc.enable_mask = MAX8973_VOUT_ENABLE;
48839- max->ops.enable = regulator_enable_regmap;
48840- max->ops.disable = regulator_disable_regmap;
48841- max->ops.is_enabled = regulator_is_enabled_regmap;
48842+ pax_open_kernel();
48843+ *(void **)&max->ops.enable = regulator_enable_regmap;
48844+ *(void **)&max->ops.disable = regulator_disable_regmap;
48845+ *(void **)&max->ops.is_enabled = regulator_is_enabled_regmap;
48846+ pax_close_kernel();
48847 }
48848
48849 if (pdata) {
48850diff --git a/drivers/regulator/mc13892-regulator.c b/drivers/regulator/mc13892-regulator.c
48851index f374fa5..26f0683 100644
48852--- a/drivers/regulator/mc13892-regulator.c
48853+++ b/drivers/regulator/mc13892-regulator.c
48854@@ -582,10 +582,12 @@ static int mc13892_regulator_probe(struct platform_device *pdev)
48855 }
48856 mc13xxx_unlock(mc13892);
48857
48858- mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
48859+ pax_open_kernel();
48860+ *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
48861 = mc13892_vcam_set_mode;
48862- mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
48863+ *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
48864 = mc13892_vcam_get_mode;
48865+ pax_close_kernel();
48866
48867 mc13xxx_data = mc13xxx_parse_regulators_dt(pdev, mc13892_regulators,
48868 ARRAY_SIZE(mc13892_regulators));
48869diff --git a/drivers/rtc/rtc-cmos.c b/drivers/rtc/rtc-cmos.c
48870index cae212f..58a3980 100644
48871--- a/drivers/rtc/rtc-cmos.c
48872+++ b/drivers/rtc/rtc-cmos.c
48873@@ -777,7 +777,9 @@ cmos_do_probe(struct device *dev, struct resource *ports, int rtc_irq)
48874 hpet_rtc_timer_init();
48875
48876 /* export at least the first block of NVRAM */
48877- nvram.size = address_space - NVRAM_OFFSET;
48878+ pax_open_kernel();
48879+ *(size_t *)&nvram.size = address_space - NVRAM_OFFSET;
48880+ pax_close_kernel();
48881 retval = sysfs_create_bin_file(&dev->kobj, &nvram);
48882 if (retval < 0) {
48883 dev_dbg(dev, "can't create nvram file? %d\n", retval);
48884diff --git a/drivers/rtc/rtc-dev.c b/drivers/rtc/rtc-dev.c
48885index d049393..bb20be0 100644
48886--- a/drivers/rtc/rtc-dev.c
48887+++ b/drivers/rtc/rtc-dev.c
48888@@ -16,6 +16,7 @@
48889 #include <linux/module.h>
48890 #include <linux/rtc.h>
48891 #include <linux/sched.h>
48892+#include <linux/grsecurity.h>
48893 #include "rtc-core.h"
48894
48895 static dev_t rtc_devt;
48896@@ -347,6 +348,8 @@ static long rtc_dev_ioctl(struct file *file,
48897 if (copy_from_user(&tm, uarg, sizeof(tm)))
48898 return -EFAULT;
48899
48900+ gr_log_timechange();
48901+
48902 return rtc_set_time(rtc, &tm);
48903
48904 case RTC_PIE_ON:
48905diff --git a/drivers/rtc/rtc-ds1307.c b/drivers/rtc/rtc-ds1307.c
48906index 4e75345..09f8663 100644
48907--- a/drivers/rtc/rtc-ds1307.c
48908+++ b/drivers/rtc/rtc-ds1307.c
48909@@ -107,7 +107,7 @@ struct ds1307 {
48910 u8 offset; /* register's offset */
48911 u8 regs[11];
48912 u16 nvram_offset;
48913- struct bin_attribute *nvram;
48914+ bin_attribute_no_const *nvram;
48915 enum ds_type type;
48916 unsigned long flags;
48917 #define HAS_NVRAM 0 /* bit 0 == sysfs file active */
48918diff --git a/drivers/rtc/rtc-m48t59.c b/drivers/rtc/rtc-m48t59.c
48919index 11880c1..b823aa4 100644
48920--- a/drivers/rtc/rtc-m48t59.c
48921+++ b/drivers/rtc/rtc-m48t59.c
48922@@ -483,7 +483,9 @@ static int m48t59_rtc_probe(struct platform_device *pdev)
48923 if (IS_ERR(m48t59->rtc))
48924 return PTR_ERR(m48t59->rtc);
48925
48926- m48t59_nvram_attr.size = pdata->offset;
48927+ pax_open_kernel();
48928+ *(size_t *)&m48t59_nvram_attr.size = pdata->offset;
48929+ pax_close_kernel();
48930
48931 ret = sysfs_create_bin_file(&pdev->dev.kobj, &m48t59_nvram_attr);
48932 if (ret)
48933diff --git a/drivers/scsi/aic7xxx/aic79xx_pci.c b/drivers/scsi/aic7xxx/aic79xx_pci.c
48934index 14b5f8d..cc9bd26 100644
48935--- a/drivers/scsi/aic7xxx/aic79xx_pci.c
48936+++ b/drivers/scsi/aic7xxx/aic79xx_pci.c
48937@@ -827,7 +827,7 @@ ahd_pci_intr(struct ahd_softc *ahd)
48938 for (bit = 0; bit < 8; bit++) {
48939
48940 if ((pci_status[i] & (0x1 << bit)) != 0) {
48941- static const char *s;
48942+ const char *s;
48943
48944 s = pci_status_strings[bit];
48945 if (i == 7/*TARG*/ && bit == 3)
48946@@ -887,23 +887,15 @@ ahd_pci_split_intr(struct ahd_softc *ahd, u_int intstat)
48947
48948 for (bit = 0; bit < 8; bit++) {
48949
48950- if ((split_status[i] & (0x1 << bit)) != 0) {
48951- static const char *s;
48952-
48953- s = split_status_strings[bit];
48954- printk(s, ahd_name(ahd),
48955+ if ((split_status[i] & (0x1 << bit)) != 0)
48956+ printk(split_status_strings[bit], ahd_name(ahd),
48957 split_status_source[i]);
48958- }
48959
48960 if (i > 1)
48961 continue;
48962
48963- if ((sg_split_status[i] & (0x1 << bit)) != 0) {
48964- static const char *s;
48965-
48966- s = split_status_strings[bit];
48967- printk(s, ahd_name(ahd), "SG");
48968- }
48969+ if ((sg_split_status[i] & (0x1 << bit)) != 0)
48970+ printk(split_status_strings[bit], ahd_name(ahd), "SG");
48971 }
48972 }
48973 /*
48974diff --git a/drivers/scsi/bfa/bfa_fcpim.h b/drivers/scsi/bfa/bfa_fcpim.h
48975index e693af6..2e525b6 100644
48976--- a/drivers/scsi/bfa/bfa_fcpim.h
48977+++ b/drivers/scsi/bfa/bfa_fcpim.h
48978@@ -36,7 +36,7 @@ struct bfa_iotag_s {
48979
48980 struct bfa_itn_s {
48981 bfa_isr_func_t isr;
48982-};
48983+} __no_const;
48984
48985 void bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
48986 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m));
48987diff --git a/drivers/scsi/bfa/bfa_fcs.c b/drivers/scsi/bfa/bfa_fcs.c
48988index a3ab5cc..8143622 100644
48989--- a/drivers/scsi/bfa/bfa_fcs.c
48990+++ b/drivers/scsi/bfa/bfa_fcs.c
48991@@ -38,10 +38,21 @@ struct bfa_fcs_mod_s {
48992 #define BFA_FCS_MODULE(_mod) { _mod ## _modinit, _mod ## _modexit }
48993
48994 static struct bfa_fcs_mod_s fcs_modules[] = {
48995- { bfa_fcs_port_attach, NULL, NULL },
48996- { bfa_fcs_uf_attach, NULL, NULL },
48997- { bfa_fcs_fabric_attach, bfa_fcs_fabric_modinit,
48998- bfa_fcs_fabric_modexit },
48999+ {
49000+ .attach = bfa_fcs_port_attach,
49001+ .modinit = NULL,
49002+ .modexit = NULL
49003+ },
49004+ {
49005+ .attach = bfa_fcs_uf_attach,
49006+ .modinit = NULL,
49007+ .modexit = NULL
49008+ },
49009+ {
49010+ .attach = bfa_fcs_fabric_attach,
49011+ .modinit = bfa_fcs_fabric_modinit,
49012+ .modexit = bfa_fcs_fabric_modexit
49013+ },
49014 };
49015
49016 /*
49017diff --git a/drivers/scsi/bfa/bfa_fcs_lport.c b/drivers/scsi/bfa/bfa_fcs_lport.c
49018index ff75ef8..2dfe00a 100644
49019--- a/drivers/scsi/bfa/bfa_fcs_lport.c
49020+++ b/drivers/scsi/bfa/bfa_fcs_lport.c
49021@@ -89,15 +89,26 @@ static struct {
49022 void (*offline) (struct bfa_fcs_lport_s *port);
49023 } __port_action[] = {
49024 {
49025- bfa_fcs_lport_unknown_init, bfa_fcs_lport_unknown_online,
49026- bfa_fcs_lport_unknown_offline}, {
49027- bfa_fcs_lport_fab_init, bfa_fcs_lport_fab_online,
49028- bfa_fcs_lport_fab_offline}, {
49029- bfa_fcs_lport_n2n_init, bfa_fcs_lport_n2n_online,
49030- bfa_fcs_lport_n2n_offline}, {
49031- bfa_fcs_lport_loop_init, bfa_fcs_lport_loop_online,
49032- bfa_fcs_lport_loop_offline},
49033- };
49034+ .init = bfa_fcs_lport_unknown_init,
49035+ .online = bfa_fcs_lport_unknown_online,
49036+ .offline = bfa_fcs_lport_unknown_offline
49037+ },
49038+ {
49039+ .init = bfa_fcs_lport_fab_init,
49040+ .online = bfa_fcs_lport_fab_online,
49041+ .offline = bfa_fcs_lport_fab_offline
49042+ },
49043+ {
49044+ .init = bfa_fcs_lport_n2n_init,
49045+ .online = bfa_fcs_lport_n2n_online,
49046+ .offline = bfa_fcs_lport_n2n_offline
49047+ },
49048+ {
49049+ .init = bfa_fcs_lport_loop_init,
49050+ .online = bfa_fcs_lport_loop_online,
49051+ .offline = bfa_fcs_lport_loop_offline
49052+ },
49053+};
49054
49055 /*
49056 * fcs_port_sm FCS logical port state machine
49057diff --git a/drivers/scsi/bfa/bfa_ioc.h b/drivers/scsi/bfa/bfa_ioc.h
49058index 2e28392..9d865b6 100644
49059--- a/drivers/scsi/bfa/bfa_ioc.h
49060+++ b/drivers/scsi/bfa/bfa_ioc.h
49061@@ -258,7 +258,7 @@ struct bfa_ioc_cbfn_s {
49062 bfa_ioc_disable_cbfn_t disable_cbfn;
49063 bfa_ioc_hbfail_cbfn_t hbfail_cbfn;
49064 bfa_ioc_reset_cbfn_t reset_cbfn;
49065-};
49066+} __no_const;
49067
49068 /*
49069 * IOC event notification mechanism.
49070@@ -352,7 +352,7 @@ struct bfa_ioc_hwif_s {
49071 void (*ioc_set_alt_fwstate) (struct bfa_ioc_s *ioc,
49072 enum bfi_ioc_state fwstate);
49073 enum bfi_ioc_state (*ioc_get_alt_fwstate) (struct bfa_ioc_s *ioc);
49074-};
49075+} __no_const;
49076
49077 /*
49078 * Queue element to wait for room in request queue. FIFO order is
49079diff --git a/drivers/scsi/bfa/bfa_modules.h b/drivers/scsi/bfa/bfa_modules.h
49080index a14c784..6de6790 100644
49081--- a/drivers/scsi/bfa/bfa_modules.h
49082+++ b/drivers/scsi/bfa/bfa_modules.h
49083@@ -78,12 +78,12 @@ enum {
49084 \
49085 extern struct bfa_module_s hal_mod_ ## __mod; \
49086 struct bfa_module_s hal_mod_ ## __mod = { \
49087- bfa_ ## __mod ## _meminfo, \
49088- bfa_ ## __mod ## _attach, \
49089- bfa_ ## __mod ## _detach, \
49090- bfa_ ## __mod ## _start, \
49091- bfa_ ## __mod ## _stop, \
49092- bfa_ ## __mod ## _iocdisable, \
49093+ .meminfo = bfa_ ## __mod ## _meminfo, \
49094+ .attach = bfa_ ## __mod ## _attach, \
49095+ .detach = bfa_ ## __mod ## _detach, \
49096+ .start = bfa_ ## __mod ## _start, \
49097+ .stop = bfa_ ## __mod ## _stop, \
49098+ .iocdisable = bfa_ ## __mod ## _iocdisable, \
49099 }
49100
49101 #define BFA_CACHELINE_SZ (256)
49102diff --git a/drivers/scsi/fcoe/fcoe_sysfs.c b/drivers/scsi/fcoe/fcoe_sysfs.c
49103index 045c4e1..13de803 100644
49104--- a/drivers/scsi/fcoe/fcoe_sysfs.c
49105+++ b/drivers/scsi/fcoe/fcoe_sysfs.c
49106@@ -33,8 +33,8 @@
49107 */
49108 #include "libfcoe.h"
49109
49110-static atomic_t ctlr_num;
49111-static atomic_t fcf_num;
49112+static atomic_unchecked_t ctlr_num;
49113+static atomic_unchecked_t fcf_num;
49114
49115 /*
49116 * fcoe_fcf_dev_loss_tmo: the default number of seconds that fcoe sysfs
49117@@ -685,7 +685,7 @@ struct fcoe_ctlr_device *fcoe_ctlr_device_add(struct device *parent,
49118 if (!ctlr)
49119 goto out;
49120
49121- ctlr->id = atomic_inc_return(&ctlr_num) - 1;
49122+ ctlr->id = atomic_inc_return_unchecked(&ctlr_num) - 1;
49123 ctlr->f = f;
49124 ctlr->mode = FIP_CONN_TYPE_FABRIC;
49125 INIT_LIST_HEAD(&ctlr->fcfs);
49126@@ -902,7 +902,7 @@ struct fcoe_fcf_device *fcoe_fcf_device_add(struct fcoe_ctlr_device *ctlr,
49127 fcf->dev.parent = &ctlr->dev;
49128 fcf->dev.bus = &fcoe_bus_type;
49129 fcf->dev.type = &fcoe_fcf_device_type;
49130- fcf->id = atomic_inc_return(&fcf_num) - 1;
49131+ fcf->id = atomic_inc_return_unchecked(&fcf_num) - 1;
49132 fcf->state = FCOE_FCF_STATE_UNKNOWN;
49133
49134 fcf->dev_loss_tmo = ctlr->fcf_dev_loss_tmo;
49135@@ -938,8 +938,8 @@ int __init fcoe_sysfs_setup(void)
49136 {
49137 int error;
49138
49139- atomic_set(&ctlr_num, 0);
49140- atomic_set(&fcf_num, 0);
49141+ atomic_set_unchecked(&ctlr_num, 0);
49142+ atomic_set_unchecked(&fcf_num, 0);
49143
49144 error = bus_register(&fcoe_bus_type);
49145 if (error)
49146diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c
49147index f28ea07..34b16d3 100644
49148--- a/drivers/scsi/hosts.c
49149+++ b/drivers/scsi/hosts.c
49150@@ -42,7 +42,7 @@
49151 #include "scsi_logging.h"
49152
49153
49154-static atomic_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
49155+static atomic_unchecked_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
49156
49157
49158 static void scsi_host_cls_release(struct device *dev)
49159@@ -369,7 +369,7 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)
49160 * subtract one because we increment first then return, but we need to
49161 * know what the next host number was before increment
49162 */
49163- shost->host_no = atomic_inc_return(&scsi_host_next_hn) - 1;
49164+ shost->host_no = atomic_inc_return_unchecked(&scsi_host_next_hn) - 1;
49165 shost->dma_channel = 0xff;
49166
49167 /* These three are default values which can be overridden */
49168diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
49169index 868318a..e07ef3b 100644
49170--- a/drivers/scsi/hpsa.c
49171+++ b/drivers/scsi/hpsa.c
49172@@ -571,7 +571,7 @@ static inline u32 next_command(struct ctlr_info *h, u8 q)
49173 unsigned long flags;
49174
49175 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
49176- return h->access.command_completed(h, q);
49177+ return h->access->command_completed(h, q);
49178
49179 if ((rq->head[rq->current_entry] & 1) == rq->wraparound) {
49180 a = rq->head[rq->current_entry];
49181@@ -3474,7 +3474,7 @@ static void start_io(struct ctlr_info *h)
49182 while (!list_empty(&h->reqQ)) {
49183 c = list_entry(h->reqQ.next, struct CommandList, list);
49184 /* can't do anything if fifo is full */
49185- if ((h->access.fifo_full(h))) {
49186+ if ((h->access->fifo_full(h))) {
49187 h->fifo_recently_full = 1;
49188 dev_warn(&h->pdev->dev, "fifo full\n");
49189 break;
49190@@ -3498,7 +3498,7 @@ static void start_io(struct ctlr_info *h)
49191
49192 /* Tell the controller execute command */
49193 spin_unlock_irqrestore(&h->lock, flags);
49194- h->access.submit_command(h, c);
49195+ h->access->submit_command(h, c);
49196 spin_lock_irqsave(&h->lock, flags);
49197 }
49198 spin_unlock_irqrestore(&h->lock, flags);
49199@@ -3506,17 +3506,17 @@ static void start_io(struct ctlr_info *h)
49200
49201 static inline unsigned long get_next_completion(struct ctlr_info *h, u8 q)
49202 {
49203- return h->access.command_completed(h, q);
49204+ return h->access->command_completed(h, q);
49205 }
49206
49207 static inline bool interrupt_pending(struct ctlr_info *h)
49208 {
49209- return h->access.intr_pending(h);
49210+ return h->access->intr_pending(h);
49211 }
49212
49213 static inline long interrupt_not_for_us(struct ctlr_info *h)
49214 {
49215- return (h->access.intr_pending(h) == 0) ||
49216+ return (h->access->intr_pending(h) == 0) ||
49217 (h->interrupts_enabled == 0);
49218 }
49219
49220@@ -4442,7 +4442,7 @@ static int hpsa_pci_init(struct ctlr_info *h)
49221 if (prod_index < 0)
49222 return -ENODEV;
49223 h->product_name = products[prod_index].product_name;
49224- h->access = *(products[prod_index].access);
49225+ h->access = products[prod_index].access;
49226
49227 pci_disable_link_state(h->pdev, PCIE_LINK_STATE_L0S |
49228 PCIE_LINK_STATE_L1 | PCIE_LINK_STATE_CLKPM);
49229@@ -4712,7 +4712,7 @@ static void controller_lockup_detected(struct ctlr_info *h)
49230 {
49231 unsigned long flags;
49232
49233- h->access.set_intr_mask(h, HPSA_INTR_OFF);
49234+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
49235 spin_lock_irqsave(&h->lock, flags);
49236 h->lockup_detected = readl(h->vaddr + SA5_SCRATCHPAD_OFFSET);
49237 spin_unlock_irqrestore(&h->lock, flags);
49238@@ -4843,7 +4843,7 @@ reinit_after_soft_reset:
49239 }
49240
49241 /* make sure the board interrupts are off */
49242- h->access.set_intr_mask(h, HPSA_INTR_OFF);
49243+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
49244
49245 if (hpsa_request_irq(h, do_hpsa_intr_msi, do_hpsa_intr_intx))
49246 goto clean2;
49247@@ -4877,7 +4877,7 @@ reinit_after_soft_reset:
49248 * fake ones to scoop up any residual completions.
49249 */
49250 spin_lock_irqsave(&h->lock, flags);
49251- h->access.set_intr_mask(h, HPSA_INTR_OFF);
49252+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
49253 spin_unlock_irqrestore(&h->lock, flags);
49254 free_irqs(h);
49255 rc = hpsa_request_irq(h, hpsa_msix_discard_completions,
49256@@ -4896,9 +4896,9 @@ reinit_after_soft_reset:
49257 dev_info(&h->pdev->dev, "Board READY.\n");
49258 dev_info(&h->pdev->dev,
49259 "Waiting for stale completions to drain.\n");
49260- h->access.set_intr_mask(h, HPSA_INTR_ON);
49261+ h->access->set_intr_mask(h, HPSA_INTR_ON);
49262 msleep(10000);
49263- h->access.set_intr_mask(h, HPSA_INTR_OFF);
49264+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
49265
49266 rc = controller_reset_failed(h->cfgtable);
49267 if (rc)
49268@@ -4919,7 +4919,7 @@ reinit_after_soft_reset:
49269 }
49270
49271 /* Turn the interrupts on so we can service requests */
49272- h->access.set_intr_mask(h, HPSA_INTR_ON);
49273+ h->access->set_intr_mask(h, HPSA_INTR_ON);
49274
49275 hpsa_hba_inquiry(h);
49276 hpsa_register_scsi(h); /* hook ourselves into SCSI subsystem */
49277@@ -4988,7 +4988,7 @@ static void hpsa_shutdown(struct pci_dev *pdev)
49278 * To write all data in the battery backed cache to disks
49279 */
49280 hpsa_flush_cache(h);
49281- h->access.set_intr_mask(h, HPSA_INTR_OFF);
49282+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
49283 hpsa_free_irqs_and_disable_msix(h);
49284 }
49285
49286@@ -5162,7 +5162,7 @@ static void hpsa_enter_performant_mode(struct ctlr_info *h, u32 use_short_tags)
49287 return;
49288 }
49289 /* Change the access methods to the performant access methods */
49290- h->access = SA5_performant_access;
49291+ h->access = &SA5_performant_access;
49292 h->transMethod = CFGTBL_Trans_Performant;
49293 }
49294
49295diff --git a/drivers/scsi/hpsa.h b/drivers/scsi/hpsa.h
49296index 01c3283..4655219 100644
49297--- a/drivers/scsi/hpsa.h
49298+++ b/drivers/scsi/hpsa.h
49299@@ -79,7 +79,7 @@ struct ctlr_info {
49300 unsigned int msix_vector;
49301 unsigned int msi_vector;
49302 int intr_mode; /* either PERF_MODE_INT or SIMPLE_MODE_INT */
49303- struct access_method access;
49304+ struct access_method *access;
49305
49306 /* queue and queue Info */
49307 struct list_head reqQ;
49308@@ -388,19 +388,19 @@ static bool SA5_performant_intr_pending(struct ctlr_info *h)
49309 }
49310
49311 static struct access_method SA5_access = {
49312- SA5_submit_command,
49313- SA5_intr_mask,
49314- SA5_fifo_full,
49315- SA5_intr_pending,
49316- SA5_completed,
49317+ .submit_command = SA5_submit_command,
49318+ .set_intr_mask = SA5_intr_mask,
49319+ .fifo_full = SA5_fifo_full,
49320+ .intr_pending = SA5_intr_pending,
49321+ .command_completed = SA5_completed,
49322 };
49323
49324 static struct access_method SA5_performant_access = {
49325- SA5_submit_command,
49326- SA5_performant_intr_mask,
49327- SA5_fifo_full,
49328- SA5_performant_intr_pending,
49329- SA5_performant_completed,
49330+ .submit_command = SA5_submit_command,
49331+ .set_intr_mask = SA5_performant_intr_mask,
49332+ .fifo_full = SA5_fifo_full,
49333+ .intr_pending = SA5_performant_intr_pending,
49334+ .command_completed = SA5_performant_completed,
49335 };
49336
49337 struct board_type {
49338diff --git a/drivers/scsi/libfc/fc_exch.c b/drivers/scsi/libfc/fc_exch.c
49339index 1b3a094..068e683 100644
49340--- a/drivers/scsi/libfc/fc_exch.c
49341+++ b/drivers/scsi/libfc/fc_exch.c
49342@@ -101,12 +101,12 @@ struct fc_exch_mgr {
49343 u16 pool_max_index;
49344
49345 struct {
49346- atomic_t no_free_exch;
49347- atomic_t no_free_exch_xid;
49348- atomic_t xid_not_found;
49349- atomic_t xid_busy;
49350- atomic_t seq_not_found;
49351- atomic_t non_bls_resp;
49352+ atomic_unchecked_t no_free_exch;
49353+ atomic_unchecked_t no_free_exch_xid;
49354+ atomic_unchecked_t xid_not_found;
49355+ atomic_unchecked_t xid_busy;
49356+ atomic_unchecked_t seq_not_found;
49357+ atomic_unchecked_t non_bls_resp;
49358 } stats;
49359 };
49360
49361@@ -811,7 +811,7 @@ static struct fc_exch *fc_exch_em_alloc(struct fc_lport *lport,
49362 /* allocate memory for exchange */
49363 ep = mempool_alloc(mp->ep_pool, GFP_ATOMIC);
49364 if (!ep) {
49365- atomic_inc(&mp->stats.no_free_exch);
49366+ atomic_inc_unchecked(&mp->stats.no_free_exch);
49367 goto out;
49368 }
49369 memset(ep, 0, sizeof(*ep));
49370@@ -874,7 +874,7 @@ out:
49371 return ep;
49372 err:
49373 spin_unlock_bh(&pool->lock);
49374- atomic_inc(&mp->stats.no_free_exch_xid);
49375+ atomic_inc_unchecked(&mp->stats.no_free_exch_xid);
49376 mempool_free(ep, mp->ep_pool);
49377 return NULL;
49378 }
49379@@ -1023,7 +1023,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
49380 xid = ntohs(fh->fh_ox_id); /* we originated exch */
49381 ep = fc_exch_find(mp, xid);
49382 if (!ep) {
49383- atomic_inc(&mp->stats.xid_not_found);
49384+ atomic_inc_unchecked(&mp->stats.xid_not_found);
49385 reject = FC_RJT_OX_ID;
49386 goto out;
49387 }
49388@@ -1053,7 +1053,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
49389 ep = fc_exch_find(mp, xid);
49390 if ((f_ctl & FC_FC_FIRST_SEQ) && fc_sof_is_init(fr_sof(fp))) {
49391 if (ep) {
49392- atomic_inc(&mp->stats.xid_busy);
49393+ atomic_inc_unchecked(&mp->stats.xid_busy);
49394 reject = FC_RJT_RX_ID;
49395 goto rel;
49396 }
49397@@ -1064,7 +1064,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
49398 }
49399 xid = ep->xid; /* get our XID */
49400 } else if (!ep) {
49401- atomic_inc(&mp->stats.xid_not_found);
49402+ atomic_inc_unchecked(&mp->stats.xid_not_found);
49403 reject = FC_RJT_RX_ID; /* XID not found */
49404 goto out;
49405 }
49406@@ -1082,7 +1082,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
49407 } else {
49408 sp = &ep->seq;
49409 if (sp->id != fh->fh_seq_id) {
49410- atomic_inc(&mp->stats.seq_not_found);
49411+ atomic_inc_unchecked(&mp->stats.seq_not_found);
49412 if (f_ctl & FC_FC_END_SEQ) {
49413 /*
49414 * Update sequence_id based on incoming last
49415@@ -1533,22 +1533,22 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
49416
49417 ep = fc_exch_find(mp, ntohs(fh->fh_ox_id));
49418 if (!ep) {
49419- atomic_inc(&mp->stats.xid_not_found);
49420+ atomic_inc_unchecked(&mp->stats.xid_not_found);
49421 goto out;
49422 }
49423 if (ep->esb_stat & ESB_ST_COMPLETE) {
49424- atomic_inc(&mp->stats.xid_not_found);
49425+ atomic_inc_unchecked(&mp->stats.xid_not_found);
49426 goto rel;
49427 }
49428 if (ep->rxid == FC_XID_UNKNOWN)
49429 ep->rxid = ntohs(fh->fh_rx_id);
49430 if (ep->sid != 0 && ep->sid != ntoh24(fh->fh_d_id)) {
49431- atomic_inc(&mp->stats.xid_not_found);
49432+ atomic_inc_unchecked(&mp->stats.xid_not_found);
49433 goto rel;
49434 }
49435 if (ep->did != ntoh24(fh->fh_s_id) &&
49436 ep->did != FC_FID_FLOGI) {
49437- atomic_inc(&mp->stats.xid_not_found);
49438+ atomic_inc_unchecked(&mp->stats.xid_not_found);
49439 goto rel;
49440 }
49441 sof = fr_sof(fp);
49442@@ -1557,7 +1557,7 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
49443 sp->ssb_stat |= SSB_ST_RESP;
49444 sp->id = fh->fh_seq_id;
49445 } else if (sp->id != fh->fh_seq_id) {
49446- atomic_inc(&mp->stats.seq_not_found);
49447+ atomic_inc_unchecked(&mp->stats.seq_not_found);
49448 goto rel;
49449 }
49450
49451@@ -1619,9 +1619,9 @@ static void fc_exch_recv_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
49452 sp = fc_seq_lookup_orig(mp, fp); /* doesn't hold sequence */
49453
49454 if (!sp)
49455- atomic_inc(&mp->stats.xid_not_found);
49456+ atomic_inc_unchecked(&mp->stats.xid_not_found);
49457 else
49458- atomic_inc(&mp->stats.non_bls_resp);
49459+ atomic_inc_unchecked(&mp->stats.non_bls_resp);
49460
49461 fc_frame_free(fp);
49462 }
49463@@ -2261,13 +2261,13 @@ void fc_exch_update_stats(struct fc_lport *lport)
49464
49465 list_for_each_entry(ema, &lport->ema_list, ema_list) {
49466 mp = ema->mp;
49467- st->fc_no_free_exch += atomic_read(&mp->stats.no_free_exch);
49468+ st->fc_no_free_exch += atomic_read_unchecked(&mp->stats.no_free_exch);
49469 st->fc_no_free_exch_xid +=
49470- atomic_read(&mp->stats.no_free_exch_xid);
49471- st->fc_xid_not_found += atomic_read(&mp->stats.xid_not_found);
49472- st->fc_xid_busy += atomic_read(&mp->stats.xid_busy);
49473- st->fc_seq_not_found += atomic_read(&mp->stats.seq_not_found);
49474- st->fc_non_bls_resp += atomic_read(&mp->stats.non_bls_resp);
49475+ atomic_read_unchecked(&mp->stats.no_free_exch_xid);
49476+ st->fc_xid_not_found += atomic_read_unchecked(&mp->stats.xid_not_found);
49477+ st->fc_xid_busy += atomic_read_unchecked(&mp->stats.xid_busy);
49478+ st->fc_seq_not_found += atomic_read_unchecked(&mp->stats.seq_not_found);
49479+ st->fc_non_bls_resp += atomic_read_unchecked(&mp->stats.non_bls_resp);
49480 }
49481 }
49482 EXPORT_SYMBOL(fc_exch_update_stats);
49483diff --git a/drivers/scsi/libsas/sas_ata.c b/drivers/scsi/libsas/sas_ata.c
49484index d289583..b745eec 100644
49485--- a/drivers/scsi/libsas/sas_ata.c
49486+++ b/drivers/scsi/libsas/sas_ata.c
49487@@ -554,7 +554,7 @@ static struct ata_port_operations sas_sata_ops = {
49488 .postreset = ata_std_postreset,
49489 .error_handler = ata_std_error_handler,
49490 .post_internal_cmd = sas_ata_post_internal,
49491- .qc_defer = ata_std_qc_defer,
49492+ .qc_defer = ata_std_qc_defer,
49493 .qc_prep = ata_noop_qc_prep,
49494 .qc_issue = sas_ata_qc_issue,
49495 .qc_fill_rtf = sas_ata_qc_fill_rtf,
49496diff --git a/drivers/scsi/lpfc/lpfc.h b/drivers/scsi/lpfc/lpfc.h
49497index 4e1b75c..0bbdfa9 100644
49498--- a/drivers/scsi/lpfc/lpfc.h
49499+++ b/drivers/scsi/lpfc/lpfc.h
49500@@ -432,7 +432,7 @@ struct lpfc_vport {
49501 struct dentry *debug_nodelist;
49502 struct dentry *vport_debugfs_root;
49503 struct lpfc_debugfs_trc *disc_trc;
49504- atomic_t disc_trc_cnt;
49505+ atomic_unchecked_t disc_trc_cnt;
49506 #endif
49507 uint8_t stat_data_enabled;
49508 uint8_t stat_data_blocked;
49509@@ -865,8 +865,8 @@ struct lpfc_hba {
49510 struct timer_list fabric_block_timer;
49511 unsigned long bit_flags;
49512 #define FABRIC_COMANDS_BLOCKED 0
49513- atomic_t num_rsrc_err;
49514- atomic_t num_cmd_success;
49515+ atomic_unchecked_t num_rsrc_err;
49516+ atomic_unchecked_t num_cmd_success;
49517 unsigned long last_rsrc_error_time;
49518 unsigned long last_ramp_down_time;
49519 unsigned long last_ramp_up_time;
49520@@ -902,7 +902,7 @@ struct lpfc_hba {
49521
49522 struct dentry *debug_slow_ring_trc;
49523 struct lpfc_debugfs_trc *slow_ring_trc;
49524- atomic_t slow_ring_trc_cnt;
49525+ atomic_unchecked_t slow_ring_trc_cnt;
49526 /* iDiag debugfs sub-directory */
49527 struct dentry *idiag_root;
49528 struct dentry *idiag_pci_cfg;
49529diff --git a/drivers/scsi/lpfc/lpfc_debugfs.c b/drivers/scsi/lpfc/lpfc_debugfs.c
49530index b800cc9..16b6a91 100644
49531--- a/drivers/scsi/lpfc/lpfc_debugfs.c
49532+++ b/drivers/scsi/lpfc/lpfc_debugfs.c
49533@@ -106,7 +106,7 @@ MODULE_PARM_DESC(lpfc_debugfs_mask_disc_trc,
49534
49535 #include <linux/debugfs.h>
49536
49537-static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
49538+static atomic_unchecked_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
49539 static unsigned long lpfc_debugfs_start_time = 0L;
49540
49541 /* iDiag */
49542@@ -147,7 +147,7 @@ lpfc_debugfs_disc_trc_data(struct lpfc_vport *vport, char *buf, int size)
49543 lpfc_debugfs_enable = 0;
49544
49545 len = 0;
49546- index = (atomic_read(&vport->disc_trc_cnt) + 1) &
49547+ index = (atomic_read_unchecked(&vport->disc_trc_cnt) + 1) &
49548 (lpfc_debugfs_max_disc_trc - 1);
49549 for (i = index; i < lpfc_debugfs_max_disc_trc; i++) {
49550 dtp = vport->disc_trc + i;
49551@@ -213,7 +213,7 @@ lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba *phba, char *buf, int size)
49552 lpfc_debugfs_enable = 0;
49553
49554 len = 0;
49555- index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
49556+ index = (atomic_read_unchecked(&phba->slow_ring_trc_cnt) + 1) &
49557 (lpfc_debugfs_max_slow_ring_trc - 1);
49558 for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
49559 dtp = phba->slow_ring_trc + i;
49560@@ -646,14 +646,14 @@ lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
49561 !vport || !vport->disc_trc)
49562 return;
49563
49564- index = atomic_inc_return(&vport->disc_trc_cnt) &
49565+ index = atomic_inc_return_unchecked(&vport->disc_trc_cnt) &
49566 (lpfc_debugfs_max_disc_trc - 1);
49567 dtp = vport->disc_trc + index;
49568 dtp->fmt = fmt;
49569 dtp->data1 = data1;
49570 dtp->data2 = data2;
49571 dtp->data3 = data3;
49572- dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
49573+ dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
49574 dtp->jif = jiffies;
49575 #endif
49576 return;
49577@@ -684,14 +684,14 @@ lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
49578 !phba || !phba->slow_ring_trc)
49579 return;
49580
49581- index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
49582+ index = atomic_inc_return_unchecked(&phba->slow_ring_trc_cnt) &
49583 (lpfc_debugfs_max_slow_ring_trc - 1);
49584 dtp = phba->slow_ring_trc + index;
49585 dtp->fmt = fmt;
49586 dtp->data1 = data1;
49587 dtp->data2 = data2;
49588 dtp->data3 = data3;
49589- dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
49590+ dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
49591 dtp->jif = jiffies;
49592 #endif
49593 return;
49594@@ -4168,7 +4168,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
49595 "slow_ring buffer\n");
49596 goto debug_failed;
49597 }
49598- atomic_set(&phba->slow_ring_trc_cnt, 0);
49599+ atomic_set_unchecked(&phba->slow_ring_trc_cnt, 0);
49600 memset(phba->slow_ring_trc, 0,
49601 (sizeof(struct lpfc_debugfs_trc) *
49602 lpfc_debugfs_max_slow_ring_trc));
49603@@ -4214,7 +4214,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
49604 "buffer\n");
49605 goto debug_failed;
49606 }
49607- atomic_set(&vport->disc_trc_cnt, 0);
49608+ atomic_set_unchecked(&vport->disc_trc_cnt, 0);
49609
49610 snprintf(name, sizeof(name), "discovery_trace");
49611 vport->debug_disc_trc =
49612diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
49613index 68c94cc..8c27be5 100644
49614--- a/drivers/scsi/lpfc/lpfc_init.c
49615+++ b/drivers/scsi/lpfc/lpfc_init.c
49616@@ -10949,8 +10949,10 @@ lpfc_init(void)
49617 "misc_register returned with status %d", error);
49618
49619 if (lpfc_enable_npiv) {
49620- lpfc_transport_functions.vport_create = lpfc_vport_create;
49621- lpfc_transport_functions.vport_delete = lpfc_vport_delete;
49622+ pax_open_kernel();
49623+ *(void **)&lpfc_transport_functions.vport_create = lpfc_vport_create;
49624+ *(void **)&lpfc_transport_functions.vport_delete = lpfc_vport_delete;
49625+ pax_close_kernel();
49626 }
49627 lpfc_transport_template =
49628 fc_attach_transport(&lpfc_transport_functions);
49629diff --git a/drivers/scsi/lpfc/lpfc_scsi.c b/drivers/scsi/lpfc/lpfc_scsi.c
49630index b2ede05..aaf482ca 100644
49631--- a/drivers/scsi/lpfc/lpfc_scsi.c
49632+++ b/drivers/scsi/lpfc/lpfc_scsi.c
49633@@ -353,7 +353,7 @@ lpfc_rampdown_queue_depth(struct lpfc_hba *phba)
49634 uint32_t evt_posted;
49635
49636 spin_lock_irqsave(&phba->hbalock, flags);
49637- atomic_inc(&phba->num_rsrc_err);
49638+ atomic_inc_unchecked(&phba->num_rsrc_err);
49639 phba->last_rsrc_error_time = jiffies;
49640
49641 if ((phba->last_ramp_down_time + QUEUE_RAMP_DOWN_INTERVAL) > jiffies) {
49642@@ -394,7 +394,7 @@ lpfc_rampup_queue_depth(struct lpfc_vport *vport,
49643 unsigned long flags;
49644 struct lpfc_hba *phba = vport->phba;
49645 uint32_t evt_posted;
49646- atomic_inc(&phba->num_cmd_success);
49647+ atomic_inc_unchecked(&phba->num_cmd_success);
49648
49649 if (vport->cfg_lun_queue_depth <= queue_depth)
49650 return;
49651@@ -438,8 +438,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
49652 unsigned long num_rsrc_err, num_cmd_success;
49653 int i;
49654
49655- num_rsrc_err = atomic_read(&phba->num_rsrc_err);
49656- num_cmd_success = atomic_read(&phba->num_cmd_success);
49657+ num_rsrc_err = atomic_read_unchecked(&phba->num_rsrc_err);
49658+ num_cmd_success = atomic_read_unchecked(&phba->num_cmd_success);
49659
49660 /*
49661 * The error and success command counters are global per
49662@@ -467,8 +467,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
49663 }
49664 }
49665 lpfc_destroy_vport_work_array(phba, vports);
49666- atomic_set(&phba->num_rsrc_err, 0);
49667- atomic_set(&phba->num_cmd_success, 0);
49668+ atomic_set_unchecked(&phba->num_rsrc_err, 0);
49669+ atomic_set_unchecked(&phba->num_cmd_success, 0);
49670 }
49671
49672 /**
49673@@ -502,8 +502,8 @@ lpfc_ramp_up_queue_handler(struct lpfc_hba *phba)
49674 }
49675 }
49676 lpfc_destroy_vport_work_array(phba, vports);
49677- atomic_set(&phba->num_rsrc_err, 0);
49678- atomic_set(&phba->num_cmd_success, 0);
49679+ atomic_set_unchecked(&phba->num_rsrc_err, 0);
49680+ atomic_set_unchecked(&phba->num_cmd_success, 0);
49681 }
49682
49683 /**
49684diff --git a/drivers/scsi/mpt2sas/mpt2sas_scsih.c b/drivers/scsi/mpt2sas/mpt2sas_scsih.c
49685index 6fd7d40..b444223 100644
49686--- a/drivers/scsi/mpt2sas/mpt2sas_scsih.c
49687+++ b/drivers/scsi/mpt2sas/mpt2sas_scsih.c
49688@@ -1557,7 +1557,7 @@ _scsih_get_resync(struct device *dev)
49689 {
49690 struct scsi_device *sdev = to_scsi_device(dev);
49691 struct MPT2SAS_ADAPTER *ioc = shost_priv(sdev->host);
49692- static struct _raid_device *raid_device;
49693+ struct _raid_device *raid_device;
49694 unsigned long flags;
49695 Mpi2RaidVolPage0_t vol_pg0;
49696 Mpi2ConfigReply_t mpi_reply;
49697@@ -1609,7 +1609,7 @@ _scsih_get_state(struct device *dev)
49698 {
49699 struct scsi_device *sdev = to_scsi_device(dev);
49700 struct MPT2SAS_ADAPTER *ioc = shost_priv(sdev->host);
49701- static struct _raid_device *raid_device;
49702+ struct _raid_device *raid_device;
49703 unsigned long flags;
49704 Mpi2RaidVolPage0_t vol_pg0;
49705 Mpi2ConfigReply_t mpi_reply;
49706@@ -6637,7 +6637,7 @@ _scsih_sas_ir_operation_status_event(struct MPT2SAS_ADAPTER *ioc,
49707 struct fw_event_work *fw_event)
49708 {
49709 Mpi2EventDataIrOperationStatus_t *event_data = fw_event->event_data;
49710- static struct _raid_device *raid_device;
49711+ struct _raid_device *raid_device;
49712 unsigned long flags;
49713 u16 handle;
49714
49715@@ -7108,7 +7108,7 @@ _scsih_scan_for_devices_after_reset(struct MPT2SAS_ADAPTER *ioc)
49716 u64 sas_address;
49717 struct _sas_device *sas_device;
49718 struct _sas_node *expander_device;
49719- static struct _raid_device *raid_device;
49720+ struct _raid_device *raid_device;
49721 u8 retry_count;
49722 unsigned long flags;
49723
49724diff --git a/drivers/scsi/pmcraid.c b/drivers/scsi/pmcraid.c
49725index be8ce54..94ed33a 100644
49726--- a/drivers/scsi/pmcraid.c
49727+++ b/drivers/scsi/pmcraid.c
49728@@ -200,8 +200,8 @@ static int pmcraid_slave_alloc(struct scsi_device *scsi_dev)
49729 res->scsi_dev = scsi_dev;
49730 scsi_dev->hostdata = res;
49731 res->change_detected = 0;
49732- atomic_set(&res->read_failures, 0);
49733- atomic_set(&res->write_failures, 0);
49734+ atomic_set_unchecked(&res->read_failures, 0);
49735+ atomic_set_unchecked(&res->write_failures, 0);
49736 rc = 0;
49737 }
49738 spin_unlock_irqrestore(&pinstance->resource_lock, lock_flags);
49739@@ -2687,9 +2687,9 @@ static int pmcraid_error_handler(struct pmcraid_cmd *cmd)
49740
49741 /* If this was a SCSI read/write command keep count of errors */
49742 if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_READ_CMD)
49743- atomic_inc(&res->read_failures);
49744+ atomic_inc_unchecked(&res->read_failures);
49745 else if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_WRITE_CMD)
49746- atomic_inc(&res->write_failures);
49747+ atomic_inc_unchecked(&res->write_failures);
49748
49749 if (!RES_IS_GSCSI(res->cfg_entry) &&
49750 masked_ioasc != PMCRAID_IOASC_HW_DEVICE_BUS_STATUS_ERROR) {
49751@@ -3545,7 +3545,7 @@ static int pmcraid_queuecommand_lck(
49752 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
49753 * hrrq_id assigned here in queuecommand
49754 */
49755- ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
49756+ ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
49757 pinstance->num_hrrq;
49758 cmd->cmd_done = pmcraid_io_done;
49759
49760@@ -3857,7 +3857,7 @@ static long pmcraid_ioctl_passthrough(
49761 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
49762 * hrrq_id assigned here in queuecommand
49763 */
49764- ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
49765+ ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
49766 pinstance->num_hrrq;
49767
49768 if (request_size) {
49769@@ -4495,7 +4495,7 @@ static void pmcraid_worker_function(struct work_struct *workp)
49770
49771 pinstance = container_of(workp, struct pmcraid_instance, worker_q);
49772 /* add resources only after host is added into system */
49773- if (!atomic_read(&pinstance->expose_resources))
49774+ if (!atomic_read_unchecked(&pinstance->expose_resources))
49775 return;
49776
49777 fw_version = be16_to_cpu(pinstance->inq_data->fw_version);
49778@@ -5322,8 +5322,8 @@ static int pmcraid_init_instance(struct pci_dev *pdev, struct Scsi_Host *host,
49779 init_waitqueue_head(&pinstance->reset_wait_q);
49780
49781 atomic_set(&pinstance->outstanding_cmds, 0);
49782- atomic_set(&pinstance->last_message_id, 0);
49783- atomic_set(&pinstance->expose_resources, 0);
49784+ atomic_set_unchecked(&pinstance->last_message_id, 0);
49785+ atomic_set_unchecked(&pinstance->expose_resources, 0);
49786
49787 INIT_LIST_HEAD(&pinstance->free_res_q);
49788 INIT_LIST_HEAD(&pinstance->used_res_q);
49789@@ -6036,7 +6036,7 @@ static int pmcraid_probe(struct pci_dev *pdev,
49790 /* Schedule worker thread to handle CCN and take care of adding and
49791 * removing devices to OS
49792 */
49793- atomic_set(&pinstance->expose_resources, 1);
49794+ atomic_set_unchecked(&pinstance->expose_resources, 1);
49795 schedule_work(&pinstance->worker_q);
49796 return rc;
49797
49798diff --git a/drivers/scsi/pmcraid.h b/drivers/scsi/pmcraid.h
49799index e1d150f..6c6df44 100644
49800--- a/drivers/scsi/pmcraid.h
49801+++ b/drivers/scsi/pmcraid.h
49802@@ -748,7 +748,7 @@ struct pmcraid_instance {
49803 struct pmcraid_isr_param hrrq_vector[PMCRAID_NUM_MSIX_VECTORS];
49804
49805 /* Message id as filled in last fired IOARCB, used to identify HRRQ */
49806- atomic_t last_message_id;
49807+ atomic_unchecked_t last_message_id;
49808
49809 /* configuration table */
49810 struct pmcraid_config_table *cfg_table;
49811@@ -777,7 +777,7 @@ struct pmcraid_instance {
49812 atomic_t outstanding_cmds;
49813
49814 /* should add/delete resources to mid-layer now ?*/
49815- atomic_t expose_resources;
49816+ atomic_unchecked_t expose_resources;
49817
49818
49819
49820@@ -813,8 +813,8 @@ struct pmcraid_resource_entry {
49821 struct pmcraid_config_table_entry_ext cfg_entry_ext;
49822 };
49823 struct scsi_device *scsi_dev; /* Link scsi_device structure */
49824- atomic_t read_failures; /* count of failed READ commands */
49825- atomic_t write_failures; /* count of failed WRITE commands */
49826+ atomic_unchecked_t read_failures; /* count of failed READ commands */
49827+ atomic_unchecked_t write_failures; /* count of failed WRITE commands */
49828
49829 /* To indicate add/delete/modify during CCN */
49830 u8 change_detected;
49831diff --git a/drivers/scsi/qla2xxx/qla_attr.c b/drivers/scsi/qla2xxx/qla_attr.c
49832index 4a0d7c9..3d658d7 100644
49833--- a/drivers/scsi/qla2xxx/qla_attr.c
49834+++ b/drivers/scsi/qla2xxx/qla_attr.c
49835@@ -2038,7 +2038,7 @@ qla24xx_vport_disable(struct fc_vport *fc_vport, bool disable)
49836 return 0;
49837 }
49838
49839-struct fc_function_template qla2xxx_transport_functions = {
49840+fc_function_template_no_const qla2xxx_transport_functions = {
49841
49842 .show_host_node_name = 1,
49843 .show_host_port_name = 1,
49844@@ -2086,7 +2086,7 @@ struct fc_function_template qla2xxx_transport_functions = {
49845 .bsg_timeout = qla24xx_bsg_timeout,
49846 };
49847
49848-struct fc_function_template qla2xxx_transport_vport_functions = {
49849+fc_function_template_no_const qla2xxx_transport_vport_functions = {
49850
49851 .show_host_node_name = 1,
49852 .show_host_port_name = 1,
49853diff --git a/drivers/scsi/qla2xxx/qla_gbl.h b/drivers/scsi/qla2xxx/qla_gbl.h
49854index 1f42662..bf9836c 100644
49855--- a/drivers/scsi/qla2xxx/qla_gbl.h
49856+++ b/drivers/scsi/qla2xxx/qla_gbl.h
49857@@ -546,8 +546,8 @@ extern void qla2x00_get_sym_node_name(scsi_qla_host_t *, uint8_t *);
49858 struct device_attribute;
49859 extern struct device_attribute *qla2x00_host_attrs[];
49860 struct fc_function_template;
49861-extern struct fc_function_template qla2xxx_transport_functions;
49862-extern struct fc_function_template qla2xxx_transport_vport_functions;
49863+extern fc_function_template_no_const qla2xxx_transport_functions;
49864+extern fc_function_template_no_const qla2xxx_transport_vport_functions;
49865 extern void qla2x00_alloc_sysfs_attr(scsi_qla_host_t *);
49866 extern void qla2x00_free_sysfs_attr(scsi_qla_host_t *, bool);
49867 extern void qla2x00_init_host_attr(scsi_qla_host_t *);
49868diff --git a/drivers/scsi/qla2xxx/qla_os.c b/drivers/scsi/qla2xxx/qla_os.c
49869index 83cb612..9b7b08c 100644
49870--- a/drivers/scsi/qla2xxx/qla_os.c
49871+++ b/drivers/scsi/qla2xxx/qla_os.c
49872@@ -1491,8 +1491,10 @@ qla2x00_config_dma_addressing(struct qla_hw_data *ha)
49873 !pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) {
49874 /* Ok, a 64bit DMA mask is applicable. */
49875 ha->flags.enable_64bit_addressing = 1;
49876- ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
49877- ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
49878+ pax_open_kernel();
49879+ *(void **)&ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
49880+ *(void **)&ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
49881+ pax_close_kernel();
49882 return;
49883 }
49884 }
49885diff --git a/drivers/scsi/qla4xxx/ql4_def.h b/drivers/scsi/qla4xxx/ql4_def.h
49886index aa67bb9..06d0e2a 100644
49887--- a/drivers/scsi/qla4xxx/ql4_def.h
49888+++ b/drivers/scsi/qla4xxx/ql4_def.h
49889@@ -303,7 +303,7 @@ struct ddb_entry {
49890 * (4000 only) */
49891 atomic_t relogin_timer; /* Max Time to wait for
49892 * relogin to complete */
49893- atomic_t relogin_retry_count; /* Num of times relogin has been
49894+ atomic_unchecked_t relogin_retry_count; /* Num of times relogin has been
49895 * retried */
49896 uint32_t default_time2wait; /* Default Min time between
49897 * relogins (+aens) */
49898diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c
49899index c21adc3..1b4155f 100644
49900--- a/drivers/scsi/qla4xxx/ql4_os.c
49901+++ b/drivers/scsi/qla4xxx/ql4_os.c
49902@@ -4463,12 +4463,12 @@ static void qla4xxx_check_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
49903 */
49904 if (!iscsi_is_session_online(cls_sess)) {
49905 /* Reset retry relogin timer */
49906- atomic_inc(&ddb_entry->relogin_retry_count);
49907+ atomic_inc_unchecked(&ddb_entry->relogin_retry_count);
49908 DEBUG2(ql4_printk(KERN_INFO, ha,
49909 "%s: index[%d] relogin timed out-retrying"
49910 " relogin (%d), retry (%d)\n", __func__,
49911 ddb_entry->fw_ddb_index,
49912- atomic_read(&ddb_entry->relogin_retry_count),
49913+ atomic_read_unchecked(&ddb_entry->relogin_retry_count),
49914 ddb_entry->default_time2wait + 4));
49915 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
49916 atomic_set(&ddb_entry->retry_relogin_timer,
49917@@ -6552,7 +6552,7 @@ static void qla4xxx_setup_flash_ddb_entry(struct scsi_qla_host *ha,
49918
49919 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
49920 atomic_set(&ddb_entry->relogin_timer, 0);
49921- atomic_set(&ddb_entry->relogin_retry_count, 0);
49922+ atomic_set_unchecked(&ddb_entry->relogin_retry_count, 0);
49923 def_timeout = le16_to_cpu(ddb_entry->fw_ddb_entry.def_timeout);
49924 ddb_entry->default_relogin_timeout =
49925 (def_timeout > LOGIN_TOV) && (def_timeout < LOGIN_TOV * 10) ?
49926diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
49927index d8afec8..3ec7152 100644
49928--- a/drivers/scsi/scsi.c
49929+++ b/drivers/scsi/scsi.c
49930@@ -658,7 +658,7 @@ int scsi_dispatch_cmd(struct scsi_cmnd *cmd)
49931 struct Scsi_Host *host = cmd->device->host;
49932 int rtn = 0;
49933
49934- atomic_inc(&cmd->device->iorequest_cnt);
49935+ atomic_inc_unchecked(&cmd->device->iorequest_cnt);
49936
49937 /* check if the device is still usable */
49938 if (unlikely(cmd->device->sdev_state == SDEV_DEL)) {
49939diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
49940index 62ec84b..93159d8 100644
49941--- a/drivers/scsi/scsi_lib.c
49942+++ b/drivers/scsi/scsi_lib.c
49943@@ -1474,7 +1474,7 @@ static void scsi_kill_request(struct request *req, struct request_queue *q)
49944 shost = sdev->host;
49945 scsi_init_cmd_errh(cmd);
49946 cmd->result = DID_NO_CONNECT << 16;
49947- atomic_inc(&cmd->device->iorequest_cnt);
49948+ atomic_inc_unchecked(&cmd->device->iorequest_cnt);
49949
49950 /*
49951 * SCSI request completion path will do scsi_device_unbusy(),
49952@@ -1500,9 +1500,9 @@ static void scsi_softirq_done(struct request *rq)
49953
49954 INIT_LIST_HEAD(&cmd->eh_entry);
49955
49956- atomic_inc(&cmd->device->iodone_cnt);
49957+ atomic_inc_unchecked(&cmd->device->iodone_cnt);
49958 if (cmd->result)
49959- atomic_inc(&cmd->device->ioerr_cnt);
49960+ atomic_inc_unchecked(&cmd->device->ioerr_cnt);
49961
49962 disposition = scsi_decide_disposition(cmd);
49963 if (disposition != SUCCESS &&
49964diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
49965index 9117d0b..d289a7a 100644
49966--- a/drivers/scsi/scsi_sysfs.c
49967+++ b/drivers/scsi/scsi_sysfs.c
49968@@ -739,7 +739,7 @@ show_iostat_##field(struct device *dev, struct device_attribute *attr, \
49969 char *buf) \
49970 { \
49971 struct scsi_device *sdev = to_scsi_device(dev); \
49972- unsigned long long count = atomic_read(&sdev->field); \
49973+ unsigned long long count = atomic_read_unchecked(&sdev->field); \
49974 return snprintf(buf, 20, "0x%llx\n", count); \
49975 } \
49976 static DEVICE_ATTR(field, S_IRUGO, show_iostat_##field, NULL)
49977diff --git a/drivers/scsi/scsi_tgt_lib.c b/drivers/scsi/scsi_tgt_lib.c
49978index 84a1fdf..693b0d6 100644
49979--- a/drivers/scsi/scsi_tgt_lib.c
49980+++ b/drivers/scsi/scsi_tgt_lib.c
49981@@ -362,7 +362,7 @@ static int scsi_map_user_pages(struct scsi_tgt_cmd *tcmd, struct scsi_cmnd *cmd,
49982 int err;
49983
49984 dprintk("%lx %u\n", uaddr, len);
49985- err = blk_rq_map_user(q, rq, NULL, (void *)uaddr, len, GFP_KERNEL);
49986+ err = blk_rq_map_user(q, rq, NULL, (void __user *)uaddr, len, GFP_KERNEL);
49987 if (err) {
49988 /*
49989 * TODO: need to fixup sg_tablesize, max_segment_size,
49990diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
49991index 4628fd5..a94a1c2 100644
49992--- a/drivers/scsi/scsi_transport_fc.c
49993+++ b/drivers/scsi/scsi_transport_fc.c
49994@@ -497,7 +497,7 @@ static DECLARE_TRANSPORT_CLASS(fc_vport_class,
49995 * Netlink Infrastructure
49996 */
49997
49998-static atomic_t fc_event_seq;
49999+static atomic_unchecked_t fc_event_seq;
50000
50001 /**
50002 * fc_get_event_number - Obtain the next sequential FC event number
50003@@ -510,7 +510,7 @@ static atomic_t fc_event_seq;
50004 u32
50005 fc_get_event_number(void)
50006 {
50007- return atomic_add_return(1, &fc_event_seq);
50008+ return atomic_add_return_unchecked(1, &fc_event_seq);
50009 }
50010 EXPORT_SYMBOL(fc_get_event_number);
50011
50012@@ -654,7 +654,7 @@ static __init int fc_transport_init(void)
50013 {
50014 int error;
50015
50016- atomic_set(&fc_event_seq, 0);
50017+ atomic_set_unchecked(&fc_event_seq, 0);
50018
50019 error = transport_class_register(&fc_host_class);
50020 if (error)
50021@@ -844,7 +844,7 @@ static int fc_str_to_dev_loss(const char *buf, unsigned long *val)
50022 char *cp;
50023
50024 *val = simple_strtoul(buf, &cp, 0);
50025- if ((*cp && (*cp != '\n')) || (*val < 0))
50026+ if (*cp && (*cp != '\n'))
50027 return -EINVAL;
50028 /*
50029 * Check for overflow; dev_loss_tmo is u32
50030diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c
50031index fd8ffe6..fd0bebf 100644
50032--- a/drivers/scsi/scsi_transport_iscsi.c
50033+++ b/drivers/scsi/scsi_transport_iscsi.c
50034@@ -79,7 +79,7 @@ struct iscsi_internal {
50035 struct transport_container session_cont;
50036 };
50037
50038-static atomic_t iscsi_session_nr; /* sysfs session id for next new session */
50039+static atomic_unchecked_t iscsi_session_nr; /* sysfs session id for next new session */
50040 static struct workqueue_struct *iscsi_eh_timer_workq;
50041
50042 static DEFINE_IDA(iscsi_sess_ida);
50043@@ -2071,7 +2071,7 @@ int iscsi_add_session(struct iscsi_cls_session *session, unsigned int target_id)
50044 int err;
50045
50046 ihost = shost->shost_data;
50047- session->sid = atomic_add_return(1, &iscsi_session_nr);
50048+ session->sid = atomic_add_return_unchecked(1, &iscsi_session_nr);
50049
50050 if (target_id == ISCSI_MAX_TARGET) {
50051 id = ida_simple_get(&iscsi_sess_ida, 0, 0, GFP_KERNEL);
50052@@ -4511,7 +4511,7 @@ static __init int iscsi_transport_init(void)
50053 printk(KERN_INFO "Loading iSCSI transport class v%s.\n",
50054 ISCSI_TRANSPORT_VERSION);
50055
50056- atomic_set(&iscsi_session_nr, 0);
50057+ atomic_set_unchecked(&iscsi_session_nr, 0);
50058
50059 err = class_register(&iscsi_transport_class);
50060 if (err)
50061diff --git a/drivers/scsi/scsi_transport_srp.c b/drivers/scsi/scsi_transport_srp.c
50062index d47ffc8..30f46a9 100644
50063--- a/drivers/scsi/scsi_transport_srp.c
50064+++ b/drivers/scsi/scsi_transport_srp.c
50065@@ -36,7 +36,7 @@
50066 #include "scsi_transport_srp_internal.h"
50067
50068 struct srp_host_attrs {
50069- atomic_t next_port_id;
50070+ atomic_unchecked_t next_port_id;
50071 };
50072 #define to_srp_host_attrs(host) ((struct srp_host_attrs *)(host)->shost_data)
50073
50074@@ -101,7 +101,7 @@ static int srp_host_setup(struct transport_container *tc, struct device *dev,
50075 struct Scsi_Host *shost = dev_to_shost(dev);
50076 struct srp_host_attrs *srp_host = to_srp_host_attrs(shost);
50077
50078- atomic_set(&srp_host->next_port_id, 0);
50079+ atomic_set_unchecked(&srp_host->next_port_id, 0);
50080 return 0;
50081 }
50082
50083@@ -734,7 +734,7 @@ struct srp_rport *srp_rport_add(struct Scsi_Host *shost,
50084 rport_fast_io_fail_timedout);
50085 INIT_DELAYED_WORK(&rport->dev_loss_work, rport_dev_loss_timedout);
50086
50087- id = atomic_inc_return(&to_srp_host_attrs(shost)->next_port_id);
50088+ id = atomic_inc_return_unchecked(&to_srp_host_attrs(shost)->next_port_id);
50089 dev_set_name(&rport->dev, "port-%d:%d", shost->host_no, id);
50090
50091 transport_setup_device(&rport->dev);
50092diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
50093index 36d1a23..3f33303 100644
50094--- a/drivers/scsi/sd.c
50095+++ b/drivers/scsi/sd.c
50096@@ -2962,7 +2962,7 @@ static int sd_probe(struct device *dev)
50097 sdkp->disk = gd;
50098 sdkp->index = index;
50099 atomic_set(&sdkp->openers, 0);
50100- atomic_set(&sdkp->device->ioerr_cnt, 0);
50101+ atomic_set_unchecked(&sdkp->device->ioerr_cnt, 0);
50102
50103 if (!sdp->request_queue->rq_timeout) {
50104 if (sdp->type != TYPE_MOD)
50105diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
50106index df5e961..df6b97f 100644
50107--- a/drivers/scsi/sg.c
50108+++ b/drivers/scsi/sg.c
50109@@ -1102,7 +1102,7 @@ sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg)
50110 sdp->disk->disk_name,
50111 MKDEV(SCSI_GENERIC_MAJOR, sdp->index),
50112 NULL,
50113- (char *)arg);
50114+ (char __user *)arg);
50115 case BLKTRACESTART:
50116 return blk_trace_startstop(sdp->device->request_queue, 1);
50117 case BLKTRACESTOP:
50118diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
50119index d0b28bb..a263613 100644
50120--- a/drivers/spi/spi.c
50121+++ b/drivers/spi/spi.c
50122@@ -1971,7 +1971,7 @@ int spi_bus_unlock(struct spi_master *master)
50123 EXPORT_SYMBOL_GPL(spi_bus_unlock);
50124
50125 /* portable code must never pass more than 32 bytes */
50126-#define SPI_BUFSIZ max(32, SMP_CACHE_BYTES)
50127+#define SPI_BUFSIZ max(32UL, SMP_CACHE_BYTES)
50128
50129 static u8 *buf;
50130
50131diff --git a/drivers/staging/android/timed_output.c b/drivers/staging/android/timed_output.c
50132index 2c61783..4d49e4e 100644
50133--- a/drivers/staging/android/timed_output.c
50134+++ b/drivers/staging/android/timed_output.c
50135@@ -25,7 +25,7 @@
50136 #include "timed_output.h"
50137
50138 static struct class *timed_output_class;
50139-static atomic_t device_count;
50140+static atomic_unchecked_t device_count;
50141
50142 static ssize_t enable_show(struct device *dev, struct device_attribute *attr,
50143 char *buf)
50144@@ -63,7 +63,7 @@ static int create_timed_output_class(void)
50145 timed_output_class = class_create(THIS_MODULE, "timed_output");
50146 if (IS_ERR(timed_output_class))
50147 return PTR_ERR(timed_output_class);
50148- atomic_set(&device_count, 0);
50149+ atomic_set_unchecked(&device_count, 0);
50150 timed_output_class->dev_groups = timed_output_groups;
50151 }
50152
50153@@ -81,7 +81,7 @@ int timed_output_dev_register(struct timed_output_dev *tdev)
50154 if (ret < 0)
50155 return ret;
50156
50157- tdev->index = atomic_inc_return(&device_count);
50158+ tdev->index = atomic_inc_return_unchecked(&device_count);
50159 tdev->dev = device_create(timed_output_class, NULL,
50160 MKDEV(0, tdev->index), NULL, "%s", tdev->name);
50161 if (IS_ERR(tdev->dev))
50162diff --git a/drivers/staging/gdm724x/gdm_tty.c b/drivers/staging/gdm724x/gdm_tty.c
50163index fe47cd3..19a1bd1 100644
50164--- a/drivers/staging/gdm724x/gdm_tty.c
50165+++ b/drivers/staging/gdm724x/gdm_tty.c
50166@@ -44,7 +44,7 @@
50167 #define gdm_tty_send_control(n, r, v, d, l) (\
50168 n->tty_dev->send_control(n->tty_dev->priv_dev, r, v, d, l))
50169
50170-#define GDM_TTY_READY(gdm) (gdm && gdm->tty_dev && gdm->port.count)
50171+#define GDM_TTY_READY(gdm) (gdm && gdm->tty_dev && atomic_read(&gdm->port.count))
50172
50173 static struct tty_driver *gdm_driver[TTY_MAX_COUNT];
50174 static struct gdm *gdm_table[TTY_MAX_COUNT][GDM_TTY_MINOR];
50175diff --git a/drivers/staging/imx-drm/imx-drm-core.c b/drivers/staging/imx-drm/imx-drm-core.c
50176index 236ed66..dd9cd74 100644
50177--- a/drivers/staging/imx-drm/imx-drm-core.c
50178+++ b/drivers/staging/imx-drm/imx-drm-core.c
50179@@ -488,7 +488,7 @@ int imx_drm_add_crtc(struct drm_crtc *crtc,
50180 goto err_busy;
50181 }
50182
50183- if (imxdrm->drm->open_count) {
50184+ if (local_read(&imxdrm->drm->open_count)) {
50185 ret = -EBUSY;
50186 goto err_busy;
50187 }
50188@@ -576,7 +576,7 @@ int imx_drm_add_encoder(struct drm_encoder *encoder,
50189
50190 mutex_lock(&imxdrm->mutex);
50191
50192- if (imxdrm->drm->open_count) {
50193+ if (local_read(&imxdrm->drm->open_count)) {
50194 ret = -EBUSY;
50195 goto err_busy;
50196 }
50197@@ -715,7 +715,7 @@ int imx_drm_add_connector(struct drm_connector *connector,
50198
50199 mutex_lock(&imxdrm->mutex);
50200
50201- if (imxdrm->drm->open_count) {
50202+ if (local_read(&imxdrm->drm->open_count)) {
50203 ret = -EBUSY;
50204 goto err_busy;
50205 }
50206diff --git a/drivers/staging/lustre/lnet/selftest/brw_test.c b/drivers/staging/lustre/lnet/selftest/brw_test.c
50207index 3f8020c..649fded 100644
50208--- a/drivers/staging/lustre/lnet/selftest/brw_test.c
50209+++ b/drivers/staging/lustre/lnet/selftest/brw_test.c
50210@@ -488,13 +488,11 @@ brw_server_handle(struct srpc_server_rpc *rpc)
50211 return 0;
50212 }
50213
50214-sfw_test_client_ops_t brw_test_client;
50215-void brw_init_test_client(void)
50216-{
50217- brw_test_client.tso_init = brw_client_init;
50218- brw_test_client.tso_fini = brw_client_fini;
50219- brw_test_client.tso_prep_rpc = brw_client_prep_rpc;
50220- brw_test_client.tso_done_rpc = brw_client_done_rpc;
50221+sfw_test_client_ops_t brw_test_client = {
50222+ .tso_init = brw_client_init,
50223+ .tso_fini = brw_client_fini,
50224+ .tso_prep_rpc = brw_client_prep_rpc,
50225+ .tso_done_rpc = brw_client_done_rpc,
50226 };
50227
50228 srpc_service_t brw_test_service;
50229diff --git a/drivers/staging/lustre/lnet/selftest/framework.c b/drivers/staging/lustre/lnet/selftest/framework.c
50230index 050723a..fa6fdf1 100644
50231--- a/drivers/staging/lustre/lnet/selftest/framework.c
50232+++ b/drivers/staging/lustre/lnet/selftest/framework.c
50233@@ -1635,12 +1635,10 @@ static srpc_service_t sfw_services[] =
50234
50235 extern sfw_test_client_ops_t ping_test_client;
50236 extern srpc_service_t ping_test_service;
50237-extern void ping_init_test_client(void);
50238 extern void ping_init_test_service(void);
50239
50240 extern sfw_test_client_ops_t brw_test_client;
50241 extern srpc_service_t brw_test_service;
50242-extern void brw_init_test_client(void);
50243 extern void brw_init_test_service(void);
50244
50245
50246@@ -1684,12 +1682,10 @@ sfw_startup (void)
50247 INIT_LIST_HEAD(&sfw_data.fw_zombie_rpcs);
50248 INIT_LIST_HEAD(&sfw_data.fw_zombie_sessions);
50249
50250- brw_init_test_client();
50251 brw_init_test_service();
50252 rc = sfw_register_test(&brw_test_service, &brw_test_client);
50253 LASSERT (rc == 0);
50254
50255- ping_init_test_client();
50256 ping_init_test_service();
50257 rc = sfw_register_test(&ping_test_service, &ping_test_client);
50258 LASSERT (rc == 0);
50259diff --git a/drivers/staging/lustre/lnet/selftest/ping_test.c b/drivers/staging/lustre/lnet/selftest/ping_test.c
50260index 750cac4..e4d751f 100644
50261--- a/drivers/staging/lustre/lnet/selftest/ping_test.c
50262+++ b/drivers/staging/lustre/lnet/selftest/ping_test.c
50263@@ -211,14 +211,12 @@ ping_server_handle(struct srpc_server_rpc *rpc)
50264 return 0;
50265 }
50266
50267-sfw_test_client_ops_t ping_test_client;
50268-void ping_init_test_client(void)
50269-{
50270- ping_test_client.tso_init = ping_client_init;
50271- ping_test_client.tso_fini = ping_client_fini;
50272- ping_test_client.tso_prep_rpc = ping_client_prep_rpc;
50273- ping_test_client.tso_done_rpc = ping_client_done_rpc;
50274-}
50275+sfw_test_client_ops_t ping_test_client = {
50276+ .tso_init = ping_client_init,
50277+ .tso_fini = ping_client_fini,
50278+ .tso_prep_rpc = ping_client_prep_rpc,
50279+ .tso_done_rpc = ping_client_done_rpc,
50280+};
50281
50282 srpc_service_t ping_test_service;
50283 void ping_init_test_service(void)
50284diff --git a/drivers/staging/lustre/lustre/include/lustre_dlm.h b/drivers/staging/lustre/lustre/include/lustre_dlm.h
50285index ec4bb5e..740c6dd 100644
50286--- a/drivers/staging/lustre/lustre/include/lustre_dlm.h
50287+++ b/drivers/staging/lustre/lustre/include/lustre_dlm.h
50288@@ -1141,7 +1141,7 @@ struct ldlm_callback_suite {
50289 ldlm_completion_callback lcs_completion;
50290 ldlm_blocking_callback lcs_blocking;
50291 ldlm_glimpse_callback lcs_glimpse;
50292-};
50293+} __no_const;
50294
50295 /* ldlm_lockd.c */
50296 int ldlm_del_waiting_lock(struct ldlm_lock *lock);
50297diff --git a/drivers/staging/lustre/lustre/include/obd.h b/drivers/staging/lustre/lustre/include/obd.h
50298index c3470ce..2bef527 100644
50299--- a/drivers/staging/lustre/lustre/include/obd.h
50300+++ b/drivers/staging/lustre/lustre/include/obd.h
50301@@ -1426,7 +1426,7 @@ struct md_ops {
50302 * lprocfs_alloc_md_stats() in obdclass/lprocfs_status.c. Also, add a
50303 * wrapper function in include/linux/obd_class.h.
50304 */
50305-};
50306+} __no_const;
50307
50308 struct lsm_operations {
50309 void (*lsm_free)(struct lov_stripe_md *);
50310diff --git a/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c b/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c
50311index c9aae13..60ea292 100644
50312--- a/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c
50313+++ b/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c
50314@@ -239,7 +239,7 @@ ldlm_process_flock_lock(struct ldlm_lock *req, __u64 *flags, int first_enq,
50315 int added = (mode == LCK_NL);
50316 int overlaps = 0;
50317 int splitted = 0;
50318- const struct ldlm_callback_suite null_cbs = { NULL };
50319+ const struct ldlm_callback_suite null_cbs = { };
50320
50321 CDEBUG(D_DLMTRACE, "flags %#llx owner "LPU64" pid %u mode %u start "
50322 LPU64" end "LPU64"\n", *flags,
50323diff --git a/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c b/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c
50324index e947b91..f408990 100644
50325--- a/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c
50326+++ b/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c
50327@@ -217,7 +217,7 @@ DECLARE_PROC_HANDLER(proc_debug_mb)
50328 int LL_PROC_PROTO(proc_console_max_delay_cs)
50329 {
50330 int rc, max_delay_cs;
50331- ctl_table_t dummy = *table;
50332+ ctl_table_no_const dummy = *table;
50333 cfs_duration_t d;
50334
50335 dummy.data = &max_delay_cs;
50336@@ -248,7 +248,7 @@ int LL_PROC_PROTO(proc_console_max_delay_cs)
50337 int LL_PROC_PROTO(proc_console_min_delay_cs)
50338 {
50339 int rc, min_delay_cs;
50340- ctl_table_t dummy = *table;
50341+ ctl_table_no_const dummy = *table;
50342 cfs_duration_t d;
50343
50344 dummy.data = &min_delay_cs;
50345@@ -279,7 +279,7 @@ int LL_PROC_PROTO(proc_console_min_delay_cs)
50346 int LL_PROC_PROTO(proc_console_backoff)
50347 {
50348 int rc, backoff;
50349- ctl_table_t dummy = *table;
50350+ ctl_table_no_const dummy = *table;
50351
50352 dummy.data = &backoff;
50353 dummy.proc_handler = &proc_dointvec;
50354diff --git a/drivers/staging/lustre/lustre/libcfs/module.c b/drivers/staging/lustre/lustre/libcfs/module.c
50355index 24ae26d..9d09cab 100644
50356--- a/drivers/staging/lustre/lustre/libcfs/module.c
50357+++ b/drivers/staging/lustre/lustre/libcfs/module.c
50358@@ -313,11 +313,11 @@ out:
50359
50360
50361 struct cfs_psdev_ops libcfs_psdev_ops = {
50362- libcfs_psdev_open,
50363- libcfs_psdev_release,
50364- NULL,
50365- NULL,
50366- libcfs_ioctl
50367+ .p_open = libcfs_psdev_open,
50368+ .p_close = libcfs_psdev_release,
50369+ .p_read = NULL,
50370+ .p_write = NULL,
50371+ .p_ioctl = libcfs_ioctl
50372 };
50373
50374 extern int insert_proc(void);
50375diff --git a/drivers/staging/lustre/lustre/llite/dir.c b/drivers/staging/lustre/lustre/llite/dir.c
50376index 52b7731..d604da0 100644
50377--- a/drivers/staging/lustre/lustre/llite/dir.c
50378+++ b/drivers/staging/lustre/lustre/llite/dir.c
50379@@ -660,7 +660,7 @@ int ll_dir_setdirstripe(struct inode *dir, struct lmv_user_md *lump,
50380 int mode;
50381 int err;
50382
50383- mode = (0755 & (S_IRWXUGO|S_ISVTX) & ~current->fs->umask) | S_IFDIR;
50384+ mode = (0755 & (S_IRWXUGO|S_ISVTX) & ~current_umask()) | S_IFDIR;
50385 op_data = ll_prep_md_op_data(NULL, dir, NULL, filename,
50386 strlen(filename), mode, LUSTRE_OPC_MKDIR,
50387 lump);
50388diff --git a/drivers/staging/media/solo6x10/solo6x10-core.c b/drivers/staging/media/solo6x10/solo6x10-core.c
50389index 480b7c4..6846324 100644
50390--- a/drivers/staging/media/solo6x10/solo6x10-core.c
50391+++ b/drivers/staging/media/solo6x10/solo6x10-core.c
50392@@ -434,7 +434,7 @@ static void solo_device_release(struct device *dev)
50393
50394 static int solo_sysfs_init(struct solo_dev *solo_dev)
50395 {
50396- struct bin_attribute *sdram_attr = &solo_dev->sdram_attr;
50397+ bin_attribute_no_const *sdram_attr = &solo_dev->sdram_attr;
50398 struct device *dev = &solo_dev->dev;
50399 const char *driver;
50400 int i;
50401diff --git a/drivers/staging/media/solo6x10/solo6x10-g723.c b/drivers/staging/media/solo6x10/solo6x10-g723.c
50402index 1db18c7..35e6afc 100644
50403--- a/drivers/staging/media/solo6x10/solo6x10-g723.c
50404+++ b/drivers/staging/media/solo6x10/solo6x10-g723.c
50405@@ -355,7 +355,7 @@ static int solo_snd_pcm_init(struct solo_dev *solo_dev)
50406
50407 int solo_g723_init(struct solo_dev *solo_dev)
50408 {
50409- static struct snd_device_ops ops = { NULL };
50410+ static struct snd_device_ops ops = { };
50411 struct snd_card *card;
50412 struct snd_kcontrol_new kctl;
50413 char name[32];
50414diff --git a/drivers/staging/media/solo6x10/solo6x10-p2m.c b/drivers/staging/media/solo6x10/solo6x10-p2m.c
50415index 7f2f247..d999137 100644
50416--- a/drivers/staging/media/solo6x10/solo6x10-p2m.c
50417+++ b/drivers/staging/media/solo6x10/solo6x10-p2m.c
50418@@ -77,7 +77,7 @@ int solo_p2m_dma_desc(struct solo_dev *solo_dev,
50419
50420 /* Get next ID. According to Softlogic, 6110 has problems on !=0 P2M */
50421 if (solo_dev->type != SOLO_DEV_6110 && multi_p2m) {
50422- p2m_id = atomic_inc_return(&solo_dev->p2m_count) % SOLO_NR_P2M;
50423+ p2m_id = atomic_inc_return_unchecked(&solo_dev->p2m_count) % SOLO_NR_P2M;
50424 if (p2m_id < 0)
50425 p2m_id = -p2m_id;
50426 }
50427diff --git a/drivers/staging/media/solo6x10/solo6x10.h b/drivers/staging/media/solo6x10/solo6x10.h
50428index 8964f8b..36eb087 100644
50429--- a/drivers/staging/media/solo6x10/solo6x10.h
50430+++ b/drivers/staging/media/solo6x10/solo6x10.h
50431@@ -237,7 +237,7 @@ struct solo_dev {
50432
50433 /* P2M DMA Engine */
50434 struct solo_p2m_dev p2m_dev[SOLO_NR_P2M];
50435- atomic_t p2m_count;
50436+ atomic_unchecked_t p2m_count;
50437 int p2m_jiffies;
50438 unsigned int p2m_timeouts;
50439
50440diff --git a/drivers/staging/octeon/ethernet-rx.c b/drivers/staging/octeon/ethernet-rx.c
50441index a0f4868..139f1fb 100644
50442--- a/drivers/staging/octeon/ethernet-rx.c
50443+++ b/drivers/staging/octeon/ethernet-rx.c
50444@@ -417,11 +417,11 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
50445 /* Increment RX stats for virtual ports */
50446 if (work->ipprt >= CVMX_PIP_NUM_INPUT_PORTS) {
50447 #ifdef CONFIG_64BIT
50448- atomic64_add(1, (atomic64_t *)&priv->stats.rx_packets);
50449- atomic64_add(skb->len, (atomic64_t *)&priv->stats.rx_bytes);
50450+ atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_packets);
50451+ atomic64_add_unchecked(skb->len, (atomic64_unchecked_t *)&priv->stats.rx_bytes);
50452 #else
50453- atomic_add(1, (atomic_t *)&priv->stats.rx_packets);
50454- atomic_add(skb->len, (atomic_t *)&priv->stats.rx_bytes);
50455+ atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_packets);
50456+ atomic_add_unchecked(skb->len, (atomic_unchecked_t *)&priv->stats.rx_bytes);
50457 #endif
50458 }
50459 netif_receive_skb(skb);
50460@@ -432,9 +432,9 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
50461 dev->name);
50462 */
50463 #ifdef CONFIG_64BIT
50464- atomic64_add(1, (atomic64_t *)&priv->stats.rx_dropped);
50465+ atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_dropped);
50466 #else
50467- atomic_add(1, (atomic_t *)&priv->stats.rx_dropped);
50468+ atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_dropped);
50469 #endif
50470 dev_kfree_skb_irq(skb);
50471 }
50472diff --git a/drivers/staging/octeon/ethernet.c b/drivers/staging/octeon/ethernet.c
50473index 089dc4b..c9a687e 100644
50474--- a/drivers/staging/octeon/ethernet.c
50475+++ b/drivers/staging/octeon/ethernet.c
50476@@ -253,11 +253,11 @@ static struct net_device_stats *cvm_oct_common_get_stats(struct net_device *dev)
50477 * since the RX tasklet also increments it.
50478 */
50479 #ifdef CONFIG_64BIT
50480- atomic64_add(rx_status.dropped_packets,
50481- (atomic64_t *)&priv->stats.rx_dropped);
50482+ atomic64_add_unchecked(rx_status.dropped_packets,
50483+ (atomic64_unchecked_t *)&priv->stats.rx_dropped);
50484 #else
50485- atomic_add(rx_status.dropped_packets,
50486- (atomic_t *)&priv->stats.rx_dropped);
50487+ atomic_add_unchecked(rx_status.dropped_packets,
50488+ (atomic_unchecked_t *)&priv->stats.rx_dropped);
50489 #endif
50490 }
50491
50492diff --git a/drivers/staging/rtl8188eu/include/hal_intf.h b/drivers/staging/rtl8188eu/include/hal_intf.h
50493index c274b34..f84de76 100644
50494--- a/drivers/staging/rtl8188eu/include/hal_intf.h
50495+++ b/drivers/staging/rtl8188eu/include/hal_intf.h
50496@@ -271,7 +271,7 @@ struct hal_ops {
50497 s32 (*c2h_handler)(struct adapter *padapter,
50498 struct c2h_evt_hdr *c2h_evt);
50499 c2h_id_filter c2h_id_filter_ccx;
50500-};
50501+} __no_const;
50502
50503 enum rt_eeprom_type {
50504 EEPROM_93C46,
50505diff --git a/drivers/staging/rtl8188eu/include/rtw_io.h b/drivers/staging/rtl8188eu/include/rtw_io.h
50506index 3d1dfcc..ff5620a 100644
50507--- a/drivers/staging/rtl8188eu/include/rtw_io.h
50508+++ b/drivers/staging/rtl8188eu/include/rtw_io.h
50509@@ -126,7 +126,7 @@ struct _io_ops {
50510 u32 (*_write_scsi)(struct intf_hdl *pintfhdl, u32 cnt, u8 *pmem);
50511 void (*_read_port_cancel)(struct intf_hdl *pintfhdl);
50512 void (*_write_port_cancel)(struct intf_hdl *pintfhdl);
50513-};
50514+} __no_const;
50515
50516 struct io_req {
50517 struct list_head list;
50518diff --git a/drivers/staging/rtl8712/rtl871x_io.h b/drivers/staging/rtl8712/rtl871x_io.h
50519index dc23395..cf7e9b1 100644
50520--- a/drivers/staging/rtl8712/rtl871x_io.h
50521+++ b/drivers/staging/rtl8712/rtl871x_io.h
50522@@ -108,7 +108,7 @@ struct _io_ops {
50523 u8 *pmem);
50524 u32 (*_write_port)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt,
50525 u8 *pmem);
50526-};
50527+} __no_const;
50528
50529 struct io_req {
50530 struct list_head list;
50531diff --git a/drivers/staging/sbe-2t3e3/netdev.c b/drivers/staging/sbe-2t3e3/netdev.c
50532index 1f5088b..0e59820 100644
50533--- a/drivers/staging/sbe-2t3e3/netdev.c
50534+++ b/drivers/staging/sbe-2t3e3/netdev.c
50535@@ -51,7 +51,7 @@ static int t3e3_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
50536 t3e3_if_config(sc, cmd_2t3e3, (char *)&param, &resp, &rlen);
50537
50538 if (rlen)
50539- if (copy_to_user(data, &resp, rlen))
50540+ if (rlen > sizeof resp || copy_to_user(data, &resp, rlen))
50541 return -EFAULT;
50542
50543 return 0;
50544diff --git a/drivers/staging/usbip/vhci.h b/drivers/staging/usbip/vhci.h
50545index a863a98..d272795 100644
50546--- a/drivers/staging/usbip/vhci.h
50547+++ b/drivers/staging/usbip/vhci.h
50548@@ -83,7 +83,7 @@ struct vhci_hcd {
50549 unsigned resuming:1;
50550 unsigned long re_timeout;
50551
50552- atomic_t seqnum;
50553+ atomic_unchecked_t seqnum;
50554
50555 /*
50556 * NOTE:
50557diff --git a/drivers/staging/usbip/vhci_hcd.c b/drivers/staging/usbip/vhci_hcd.c
50558index 72391ef..7c6717a 100644
50559--- a/drivers/staging/usbip/vhci_hcd.c
50560+++ b/drivers/staging/usbip/vhci_hcd.c
50561@@ -440,7 +440,7 @@ static void vhci_tx_urb(struct urb *urb)
50562
50563 spin_lock(&vdev->priv_lock);
50564
50565- priv->seqnum = atomic_inc_return(&the_controller->seqnum);
50566+ priv->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
50567 if (priv->seqnum == 0xffff)
50568 dev_info(&urb->dev->dev, "seqnum max\n");
50569
50570@@ -686,7 +686,7 @@ static int vhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
50571 return -ENOMEM;
50572 }
50573
50574- unlink->seqnum = atomic_inc_return(&the_controller->seqnum);
50575+ unlink->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
50576 if (unlink->seqnum == 0xffff)
50577 pr_info("seqnum max\n");
50578
50579@@ -890,7 +890,7 @@ static int vhci_start(struct usb_hcd *hcd)
50580 vdev->rhport = rhport;
50581 }
50582
50583- atomic_set(&vhci->seqnum, 0);
50584+ atomic_set_unchecked(&vhci->seqnum, 0);
50585 spin_lock_init(&vhci->lock);
50586
50587 hcd->power_budget = 0; /* no limit */
50588diff --git a/drivers/staging/usbip/vhci_rx.c b/drivers/staging/usbip/vhci_rx.c
50589index d07fcb5..358e1e1 100644
50590--- a/drivers/staging/usbip/vhci_rx.c
50591+++ b/drivers/staging/usbip/vhci_rx.c
50592@@ -80,7 +80,7 @@ static void vhci_recv_ret_submit(struct vhci_device *vdev,
50593 if (!urb) {
50594 pr_err("cannot find a urb of seqnum %u\n", pdu->base.seqnum);
50595 pr_info("max seqnum %d\n",
50596- atomic_read(&the_controller->seqnum));
50597+ atomic_read_unchecked(&the_controller->seqnum));
50598 usbip_event_add(ud, VDEV_EVENT_ERROR_TCP);
50599 return;
50600 }
50601diff --git a/drivers/staging/vt6655/hostap.c b/drivers/staging/vt6655/hostap.c
50602index 6eecd53..29317c6 100644
50603--- a/drivers/staging/vt6655/hostap.c
50604+++ b/drivers/staging/vt6655/hostap.c
50605@@ -69,14 +69,13 @@ static int msglevel = MSG_LEVEL_INFO;
50606 *
50607 */
50608
50609+static net_device_ops_no_const apdev_netdev_ops;
50610+
50611 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
50612 {
50613 PSDevice apdev_priv;
50614 struct net_device *dev = pDevice->dev;
50615 int ret;
50616- const struct net_device_ops apdev_netdev_ops = {
50617- .ndo_start_xmit = pDevice->tx_80211,
50618- };
50619
50620 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
50621
50622@@ -88,6 +87,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
50623 *apdev_priv = *pDevice;
50624 eth_hw_addr_inherit(pDevice->apdev, dev);
50625
50626+ /* only half broken now */
50627+ apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
50628 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
50629
50630 pDevice->apdev->type = ARPHRD_IEEE80211;
50631diff --git a/drivers/staging/vt6656/hostap.c b/drivers/staging/vt6656/hostap.c
50632index 67ba48b..24e602f 100644
50633--- a/drivers/staging/vt6656/hostap.c
50634+++ b/drivers/staging/vt6656/hostap.c
50635@@ -60,14 +60,13 @@ static int msglevel =MSG_LEVEL_INFO;
50636 *
50637 */
50638
50639+static net_device_ops_no_const apdev_netdev_ops;
50640+
50641 static int hostap_enable_hostapd(struct vnt_private *pDevice, int rtnl_locked)
50642 {
50643 struct vnt_private *apdev_priv;
50644 struct net_device *dev = pDevice->dev;
50645 int ret;
50646- const struct net_device_ops apdev_netdev_ops = {
50647- .ndo_start_xmit = pDevice->tx_80211,
50648- };
50649
50650 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
50651
50652@@ -79,6 +78,8 @@ static int hostap_enable_hostapd(struct vnt_private *pDevice, int rtnl_locked)
50653 *apdev_priv = *pDevice;
50654 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
50655
50656+ /* only half broken now */
50657+ apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
50658 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
50659
50660 pDevice->apdev->type = ARPHRD_IEEE80211;
50661diff --git a/drivers/target/sbp/sbp_target.c b/drivers/target/sbp/sbp_target.c
50662index 24884ca..26c8220 100644
50663--- a/drivers/target/sbp/sbp_target.c
50664+++ b/drivers/target/sbp/sbp_target.c
50665@@ -62,7 +62,7 @@ static const u32 sbp_unit_directory_template[] = {
50666
50667 #define SESSION_MAINTENANCE_INTERVAL HZ
50668
50669-static atomic_t login_id = ATOMIC_INIT(0);
50670+static atomic_unchecked_t login_id = ATOMIC_INIT(0);
50671
50672 static void session_maintenance_work(struct work_struct *);
50673 static int sbp_run_transaction(struct fw_card *, int, int, int, int,
50674@@ -444,7 +444,7 @@ static void sbp_management_request_login(
50675 login->lun = se_lun;
50676 login->status_fifo_addr = sbp2_pointer_to_addr(&req->orb.status_fifo);
50677 login->exclusive = LOGIN_ORB_EXCLUSIVE(be32_to_cpu(req->orb.misc));
50678- login->login_id = atomic_inc_return(&login_id);
50679+ login->login_id = atomic_inc_return_unchecked(&login_id);
50680
50681 login->tgt_agt = sbp_target_agent_register(login);
50682 if (IS_ERR(login->tgt_agt)) {
50683diff --git a/drivers/target/target_core_device.c b/drivers/target/target_core_device.c
50684index 65001e1..2ebfbb9 100644
50685--- a/drivers/target/target_core_device.c
50686+++ b/drivers/target/target_core_device.c
50687@@ -1520,7 +1520,7 @@ struct se_device *target_alloc_device(struct se_hba *hba, const char *name)
50688 spin_lock_init(&dev->se_tmr_lock);
50689 spin_lock_init(&dev->qf_cmd_lock);
50690 sema_init(&dev->caw_sem, 1);
50691- atomic_set(&dev->dev_ordered_id, 0);
50692+ atomic_set_unchecked(&dev->dev_ordered_id, 0);
50693 INIT_LIST_HEAD(&dev->t10_wwn.t10_vpd_list);
50694 spin_lock_init(&dev->t10_wwn.t10_vpd_lock);
50695 INIT_LIST_HEAD(&dev->t10_pr.registration_list);
50696diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
50697index 2956250..b10f722 100644
50698--- a/drivers/target/target_core_transport.c
50699+++ b/drivers/target/target_core_transport.c
50700@@ -1136,7 +1136,7 @@ transport_check_alloc_task_attr(struct se_cmd *cmd)
50701 * Used to determine when ORDERED commands should go from
50702 * Dormant to Active status.
50703 */
50704- cmd->se_ordered_id = atomic_inc_return(&dev->dev_ordered_id);
50705+ cmd->se_ordered_id = atomic_inc_return_unchecked(&dev->dev_ordered_id);
50706 smp_mb__after_atomic_inc();
50707 pr_debug("Allocated se_ordered_id: %u for Task Attr: 0x%02x on %s\n",
50708 cmd->se_ordered_id, cmd->sam_task_attr,
50709diff --git a/drivers/thermal/of-thermal.c b/drivers/thermal/of-thermal.c
50710index 04b1be7..5eff86d 100644
50711--- a/drivers/thermal/of-thermal.c
50712+++ b/drivers/thermal/of-thermal.c
50713@@ -30,6 +30,7 @@
50714 #include <linux/err.h>
50715 #include <linux/export.h>
50716 #include <linux/string.h>
50717+#include <linux/mm.h>
50718
50719 #include "thermal_core.h"
50720
50721@@ -341,8 +342,10 @@ thermal_zone_of_add_sensor(struct device_node *zone,
50722 tz->get_trend = get_trend;
50723 tz->sensor_data = data;
50724
50725- tzd->ops->get_temp = of_thermal_get_temp;
50726- tzd->ops->get_trend = of_thermal_get_trend;
50727+ pax_open_kernel();
50728+ *(void **)&tzd->ops->get_temp = of_thermal_get_temp;
50729+ *(void **)&tzd->ops->get_trend = of_thermal_get_trend;
50730+ pax_close_kernel();
50731 mutex_unlock(&tzd->lock);
50732
50733 return tzd;
50734@@ -461,8 +464,10 @@ void thermal_zone_of_sensor_unregister(struct device *dev,
50735 return;
50736
50737 mutex_lock(&tzd->lock);
50738- tzd->ops->get_temp = NULL;
50739- tzd->ops->get_trend = NULL;
50740+ pax_open_kernel();
50741+ *(void **)&tzd->ops->get_temp = NULL;
50742+ *(void **)&tzd->ops->get_trend = NULL;
50743+ pax_close_kernel();
50744
50745 tz->get_temp = NULL;
50746 tz->get_trend = NULL;
50747diff --git a/drivers/tty/cyclades.c b/drivers/tty/cyclades.c
50748index a57bb5a..1f727d33 100644
50749--- a/drivers/tty/cyclades.c
50750+++ b/drivers/tty/cyclades.c
50751@@ -1570,10 +1570,10 @@ static int cy_open(struct tty_struct *tty, struct file *filp)
50752 printk(KERN_DEBUG "cyc:cy_open ttyC%d, count = %d\n", info->line,
50753 info->port.count);
50754 #endif
50755- info->port.count++;
50756+ atomic_inc(&info->port.count);
50757 #ifdef CY_DEBUG_COUNT
50758 printk(KERN_DEBUG "cyc:cy_open (%d): incrementing count to %d\n",
50759- current->pid, info->port.count);
50760+ current->pid, atomic_read(&info->port.count));
50761 #endif
50762
50763 /*
50764@@ -3974,7 +3974,7 @@ static int cyclades_proc_show(struct seq_file *m, void *v)
50765 for (j = 0; j < cy_card[i].nports; j++) {
50766 info = &cy_card[i].ports[j];
50767
50768- if (info->port.count) {
50769+ if (atomic_read(&info->port.count)) {
50770 /* XXX is the ldisc num worth this? */
50771 struct tty_struct *tty;
50772 struct tty_ldisc *ld;
50773diff --git a/drivers/tty/hvc/hvc_console.c b/drivers/tty/hvc/hvc_console.c
50774index 0ff7fda..dbc7d52 100644
50775--- a/drivers/tty/hvc/hvc_console.c
50776+++ b/drivers/tty/hvc/hvc_console.c
50777@@ -342,7 +342,7 @@ static int hvc_open(struct tty_struct *tty, struct file * filp)
50778
50779 spin_lock_irqsave(&hp->port.lock, flags);
50780 /* Check and then increment for fast path open. */
50781- if (hp->port.count++ > 0) {
50782+ if (atomic_inc_return(&hp->port.count) > 1) {
50783 spin_unlock_irqrestore(&hp->port.lock, flags);
50784 hvc_kick();
50785 return 0;
50786@@ -397,7 +397,7 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
50787
50788 spin_lock_irqsave(&hp->port.lock, flags);
50789
50790- if (--hp->port.count == 0) {
50791+ if (atomic_dec_return(&hp->port.count) == 0) {
50792 spin_unlock_irqrestore(&hp->port.lock, flags);
50793 /* We are done with the tty pointer now. */
50794 tty_port_tty_set(&hp->port, NULL);
50795@@ -419,9 +419,9 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
50796 */
50797 tty_wait_until_sent_from_close(tty, HVC_CLOSE_WAIT);
50798 } else {
50799- if (hp->port.count < 0)
50800+ if (atomic_read(&hp->port.count) < 0)
50801 printk(KERN_ERR "hvc_close %X: oops, count is %d\n",
50802- hp->vtermno, hp->port.count);
50803+ hp->vtermno, atomic_read(&hp->port.count));
50804 spin_unlock_irqrestore(&hp->port.lock, flags);
50805 }
50806 }
50807@@ -451,12 +451,12 @@ static void hvc_hangup(struct tty_struct *tty)
50808 * open->hangup case this can be called after the final close so prevent
50809 * that from happening for now.
50810 */
50811- if (hp->port.count <= 0) {
50812+ if (atomic_read(&hp->port.count) <= 0) {
50813 spin_unlock_irqrestore(&hp->port.lock, flags);
50814 return;
50815 }
50816
50817- hp->port.count = 0;
50818+ atomic_set(&hp->port.count, 0);
50819 spin_unlock_irqrestore(&hp->port.lock, flags);
50820 tty_port_tty_set(&hp->port, NULL);
50821
50822@@ -504,7 +504,7 @@ static int hvc_write(struct tty_struct *tty, const unsigned char *buf, int count
50823 return -EPIPE;
50824
50825 /* FIXME what's this (unprotected) check for? */
50826- if (hp->port.count <= 0)
50827+ if (atomic_read(&hp->port.count) <= 0)
50828 return -EIO;
50829
50830 spin_lock_irqsave(&hp->lock, flags);
50831diff --git a/drivers/tty/hvc/hvcs.c b/drivers/tty/hvc/hvcs.c
50832index 81e939e..95ead10 100644
50833--- a/drivers/tty/hvc/hvcs.c
50834+++ b/drivers/tty/hvc/hvcs.c
50835@@ -83,6 +83,7 @@
50836 #include <asm/hvcserver.h>
50837 #include <asm/uaccess.h>
50838 #include <asm/vio.h>
50839+#include <asm/local.h>
50840
50841 /*
50842 * 1.3.0 -> 1.3.1 In hvcs_open memset(..,0x00,..) instead of memset(..,0x3F,00).
50843@@ -416,7 +417,7 @@ static ssize_t hvcs_vterm_state_store(struct device *dev, struct device_attribut
50844
50845 spin_lock_irqsave(&hvcsd->lock, flags);
50846
50847- if (hvcsd->port.count > 0) {
50848+ if (atomic_read(&hvcsd->port.count) > 0) {
50849 spin_unlock_irqrestore(&hvcsd->lock, flags);
50850 printk(KERN_INFO "HVCS: vterm state unchanged. "
50851 "The hvcs device node is still in use.\n");
50852@@ -1127,7 +1128,7 @@ static int hvcs_install(struct tty_driver *driver, struct tty_struct *tty)
50853 }
50854 }
50855
50856- hvcsd->port.count = 0;
50857+ atomic_set(&hvcsd->port.count, 0);
50858 hvcsd->port.tty = tty;
50859 tty->driver_data = hvcsd;
50860
50861@@ -1180,7 +1181,7 @@ static int hvcs_open(struct tty_struct *tty, struct file *filp)
50862 unsigned long flags;
50863
50864 spin_lock_irqsave(&hvcsd->lock, flags);
50865- hvcsd->port.count++;
50866+ atomic_inc(&hvcsd->port.count);
50867 hvcsd->todo_mask |= HVCS_SCHED_READ;
50868 spin_unlock_irqrestore(&hvcsd->lock, flags);
50869
50870@@ -1216,7 +1217,7 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
50871 hvcsd = tty->driver_data;
50872
50873 spin_lock_irqsave(&hvcsd->lock, flags);
50874- if (--hvcsd->port.count == 0) {
50875+ if (atomic_dec_and_test(&hvcsd->port.count)) {
50876
50877 vio_disable_interrupts(hvcsd->vdev);
50878
50879@@ -1241,10 +1242,10 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
50880
50881 free_irq(irq, hvcsd);
50882 return;
50883- } else if (hvcsd->port.count < 0) {
50884+ } else if (atomic_read(&hvcsd->port.count) < 0) {
50885 printk(KERN_ERR "HVCS: vty-server@%X open_count: %d"
50886 " is missmanaged.\n",
50887- hvcsd->vdev->unit_address, hvcsd->port.count);
50888+ hvcsd->vdev->unit_address, atomic_read(&hvcsd->port.count));
50889 }
50890
50891 spin_unlock_irqrestore(&hvcsd->lock, flags);
50892@@ -1266,7 +1267,7 @@ static void hvcs_hangup(struct tty_struct * tty)
50893
50894 spin_lock_irqsave(&hvcsd->lock, flags);
50895 /* Preserve this so that we know how many kref refs to put */
50896- temp_open_count = hvcsd->port.count;
50897+ temp_open_count = atomic_read(&hvcsd->port.count);
50898
50899 /*
50900 * Don't kref put inside the spinlock because the destruction
50901@@ -1281,7 +1282,7 @@ static void hvcs_hangup(struct tty_struct * tty)
50902 tty->driver_data = NULL;
50903 hvcsd->port.tty = NULL;
50904
50905- hvcsd->port.count = 0;
50906+ atomic_set(&hvcsd->port.count, 0);
50907
50908 /* This will drop any buffered data on the floor which is OK in a hangup
50909 * scenario. */
50910@@ -1352,7 +1353,7 @@ static int hvcs_write(struct tty_struct *tty,
50911 * the middle of a write operation? This is a crummy place to do this
50912 * but we want to keep it all in the spinlock.
50913 */
50914- if (hvcsd->port.count <= 0) {
50915+ if (atomic_read(&hvcsd->port.count) <= 0) {
50916 spin_unlock_irqrestore(&hvcsd->lock, flags);
50917 return -ENODEV;
50918 }
50919@@ -1426,7 +1427,7 @@ static int hvcs_write_room(struct tty_struct *tty)
50920 {
50921 struct hvcs_struct *hvcsd = tty->driver_data;
50922
50923- if (!hvcsd || hvcsd->port.count <= 0)
50924+ if (!hvcsd || atomic_read(&hvcsd->port.count) <= 0)
50925 return 0;
50926
50927 return HVCS_BUFF_LEN - hvcsd->chars_in_buffer;
50928diff --git a/drivers/tty/hvc/hvsi.c b/drivers/tty/hvc/hvsi.c
50929index 4190199..06d5bfa 100644
50930--- a/drivers/tty/hvc/hvsi.c
50931+++ b/drivers/tty/hvc/hvsi.c
50932@@ -85,7 +85,7 @@ struct hvsi_struct {
50933 int n_outbuf;
50934 uint32_t vtermno;
50935 uint32_t virq;
50936- atomic_t seqno; /* HVSI packet sequence number */
50937+ atomic_unchecked_t seqno; /* HVSI packet sequence number */
50938 uint16_t mctrl;
50939 uint8_t state; /* HVSI protocol state */
50940 uint8_t flags;
50941@@ -295,7 +295,7 @@ static int hvsi_version_respond(struct hvsi_struct *hp, uint16_t query_seqno)
50942
50943 packet.hdr.type = VS_QUERY_RESPONSE_PACKET_HEADER;
50944 packet.hdr.len = sizeof(struct hvsi_query_response);
50945- packet.hdr.seqno = atomic_inc_return(&hp->seqno);
50946+ packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
50947 packet.verb = VSV_SEND_VERSION_NUMBER;
50948 packet.u.version = HVSI_VERSION;
50949 packet.query_seqno = query_seqno+1;
50950@@ -555,7 +555,7 @@ static int hvsi_query(struct hvsi_struct *hp, uint16_t verb)
50951
50952 packet.hdr.type = VS_QUERY_PACKET_HEADER;
50953 packet.hdr.len = sizeof(struct hvsi_query);
50954- packet.hdr.seqno = atomic_inc_return(&hp->seqno);
50955+ packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
50956 packet.verb = verb;
50957
50958 pr_debug("%s: sending %i bytes\n", __func__, packet.hdr.len);
50959@@ -597,7 +597,7 @@ static int hvsi_set_mctrl(struct hvsi_struct *hp, uint16_t mctrl)
50960 int wrote;
50961
50962 packet.hdr.type = VS_CONTROL_PACKET_HEADER,
50963- packet.hdr.seqno = atomic_inc_return(&hp->seqno);
50964+ packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
50965 packet.hdr.len = sizeof(struct hvsi_control);
50966 packet.verb = VSV_SET_MODEM_CTL;
50967 packet.mask = HVSI_TSDTR;
50968@@ -680,7 +680,7 @@ static int hvsi_put_chars(struct hvsi_struct *hp, const char *buf, int count)
50969 BUG_ON(count > HVSI_MAX_OUTGOING_DATA);
50970
50971 packet.hdr.type = VS_DATA_PACKET_HEADER;
50972- packet.hdr.seqno = atomic_inc_return(&hp->seqno);
50973+ packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
50974 packet.hdr.len = count + sizeof(struct hvsi_header);
50975 memcpy(&packet.data, buf, count);
50976
50977@@ -697,7 +697,7 @@ static void hvsi_close_protocol(struct hvsi_struct *hp)
50978 struct hvsi_control packet __ALIGNED__;
50979
50980 packet.hdr.type = VS_CONTROL_PACKET_HEADER;
50981- packet.hdr.seqno = atomic_inc_return(&hp->seqno);
50982+ packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
50983 packet.hdr.len = 6;
50984 packet.verb = VSV_CLOSE_PROTOCOL;
50985
50986@@ -725,7 +725,7 @@ static int hvsi_open(struct tty_struct *tty, struct file *filp)
50987
50988 tty_port_tty_set(&hp->port, tty);
50989 spin_lock_irqsave(&hp->lock, flags);
50990- hp->port.count++;
50991+ atomic_inc(&hp->port.count);
50992 atomic_set(&hp->seqno, 0);
50993 h_vio_signal(hp->vtermno, VIO_IRQ_ENABLE);
50994 spin_unlock_irqrestore(&hp->lock, flags);
50995@@ -782,7 +782,7 @@ static void hvsi_close(struct tty_struct *tty, struct file *filp)
50996
50997 spin_lock_irqsave(&hp->lock, flags);
50998
50999- if (--hp->port.count == 0) {
51000+ if (atomic_dec_return(&hp->port.count) == 0) {
51001 tty_port_tty_set(&hp->port, NULL);
51002 hp->inbuf_end = hp->inbuf; /* discard remaining partial packets */
51003
51004@@ -815,9 +815,9 @@ static void hvsi_close(struct tty_struct *tty, struct file *filp)
51005
51006 spin_lock_irqsave(&hp->lock, flags);
51007 }
51008- } else if (hp->port.count < 0)
51009+ } else if (atomic_read(&hp->port.count) < 0)
51010 printk(KERN_ERR "hvsi_close %lu: oops, count is %d\n",
51011- hp - hvsi_ports, hp->port.count);
51012+ hp - hvsi_ports, atomic_read(&hp->port.count));
51013
51014 spin_unlock_irqrestore(&hp->lock, flags);
51015 }
51016@@ -832,7 +832,7 @@ static void hvsi_hangup(struct tty_struct *tty)
51017 tty_port_tty_set(&hp->port, NULL);
51018
51019 spin_lock_irqsave(&hp->lock, flags);
51020- hp->port.count = 0;
51021+ atomic_set(&hp->port.count, 0);
51022 hp->n_outbuf = 0;
51023 spin_unlock_irqrestore(&hp->lock, flags);
51024 }
51025diff --git a/drivers/tty/hvc/hvsi_lib.c b/drivers/tty/hvc/hvsi_lib.c
51026index 7ae6c29..05c6dba 100644
51027--- a/drivers/tty/hvc/hvsi_lib.c
51028+++ b/drivers/tty/hvc/hvsi_lib.c
51029@@ -8,7 +8,7 @@
51030
51031 static int hvsi_send_packet(struct hvsi_priv *pv, struct hvsi_header *packet)
51032 {
51033- packet->seqno = cpu_to_be16(atomic_inc_return(&pv->seqno));
51034+ packet->seqno = cpu_to_be16(atomic_inc_return_unchecked(&pv->seqno));
51035
51036 /* Assumes that always succeeds, works in practice */
51037 return pv->put_chars(pv->termno, (char *)packet, packet->len);
51038@@ -20,7 +20,7 @@ static void hvsi_start_handshake(struct hvsi_priv *pv)
51039
51040 /* Reset state */
51041 pv->established = 0;
51042- atomic_set(&pv->seqno, 0);
51043+ atomic_set_unchecked(&pv->seqno, 0);
51044
51045 pr_devel("HVSI@%x: Handshaking started\n", pv->termno);
51046
51047diff --git a/drivers/tty/ipwireless/tty.c b/drivers/tty/ipwireless/tty.c
51048index 17ee3bf..8d2520d 100644
51049--- a/drivers/tty/ipwireless/tty.c
51050+++ b/drivers/tty/ipwireless/tty.c
51051@@ -28,6 +28,7 @@
51052 #include <linux/tty_driver.h>
51053 #include <linux/tty_flip.h>
51054 #include <linux/uaccess.h>
51055+#include <asm/local.h>
51056
51057 #include "tty.h"
51058 #include "network.h"
51059@@ -98,10 +99,10 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
51060 mutex_unlock(&tty->ipw_tty_mutex);
51061 return -ENODEV;
51062 }
51063- if (tty->port.count == 0)
51064+ if (atomic_read(&tty->port.count) == 0)
51065 tty->tx_bytes_queued = 0;
51066
51067- tty->port.count++;
51068+ atomic_inc(&tty->port.count);
51069
51070 tty->port.tty = linux_tty;
51071 linux_tty->driver_data = tty;
51072@@ -117,9 +118,7 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
51073
51074 static void do_ipw_close(struct ipw_tty *tty)
51075 {
51076- tty->port.count--;
51077-
51078- if (tty->port.count == 0) {
51079+ if (atomic_dec_return(&tty->port.count) == 0) {
51080 struct tty_struct *linux_tty = tty->port.tty;
51081
51082 if (linux_tty != NULL) {
51083@@ -140,7 +139,7 @@ static void ipw_hangup(struct tty_struct *linux_tty)
51084 return;
51085
51086 mutex_lock(&tty->ipw_tty_mutex);
51087- if (tty->port.count == 0) {
51088+ if (atomic_read(&tty->port.count) == 0) {
51089 mutex_unlock(&tty->ipw_tty_mutex);
51090 return;
51091 }
51092@@ -163,7 +162,7 @@ void ipwireless_tty_received(struct ipw_tty *tty, unsigned char *data,
51093
51094 mutex_lock(&tty->ipw_tty_mutex);
51095
51096- if (!tty->port.count) {
51097+ if (!atomic_read(&tty->port.count)) {
51098 mutex_unlock(&tty->ipw_tty_mutex);
51099 return;
51100 }
51101@@ -202,7 +201,7 @@ static int ipw_write(struct tty_struct *linux_tty,
51102 return -ENODEV;
51103
51104 mutex_lock(&tty->ipw_tty_mutex);
51105- if (!tty->port.count) {
51106+ if (!atomic_read(&tty->port.count)) {
51107 mutex_unlock(&tty->ipw_tty_mutex);
51108 return -EINVAL;
51109 }
51110@@ -242,7 +241,7 @@ static int ipw_write_room(struct tty_struct *linux_tty)
51111 if (!tty)
51112 return -ENODEV;
51113
51114- if (!tty->port.count)
51115+ if (!atomic_read(&tty->port.count))
51116 return -EINVAL;
51117
51118 room = IPWIRELESS_TX_QUEUE_SIZE - tty->tx_bytes_queued;
51119@@ -284,7 +283,7 @@ static int ipw_chars_in_buffer(struct tty_struct *linux_tty)
51120 if (!tty)
51121 return 0;
51122
51123- if (!tty->port.count)
51124+ if (!atomic_read(&tty->port.count))
51125 return 0;
51126
51127 return tty->tx_bytes_queued;
51128@@ -365,7 +364,7 @@ static int ipw_tiocmget(struct tty_struct *linux_tty)
51129 if (!tty)
51130 return -ENODEV;
51131
51132- if (!tty->port.count)
51133+ if (!atomic_read(&tty->port.count))
51134 return -EINVAL;
51135
51136 return get_control_lines(tty);
51137@@ -381,7 +380,7 @@ ipw_tiocmset(struct tty_struct *linux_tty,
51138 if (!tty)
51139 return -ENODEV;
51140
51141- if (!tty->port.count)
51142+ if (!atomic_read(&tty->port.count))
51143 return -EINVAL;
51144
51145 return set_control_lines(tty, set, clear);
51146@@ -395,7 +394,7 @@ static int ipw_ioctl(struct tty_struct *linux_tty,
51147 if (!tty)
51148 return -ENODEV;
51149
51150- if (!tty->port.count)
51151+ if (!atomic_read(&tty->port.count))
51152 return -EINVAL;
51153
51154 /* FIXME: Exactly how is the tty object locked here .. */
51155@@ -551,7 +550,7 @@ void ipwireless_tty_free(struct ipw_tty *tty)
51156 * are gone */
51157 mutex_lock(&ttyj->ipw_tty_mutex);
51158 }
51159- while (ttyj->port.count)
51160+ while (atomic_read(&ttyj->port.count))
51161 do_ipw_close(ttyj);
51162 ipwireless_disassociate_network_ttys(network,
51163 ttyj->channel_idx);
51164diff --git a/drivers/tty/moxa.c b/drivers/tty/moxa.c
51165index 1deaca4..c8582d4 100644
51166--- a/drivers/tty/moxa.c
51167+++ b/drivers/tty/moxa.c
51168@@ -1189,7 +1189,7 @@ static int moxa_open(struct tty_struct *tty, struct file *filp)
51169 }
51170
51171 ch = &brd->ports[port % MAX_PORTS_PER_BOARD];
51172- ch->port.count++;
51173+ atomic_inc(&ch->port.count);
51174 tty->driver_data = ch;
51175 tty_port_tty_set(&ch->port, tty);
51176 mutex_lock(&ch->port.mutex);
51177diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
51178index 2ebe47b..3205833 100644
51179--- a/drivers/tty/n_gsm.c
51180+++ b/drivers/tty/n_gsm.c
51181@@ -1644,7 +1644,7 @@ static struct gsm_dlci *gsm_dlci_alloc(struct gsm_mux *gsm, int addr)
51182 spin_lock_init(&dlci->lock);
51183 mutex_init(&dlci->mutex);
51184 dlci->fifo = &dlci->_fifo;
51185- if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL) < 0) {
51186+ if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL)) {
51187 kfree(dlci);
51188 return NULL;
51189 }
51190@@ -2954,7 +2954,7 @@ static int gsmtty_open(struct tty_struct *tty, struct file *filp)
51191 struct gsm_dlci *dlci = tty->driver_data;
51192 struct tty_port *port = &dlci->port;
51193
51194- port->count++;
51195+ atomic_inc(&port->count);
51196 tty_port_tty_set(port, tty);
51197
51198 dlci->modem_rx = 0;
51199diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
51200index e36d1f5..9938e3e 100644
51201--- a/drivers/tty/n_tty.c
51202+++ b/drivers/tty/n_tty.c
51203@@ -115,7 +115,7 @@ struct n_tty_data {
51204 int minimum_to_wake;
51205
51206 /* consumer-published */
51207- size_t read_tail;
51208+ size_t read_tail __intentional_overflow(-1);
51209 size_t line_start;
51210
51211 /* protected by output lock */
51212@@ -2519,6 +2519,7 @@ void n_tty_inherit_ops(struct tty_ldisc_ops *ops)
51213 {
51214 *ops = tty_ldisc_N_TTY;
51215 ops->owner = NULL;
51216- ops->refcount = ops->flags = 0;
51217+ atomic_set(&ops->refcount, 0);
51218+ ops->flags = 0;
51219 }
51220 EXPORT_SYMBOL_GPL(n_tty_inherit_ops);
51221diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
51222index 25c9bc7..24077b7 100644
51223--- a/drivers/tty/pty.c
51224+++ b/drivers/tty/pty.c
51225@@ -790,8 +790,10 @@ static void __init unix98_pty_init(void)
51226 panic("Couldn't register Unix98 pts driver");
51227
51228 /* Now create the /dev/ptmx special device */
51229+ pax_open_kernel();
51230 tty_default_fops(&ptmx_fops);
51231- ptmx_fops.open = ptmx_open;
51232+ *(void **)&ptmx_fops.open = ptmx_open;
51233+ pax_close_kernel();
51234
51235 cdev_init(&ptmx_cdev, &ptmx_fops);
51236 if (cdev_add(&ptmx_cdev, MKDEV(TTYAUX_MAJOR, 2), 1) ||
51237diff --git a/drivers/tty/rocket.c b/drivers/tty/rocket.c
51238index 383c4c7..d408e21 100644
51239--- a/drivers/tty/rocket.c
51240+++ b/drivers/tty/rocket.c
51241@@ -914,7 +914,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
51242 tty->driver_data = info;
51243 tty_port_tty_set(port, tty);
51244
51245- if (port->count++ == 0) {
51246+ if (atomic_inc_return(&port->count) == 1) {
51247 atomic_inc(&rp_num_ports_open);
51248
51249 #ifdef ROCKET_DEBUG_OPEN
51250@@ -923,7 +923,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
51251 #endif
51252 }
51253 #ifdef ROCKET_DEBUG_OPEN
51254- printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, info->port.count);
51255+ printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, atomic-read(&info->port.count));
51256 #endif
51257
51258 /*
51259@@ -1515,7 +1515,7 @@ static void rp_hangup(struct tty_struct *tty)
51260 spin_unlock_irqrestore(&info->port.lock, flags);
51261 return;
51262 }
51263- if (info->port.count)
51264+ if (atomic_read(&info->port.count))
51265 atomic_dec(&rp_num_ports_open);
51266 clear_bit((info->aiop * 8) + info->chan, (void *) &xmit_flags[info->board]);
51267 spin_unlock_irqrestore(&info->port.lock, flags);
51268diff --git a/drivers/tty/serial/ioc4_serial.c b/drivers/tty/serial/ioc4_serial.c
51269index 1274499..f541382 100644
51270--- a/drivers/tty/serial/ioc4_serial.c
51271+++ b/drivers/tty/serial/ioc4_serial.c
51272@@ -437,7 +437,7 @@ struct ioc4_soft {
51273 } is_intr_info[MAX_IOC4_INTR_ENTS];
51274
51275 /* Number of entries active in the above array */
51276- atomic_t is_num_intrs;
51277+ atomic_unchecked_t is_num_intrs;
51278 } is_intr_type[IOC4_NUM_INTR_TYPES];
51279
51280 /* is_ir_lock must be held while
51281@@ -974,7 +974,7 @@ intr_connect(struct ioc4_soft *soft, int type,
51282 BUG_ON(!((type == IOC4_SIO_INTR_TYPE)
51283 || (type == IOC4_OTHER_INTR_TYPE)));
51284
51285- i = atomic_inc_return(&soft-> is_intr_type[type].is_num_intrs) - 1;
51286+ i = atomic_inc_return_unchecked(&soft-> is_intr_type[type].is_num_intrs) - 1;
51287 BUG_ON(!(i < MAX_IOC4_INTR_ENTS || (printk("i %d\n", i), 0)));
51288
51289 /* Save off the lower level interrupt handler */
51290@@ -1001,7 +1001,7 @@ static irqreturn_t ioc4_intr(int irq, void *arg)
51291
51292 soft = arg;
51293 for (intr_type = 0; intr_type < IOC4_NUM_INTR_TYPES; intr_type++) {
51294- num_intrs = (int)atomic_read(
51295+ num_intrs = (int)atomic_read_unchecked(
51296 &soft->is_intr_type[intr_type].is_num_intrs);
51297
51298 this_mir = this_ir = pending_intrs(soft, intr_type);
51299diff --git a/drivers/tty/serial/kgdboc.c b/drivers/tty/serial/kgdboc.c
51300index a260cde..6b2b5ce 100644
51301--- a/drivers/tty/serial/kgdboc.c
51302+++ b/drivers/tty/serial/kgdboc.c
51303@@ -24,8 +24,9 @@
51304 #define MAX_CONFIG_LEN 40
51305
51306 static struct kgdb_io kgdboc_io_ops;
51307+static struct kgdb_io kgdboc_io_ops_console;
51308
51309-/* -1 = init not run yet, 0 = unconfigured, 1 = configured. */
51310+/* -1 = init not run yet, 0 = unconfigured, 1/2 = configured. */
51311 static int configured = -1;
51312
51313 static char config[MAX_CONFIG_LEN];
51314@@ -151,6 +152,8 @@ static void cleanup_kgdboc(void)
51315 kgdboc_unregister_kbd();
51316 if (configured == 1)
51317 kgdb_unregister_io_module(&kgdboc_io_ops);
51318+ else if (configured == 2)
51319+ kgdb_unregister_io_module(&kgdboc_io_ops_console);
51320 }
51321
51322 static int configure_kgdboc(void)
51323@@ -160,13 +163,13 @@ static int configure_kgdboc(void)
51324 int err;
51325 char *cptr = config;
51326 struct console *cons;
51327+ int is_console = 0;
51328
51329 err = kgdboc_option_setup(config);
51330 if (err || !strlen(config) || isspace(config[0]))
51331 goto noconfig;
51332
51333 err = -ENODEV;
51334- kgdboc_io_ops.is_console = 0;
51335 kgdb_tty_driver = NULL;
51336
51337 kgdboc_use_kms = 0;
51338@@ -187,7 +190,7 @@ static int configure_kgdboc(void)
51339 int idx;
51340 if (cons->device && cons->device(cons, &idx) == p &&
51341 idx == tty_line) {
51342- kgdboc_io_ops.is_console = 1;
51343+ is_console = 1;
51344 break;
51345 }
51346 cons = cons->next;
51347@@ -197,7 +200,13 @@ static int configure_kgdboc(void)
51348 kgdb_tty_line = tty_line;
51349
51350 do_register:
51351- err = kgdb_register_io_module(&kgdboc_io_ops);
51352+ if (is_console) {
51353+ err = kgdb_register_io_module(&kgdboc_io_ops_console);
51354+ configured = 2;
51355+ } else {
51356+ err = kgdb_register_io_module(&kgdboc_io_ops);
51357+ configured = 1;
51358+ }
51359 if (err)
51360 goto noconfig;
51361
51362@@ -205,8 +214,6 @@ do_register:
51363 if (err)
51364 goto nmi_con_failed;
51365
51366- configured = 1;
51367-
51368 return 0;
51369
51370 nmi_con_failed:
51371@@ -223,7 +230,7 @@ noconfig:
51372 static int __init init_kgdboc(void)
51373 {
51374 /* Already configured? */
51375- if (configured == 1)
51376+ if (configured >= 1)
51377 return 0;
51378
51379 return configure_kgdboc();
51380@@ -272,7 +279,7 @@ static int param_set_kgdboc_var(const char *kmessage, struct kernel_param *kp)
51381 if (config[len - 1] == '\n')
51382 config[len - 1] = '\0';
51383
51384- if (configured == 1)
51385+ if (configured >= 1)
51386 cleanup_kgdboc();
51387
51388 /* Go and configure with the new params. */
51389@@ -312,6 +319,15 @@ static struct kgdb_io kgdboc_io_ops = {
51390 .post_exception = kgdboc_post_exp_handler,
51391 };
51392
51393+static struct kgdb_io kgdboc_io_ops_console = {
51394+ .name = "kgdboc",
51395+ .read_char = kgdboc_get_char,
51396+ .write_char = kgdboc_put_char,
51397+ .pre_exception = kgdboc_pre_exp_handler,
51398+ .post_exception = kgdboc_post_exp_handler,
51399+ .is_console = 1
51400+};
51401+
51402 #ifdef CONFIG_KGDB_SERIAL_CONSOLE
51403 /* This is only available if kgdboc is a built in for early debugging */
51404 static int __init kgdboc_early_init(char *opt)
51405diff --git a/drivers/tty/serial/msm_serial.c b/drivers/tty/serial/msm_serial.c
51406index b5d779c..3622cfe 100644
51407--- a/drivers/tty/serial/msm_serial.c
51408+++ b/drivers/tty/serial/msm_serial.c
51409@@ -897,7 +897,7 @@ static struct uart_driver msm_uart_driver = {
51410 .cons = MSM_CONSOLE,
51411 };
51412
51413-static atomic_t msm_uart_next_id = ATOMIC_INIT(0);
51414+static atomic_unchecked_t msm_uart_next_id = ATOMIC_INIT(0);
51415
51416 static const struct of_device_id msm_uartdm_table[] = {
51417 { .compatible = "qcom,msm-uartdm" },
51418@@ -912,7 +912,7 @@ static int __init msm_serial_probe(struct platform_device *pdev)
51419 int irq;
51420
51421 if (pdev->id == -1)
51422- pdev->id = atomic_inc_return(&msm_uart_next_id) - 1;
51423+ pdev->id = atomic_inc_return_unchecked(&msm_uart_next_id) - 1;
51424
51425 if (unlikely(pdev->id < 0 || pdev->id >= UART_NR))
51426 return -ENXIO;
51427diff --git a/drivers/tty/serial/samsung.c b/drivers/tty/serial/samsung.c
51428index 9cd706d..6ff2de7 100644
51429--- a/drivers/tty/serial/samsung.c
51430+++ b/drivers/tty/serial/samsung.c
51431@@ -463,11 +463,16 @@ static void s3c24xx_serial_shutdown(struct uart_port *port)
51432 }
51433 }
51434
51435+static int s3c64xx_serial_startup(struct uart_port *port);
51436 static int s3c24xx_serial_startup(struct uart_port *port)
51437 {
51438 struct s3c24xx_uart_port *ourport = to_ourport(port);
51439 int ret;
51440
51441+ /* Startup sequence is different for s3c64xx and higher SoC's */
51442+ if (s3c24xx_serial_has_interrupt_mask(port))
51443+ return s3c64xx_serial_startup(port);
51444+
51445 dbg("s3c24xx_serial_startup: port=%p (%08lx,%p)\n",
51446 port->mapbase, port->membase);
51447
51448@@ -1141,10 +1146,6 @@ static int s3c24xx_serial_init_port(struct s3c24xx_uart_port *ourport,
51449 /* setup info for port */
51450 port->dev = &platdev->dev;
51451
51452- /* Startup sequence is different for s3c64xx and higher SoC's */
51453- if (s3c24xx_serial_has_interrupt_mask(port))
51454- s3c24xx_serial_ops.startup = s3c64xx_serial_startup;
51455-
51456 port->uartclk = 1;
51457
51458 if (cfg->uart_flags & UPF_CONS_FLOW) {
51459diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
51460index ece2049..fba2524 100644
51461--- a/drivers/tty/serial/serial_core.c
51462+++ b/drivers/tty/serial/serial_core.c
51463@@ -1448,7 +1448,7 @@ static void uart_hangup(struct tty_struct *tty)
51464 uart_flush_buffer(tty);
51465 uart_shutdown(tty, state);
51466 spin_lock_irqsave(&port->lock, flags);
51467- port->count = 0;
51468+ atomic_set(&port->count, 0);
51469 clear_bit(ASYNCB_NORMAL_ACTIVE, &port->flags);
51470 spin_unlock_irqrestore(&port->lock, flags);
51471 tty_port_tty_set(port, NULL);
51472@@ -1544,7 +1544,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
51473 goto end;
51474 }
51475
51476- port->count++;
51477+ atomic_inc(&port->count);
51478 if (!state->uart_port || state->uart_port->flags & UPF_DEAD) {
51479 retval = -ENXIO;
51480 goto err_dec_count;
51481@@ -1572,7 +1572,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
51482 /*
51483 * Make sure the device is in D0 state.
51484 */
51485- if (port->count == 1)
51486+ if (atomic_read(&port->count) == 1)
51487 uart_change_pm(state, UART_PM_STATE_ON);
51488
51489 /*
51490@@ -1590,7 +1590,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
51491 end:
51492 return retval;
51493 err_dec_count:
51494- port->count--;
51495+ atomic_inc(&port->count);
51496 mutex_unlock(&port->mutex);
51497 goto end;
51498 }
51499diff --git a/drivers/tty/synclink.c b/drivers/tty/synclink.c
51500index 5ae14b4..2c1288f 100644
51501--- a/drivers/tty/synclink.c
51502+++ b/drivers/tty/synclink.c
51503@@ -3090,7 +3090,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
51504
51505 if (debug_level >= DEBUG_LEVEL_INFO)
51506 printk("%s(%d):mgsl_close(%s) entry, count=%d\n",
51507- __FILE__,__LINE__, info->device_name, info->port.count);
51508+ __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
51509
51510 if (tty_port_close_start(&info->port, tty, filp) == 0)
51511 goto cleanup;
51512@@ -3108,7 +3108,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
51513 cleanup:
51514 if (debug_level >= DEBUG_LEVEL_INFO)
51515 printk("%s(%d):mgsl_close(%s) exit, count=%d\n", __FILE__,__LINE__,
51516- tty->driver->name, info->port.count);
51517+ tty->driver->name, atomic_read(&info->port.count));
51518
51519 } /* end of mgsl_close() */
51520
51521@@ -3207,8 +3207,8 @@ static void mgsl_hangup(struct tty_struct *tty)
51522
51523 mgsl_flush_buffer(tty);
51524 shutdown(info);
51525-
51526- info->port.count = 0;
51527+
51528+ atomic_set(&info->port.count, 0);
51529 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
51530 info->port.tty = NULL;
51531
51532@@ -3297,12 +3297,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
51533
51534 if (debug_level >= DEBUG_LEVEL_INFO)
51535 printk("%s(%d):block_til_ready before block on %s count=%d\n",
51536- __FILE__,__LINE__, tty->driver->name, port->count );
51537+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
51538
51539 spin_lock_irqsave(&info->irq_spinlock, flags);
51540 if (!tty_hung_up_p(filp)) {
51541 extra_count = true;
51542- port->count--;
51543+ atomic_dec(&port->count);
51544 }
51545 spin_unlock_irqrestore(&info->irq_spinlock, flags);
51546 port->blocked_open++;
51547@@ -3331,7 +3331,7 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
51548
51549 if (debug_level >= DEBUG_LEVEL_INFO)
51550 printk("%s(%d):block_til_ready blocking on %s count=%d\n",
51551- __FILE__,__LINE__, tty->driver->name, port->count );
51552+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
51553
51554 tty_unlock(tty);
51555 schedule();
51556@@ -3343,12 +3343,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
51557
51558 /* FIXME: Racy on hangup during close wait */
51559 if (extra_count)
51560- port->count++;
51561+ atomic_inc(&port->count);
51562 port->blocked_open--;
51563
51564 if (debug_level >= DEBUG_LEVEL_INFO)
51565 printk("%s(%d):block_til_ready after blocking on %s count=%d\n",
51566- __FILE__,__LINE__, tty->driver->name, port->count );
51567+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
51568
51569 if (!retval)
51570 port->flags |= ASYNC_NORMAL_ACTIVE;
51571@@ -3400,7 +3400,7 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
51572
51573 if (debug_level >= DEBUG_LEVEL_INFO)
51574 printk("%s(%d):mgsl_open(%s), old ref count = %d\n",
51575- __FILE__,__LINE__,tty->driver->name, info->port.count);
51576+ __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
51577
51578 /* If port is closing, signal caller to try again */
51579 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
51580@@ -3419,10 +3419,10 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
51581 spin_unlock_irqrestore(&info->netlock, flags);
51582 goto cleanup;
51583 }
51584- info->port.count++;
51585+ atomic_inc(&info->port.count);
51586 spin_unlock_irqrestore(&info->netlock, flags);
51587
51588- if (info->port.count == 1) {
51589+ if (atomic_read(&info->port.count) == 1) {
51590 /* 1st open on this device, init hardware */
51591 retval = startup(info);
51592 if (retval < 0)
51593@@ -3446,8 +3446,8 @@ cleanup:
51594 if (retval) {
51595 if (tty->count == 1)
51596 info->port.tty = NULL; /* tty layer will release tty struct */
51597- if(info->port.count)
51598- info->port.count--;
51599+ if (atomic_read(&info->port.count))
51600+ atomic_dec(&info->port.count);
51601 }
51602
51603 return retval;
51604@@ -7665,7 +7665,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
51605 unsigned short new_crctype;
51606
51607 /* return error if TTY interface open */
51608- if (info->port.count)
51609+ if (atomic_read(&info->port.count))
51610 return -EBUSY;
51611
51612 switch (encoding)
51613@@ -7760,7 +7760,7 @@ static int hdlcdev_open(struct net_device *dev)
51614
51615 /* arbitrate between network and tty opens */
51616 spin_lock_irqsave(&info->netlock, flags);
51617- if (info->port.count != 0 || info->netcount != 0) {
51618+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
51619 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
51620 spin_unlock_irqrestore(&info->netlock, flags);
51621 return -EBUSY;
51622@@ -7846,7 +7846,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
51623 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
51624
51625 /* return error if TTY interface open */
51626- if (info->port.count)
51627+ if (atomic_read(&info->port.count))
51628 return -EBUSY;
51629
51630 if (cmd != SIOCWANDEV)
51631diff --git a/drivers/tty/synclink_gt.c b/drivers/tty/synclink_gt.c
51632index c359a91..959fc26 100644
51633--- a/drivers/tty/synclink_gt.c
51634+++ b/drivers/tty/synclink_gt.c
51635@@ -670,7 +670,7 @@ static int open(struct tty_struct *tty, struct file *filp)
51636 tty->driver_data = info;
51637 info->port.tty = tty;
51638
51639- DBGINFO(("%s open, old ref count = %d\n", info->device_name, info->port.count));
51640+ DBGINFO(("%s open, old ref count = %d\n", info->device_name, atomic_read(&info->port.count)));
51641
51642 /* If port is closing, signal caller to try again */
51643 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
51644@@ -691,10 +691,10 @@ static int open(struct tty_struct *tty, struct file *filp)
51645 mutex_unlock(&info->port.mutex);
51646 goto cleanup;
51647 }
51648- info->port.count++;
51649+ atomic_inc(&info->port.count);
51650 spin_unlock_irqrestore(&info->netlock, flags);
51651
51652- if (info->port.count == 1) {
51653+ if (atomic_read(&info->port.count) == 1) {
51654 /* 1st open on this device, init hardware */
51655 retval = startup(info);
51656 if (retval < 0) {
51657@@ -715,8 +715,8 @@ cleanup:
51658 if (retval) {
51659 if (tty->count == 1)
51660 info->port.tty = NULL; /* tty layer will release tty struct */
51661- if(info->port.count)
51662- info->port.count--;
51663+ if(atomic_read(&info->port.count))
51664+ atomic_dec(&info->port.count);
51665 }
51666
51667 DBGINFO(("%s open rc=%d\n", info->device_name, retval));
51668@@ -729,7 +729,7 @@ static void close(struct tty_struct *tty, struct file *filp)
51669
51670 if (sanity_check(info, tty->name, "close"))
51671 return;
51672- DBGINFO(("%s close entry, count=%d\n", info->device_name, info->port.count));
51673+ DBGINFO(("%s close entry, count=%d\n", info->device_name, atomic_read(&info->port.count)));
51674
51675 if (tty_port_close_start(&info->port, tty, filp) == 0)
51676 goto cleanup;
51677@@ -746,7 +746,7 @@ static void close(struct tty_struct *tty, struct file *filp)
51678 tty_port_close_end(&info->port, tty);
51679 info->port.tty = NULL;
51680 cleanup:
51681- DBGINFO(("%s close exit, count=%d\n", tty->driver->name, info->port.count));
51682+ DBGINFO(("%s close exit, count=%d\n", tty->driver->name, atomic_read(&info->port.count)));
51683 }
51684
51685 static void hangup(struct tty_struct *tty)
51686@@ -764,7 +764,7 @@ static void hangup(struct tty_struct *tty)
51687 shutdown(info);
51688
51689 spin_lock_irqsave(&info->port.lock, flags);
51690- info->port.count = 0;
51691+ atomic_set(&info->port.count, 0);
51692 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
51693 info->port.tty = NULL;
51694 spin_unlock_irqrestore(&info->port.lock, flags);
51695@@ -1449,7 +1449,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
51696 unsigned short new_crctype;
51697
51698 /* return error if TTY interface open */
51699- if (info->port.count)
51700+ if (atomic_read(&info->port.count))
51701 return -EBUSY;
51702
51703 DBGINFO(("%s hdlcdev_attach\n", info->device_name));
51704@@ -1544,7 +1544,7 @@ static int hdlcdev_open(struct net_device *dev)
51705
51706 /* arbitrate between network and tty opens */
51707 spin_lock_irqsave(&info->netlock, flags);
51708- if (info->port.count != 0 || info->netcount != 0) {
51709+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
51710 DBGINFO(("%s hdlc_open busy\n", dev->name));
51711 spin_unlock_irqrestore(&info->netlock, flags);
51712 return -EBUSY;
51713@@ -1629,7 +1629,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
51714 DBGINFO(("%s hdlcdev_ioctl\n", dev->name));
51715
51716 /* return error if TTY interface open */
51717- if (info->port.count)
51718+ if (atomic_read(&info->port.count))
51719 return -EBUSY;
51720
51721 if (cmd != SIOCWANDEV)
51722@@ -2413,7 +2413,7 @@ static irqreturn_t slgt_interrupt(int dummy, void *dev_id)
51723 if (port == NULL)
51724 continue;
51725 spin_lock(&port->lock);
51726- if ((port->port.count || port->netcount) &&
51727+ if ((atomic_read(&port->port.count) || port->netcount) &&
51728 port->pending_bh && !port->bh_running &&
51729 !port->bh_requested) {
51730 DBGISR(("%s bh queued\n", port->device_name));
51731@@ -3302,7 +3302,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
51732 spin_lock_irqsave(&info->lock, flags);
51733 if (!tty_hung_up_p(filp)) {
51734 extra_count = true;
51735- port->count--;
51736+ atomic_dec(&port->count);
51737 }
51738 spin_unlock_irqrestore(&info->lock, flags);
51739 port->blocked_open++;
51740@@ -3339,7 +3339,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
51741 remove_wait_queue(&port->open_wait, &wait);
51742
51743 if (extra_count)
51744- port->count++;
51745+ atomic_inc(&port->count);
51746 port->blocked_open--;
51747
51748 if (!retval)
51749diff --git a/drivers/tty/synclinkmp.c b/drivers/tty/synclinkmp.c
51750index 144202e..4ccb07d 100644
51751--- a/drivers/tty/synclinkmp.c
51752+++ b/drivers/tty/synclinkmp.c
51753@@ -750,7 +750,7 @@ static int open(struct tty_struct *tty, struct file *filp)
51754
51755 if (debug_level >= DEBUG_LEVEL_INFO)
51756 printk("%s(%d):%s open(), old ref count = %d\n",
51757- __FILE__,__LINE__,tty->driver->name, info->port.count);
51758+ __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
51759
51760 /* If port is closing, signal caller to try again */
51761 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
51762@@ -769,10 +769,10 @@ static int open(struct tty_struct *tty, struct file *filp)
51763 spin_unlock_irqrestore(&info->netlock, flags);
51764 goto cleanup;
51765 }
51766- info->port.count++;
51767+ atomic_inc(&info->port.count);
51768 spin_unlock_irqrestore(&info->netlock, flags);
51769
51770- if (info->port.count == 1) {
51771+ if (atomic_read(&info->port.count) == 1) {
51772 /* 1st open on this device, init hardware */
51773 retval = startup(info);
51774 if (retval < 0)
51775@@ -796,8 +796,8 @@ cleanup:
51776 if (retval) {
51777 if (tty->count == 1)
51778 info->port.tty = NULL; /* tty layer will release tty struct */
51779- if(info->port.count)
51780- info->port.count--;
51781+ if(atomic_read(&info->port.count))
51782+ atomic_dec(&info->port.count);
51783 }
51784
51785 return retval;
51786@@ -815,7 +815,7 @@ static void close(struct tty_struct *tty, struct file *filp)
51787
51788 if (debug_level >= DEBUG_LEVEL_INFO)
51789 printk("%s(%d):%s close() entry, count=%d\n",
51790- __FILE__,__LINE__, info->device_name, info->port.count);
51791+ __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
51792
51793 if (tty_port_close_start(&info->port, tty, filp) == 0)
51794 goto cleanup;
51795@@ -834,7 +834,7 @@ static void close(struct tty_struct *tty, struct file *filp)
51796 cleanup:
51797 if (debug_level >= DEBUG_LEVEL_INFO)
51798 printk("%s(%d):%s close() exit, count=%d\n", __FILE__,__LINE__,
51799- tty->driver->name, info->port.count);
51800+ tty->driver->name, atomic_read(&info->port.count));
51801 }
51802
51803 /* Called by tty_hangup() when a hangup is signaled.
51804@@ -857,7 +857,7 @@ static void hangup(struct tty_struct *tty)
51805 shutdown(info);
51806
51807 spin_lock_irqsave(&info->port.lock, flags);
51808- info->port.count = 0;
51809+ atomic_set(&info->port.count, 0);
51810 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
51811 info->port.tty = NULL;
51812 spin_unlock_irqrestore(&info->port.lock, flags);
51813@@ -1565,7 +1565,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
51814 unsigned short new_crctype;
51815
51816 /* return error if TTY interface open */
51817- if (info->port.count)
51818+ if (atomic_read(&info->port.count))
51819 return -EBUSY;
51820
51821 switch (encoding)
51822@@ -1660,7 +1660,7 @@ static int hdlcdev_open(struct net_device *dev)
51823
51824 /* arbitrate between network and tty opens */
51825 spin_lock_irqsave(&info->netlock, flags);
51826- if (info->port.count != 0 || info->netcount != 0) {
51827+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
51828 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
51829 spin_unlock_irqrestore(&info->netlock, flags);
51830 return -EBUSY;
51831@@ -1746,7 +1746,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
51832 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
51833
51834 /* return error if TTY interface open */
51835- if (info->port.count)
51836+ if (atomic_read(&info->port.count))
51837 return -EBUSY;
51838
51839 if (cmd != SIOCWANDEV)
51840@@ -2620,7 +2620,7 @@ static irqreturn_t synclinkmp_interrupt(int dummy, void *dev_id)
51841 * do not request bottom half processing if the
51842 * device is not open in a normal mode.
51843 */
51844- if ( port && (port->port.count || port->netcount) &&
51845+ if ( port && (atomic_read(&port->port.count) || port->netcount) &&
51846 port->pending_bh && !port->bh_running &&
51847 !port->bh_requested ) {
51848 if ( debug_level >= DEBUG_LEVEL_ISR )
51849@@ -3318,12 +3318,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
51850
51851 if (debug_level >= DEBUG_LEVEL_INFO)
51852 printk("%s(%d):%s block_til_ready() before block, count=%d\n",
51853- __FILE__,__LINE__, tty->driver->name, port->count );
51854+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
51855
51856 spin_lock_irqsave(&info->lock, flags);
51857 if (!tty_hung_up_p(filp)) {
51858 extra_count = true;
51859- port->count--;
51860+ atomic_dec(&port->count);
51861 }
51862 spin_unlock_irqrestore(&info->lock, flags);
51863 port->blocked_open++;
51864@@ -3352,7 +3352,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
51865
51866 if (debug_level >= DEBUG_LEVEL_INFO)
51867 printk("%s(%d):%s block_til_ready() count=%d\n",
51868- __FILE__,__LINE__, tty->driver->name, port->count );
51869+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
51870
51871 tty_unlock(tty);
51872 schedule();
51873@@ -3363,12 +3363,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
51874 remove_wait_queue(&port->open_wait, &wait);
51875
51876 if (extra_count)
51877- port->count++;
51878+ atomic_inc(&port->count);
51879 port->blocked_open--;
51880
51881 if (debug_level >= DEBUG_LEVEL_INFO)
51882 printk("%s(%d):%s block_til_ready() after, count=%d\n",
51883- __FILE__,__LINE__, tty->driver->name, port->count );
51884+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
51885
51886 if (!retval)
51887 port->flags |= ASYNC_NORMAL_ACTIVE;
51888diff --git a/drivers/tty/sysrq.c b/drivers/tty/sysrq.c
51889index ce396ec..04a37be 100644
51890--- a/drivers/tty/sysrq.c
51891+++ b/drivers/tty/sysrq.c
51892@@ -1075,7 +1075,7 @@ EXPORT_SYMBOL(unregister_sysrq_key);
51893 static ssize_t write_sysrq_trigger(struct file *file, const char __user *buf,
51894 size_t count, loff_t *ppos)
51895 {
51896- if (count) {
51897+ if (count && capable(CAP_SYS_ADMIN)) {
51898 char c;
51899
51900 if (get_user(c, buf))
51901diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
51902index d3448a9..28e8db0 100644
51903--- a/drivers/tty/tty_io.c
51904+++ b/drivers/tty/tty_io.c
51905@@ -3475,7 +3475,7 @@ EXPORT_SYMBOL_GPL(get_current_tty);
51906
51907 void tty_default_fops(struct file_operations *fops)
51908 {
51909- *fops = tty_fops;
51910+ memcpy((void *)fops, &tty_fops, sizeof(tty_fops));
51911 }
51912
51913 /*
51914diff --git a/drivers/tty/tty_ldisc.c b/drivers/tty/tty_ldisc.c
51915index 2d822aa..a566234 100644
51916--- a/drivers/tty/tty_ldisc.c
51917+++ b/drivers/tty/tty_ldisc.c
51918@@ -71,7 +71,7 @@ int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc)
51919 raw_spin_lock_irqsave(&tty_ldiscs_lock, flags);
51920 tty_ldiscs[disc] = new_ldisc;
51921 new_ldisc->num = disc;
51922- new_ldisc->refcount = 0;
51923+ atomic_set(&new_ldisc->refcount, 0);
51924 raw_spin_unlock_irqrestore(&tty_ldiscs_lock, flags);
51925
51926 return ret;
51927@@ -99,7 +99,7 @@ int tty_unregister_ldisc(int disc)
51928 return -EINVAL;
51929
51930 raw_spin_lock_irqsave(&tty_ldiscs_lock, flags);
51931- if (tty_ldiscs[disc]->refcount)
51932+ if (atomic_read(&tty_ldiscs[disc]->refcount))
51933 ret = -EBUSY;
51934 else
51935 tty_ldiscs[disc] = NULL;
51936@@ -120,7 +120,7 @@ static struct tty_ldisc_ops *get_ldops(int disc)
51937 if (ldops) {
51938 ret = ERR_PTR(-EAGAIN);
51939 if (try_module_get(ldops->owner)) {
51940- ldops->refcount++;
51941+ atomic_inc(&ldops->refcount);
51942 ret = ldops;
51943 }
51944 }
51945@@ -133,7 +133,7 @@ static void put_ldops(struct tty_ldisc_ops *ldops)
51946 unsigned long flags;
51947
51948 raw_spin_lock_irqsave(&tty_ldiscs_lock, flags);
51949- ldops->refcount--;
51950+ atomic_dec(&ldops->refcount);
51951 module_put(ldops->owner);
51952 raw_spin_unlock_irqrestore(&tty_ldiscs_lock, flags);
51953 }
51954diff --git a/drivers/tty/tty_port.c b/drivers/tty/tty_port.c
51955index 3f746c8..2f2fcaa 100644
51956--- a/drivers/tty/tty_port.c
51957+++ b/drivers/tty/tty_port.c
51958@@ -235,7 +235,7 @@ void tty_port_hangup(struct tty_port *port)
51959 unsigned long flags;
51960
51961 spin_lock_irqsave(&port->lock, flags);
51962- port->count = 0;
51963+ atomic_set(&port->count, 0);
51964 port->flags &= ~ASYNC_NORMAL_ACTIVE;
51965 tty = port->tty;
51966 if (tty)
51967@@ -393,7 +393,7 @@ int tty_port_block_til_ready(struct tty_port *port,
51968 /* The port lock protects the port counts */
51969 spin_lock_irqsave(&port->lock, flags);
51970 if (!tty_hung_up_p(filp))
51971- port->count--;
51972+ atomic_dec(&port->count);
51973 port->blocked_open++;
51974 spin_unlock_irqrestore(&port->lock, flags);
51975
51976@@ -435,7 +435,7 @@ int tty_port_block_til_ready(struct tty_port *port,
51977 we must not mess that up further */
51978 spin_lock_irqsave(&port->lock, flags);
51979 if (!tty_hung_up_p(filp))
51980- port->count++;
51981+ atomic_inc(&port->count);
51982 port->blocked_open--;
51983 if (retval == 0)
51984 port->flags |= ASYNC_NORMAL_ACTIVE;
51985@@ -469,19 +469,19 @@ int tty_port_close_start(struct tty_port *port,
51986 return 0;
51987 }
51988
51989- if (tty->count == 1 && port->count != 1) {
51990+ if (tty->count == 1 && atomic_read(&port->count) != 1) {
51991 printk(KERN_WARNING
51992 "tty_port_close_start: tty->count = 1 port count = %d.\n",
51993- port->count);
51994- port->count = 1;
51995+ atomic_read(&port->count));
51996+ atomic_set(&port->count, 1);
51997 }
51998- if (--port->count < 0) {
51999+ if (atomic_dec_return(&port->count) < 0) {
52000 printk(KERN_WARNING "tty_port_close_start: count = %d\n",
52001- port->count);
52002- port->count = 0;
52003+ atomic_read(&port->count));
52004+ atomic_set(&port->count, 0);
52005 }
52006
52007- if (port->count) {
52008+ if (atomic_read(&port->count)) {
52009 spin_unlock_irqrestore(&port->lock, flags);
52010 return 0;
52011 }
52012@@ -563,7 +563,7 @@ int tty_port_open(struct tty_port *port, struct tty_struct *tty,
52013 {
52014 spin_lock_irq(&port->lock);
52015 if (!tty_hung_up_p(filp))
52016- ++port->count;
52017+ atomic_inc(&port->count);
52018 spin_unlock_irq(&port->lock);
52019 tty_port_tty_set(port, tty);
52020
52021diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c
52022index d0e3a44..5f8b754 100644
52023--- a/drivers/tty/vt/keyboard.c
52024+++ b/drivers/tty/vt/keyboard.c
52025@@ -641,6 +641,16 @@ static void k_spec(struct vc_data *vc, unsigned char value, char up_flag)
52026 kbd->kbdmode == VC_OFF) &&
52027 value != KVAL(K_SAK))
52028 return; /* SAK is allowed even in raw mode */
52029+
52030+#if defined(CONFIG_GRKERNSEC_PROC) || defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
52031+ {
52032+ void *func = fn_handler[value];
52033+ if (func == fn_show_state || func == fn_show_ptregs ||
52034+ func == fn_show_mem)
52035+ return;
52036+ }
52037+#endif
52038+
52039 fn_handler[value](vc);
52040 }
52041
52042@@ -1776,9 +1786,6 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
52043 if (copy_from_user(&tmp, user_kbe, sizeof(struct kbentry)))
52044 return -EFAULT;
52045
52046- if (!capable(CAP_SYS_TTY_CONFIG))
52047- perm = 0;
52048-
52049 switch (cmd) {
52050 case KDGKBENT:
52051 /* Ensure another thread doesn't free it under us */
52052@@ -1793,6 +1800,9 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
52053 spin_unlock_irqrestore(&kbd_event_lock, flags);
52054 return put_user(val, &user_kbe->kb_value);
52055 case KDSKBENT:
52056+ if (!capable(CAP_SYS_TTY_CONFIG))
52057+ perm = 0;
52058+
52059 if (!perm)
52060 return -EPERM;
52061 if (!i && v == K_NOSUCHMAP) {
52062@@ -1883,9 +1893,6 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
52063 int i, j, k;
52064 int ret;
52065
52066- if (!capable(CAP_SYS_TTY_CONFIG))
52067- perm = 0;
52068-
52069 kbs = kmalloc(sizeof(*kbs), GFP_KERNEL);
52070 if (!kbs) {
52071 ret = -ENOMEM;
52072@@ -1919,6 +1926,9 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
52073 kfree(kbs);
52074 return ((p && *p) ? -EOVERFLOW : 0);
52075 case KDSKBSENT:
52076+ if (!capable(CAP_SYS_TTY_CONFIG))
52077+ perm = 0;
52078+
52079 if (!perm) {
52080 ret = -EPERM;
52081 goto reterr;
52082diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
52083index a673e5b..36e5d32 100644
52084--- a/drivers/uio/uio.c
52085+++ b/drivers/uio/uio.c
52086@@ -25,6 +25,7 @@
52087 #include <linux/kobject.h>
52088 #include <linux/cdev.h>
52089 #include <linux/uio_driver.h>
52090+#include <asm/local.h>
52091
52092 #define UIO_MAX_DEVICES (1U << MINORBITS)
52093
52094@@ -32,7 +33,7 @@ struct uio_device {
52095 struct module *owner;
52096 struct device *dev;
52097 int minor;
52098- atomic_t event;
52099+ atomic_unchecked_t event;
52100 struct fasync_struct *async_queue;
52101 wait_queue_head_t wait;
52102 struct uio_info *info;
52103@@ -243,7 +244,7 @@ static ssize_t event_show(struct device *dev,
52104 struct device_attribute *attr, char *buf)
52105 {
52106 struct uio_device *idev = dev_get_drvdata(dev);
52107- return sprintf(buf, "%u\n", (unsigned int)atomic_read(&idev->event));
52108+ return sprintf(buf, "%u\n", (unsigned int)atomic_read_unchecked(&idev->event));
52109 }
52110 static DEVICE_ATTR_RO(event);
52111
52112@@ -405,7 +406,7 @@ void uio_event_notify(struct uio_info *info)
52113 {
52114 struct uio_device *idev = info->uio_dev;
52115
52116- atomic_inc(&idev->event);
52117+ atomic_inc_unchecked(&idev->event);
52118 wake_up_interruptible(&idev->wait);
52119 kill_fasync(&idev->async_queue, SIGIO, POLL_IN);
52120 }
52121@@ -458,7 +459,7 @@ static int uio_open(struct inode *inode, struct file *filep)
52122 }
52123
52124 listener->dev = idev;
52125- listener->event_count = atomic_read(&idev->event);
52126+ listener->event_count = atomic_read_unchecked(&idev->event);
52127 filep->private_data = listener;
52128
52129 if (idev->info->open) {
52130@@ -509,7 +510,7 @@ static unsigned int uio_poll(struct file *filep, poll_table *wait)
52131 return -EIO;
52132
52133 poll_wait(filep, &idev->wait, wait);
52134- if (listener->event_count != atomic_read(&idev->event))
52135+ if (listener->event_count != atomic_read_unchecked(&idev->event))
52136 return POLLIN | POLLRDNORM;
52137 return 0;
52138 }
52139@@ -534,7 +535,7 @@ static ssize_t uio_read(struct file *filep, char __user *buf,
52140 do {
52141 set_current_state(TASK_INTERRUPTIBLE);
52142
52143- event_count = atomic_read(&idev->event);
52144+ event_count = atomic_read_unchecked(&idev->event);
52145 if (event_count != listener->event_count) {
52146 if (copy_to_user(buf, &event_count, count))
52147 retval = -EFAULT;
52148@@ -591,9 +592,13 @@ static ssize_t uio_write(struct file *filep, const char __user *buf,
52149 static int uio_find_mem_index(struct vm_area_struct *vma)
52150 {
52151 struct uio_device *idev = vma->vm_private_data;
52152+ unsigned long size;
52153
52154 if (vma->vm_pgoff < MAX_UIO_MAPS) {
52155- if (idev->info->mem[vma->vm_pgoff].size == 0)
52156+ size = idev->info->mem[vma->vm_pgoff].size;
52157+ if (size == 0)
52158+ return -1;
52159+ if (vma->vm_end - vma->vm_start > size)
52160 return -1;
52161 return (int)vma->vm_pgoff;
52162 }
52163@@ -825,7 +830,7 @@ int __uio_register_device(struct module *owner,
52164 idev->owner = owner;
52165 idev->info = info;
52166 init_waitqueue_head(&idev->wait);
52167- atomic_set(&idev->event, 0);
52168+ atomic_set_unchecked(&idev->event, 0);
52169
52170 ret = uio_get_minor(idev);
52171 if (ret)
52172diff --git a/drivers/usb/atm/cxacru.c b/drivers/usb/atm/cxacru.c
52173index 813d4d3..a71934f 100644
52174--- a/drivers/usb/atm/cxacru.c
52175+++ b/drivers/usb/atm/cxacru.c
52176@@ -472,7 +472,7 @@ static ssize_t cxacru_sysfs_store_adsl_config(struct device *dev,
52177 ret = sscanf(buf + pos, "%x=%x%n", &index, &value, &tmp);
52178 if (ret < 2)
52179 return -EINVAL;
52180- if (index < 0 || index > 0x7f)
52181+ if (index > 0x7f)
52182 return -EINVAL;
52183 pos += tmp;
52184
52185diff --git a/drivers/usb/atm/usbatm.c b/drivers/usb/atm/usbatm.c
52186index dada014..1d0d517 100644
52187--- a/drivers/usb/atm/usbatm.c
52188+++ b/drivers/usb/atm/usbatm.c
52189@@ -331,7 +331,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
52190 if (printk_ratelimit())
52191 atm_warn(instance, "%s: OAM not supported (vpi %d, vci %d)!\n",
52192 __func__, vpi, vci);
52193- atomic_inc(&vcc->stats->rx_err);
52194+ atomic_inc_unchecked(&vcc->stats->rx_err);
52195 return;
52196 }
52197
52198@@ -358,7 +358,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
52199 if (length > ATM_MAX_AAL5_PDU) {
52200 atm_rldbg(instance, "%s: bogus length %u (vcc: 0x%p)!\n",
52201 __func__, length, vcc);
52202- atomic_inc(&vcc->stats->rx_err);
52203+ atomic_inc_unchecked(&vcc->stats->rx_err);
52204 goto out;
52205 }
52206
52207@@ -367,14 +367,14 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
52208 if (sarb->len < pdu_length) {
52209 atm_rldbg(instance, "%s: bogus pdu_length %u (sarb->len: %u, vcc: 0x%p)!\n",
52210 __func__, pdu_length, sarb->len, vcc);
52211- atomic_inc(&vcc->stats->rx_err);
52212+ atomic_inc_unchecked(&vcc->stats->rx_err);
52213 goto out;
52214 }
52215
52216 if (crc32_be(~0, skb_tail_pointer(sarb) - pdu_length, pdu_length) != 0xc704dd7b) {
52217 atm_rldbg(instance, "%s: packet failed crc check (vcc: 0x%p)!\n",
52218 __func__, vcc);
52219- atomic_inc(&vcc->stats->rx_err);
52220+ atomic_inc_unchecked(&vcc->stats->rx_err);
52221 goto out;
52222 }
52223
52224@@ -386,7 +386,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
52225 if (printk_ratelimit())
52226 atm_err(instance, "%s: no memory for skb (length: %u)!\n",
52227 __func__, length);
52228- atomic_inc(&vcc->stats->rx_drop);
52229+ atomic_inc_unchecked(&vcc->stats->rx_drop);
52230 goto out;
52231 }
52232
52233@@ -414,7 +414,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
52234
52235 vcc->push(vcc, skb);
52236
52237- atomic_inc(&vcc->stats->rx);
52238+ atomic_inc_unchecked(&vcc->stats->rx);
52239 out:
52240 skb_trim(sarb, 0);
52241 }
52242@@ -612,7 +612,7 @@ static void usbatm_tx_process(unsigned long data)
52243 struct atm_vcc *vcc = UDSL_SKB(skb)->atm.vcc;
52244
52245 usbatm_pop(vcc, skb);
52246- atomic_inc(&vcc->stats->tx);
52247+ atomic_inc_unchecked(&vcc->stats->tx);
52248
52249 skb = skb_dequeue(&instance->sndqueue);
52250 }
52251@@ -756,11 +756,11 @@ static int usbatm_atm_proc_read(struct atm_dev *atm_dev, loff_t *pos, char *page
52252 if (!left--)
52253 return sprintf(page,
52254 "AAL5: tx %d ( %d err ), rx %d ( %d err, %d drop )\n",
52255- atomic_read(&atm_dev->stats.aal5.tx),
52256- atomic_read(&atm_dev->stats.aal5.tx_err),
52257- atomic_read(&atm_dev->stats.aal5.rx),
52258- atomic_read(&atm_dev->stats.aal5.rx_err),
52259- atomic_read(&atm_dev->stats.aal5.rx_drop));
52260+ atomic_read_unchecked(&atm_dev->stats.aal5.tx),
52261+ atomic_read_unchecked(&atm_dev->stats.aal5.tx_err),
52262+ atomic_read_unchecked(&atm_dev->stats.aal5.rx),
52263+ atomic_read_unchecked(&atm_dev->stats.aal5.rx_err),
52264+ atomic_read_unchecked(&atm_dev->stats.aal5.rx_drop));
52265
52266 if (!left--) {
52267 if (instance->disconnected)
52268diff --git a/drivers/usb/core/devices.c b/drivers/usb/core/devices.c
52269index 2a3bbdf..91d72cf 100644
52270--- a/drivers/usb/core/devices.c
52271+++ b/drivers/usb/core/devices.c
52272@@ -126,7 +126,7 @@ static const char format_endpt[] =
52273 * time it gets called.
52274 */
52275 static struct device_connect_event {
52276- atomic_t count;
52277+ atomic_unchecked_t count;
52278 wait_queue_head_t wait;
52279 } device_event = {
52280 .count = ATOMIC_INIT(1),
52281@@ -164,7 +164,7 @@ static const struct class_info clas_info[] = {
52282
52283 void usbfs_conn_disc_event(void)
52284 {
52285- atomic_add(2, &device_event.count);
52286+ atomic_add_unchecked(2, &device_event.count);
52287 wake_up(&device_event.wait);
52288 }
52289
52290@@ -652,7 +652,7 @@ static unsigned int usb_device_poll(struct file *file,
52291
52292 poll_wait(file, &device_event.wait, wait);
52293
52294- event_count = atomic_read(&device_event.count);
52295+ event_count = atomic_read_unchecked(&device_event.count);
52296 if (file->f_version != event_count) {
52297 file->f_version = event_count;
52298 return POLLIN | POLLRDNORM;
52299diff --git a/drivers/usb/core/devio.c b/drivers/usb/core/devio.c
52300index 90e18f6..5eeda46 100644
52301--- a/drivers/usb/core/devio.c
52302+++ b/drivers/usb/core/devio.c
52303@@ -187,7 +187,7 @@ static ssize_t usbdev_read(struct file *file, char __user *buf, size_t nbytes,
52304 struct dev_state *ps = file->private_data;
52305 struct usb_device *dev = ps->dev;
52306 ssize_t ret = 0;
52307- unsigned len;
52308+ size_t len;
52309 loff_t pos;
52310 int i;
52311
52312@@ -229,22 +229,22 @@ static ssize_t usbdev_read(struct file *file, char __user *buf, size_t nbytes,
52313 for (i = 0; nbytes && i < dev->descriptor.bNumConfigurations; i++) {
52314 struct usb_config_descriptor *config =
52315 (struct usb_config_descriptor *)dev->rawdescriptors[i];
52316- unsigned int length = le16_to_cpu(config->wTotalLength);
52317+ size_t length = le16_to_cpu(config->wTotalLength);
52318
52319 if (*ppos < pos + length) {
52320
52321 /* The descriptor may claim to be longer than it
52322 * really is. Here is the actual allocated length. */
52323- unsigned alloclen =
52324+ size_t alloclen =
52325 le16_to_cpu(dev->config[i].desc.wTotalLength);
52326
52327- len = length - (*ppos - pos);
52328+ len = length + pos - *ppos;
52329 if (len > nbytes)
52330 len = nbytes;
52331
52332 /* Simply don't write (skip over) unallocated parts */
52333 if (alloclen > (*ppos - pos)) {
52334- alloclen -= (*ppos - pos);
52335+ alloclen = alloclen + pos - *ppos;
52336 if (copy_to_user(buf,
52337 dev->rawdescriptors[i] + (*ppos - pos),
52338 min(len, alloclen))) {
52339diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
52340index 2518c32..1c201bb 100644
52341--- a/drivers/usb/core/hcd.c
52342+++ b/drivers/usb/core/hcd.c
52343@@ -1550,7 +1550,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
52344 */
52345 usb_get_urb(urb);
52346 atomic_inc(&urb->use_count);
52347- atomic_inc(&urb->dev->urbnum);
52348+ atomic_inc_unchecked(&urb->dev->urbnum);
52349 usbmon_urb_submit(&hcd->self, urb);
52350
52351 /* NOTE requirements on root-hub callers (usbfs and the hub
52352@@ -1577,7 +1577,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
52353 urb->hcpriv = NULL;
52354 INIT_LIST_HEAD(&urb->urb_list);
52355 atomic_dec(&urb->use_count);
52356- atomic_dec(&urb->dev->urbnum);
52357+ atomic_dec_unchecked(&urb->dev->urbnum);
52358 if (atomic_read(&urb->reject))
52359 wake_up(&usb_kill_urb_queue);
52360 usb_put_urb(urb);
52361diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
52362index d498d03..e26f959 100644
52363--- a/drivers/usb/core/hub.c
52364+++ b/drivers/usb/core/hub.c
52365@@ -27,6 +27,7 @@
52366 #include <linux/freezer.h>
52367 #include <linux/random.h>
52368 #include <linux/pm_qos.h>
52369+#include <linux/grsecurity.h>
52370
52371 #include <asm/uaccess.h>
52372 #include <asm/byteorder.h>
52373@@ -4472,6 +4473,10 @@ static void hub_port_connect_change(struct usb_hub *hub, int port1,
52374 goto done;
52375 return;
52376 }
52377+
52378+ if (gr_handle_new_usb())
52379+ goto done;
52380+
52381 if (hub_is_superspeed(hub->hdev))
52382 unit_load = 150;
52383 else
52384diff --git a/drivers/usb/core/message.c b/drivers/usb/core/message.c
52385index f829a1a..e6c334a 100644
52386--- a/drivers/usb/core/message.c
52387+++ b/drivers/usb/core/message.c
52388@@ -128,7 +128,7 @@ static int usb_internal_control_msg(struct usb_device *usb_dev,
52389 * Return: If successful, the number of bytes transferred. Otherwise, a negative
52390 * error number.
52391 */
52392-int usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request,
52393+int __intentional_overflow(-1) usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request,
52394 __u8 requesttype, __u16 value, __u16 index, void *data,
52395 __u16 size, int timeout)
52396 {
52397@@ -180,7 +180,7 @@ EXPORT_SYMBOL_GPL(usb_control_msg);
52398 * If successful, 0. Otherwise a negative error number. The number of actual
52399 * bytes transferred will be stored in the @actual_length paramater.
52400 */
52401-int usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
52402+int __intentional_overflow(-1) usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
52403 void *data, int len, int *actual_length, int timeout)
52404 {
52405 return usb_bulk_msg(usb_dev, pipe, data, len, actual_length, timeout);
52406@@ -220,7 +220,7 @@ EXPORT_SYMBOL_GPL(usb_interrupt_msg);
52407 * bytes transferred will be stored in the @actual_length parameter.
52408 *
52409 */
52410-int usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
52411+int __intentional_overflow(-1) usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
52412 void *data, int len, int *actual_length, int timeout)
52413 {
52414 struct urb *urb;
52415diff --git a/drivers/usb/core/sysfs.c b/drivers/usb/core/sysfs.c
52416index 1236c60..d47a51c 100644
52417--- a/drivers/usb/core/sysfs.c
52418+++ b/drivers/usb/core/sysfs.c
52419@@ -244,7 +244,7 @@ static ssize_t urbnum_show(struct device *dev, struct device_attribute *attr,
52420 struct usb_device *udev;
52421
52422 udev = to_usb_device(dev);
52423- return sprintf(buf, "%d\n", atomic_read(&udev->urbnum));
52424+ return sprintf(buf, "%d\n", atomic_read_unchecked(&udev->urbnum));
52425 }
52426 static DEVICE_ATTR_RO(urbnum);
52427
52428diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
52429index 4d11449..f4ccabf 100644
52430--- a/drivers/usb/core/usb.c
52431+++ b/drivers/usb/core/usb.c
52432@@ -433,7 +433,7 @@ struct usb_device *usb_alloc_dev(struct usb_device *parent,
52433 set_dev_node(&dev->dev, dev_to_node(bus->controller));
52434 dev->state = USB_STATE_ATTACHED;
52435 dev->lpm_disable_count = 1;
52436- atomic_set(&dev->urbnum, 0);
52437+ atomic_set_unchecked(&dev->urbnum, 0);
52438
52439 INIT_LIST_HEAD(&dev->ep0.urb_list);
52440 dev->ep0.desc.bLength = USB_DT_ENDPOINT_SIZE;
52441diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
52442index 2da0a5a..4870e09 100644
52443--- a/drivers/usb/dwc3/gadget.c
52444+++ b/drivers/usb/dwc3/gadget.c
52445@@ -532,8 +532,6 @@ static int __dwc3_gadget_ep_enable(struct dwc3_ep *dep,
52446 if (!usb_endpoint_xfer_isoc(desc))
52447 return 0;
52448
52449- memset(&trb_link, 0, sizeof(trb_link));
52450-
52451 /* Link TRB for ISOC. The HWO bit is never reset */
52452 trb_st_hw = &dep->trb_pool[0];
52453
52454diff --git a/drivers/usb/early/ehci-dbgp.c b/drivers/usb/early/ehci-dbgp.c
52455index 8cfc319..4868255 100644
52456--- a/drivers/usb/early/ehci-dbgp.c
52457+++ b/drivers/usb/early/ehci-dbgp.c
52458@@ -98,7 +98,8 @@ static inline u32 dbgp_len_update(u32 x, u32 len)
52459
52460 #ifdef CONFIG_KGDB
52461 static struct kgdb_io kgdbdbgp_io_ops;
52462-#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops)
52463+static struct kgdb_io kgdbdbgp_io_ops_console;
52464+#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops || dbg_io_ops == &kgdbdbgp_io_ops_console)
52465 #else
52466 #define dbgp_kgdb_mode (0)
52467 #endif
52468@@ -1043,6 +1044,13 @@ static struct kgdb_io kgdbdbgp_io_ops = {
52469 .write_char = kgdbdbgp_write_char,
52470 };
52471
52472+static struct kgdb_io kgdbdbgp_io_ops_console = {
52473+ .name = "kgdbdbgp",
52474+ .read_char = kgdbdbgp_read_char,
52475+ .write_char = kgdbdbgp_write_char,
52476+ .is_console = 1
52477+};
52478+
52479 static int kgdbdbgp_wait_time;
52480
52481 static int __init kgdbdbgp_parse_config(char *str)
52482@@ -1058,8 +1066,10 @@ static int __init kgdbdbgp_parse_config(char *str)
52483 ptr++;
52484 kgdbdbgp_wait_time = simple_strtoul(ptr, &ptr, 10);
52485 }
52486- kgdb_register_io_module(&kgdbdbgp_io_ops);
52487- kgdbdbgp_io_ops.is_console = early_dbgp_console.index != -1;
52488+ if (early_dbgp_console.index != -1)
52489+ kgdb_register_io_module(&kgdbdbgp_io_ops_console);
52490+ else
52491+ kgdb_register_io_module(&kgdbdbgp_io_ops);
52492
52493 return 0;
52494 }
52495diff --git a/drivers/usb/gadget/f_uac1.c b/drivers/usb/gadget/f_uac1.c
52496index 2b4c82d..06a8ee6 100644
52497--- a/drivers/usb/gadget/f_uac1.c
52498+++ b/drivers/usb/gadget/f_uac1.c
52499@@ -13,6 +13,7 @@
52500 #include <linux/kernel.h>
52501 #include <linux/device.h>
52502 #include <linux/atomic.h>
52503+#include <linux/module.h>
52504
52505 #include "u_uac1.h"
52506
52507diff --git a/drivers/usb/gadget/u_serial.c b/drivers/usb/gadget/u_serial.c
52508index ad0aca8..8ff84865 100644
52509--- a/drivers/usb/gadget/u_serial.c
52510+++ b/drivers/usb/gadget/u_serial.c
52511@@ -733,9 +733,9 @@ static int gs_open(struct tty_struct *tty, struct file *file)
52512 spin_lock_irq(&port->port_lock);
52513
52514 /* already open? Great. */
52515- if (port->port.count) {
52516+ if (atomic_read(&port->port.count)) {
52517 status = 0;
52518- port->port.count++;
52519+ atomic_inc(&port->port.count);
52520
52521 /* currently opening/closing? wait ... */
52522 } else if (port->openclose) {
52523@@ -794,7 +794,7 @@ static int gs_open(struct tty_struct *tty, struct file *file)
52524 tty->driver_data = port;
52525 port->port.tty = tty;
52526
52527- port->port.count = 1;
52528+ atomic_set(&port->port.count, 1);
52529 port->openclose = false;
52530
52531 /* if connected, start the I/O stream */
52532@@ -836,11 +836,11 @@ static void gs_close(struct tty_struct *tty, struct file *file)
52533
52534 spin_lock_irq(&port->port_lock);
52535
52536- if (port->port.count != 1) {
52537- if (port->port.count == 0)
52538+ if (atomic_read(&port->port.count) != 1) {
52539+ if (atomic_read(&port->port.count) == 0)
52540 WARN_ON(1);
52541 else
52542- --port->port.count;
52543+ atomic_dec(&port->port.count);
52544 goto exit;
52545 }
52546
52547@@ -850,7 +850,7 @@ static void gs_close(struct tty_struct *tty, struct file *file)
52548 * and sleep if necessary
52549 */
52550 port->openclose = true;
52551- port->port.count = 0;
52552+ atomic_set(&port->port.count, 0);
52553
52554 gser = port->port_usb;
52555 if (gser && gser->disconnect)
52556@@ -1066,7 +1066,7 @@ static int gs_closed(struct gs_port *port)
52557 int cond;
52558
52559 spin_lock_irq(&port->port_lock);
52560- cond = (port->port.count == 0) && !port->openclose;
52561+ cond = (atomic_read(&port->port.count) == 0) && !port->openclose;
52562 spin_unlock_irq(&port->port_lock);
52563 return cond;
52564 }
52565@@ -1209,7 +1209,7 @@ int gserial_connect(struct gserial *gser, u8 port_num)
52566 /* if it's already open, start I/O ... and notify the serial
52567 * protocol about open/close status (connect/disconnect).
52568 */
52569- if (port->port.count) {
52570+ if (atomic_read(&port->port.count)) {
52571 pr_debug("gserial_connect: start ttyGS%d\n", port->port_num);
52572 gs_start_io(port);
52573 if (gser->connect)
52574@@ -1256,7 +1256,7 @@ void gserial_disconnect(struct gserial *gser)
52575
52576 port->port_usb = NULL;
52577 gser->ioport = NULL;
52578- if (port->port.count > 0 || port->openclose) {
52579+ if (atomic_read(&port->port.count) > 0 || port->openclose) {
52580 wake_up_interruptible(&port->drain_wait);
52581 if (port->port.tty)
52582 tty_hangup(port->port.tty);
52583@@ -1272,7 +1272,7 @@ void gserial_disconnect(struct gserial *gser)
52584
52585 /* finally, free any unused/unusable I/O buffers */
52586 spin_lock_irqsave(&port->port_lock, flags);
52587- if (port->port.count == 0 && !port->openclose)
52588+ if (atomic_read(&port->port.count) == 0 && !port->openclose)
52589 gs_buf_free(&port->port_write_buf);
52590 gs_free_requests(gser->out, &port->read_pool, NULL);
52591 gs_free_requests(gser->out, &port->read_queue, NULL);
52592diff --git a/drivers/usb/gadget/u_uac1.c b/drivers/usb/gadget/u_uac1.c
52593index 7a55fea..cc0ed4f 100644
52594--- a/drivers/usb/gadget/u_uac1.c
52595+++ b/drivers/usb/gadget/u_uac1.c
52596@@ -16,6 +16,7 @@
52597 #include <linux/ctype.h>
52598 #include <linux/random.h>
52599 #include <linux/syscalls.h>
52600+#include <linux/module.h>
52601
52602 #include "u_uac1.h"
52603
52604diff --git a/drivers/usb/host/ehci-hub.c b/drivers/usb/host/ehci-hub.c
52605index 7ae0c4d..35521b7 100644
52606--- a/drivers/usb/host/ehci-hub.c
52607+++ b/drivers/usb/host/ehci-hub.c
52608@@ -780,7 +780,7 @@ static struct urb *request_single_step_set_feature_urb(
52609 urb->transfer_flags = URB_DIR_IN;
52610 usb_get_urb(urb);
52611 atomic_inc(&urb->use_count);
52612- atomic_inc(&urb->dev->urbnum);
52613+ atomic_inc_unchecked(&urb->dev->urbnum);
52614 urb->setup_dma = dma_map_single(
52615 hcd->self.controller,
52616 urb->setup_packet,
52617@@ -847,7 +847,7 @@ static int ehset_single_step_set_feature(struct usb_hcd *hcd, int port)
52618 urb->status = -EINPROGRESS;
52619 usb_get_urb(urb);
52620 atomic_inc(&urb->use_count);
52621- atomic_inc(&urb->dev->urbnum);
52622+ atomic_inc_unchecked(&urb->dev->urbnum);
52623 retval = submit_single_step_set_feature(hcd, urb, 0);
52624 if (!retval && !wait_for_completion_timeout(&done,
52625 msecs_to_jiffies(2000))) {
52626diff --git a/drivers/usb/misc/appledisplay.c b/drivers/usb/misc/appledisplay.c
52627index ba6a5d6..f88f7f3 100644
52628--- a/drivers/usb/misc/appledisplay.c
52629+++ b/drivers/usb/misc/appledisplay.c
52630@@ -83,7 +83,7 @@ struct appledisplay {
52631 spinlock_t lock;
52632 };
52633
52634-static atomic_t count_displays = ATOMIC_INIT(0);
52635+static atomic_unchecked_t count_displays = ATOMIC_INIT(0);
52636 static struct workqueue_struct *wq;
52637
52638 static void appledisplay_complete(struct urb *urb)
52639@@ -281,7 +281,7 @@ static int appledisplay_probe(struct usb_interface *iface,
52640
52641 /* Register backlight device */
52642 snprintf(bl_name, sizeof(bl_name), "appledisplay%d",
52643- atomic_inc_return(&count_displays) - 1);
52644+ atomic_inc_return_unchecked(&count_displays) - 1);
52645 memset(&props, 0, sizeof(struct backlight_properties));
52646 props.type = BACKLIGHT_RAW;
52647 props.max_brightness = 0xff;
52648diff --git a/drivers/usb/serial/console.c b/drivers/usb/serial/console.c
52649index 8d7fc48..01c4986 100644
52650--- a/drivers/usb/serial/console.c
52651+++ b/drivers/usb/serial/console.c
52652@@ -123,7 +123,7 @@ static int usb_console_setup(struct console *co, char *options)
52653
52654 info->port = port;
52655
52656- ++port->port.count;
52657+ atomic_inc(&port->port.count);
52658 if (!test_bit(ASYNCB_INITIALIZED, &port->port.flags)) {
52659 if (serial->type->set_termios) {
52660 /*
52661@@ -167,7 +167,7 @@ static int usb_console_setup(struct console *co, char *options)
52662 }
52663 /* Now that any required fake tty operations are completed restore
52664 * the tty port count */
52665- --port->port.count;
52666+ atomic_dec(&port->port.count);
52667 /* The console is special in terms of closing the device so
52668 * indicate this port is now acting as a system console. */
52669 port->port.console = 1;
52670@@ -180,7 +180,7 @@ static int usb_console_setup(struct console *co, char *options)
52671 free_tty:
52672 kfree(tty);
52673 reset_open_count:
52674- port->port.count = 0;
52675+ atomic_set(&port->port.count, 0);
52676 usb_autopm_put_interface(serial->interface);
52677 error_get_interface:
52678 usb_serial_put(serial);
52679@@ -191,7 +191,7 @@ static int usb_console_setup(struct console *co, char *options)
52680 static void usb_console_write(struct console *co,
52681 const char *buf, unsigned count)
52682 {
52683- static struct usbcons_info *info = &usbcons_info;
52684+ struct usbcons_info *info = &usbcons_info;
52685 struct usb_serial_port *port = info->port;
52686 struct usb_serial *serial;
52687 int retval = -ENODEV;
52688diff --git a/drivers/usb/storage/usb.h b/drivers/usb/storage/usb.h
52689index 75f70f0..d467e1a 100644
52690--- a/drivers/usb/storage/usb.h
52691+++ b/drivers/usb/storage/usb.h
52692@@ -63,7 +63,7 @@ struct us_unusual_dev {
52693 __u8 useProtocol;
52694 __u8 useTransport;
52695 int (*initFunction)(struct us_data *);
52696-};
52697+} __do_const;
52698
52699
52700 /* Dynamic bitflag definitions (us->dflags): used in set_bit() etc. */
52701diff --git a/drivers/usb/wusbcore/wa-hc.h b/drivers/usb/wusbcore/wa-hc.h
52702index a2ef84b..aa7c2b8 100644
52703--- a/drivers/usb/wusbcore/wa-hc.h
52704+++ b/drivers/usb/wusbcore/wa-hc.h
52705@@ -225,7 +225,7 @@ struct wahc {
52706 spinlock_t xfer_list_lock;
52707 struct work_struct xfer_enqueue_work;
52708 struct work_struct xfer_error_work;
52709- atomic_t xfer_id_count;
52710+ atomic_unchecked_t xfer_id_count;
52711
52712 kernel_ulong_t quirks;
52713 };
52714@@ -287,7 +287,7 @@ static inline void wa_init(struct wahc *wa)
52715 INIT_WORK(&wa->xfer_enqueue_work, wa_urb_enqueue_run);
52716 INIT_WORK(&wa->xfer_error_work, wa_process_errored_transfers_run);
52717 wa->dto_in_use = 0;
52718- atomic_set(&wa->xfer_id_count, 1);
52719+ atomic_set_unchecked(&wa->xfer_id_count, 1);
52720 }
52721
52722 /**
52723diff --git a/drivers/usb/wusbcore/wa-xfer.c b/drivers/usb/wusbcore/wa-xfer.c
52724index 3cd96e9..bd7c58d 100644
52725--- a/drivers/usb/wusbcore/wa-xfer.c
52726+++ b/drivers/usb/wusbcore/wa-xfer.c
52727@@ -312,7 +312,7 @@ static void wa_xfer_completion(struct wa_xfer *xfer)
52728 */
52729 static void wa_xfer_id_init(struct wa_xfer *xfer)
52730 {
52731- xfer->id = atomic_add_return(1, &xfer->wa->xfer_id_count);
52732+ xfer->id = atomic_add_return_unchecked(1, &xfer->wa->xfer_id_count);
52733 }
52734
52735 /* Return the xfer's ID. */
52736diff --git a/drivers/vfio/vfio.c b/drivers/vfio/vfio.c
52737index 21271d8..45b55a0 100644
52738--- a/drivers/vfio/vfio.c
52739+++ b/drivers/vfio/vfio.c
52740@@ -487,7 +487,7 @@ static int vfio_group_nb_add_dev(struct vfio_group *group, struct device *dev)
52741 return 0;
52742
52743 /* TODO Prevent device auto probing */
52744- WARN("Device %s added to live group %d!\n", dev_name(dev),
52745+ WARN(1, "Device %s added to live group %d!\n", dev_name(dev),
52746 iommu_group_id(group->iommu_group));
52747
52748 return 0;
52749diff --git a/drivers/vhost/vringh.c b/drivers/vhost/vringh.c
52750index 5174eba..451e6bc 100644
52751--- a/drivers/vhost/vringh.c
52752+++ b/drivers/vhost/vringh.c
52753@@ -530,17 +530,17 @@ static inline void __vringh_notify_disable(struct vringh *vrh,
52754 /* Userspace access helpers: in this case, addresses are really userspace. */
52755 static inline int getu16_user(u16 *val, const u16 *p)
52756 {
52757- return get_user(*val, (__force u16 __user *)p);
52758+ return get_user(*val, (u16 __force_user *)p);
52759 }
52760
52761 static inline int putu16_user(u16 *p, u16 val)
52762 {
52763- return put_user(val, (__force u16 __user *)p);
52764+ return put_user(val, (u16 __force_user *)p);
52765 }
52766
52767 static inline int copydesc_user(void *dst, const void *src, size_t len)
52768 {
52769- return copy_from_user(dst, (__force void __user *)src, len) ?
52770+ return copy_from_user(dst, (void __force_user *)src, len) ?
52771 -EFAULT : 0;
52772 }
52773
52774@@ -548,19 +548,19 @@ static inline int putused_user(struct vring_used_elem *dst,
52775 const struct vring_used_elem *src,
52776 unsigned int num)
52777 {
52778- return copy_to_user((__force void __user *)dst, src,
52779+ return copy_to_user((void __force_user *)dst, src,
52780 sizeof(*dst) * num) ? -EFAULT : 0;
52781 }
52782
52783 static inline int xfer_from_user(void *src, void *dst, size_t len)
52784 {
52785- return copy_from_user(dst, (__force void __user *)src, len) ?
52786+ return copy_from_user(dst, (void __force_user *)src, len) ?
52787 -EFAULT : 0;
52788 }
52789
52790 static inline int xfer_to_user(void *dst, void *src, size_t len)
52791 {
52792- return copy_to_user((__force void __user *)dst, src, len) ?
52793+ return copy_to_user((void __force_user *)dst, src, len) ?
52794 -EFAULT : 0;
52795 }
52796
52797@@ -596,9 +596,9 @@ int vringh_init_user(struct vringh *vrh, u32 features,
52798 vrh->last_used_idx = 0;
52799 vrh->vring.num = num;
52800 /* vring expects kernel addresses, but only used via accessors. */
52801- vrh->vring.desc = (__force struct vring_desc *)desc;
52802- vrh->vring.avail = (__force struct vring_avail *)avail;
52803- vrh->vring.used = (__force struct vring_used *)used;
52804+ vrh->vring.desc = (__force_kernel struct vring_desc *)desc;
52805+ vrh->vring.avail = (__force_kernel struct vring_avail *)avail;
52806+ vrh->vring.used = (__force_kernel struct vring_used *)used;
52807 return 0;
52808 }
52809 EXPORT_SYMBOL(vringh_init_user);
52810@@ -800,7 +800,7 @@ static inline int getu16_kern(u16 *val, const u16 *p)
52811
52812 static inline int putu16_kern(u16 *p, u16 val)
52813 {
52814- ACCESS_ONCE(*p) = val;
52815+ ACCESS_ONCE_RW(*p) = val;
52816 return 0;
52817 }
52818
52819diff --git a/drivers/video/arcfb.c b/drivers/video/arcfb.c
52820index 1b0b233..6f34c2c 100644
52821--- a/drivers/video/arcfb.c
52822+++ b/drivers/video/arcfb.c
52823@@ -458,7 +458,7 @@ static ssize_t arcfb_write(struct fb_info *info, const char __user *buf,
52824 return -ENOSPC;
52825
52826 err = 0;
52827- if ((count + p) > fbmemlength) {
52828+ if (count > (fbmemlength - p)) {
52829 count = fbmemlength - p;
52830 err = -ENOSPC;
52831 }
52832diff --git a/drivers/video/aty/aty128fb.c b/drivers/video/aty/aty128fb.c
52833index 52108be..c7c110d 100644
52834--- a/drivers/video/aty/aty128fb.c
52835+++ b/drivers/video/aty/aty128fb.c
52836@@ -149,7 +149,7 @@ enum {
52837 };
52838
52839 /* Must match above enum */
52840-static char * const r128_family[] = {
52841+static const char * const r128_family[] = {
52842 "AGP",
52843 "PCI",
52844 "PRO AGP",
52845diff --git a/drivers/video/aty/atyfb_base.c b/drivers/video/aty/atyfb_base.c
52846index 28fafbf..ae91651 100644
52847--- a/drivers/video/aty/atyfb_base.c
52848+++ b/drivers/video/aty/atyfb_base.c
52849@@ -1326,10 +1326,14 @@ static int atyfb_set_par(struct fb_info *info)
52850 par->accel_flags = var->accel_flags; /* hack */
52851
52852 if (var->accel_flags) {
52853- info->fbops->fb_sync = atyfb_sync;
52854+ pax_open_kernel();
52855+ *(void **)&info->fbops->fb_sync = atyfb_sync;
52856+ pax_close_kernel();
52857 info->flags &= ~FBINFO_HWACCEL_DISABLED;
52858 } else {
52859- info->fbops->fb_sync = NULL;
52860+ pax_open_kernel();
52861+ *(void **)&info->fbops->fb_sync = NULL;
52862+ pax_close_kernel();
52863 info->flags |= FBINFO_HWACCEL_DISABLED;
52864 }
52865
52866diff --git a/drivers/video/aty/mach64_cursor.c b/drivers/video/aty/mach64_cursor.c
52867index 0fe02e2..ab01b26 100644
52868--- a/drivers/video/aty/mach64_cursor.c
52869+++ b/drivers/video/aty/mach64_cursor.c
52870@@ -8,6 +8,7 @@
52871 #include "../fb_draw.h"
52872
52873 #include <asm/io.h>
52874+#include <asm/pgtable.h>
52875
52876 #ifdef __sparc__
52877 #include <asm/fbio.h>
52878@@ -218,7 +219,9 @@ int aty_init_cursor(struct fb_info *info)
52879 info->sprite.buf_align = 16; /* and 64 lines tall. */
52880 info->sprite.flags = FB_PIXMAP_IO;
52881
52882- info->fbops->fb_cursor = atyfb_cursor;
52883+ pax_open_kernel();
52884+ *(void **)&info->fbops->fb_cursor = atyfb_cursor;
52885+ pax_close_kernel();
52886
52887 return 0;
52888 }
52889diff --git a/drivers/video/backlight/kb3886_bl.c b/drivers/video/backlight/kb3886_bl.c
52890index 84a110a..96312c3 100644
52891--- a/drivers/video/backlight/kb3886_bl.c
52892+++ b/drivers/video/backlight/kb3886_bl.c
52893@@ -78,7 +78,7 @@ static struct kb3886bl_machinfo *bl_machinfo;
52894 static unsigned long kb3886bl_flags;
52895 #define KB3886BL_SUSPENDED 0x01
52896
52897-static struct dmi_system_id kb3886bl_device_table[] __initdata = {
52898+static const struct dmi_system_id kb3886bl_device_table[] __initconst = {
52899 {
52900 .ident = "Sahara Touch-iT",
52901 .matches = {
52902diff --git a/drivers/video/fb_defio.c b/drivers/video/fb_defio.c
52903index 900aa4e..6d49418 100644
52904--- a/drivers/video/fb_defio.c
52905+++ b/drivers/video/fb_defio.c
52906@@ -206,7 +206,9 @@ void fb_deferred_io_init(struct fb_info *info)
52907
52908 BUG_ON(!fbdefio);
52909 mutex_init(&fbdefio->lock);
52910- info->fbops->fb_mmap = fb_deferred_io_mmap;
52911+ pax_open_kernel();
52912+ *(void **)&info->fbops->fb_mmap = fb_deferred_io_mmap;
52913+ pax_close_kernel();
52914 INIT_DELAYED_WORK(&info->deferred_work, fb_deferred_io_work);
52915 INIT_LIST_HEAD(&fbdefio->pagelist);
52916 if (fbdefio->delay == 0) /* set a default of 1 s */
52917@@ -237,7 +239,7 @@ void fb_deferred_io_cleanup(struct fb_info *info)
52918 page->mapping = NULL;
52919 }
52920
52921- info->fbops->fb_mmap = NULL;
52922+ *(void **)&info->fbops->fb_mmap = NULL;
52923 mutex_destroy(&fbdefio->lock);
52924 }
52925 EXPORT_SYMBOL_GPL(fb_deferred_io_cleanup);
52926diff --git a/drivers/video/fbmem.c b/drivers/video/fbmem.c
52927index 7309ac7..be3c49c 100644
52928--- a/drivers/video/fbmem.c
52929+++ b/drivers/video/fbmem.c
52930@@ -433,7 +433,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
52931 image->dx += image->width + 8;
52932 }
52933 } else if (rotate == FB_ROTATE_UD) {
52934- for (x = 0; x < num && image->dx >= 0; x++) {
52935+ for (x = 0; x < num && (__s32)image->dx >= 0; x++) {
52936 info->fbops->fb_imageblit(info, image);
52937 image->dx -= image->width + 8;
52938 }
52939@@ -445,7 +445,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
52940 image->dy += image->height + 8;
52941 }
52942 } else if (rotate == FB_ROTATE_CCW) {
52943- for (x = 0; x < num && image->dy >= 0; x++) {
52944+ for (x = 0; x < num && (__s32)image->dy >= 0; x++) {
52945 info->fbops->fb_imageblit(info, image);
52946 image->dy -= image->height + 8;
52947 }
52948@@ -1179,7 +1179,7 @@ static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,
52949 return -EFAULT;
52950 if (con2fb.console < 1 || con2fb.console > MAX_NR_CONSOLES)
52951 return -EINVAL;
52952- if (con2fb.framebuffer < 0 || con2fb.framebuffer >= FB_MAX)
52953+ if (con2fb.framebuffer >= FB_MAX)
52954 return -EINVAL;
52955 if (!registered_fb[con2fb.framebuffer])
52956 request_module("fb%d", con2fb.framebuffer);
52957@@ -1300,7 +1300,7 @@ static int do_fscreeninfo_to_user(struct fb_fix_screeninfo *fix,
52958 __u32 data;
52959 int err;
52960
52961- err = copy_to_user(&fix32->id, &fix->id, sizeof(fix32->id));
52962+ err = copy_to_user(fix32->id, &fix->id, sizeof(fix32->id));
52963
52964 data = (__u32) (unsigned long) fix->smem_start;
52965 err |= put_user(data, &fix32->smem_start);
52966diff --git a/drivers/video/hyperv_fb.c b/drivers/video/hyperv_fb.c
52967index 130708f..cdac1a9 100644
52968--- a/drivers/video/hyperv_fb.c
52969+++ b/drivers/video/hyperv_fb.c
52970@@ -233,7 +233,7 @@ static uint screen_fb_size;
52971 static inline int synthvid_send(struct hv_device *hdev,
52972 struct synthvid_msg *msg)
52973 {
52974- static atomic64_t request_id = ATOMIC64_INIT(0);
52975+ static atomic64_unchecked_t request_id = ATOMIC64_INIT(0);
52976 int ret;
52977
52978 msg->pipe_hdr.type = PIPE_MSG_DATA;
52979@@ -241,7 +241,7 @@ static inline int synthvid_send(struct hv_device *hdev,
52980
52981 ret = vmbus_sendpacket(hdev->channel, msg,
52982 msg->vid_hdr.size + sizeof(struct pipe_msg_hdr),
52983- atomic64_inc_return(&request_id),
52984+ atomic64_inc_return_unchecked(&request_id),
52985 VM_PKT_DATA_INBAND, 0);
52986
52987 if (ret)
52988diff --git a/drivers/video/i810/i810_accel.c b/drivers/video/i810/i810_accel.c
52989index 7672d2e..b56437f 100644
52990--- a/drivers/video/i810/i810_accel.c
52991+++ b/drivers/video/i810/i810_accel.c
52992@@ -73,6 +73,7 @@ static inline int wait_for_space(struct fb_info *info, u32 space)
52993 }
52994 }
52995 printk("ringbuffer lockup!!!\n");
52996+ printk("head:%u tail:%u iring.size:%u space:%u\n", head, tail, par->iring.size, space);
52997 i810_report_error(mmio);
52998 par->dev_flags |= LOCKUP;
52999 info->pixmap.scan_align = 1;
53000diff --git a/drivers/video/logo/logo_linux_clut224.ppm b/drivers/video/logo/logo_linux_clut224.ppm
53001index 3c14e43..2630570 100644
53002--- a/drivers/video/logo/logo_linux_clut224.ppm
53003+++ b/drivers/video/logo/logo_linux_clut224.ppm
53004@@ -2,1603 +2,1123 @@ P3
53005 # Standard 224-color Linux logo
53006 80 80
53007 255
53008- 0 0 0 0 0 0 0 0 0 0 0 0
53009- 0 0 0 0 0 0 0 0 0 0 0 0
53010- 0 0 0 0 0 0 0 0 0 0 0 0
53011- 0 0 0 0 0 0 0 0 0 0 0 0
53012- 0 0 0 0 0 0 0 0 0 0 0 0
53013- 0 0 0 0 0 0 0 0 0 0 0 0
53014- 0 0 0 0 0 0 0 0 0 0 0 0
53015- 0 0 0 0 0 0 0 0 0 0 0 0
53016- 0 0 0 0 0 0 0 0 0 0 0 0
53017- 6 6 6 6 6 6 10 10 10 10 10 10
53018- 10 10 10 6 6 6 6 6 6 6 6 6
53019- 0 0 0 0 0 0 0 0 0 0 0 0
53020- 0 0 0 0 0 0 0 0 0 0 0 0
53021- 0 0 0 0 0 0 0 0 0 0 0 0
53022- 0 0 0 0 0 0 0 0 0 0 0 0
53023- 0 0 0 0 0 0 0 0 0 0 0 0
53024- 0 0 0 0 0 0 0 0 0 0 0 0
53025- 0 0 0 0 0 0 0 0 0 0 0 0
53026- 0 0 0 0 0 0 0 0 0 0 0 0
53027- 0 0 0 0 0 0 0 0 0 0 0 0
53028- 0 0 0 0 0 0 0 0 0 0 0 0
53029- 0 0 0 0 0 0 0 0 0 0 0 0
53030- 0 0 0 0 0 0 0 0 0 0 0 0
53031- 0 0 0 0 0 0 0 0 0 0 0 0
53032- 0 0 0 0 0 0 0 0 0 0 0 0
53033- 0 0 0 0 0 0 0 0 0 0 0 0
53034- 0 0 0 0 0 0 0 0 0 0 0 0
53035- 0 0 0 0 0 0 0 0 0 0 0 0
53036- 0 0 0 6 6 6 10 10 10 14 14 14
53037- 22 22 22 26 26 26 30 30 30 34 34 34
53038- 30 30 30 30 30 30 26 26 26 18 18 18
53039- 14 14 14 10 10 10 6 6 6 0 0 0
53040- 0 0 0 0 0 0 0 0 0 0 0 0
53041- 0 0 0 0 0 0 0 0 0 0 0 0
53042- 0 0 0 0 0 0 0 0 0 0 0 0
53043- 0 0 0 0 0 0 0 0 0 0 0 0
53044- 0 0 0 0 0 0 0 0 0 0 0 0
53045- 0 0 0 0 0 0 0 0 0 0 0 0
53046- 0 0 0 0 0 0 0 0 0 0 0 0
53047- 0 0 0 0 0 0 0 0 0 0 0 0
53048- 0 0 0 0 0 0 0 0 0 0 0 0
53049- 0 0 0 0 0 1 0 0 1 0 0 0
53050- 0 0 0 0 0 0 0 0 0 0 0 0
53051- 0 0 0 0 0 0 0 0 0 0 0 0
53052- 0 0 0 0 0 0 0 0 0 0 0 0
53053- 0 0 0 0 0 0 0 0 0 0 0 0
53054- 0 0 0 0 0 0 0 0 0 0 0 0
53055- 0 0 0 0 0 0 0 0 0 0 0 0
53056- 6 6 6 14 14 14 26 26 26 42 42 42
53057- 54 54 54 66 66 66 78 78 78 78 78 78
53058- 78 78 78 74 74 74 66 66 66 54 54 54
53059- 42 42 42 26 26 26 18 18 18 10 10 10
53060- 6 6 6 0 0 0 0 0 0 0 0 0
53061- 0 0 0 0 0 0 0 0 0 0 0 0
53062- 0 0 0 0 0 0 0 0 0 0 0 0
53063- 0 0 0 0 0 0 0 0 0 0 0 0
53064- 0 0 0 0 0 0 0 0 0 0 0 0
53065- 0 0 0 0 0 0 0 0 0 0 0 0
53066- 0 0 0 0 0 0 0 0 0 0 0 0
53067- 0 0 0 0 0 0 0 0 0 0 0 0
53068- 0 0 0 0 0 0 0 0 0 0 0 0
53069- 0 0 1 0 0 0 0 0 0 0 0 0
53070- 0 0 0 0 0 0 0 0 0 0 0 0
53071- 0 0 0 0 0 0 0 0 0 0 0 0
53072- 0 0 0 0 0 0 0 0 0 0 0 0
53073- 0 0 0 0 0 0 0 0 0 0 0 0
53074- 0 0 0 0 0 0 0 0 0 0 0 0
53075- 0 0 0 0 0 0 0 0 0 10 10 10
53076- 22 22 22 42 42 42 66 66 66 86 86 86
53077- 66 66 66 38 38 38 38 38 38 22 22 22
53078- 26 26 26 34 34 34 54 54 54 66 66 66
53079- 86 86 86 70 70 70 46 46 46 26 26 26
53080- 14 14 14 6 6 6 0 0 0 0 0 0
53081- 0 0 0 0 0 0 0 0 0 0 0 0
53082- 0 0 0 0 0 0 0 0 0 0 0 0
53083- 0 0 0 0 0 0 0 0 0 0 0 0
53084- 0 0 0 0 0 0 0 0 0 0 0 0
53085- 0 0 0 0 0 0 0 0 0 0 0 0
53086- 0 0 0 0 0 0 0 0 0 0 0 0
53087- 0 0 0 0 0 0 0 0 0 0 0 0
53088- 0 0 0 0 0 0 0 0 0 0 0 0
53089- 0 0 1 0 0 1 0 0 1 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 10 10 10 26 26 26
53096- 50 50 50 82 82 82 58 58 58 6 6 6
53097- 2 2 6 2 2 6 2 2 6 2 2 6
53098- 2 2 6 2 2 6 2 2 6 2 2 6
53099- 6 6 6 54 54 54 86 86 86 66 66 66
53100- 38 38 38 18 18 18 6 6 6 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 0 0 0 0 0 0 0 0 0
53107- 0 0 0 0 0 0 0 0 0 0 0 0
53108- 0 0 0 0 0 0 0 0 0 0 0 0
53109- 0 0 0 0 0 0 0 0 0 0 0 0
53110- 0 0 0 0 0 0 0 0 0 0 0 0
53111- 0 0 0 0 0 0 0 0 0 0 0 0
53112- 0 0 0 0 0 0 0 0 0 0 0 0
53113- 0 0 0 0 0 0 0 0 0 0 0 0
53114- 0 0 0 0 0 0 0 0 0 0 0 0
53115- 0 0 0 6 6 6 22 22 22 50 50 50
53116- 78 78 78 34 34 34 2 2 6 2 2 6
53117- 2 2 6 2 2 6 2 2 6 2 2 6
53118- 2 2 6 2 2 6 2 2 6 2 2 6
53119- 2 2 6 2 2 6 6 6 6 70 70 70
53120- 78 78 78 46 46 46 22 22 22 6 6 6
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- 0 0 0 0 0 0 0 0 0 0 0 0
53127- 0 0 0 0 0 0 0 0 0 0 0 0
53128- 0 0 0 0 0 0 0 0 0 0 0 0
53129- 0 0 1 0 0 1 0 0 1 0 0 0
53130- 0 0 0 0 0 0 0 0 0 0 0 0
53131- 0 0 0 0 0 0 0 0 0 0 0 0
53132- 0 0 0 0 0 0 0 0 0 0 0 0
53133- 0 0 0 0 0 0 0 0 0 0 0 0
53134- 0 0 0 0 0 0 0 0 0 0 0 0
53135- 6 6 6 18 18 18 42 42 42 82 82 82
53136- 26 26 26 2 2 6 2 2 6 2 2 6
53137- 2 2 6 2 2 6 2 2 6 2 2 6
53138- 2 2 6 2 2 6 2 2 6 14 14 14
53139- 46 46 46 34 34 34 6 6 6 2 2 6
53140- 42 42 42 78 78 78 42 42 42 18 18 18
53141- 6 6 6 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 0 0 0
53146- 0 0 0 0 0 0 0 0 0 0 0 0
53147- 0 0 0 0 0 0 0 0 0 0 0 0
53148- 0 0 0 0 0 0 0 0 0 0 0 0
53149- 0 0 1 0 0 0 0 0 1 0 0 0
53150- 0 0 0 0 0 0 0 0 0 0 0 0
53151- 0 0 0 0 0 0 0 0 0 0 0 0
53152- 0 0 0 0 0 0 0 0 0 0 0 0
53153- 0 0 0 0 0 0 0 0 0 0 0 0
53154- 0 0 0 0 0 0 0 0 0 0 0 0
53155- 10 10 10 30 30 30 66 66 66 58 58 58
53156- 2 2 6 2 2 6 2 2 6 2 2 6
53157- 2 2 6 2 2 6 2 2 6 2 2 6
53158- 2 2 6 2 2 6 2 2 6 26 26 26
53159- 86 86 86 101 101 101 46 46 46 10 10 10
53160- 2 2 6 58 58 58 70 70 70 34 34 34
53161- 10 10 10 0 0 0 0 0 0 0 0 0
53162- 0 0 0 0 0 0 0 0 0 0 0 0
53163- 0 0 0 0 0 0 0 0 0 0 0 0
53164- 0 0 0 0 0 0 0 0 0 0 0 0
53165- 0 0 0 0 0 0 0 0 0 0 0 0
53166- 0 0 0 0 0 0 0 0 0 0 0 0
53167- 0 0 0 0 0 0 0 0 0 0 0 0
53168- 0 0 0 0 0 0 0 0 0 0 0 0
53169- 0 0 1 0 0 1 0 0 1 0 0 0
53170- 0 0 0 0 0 0 0 0 0 0 0 0
53171- 0 0 0 0 0 0 0 0 0 0 0 0
53172- 0 0 0 0 0 0 0 0 0 0 0 0
53173- 0 0 0 0 0 0 0 0 0 0 0 0
53174- 0 0 0 0 0 0 0 0 0 0 0 0
53175- 14 14 14 42 42 42 86 86 86 10 10 10
53176- 2 2 6 2 2 6 2 2 6 2 2 6
53177- 2 2 6 2 2 6 2 2 6 2 2 6
53178- 2 2 6 2 2 6 2 2 6 30 30 30
53179- 94 94 94 94 94 94 58 58 58 26 26 26
53180- 2 2 6 6 6 6 78 78 78 54 54 54
53181- 22 22 22 6 6 6 0 0 0 0 0 0
53182- 0 0 0 0 0 0 0 0 0 0 0 0
53183- 0 0 0 0 0 0 0 0 0 0 0 0
53184- 0 0 0 0 0 0 0 0 0 0 0 0
53185- 0 0 0 0 0 0 0 0 0 0 0 0
53186- 0 0 0 0 0 0 0 0 0 0 0 0
53187- 0 0 0 0 0 0 0 0 0 0 0 0
53188- 0 0 0 0 0 0 0 0 0 0 0 0
53189- 0 0 0 0 0 0 0 0 0 0 0 0
53190- 0 0 0 0 0 0 0 0 0 0 0 0
53191- 0 0 0 0 0 0 0 0 0 0 0 0
53192- 0 0 0 0 0 0 0 0 0 0 0 0
53193- 0 0 0 0 0 0 0 0 0 0 0 0
53194- 0 0 0 0 0 0 0 0 0 6 6 6
53195- 22 22 22 62 62 62 62 62 62 2 2 6
53196- 2 2 6 2 2 6 2 2 6 2 2 6
53197- 2 2 6 2 2 6 2 2 6 2 2 6
53198- 2 2 6 2 2 6 2 2 6 26 26 26
53199- 54 54 54 38 38 38 18 18 18 10 10 10
53200- 2 2 6 2 2 6 34 34 34 82 82 82
53201- 38 38 38 14 14 14 0 0 0 0 0 0
53202- 0 0 0 0 0 0 0 0 0 0 0 0
53203- 0 0 0 0 0 0 0 0 0 0 0 0
53204- 0 0 0 0 0 0 0 0 0 0 0 0
53205- 0 0 0 0 0 0 0 0 0 0 0 0
53206- 0 0 0 0 0 0 0 0 0 0 0 0
53207- 0 0 0 0 0 0 0 0 0 0 0 0
53208- 0 0 0 0 0 0 0 0 0 0 0 0
53209- 0 0 0 0 0 1 0 0 1 0 0 0
53210- 0 0 0 0 0 0 0 0 0 0 0 0
53211- 0 0 0 0 0 0 0 0 0 0 0 0
53212- 0 0 0 0 0 0 0 0 0 0 0 0
53213- 0 0 0 0 0 0 0 0 0 0 0 0
53214- 0 0 0 0 0 0 0 0 0 6 6 6
53215- 30 30 30 78 78 78 30 30 30 2 2 6
53216- 2 2 6 2 2 6 2 2 6 2 2 6
53217- 2 2 6 2 2 6 2 2 6 2 2 6
53218- 2 2 6 2 2 6 2 2 6 10 10 10
53219- 10 10 10 2 2 6 2 2 6 2 2 6
53220- 2 2 6 2 2 6 2 2 6 78 78 78
53221- 50 50 50 18 18 18 6 6 6 0 0 0
53222- 0 0 0 0 0 0 0 0 0 0 0 0
53223- 0 0 0 0 0 0 0 0 0 0 0 0
53224- 0 0 0 0 0 0 0 0 0 0 0 0
53225- 0 0 0 0 0 0 0 0 0 0 0 0
53226- 0 0 0 0 0 0 0 0 0 0 0 0
53227- 0 0 0 0 0 0 0 0 0 0 0 0
53228- 0 0 0 0 0 0 0 0 0 0 0 0
53229- 0 0 1 0 0 0 0 0 0 0 0 0
53230- 0 0 0 0 0 0 0 0 0 0 0 0
53231- 0 0 0 0 0 0 0 0 0 0 0 0
53232- 0 0 0 0 0 0 0 0 0 0 0 0
53233- 0 0 0 0 0 0 0 0 0 0 0 0
53234- 0 0 0 0 0 0 0 0 0 10 10 10
53235- 38 38 38 86 86 86 14 14 14 2 2 6
53236- 2 2 6 2 2 6 2 2 6 2 2 6
53237- 2 2 6 2 2 6 2 2 6 2 2 6
53238- 2 2 6 2 2 6 2 2 6 2 2 6
53239- 2 2 6 2 2 6 2 2 6 2 2 6
53240- 2 2 6 2 2 6 2 2 6 54 54 54
53241- 66 66 66 26 26 26 6 6 6 0 0 0
53242- 0 0 0 0 0 0 0 0 0 0 0 0
53243- 0 0 0 0 0 0 0 0 0 0 0 0
53244- 0 0 0 0 0 0 0 0 0 0 0 0
53245- 0 0 0 0 0 0 0 0 0 0 0 0
53246- 0 0 0 0 0 0 0 0 0 0 0 0
53247- 0 0 0 0 0 0 0 0 0 0 0 0
53248- 0 0 0 0 0 0 0 0 0 0 0 0
53249- 0 0 0 0 0 1 0 0 1 0 0 0
53250- 0 0 0 0 0 0 0 0 0 0 0 0
53251- 0 0 0 0 0 0 0 0 0 0 0 0
53252- 0 0 0 0 0 0 0 0 0 0 0 0
53253- 0 0 0 0 0 0 0 0 0 0 0 0
53254- 0 0 0 0 0 0 0 0 0 14 14 14
53255- 42 42 42 82 82 82 2 2 6 2 2 6
53256- 2 2 6 6 6 6 10 10 10 2 2 6
53257- 2 2 6 2 2 6 2 2 6 2 2 6
53258- 2 2 6 2 2 6 2 2 6 6 6 6
53259- 14 14 14 10 10 10 2 2 6 2 2 6
53260- 2 2 6 2 2 6 2 2 6 18 18 18
53261- 82 82 82 34 34 34 10 10 10 0 0 0
53262- 0 0 0 0 0 0 0 0 0 0 0 0
53263- 0 0 0 0 0 0 0 0 0 0 0 0
53264- 0 0 0 0 0 0 0 0 0 0 0 0
53265- 0 0 0 0 0 0 0 0 0 0 0 0
53266- 0 0 0 0 0 0 0 0 0 0 0 0
53267- 0 0 0 0 0 0 0 0 0 0 0 0
53268- 0 0 0 0 0 0 0 0 0 0 0 0
53269- 0 0 1 0 0 0 0 0 0 0 0 0
53270- 0 0 0 0 0 0 0 0 0 0 0 0
53271- 0 0 0 0 0 0 0 0 0 0 0 0
53272- 0 0 0 0 0 0 0 0 0 0 0 0
53273- 0 0 0 0 0 0 0 0 0 0 0 0
53274- 0 0 0 0 0 0 0 0 0 14 14 14
53275- 46 46 46 86 86 86 2 2 6 2 2 6
53276- 6 6 6 6 6 6 22 22 22 34 34 34
53277- 6 6 6 2 2 6 2 2 6 2 2 6
53278- 2 2 6 2 2 6 18 18 18 34 34 34
53279- 10 10 10 50 50 50 22 22 22 2 2 6
53280- 2 2 6 2 2 6 2 2 6 10 10 10
53281- 86 86 86 42 42 42 14 14 14 0 0 0
53282- 0 0 0 0 0 0 0 0 0 0 0 0
53283- 0 0 0 0 0 0 0 0 0 0 0 0
53284- 0 0 0 0 0 0 0 0 0 0 0 0
53285- 0 0 0 0 0 0 0 0 0 0 0 0
53286- 0 0 0 0 0 0 0 0 0 0 0 0
53287- 0 0 0 0 0 0 0 0 0 0 0 0
53288- 0 0 0 0 0 0 0 0 0 0 0 0
53289- 0 0 1 0 0 1 0 0 1 0 0 0
53290- 0 0 0 0 0 0 0 0 0 0 0 0
53291- 0 0 0 0 0 0 0 0 0 0 0 0
53292- 0 0 0 0 0 0 0 0 0 0 0 0
53293- 0 0 0 0 0 0 0 0 0 0 0 0
53294- 0 0 0 0 0 0 0 0 0 14 14 14
53295- 46 46 46 86 86 86 2 2 6 2 2 6
53296- 38 38 38 116 116 116 94 94 94 22 22 22
53297- 22 22 22 2 2 6 2 2 6 2 2 6
53298- 14 14 14 86 86 86 138 138 138 162 162 162
53299-154 154 154 38 38 38 26 26 26 6 6 6
53300- 2 2 6 2 2 6 2 2 6 2 2 6
53301- 86 86 86 46 46 46 14 14 14 0 0 0
53302- 0 0 0 0 0 0 0 0 0 0 0 0
53303- 0 0 0 0 0 0 0 0 0 0 0 0
53304- 0 0 0 0 0 0 0 0 0 0 0 0
53305- 0 0 0 0 0 0 0 0 0 0 0 0
53306- 0 0 0 0 0 0 0 0 0 0 0 0
53307- 0 0 0 0 0 0 0 0 0 0 0 0
53308- 0 0 0 0 0 0 0 0 0 0 0 0
53309- 0 0 0 0 0 0 0 0 0 0 0 0
53310- 0 0 0 0 0 0 0 0 0 0 0 0
53311- 0 0 0 0 0 0 0 0 0 0 0 0
53312- 0 0 0 0 0 0 0 0 0 0 0 0
53313- 0 0 0 0 0 0 0 0 0 0 0 0
53314- 0 0 0 0 0 0 0 0 0 14 14 14
53315- 46 46 46 86 86 86 2 2 6 14 14 14
53316-134 134 134 198 198 198 195 195 195 116 116 116
53317- 10 10 10 2 2 6 2 2 6 6 6 6
53318-101 98 89 187 187 187 210 210 210 218 218 218
53319-214 214 214 134 134 134 14 14 14 6 6 6
53320- 2 2 6 2 2 6 2 2 6 2 2 6
53321- 86 86 86 50 50 50 18 18 18 6 6 6
53322- 0 0 0 0 0 0 0 0 0 0 0 0
53323- 0 0 0 0 0 0 0 0 0 0 0 0
53324- 0 0 0 0 0 0 0 0 0 0 0 0
53325- 0 0 0 0 0 0 0 0 0 0 0 0
53326- 0 0 0 0 0 0 0 0 0 0 0 0
53327- 0 0 0 0 0 0 0 0 0 0 0 0
53328- 0 0 0 0 0 0 0 0 1 0 0 0
53329- 0 0 1 0 0 1 0 0 1 0 0 0
53330- 0 0 0 0 0 0 0 0 0 0 0 0
53331- 0 0 0 0 0 0 0 0 0 0 0 0
53332- 0 0 0 0 0 0 0 0 0 0 0 0
53333- 0 0 0 0 0 0 0 0 0 0 0 0
53334- 0 0 0 0 0 0 0 0 0 14 14 14
53335- 46 46 46 86 86 86 2 2 6 54 54 54
53336-218 218 218 195 195 195 226 226 226 246 246 246
53337- 58 58 58 2 2 6 2 2 6 30 30 30
53338-210 210 210 253 253 253 174 174 174 123 123 123
53339-221 221 221 234 234 234 74 74 74 2 2 6
53340- 2 2 6 2 2 6 2 2 6 2 2 6
53341- 70 70 70 58 58 58 22 22 22 6 6 6
53342- 0 0 0 0 0 0 0 0 0 0 0 0
53343- 0 0 0 0 0 0 0 0 0 0 0 0
53344- 0 0 0 0 0 0 0 0 0 0 0 0
53345- 0 0 0 0 0 0 0 0 0 0 0 0
53346- 0 0 0 0 0 0 0 0 0 0 0 0
53347- 0 0 0 0 0 0 0 0 0 0 0 0
53348- 0 0 0 0 0 0 0 0 0 0 0 0
53349- 0 0 0 0 0 0 0 0 0 0 0 0
53350- 0 0 0 0 0 0 0 0 0 0 0 0
53351- 0 0 0 0 0 0 0 0 0 0 0 0
53352- 0 0 0 0 0 0 0 0 0 0 0 0
53353- 0 0 0 0 0 0 0 0 0 0 0 0
53354- 0 0 0 0 0 0 0 0 0 14 14 14
53355- 46 46 46 82 82 82 2 2 6 106 106 106
53356-170 170 170 26 26 26 86 86 86 226 226 226
53357-123 123 123 10 10 10 14 14 14 46 46 46
53358-231 231 231 190 190 190 6 6 6 70 70 70
53359- 90 90 90 238 238 238 158 158 158 2 2 6
53360- 2 2 6 2 2 6 2 2 6 2 2 6
53361- 70 70 70 58 58 58 22 22 22 6 6 6
53362- 0 0 0 0 0 0 0 0 0 0 0 0
53363- 0 0 0 0 0 0 0 0 0 0 0 0
53364- 0 0 0 0 0 0 0 0 0 0 0 0
53365- 0 0 0 0 0 0 0 0 0 0 0 0
53366- 0 0 0 0 0 0 0 0 0 0 0 0
53367- 0 0 0 0 0 0 0 0 0 0 0 0
53368- 0 0 0 0 0 0 0 0 1 0 0 0
53369- 0 0 1 0 0 1 0 0 1 0 0 0
53370- 0 0 0 0 0 0 0 0 0 0 0 0
53371- 0 0 0 0 0 0 0 0 0 0 0 0
53372- 0 0 0 0 0 0 0 0 0 0 0 0
53373- 0 0 0 0 0 0 0 0 0 0 0 0
53374- 0 0 0 0 0 0 0 0 0 14 14 14
53375- 42 42 42 86 86 86 6 6 6 116 116 116
53376-106 106 106 6 6 6 70 70 70 149 149 149
53377-128 128 128 18 18 18 38 38 38 54 54 54
53378-221 221 221 106 106 106 2 2 6 14 14 14
53379- 46 46 46 190 190 190 198 198 198 2 2 6
53380- 2 2 6 2 2 6 2 2 6 2 2 6
53381- 74 74 74 62 62 62 22 22 22 6 6 6
53382- 0 0 0 0 0 0 0 0 0 0 0 0
53383- 0 0 0 0 0 0 0 0 0 0 0 0
53384- 0 0 0 0 0 0 0 0 0 0 0 0
53385- 0 0 0 0 0 0 0 0 0 0 0 0
53386- 0 0 0 0 0 0 0 0 0 0 0 0
53387- 0 0 0 0 0 0 0 0 0 0 0 0
53388- 0 0 0 0 0 0 0 0 1 0 0 0
53389- 0 0 1 0 0 0 0 0 1 0 0 0
53390- 0 0 0 0 0 0 0 0 0 0 0 0
53391- 0 0 0 0 0 0 0 0 0 0 0 0
53392- 0 0 0 0 0 0 0 0 0 0 0 0
53393- 0 0 0 0 0 0 0 0 0 0 0 0
53394- 0 0 0 0 0 0 0 0 0 14 14 14
53395- 42 42 42 94 94 94 14 14 14 101 101 101
53396-128 128 128 2 2 6 18 18 18 116 116 116
53397-118 98 46 121 92 8 121 92 8 98 78 10
53398-162 162 162 106 106 106 2 2 6 2 2 6
53399- 2 2 6 195 195 195 195 195 195 6 6 6
53400- 2 2 6 2 2 6 2 2 6 2 2 6
53401- 74 74 74 62 62 62 22 22 22 6 6 6
53402- 0 0 0 0 0 0 0 0 0 0 0 0
53403- 0 0 0 0 0 0 0 0 0 0 0 0
53404- 0 0 0 0 0 0 0 0 0 0 0 0
53405- 0 0 0 0 0 0 0 0 0 0 0 0
53406- 0 0 0 0 0 0 0 0 0 0 0 0
53407- 0 0 0 0 0 0 0 0 0 0 0 0
53408- 0 0 0 0 0 0 0 0 1 0 0 1
53409- 0 0 1 0 0 0 0 0 1 0 0 0
53410- 0 0 0 0 0 0 0 0 0 0 0 0
53411- 0 0 0 0 0 0 0 0 0 0 0 0
53412- 0 0 0 0 0 0 0 0 0 0 0 0
53413- 0 0 0 0 0 0 0 0 0 0 0 0
53414- 0 0 0 0 0 0 0 0 0 10 10 10
53415- 38 38 38 90 90 90 14 14 14 58 58 58
53416-210 210 210 26 26 26 54 38 6 154 114 10
53417-226 170 11 236 186 11 225 175 15 184 144 12
53418-215 174 15 175 146 61 37 26 9 2 2 6
53419- 70 70 70 246 246 246 138 138 138 2 2 6
53420- 2 2 6 2 2 6 2 2 6 2 2 6
53421- 70 70 70 66 66 66 26 26 26 6 6 6
53422- 0 0 0 0 0 0 0 0 0 0 0 0
53423- 0 0 0 0 0 0 0 0 0 0 0 0
53424- 0 0 0 0 0 0 0 0 0 0 0 0
53425- 0 0 0 0 0 0 0 0 0 0 0 0
53426- 0 0 0 0 0 0 0 0 0 0 0 0
53427- 0 0 0 0 0 0 0 0 0 0 0 0
53428- 0 0 0 0 0 0 0 0 0 0 0 0
53429- 0 0 0 0 0 0 0 0 0 0 0 0
53430- 0 0 0 0 0 0 0 0 0 0 0 0
53431- 0 0 0 0 0 0 0 0 0 0 0 0
53432- 0 0 0 0 0 0 0 0 0 0 0 0
53433- 0 0 0 0 0 0 0 0 0 0 0 0
53434- 0 0 0 0 0 0 0 0 0 10 10 10
53435- 38 38 38 86 86 86 14 14 14 10 10 10
53436-195 195 195 188 164 115 192 133 9 225 175 15
53437-239 182 13 234 190 10 232 195 16 232 200 30
53438-245 207 45 241 208 19 232 195 16 184 144 12
53439-218 194 134 211 206 186 42 42 42 2 2 6
53440- 2 2 6 2 2 6 2 2 6 2 2 6
53441- 50 50 50 74 74 74 30 30 30 6 6 6
53442- 0 0 0 0 0 0 0 0 0 0 0 0
53443- 0 0 0 0 0 0 0 0 0 0 0 0
53444- 0 0 0 0 0 0 0 0 0 0 0 0
53445- 0 0 0 0 0 0 0 0 0 0 0 0
53446- 0 0 0 0 0 0 0 0 0 0 0 0
53447- 0 0 0 0 0 0 0 0 0 0 0 0
53448- 0 0 0 0 0 0 0 0 0 0 0 0
53449- 0 0 0 0 0 0 0 0 0 0 0 0
53450- 0 0 0 0 0 0 0 0 0 0 0 0
53451- 0 0 0 0 0 0 0 0 0 0 0 0
53452- 0 0 0 0 0 0 0 0 0 0 0 0
53453- 0 0 0 0 0 0 0 0 0 0 0 0
53454- 0 0 0 0 0 0 0 0 0 10 10 10
53455- 34 34 34 86 86 86 14 14 14 2 2 6
53456-121 87 25 192 133 9 219 162 10 239 182 13
53457-236 186 11 232 195 16 241 208 19 244 214 54
53458-246 218 60 246 218 38 246 215 20 241 208 19
53459-241 208 19 226 184 13 121 87 25 2 2 6
53460- 2 2 6 2 2 6 2 2 6 2 2 6
53461- 50 50 50 82 82 82 34 34 34 10 10 10
53462- 0 0 0 0 0 0 0 0 0 0 0 0
53463- 0 0 0 0 0 0 0 0 0 0 0 0
53464- 0 0 0 0 0 0 0 0 0 0 0 0
53465- 0 0 0 0 0 0 0 0 0 0 0 0
53466- 0 0 0 0 0 0 0 0 0 0 0 0
53467- 0 0 0 0 0 0 0 0 0 0 0 0
53468- 0 0 0 0 0 0 0 0 0 0 0 0
53469- 0 0 0 0 0 0 0 0 0 0 0 0
53470- 0 0 0 0 0 0 0 0 0 0 0 0
53471- 0 0 0 0 0 0 0 0 0 0 0 0
53472- 0 0 0 0 0 0 0 0 0 0 0 0
53473- 0 0 0 0 0 0 0 0 0 0 0 0
53474- 0 0 0 0 0 0 0 0 0 10 10 10
53475- 34 34 34 82 82 82 30 30 30 61 42 6
53476-180 123 7 206 145 10 230 174 11 239 182 13
53477-234 190 10 238 202 15 241 208 19 246 218 74
53478-246 218 38 246 215 20 246 215 20 246 215 20
53479-226 184 13 215 174 15 184 144 12 6 6 6
53480- 2 2 6 2 2 6 2 2 6 2 2 6
53481- 26 26 26 94 94 94 42 42 42 14 14 14
53482- 0 0 0 0 0 0 0 0 0 0 0 0
53483- 0 0 0 0 0 0 0 0 0 0 0 0
53484- 0 0 0 0 0 0 0 0 0 0 0 0
53485- 0 0 0 0 0 0 0 0 0 0 0 0
53486- 0 0 0 0 0 0 0 0 0 0 0 0
53487- 0 0 0 0 0 0 0 0 0 0 0 0
53488- 0 0 0 0 0 0 0 0 0 0 0 0
53489- 0 0 0 0 0 0 0 0 0 0 0 0
53490- 0 0 0 0 0 0 0 0 0 0 0 0
53491- 0 0 0 0 0 0 0 0 0 0 0 0
53492- 0 0 0 0 0 0 0 0 0 0 0 0
53493- 0 0 0 0 0 0 0 0 0 0 0 0
53494- 0 0 0 0 0 0 0 0 0 10 10 10
53495- 30 30 30 78 78 78 50 50 50 104 69 6
53496-192 133 9 216 158 10 236 178 12 236 186 11
53497-232 195 16 241 208 19 244 214 54 245 215 43
53498-246 215 20 246 215 20 241 208 19 198 155 10
53499-200 144 11 216 158 10 156 118 10 2 2 6
53500- 2 2 6 2 2 6 2 2 6 2 2 6
53501- 6 6 6 90 90 90 54 54 54 18 18 18
53502- 6 6 6 0 0 0 0 0 0 0 0 0
53503- 0 0 0 0 0 0 0 0 0 0 0 0
53504- 0 0 0 0 0 0 0 0 0 0 0 0
53505- 0 0 0 0 0 0 0 0 0 0 0 0
53506- 0 0 0 0 0 0 0 0 0 0 0 0
53507- 0 0 0 0 0 0 0 0 0 0 0 0
53508- 0 0 0 0 0 0 0 0 0 0 0 0
53509- 0 0 0 0 0 0 0 0 0 0 0 0
53510- 0 0 0 0 0 0 0 0 0 0 0 0
53511- 0 0 0 0 0 0 0 0 0 0 0 0
53512- 0 0 0 0 0 0 0 0 0 0 0 0
53513- 0 0 0 0 0 0 0 0 0 0 0 0
53514- 0 0 0 0 0 0 0 0 0 10 10 10
53515- 30 30 30 78 78 78 46 46 46 22 22 22
53516-137 92 6 210 162 10 239 182 13 238 190 10
53517-238 202 15 241 208 19 246 215 20 246 215 20
53518-241 208 19 203 166 17 185 133 11 210 150 10
53519-216 158 10 210 150 10 102 78 10 2 2 6
53520- 6 6 6 54 54 54 14 14 14 2 2 6
53521- 2 2 6 62 62 62 74 74 74 30 30 30
53522- 10 10 10 0 0 0 0 0 0 0 0 0
53523- 0 0 0 0 0 0 0 0 0 0 0 0
53524- 0 0 0 0 0 0 0 0 0 0 0 0
53525- 0 0 0 0 0 0 0 0 0 0 0 0
53526- 0 0 0 0 0 0 0 0 0 0 0 0
53527- 0 0 0 0 0 0 0 0 0 0 0 0
53528- 0 0 0 0 0 0 0 0 0 0 0 0
53529- 0 0 0 0 0 0 0 0 0 0 0 0
53530- 0 0 0 0 0 0 0 0 0 0 0 0
53531- 0 0 0 0 0 0 0 0 0 0 0 0
53532- 0 0 0 0 0 0 0 0 0 0 0 0
53533- 0 0 0 0 0 0 0 0 0 0 0 0
53534- 0 0 0 0 0 0 0 0 0 10 10 10
53535- 34 34 34 78 78 78 50 50 50 6 6 6
53536- 94 70 30 139 102 15 190 146 13 226 184 13
53537-232 200 30 232 195 16 215 174 15 190 146 13
53538-168 122 10 192 133 9 210 150 10 213 154 11
53539-202 150 34 182 157 106 101 98 89 2 2 6
53540- 2 2 6 78 78 78 116 116 116 58 58 58
53541- 2 2 6 22 22 22 90 90 90 46 46 46
53542- 18 18 18 6 6 6 0 0 0 0 0 0
53543- 0 0 0 0 0 0 0 0 0 0 0 0
53544- 0 0 0 0 0 0 0 0 0 0 0 0
53545- 0 0 0 0 0 0 0 0 0 0 0 0
53546- 0 0 0 0 0 0 0 0 0 0 0 0
53547- 0 0 0 0 0 0 0 0 0 0 0 0
53548- 0 0 0 0 0 0 0 0 0 0 0 0
53549- 0 0 0 0 0 0 0 0 0 0 0 0
53550- 0 0 0 0 0 0 0 0 0 0 0 0
53551- 0 0 0 0 0 0 0 0 0 0 0 0
53552- 0 0 0 0 0 0 0 0 0 0 0 0
53553- 0 0 0 0 0 0 0 0 0 0 0 0
53554- 0 0 0 0 0 0 0 0 0 10 10 10
53555- 38 38 38 86 86 86 50 50 50 6 6 6
53556-128 128 128 174 154 114 156 107 11 168 122 10
53557-198 155 10 184 144 12 197 138 11 200 144 11
53558-206 145 10 206 145 10 197 138 11 188 164 115
53559-195 195 195 198 198 198 174 174 174 14 14 14
53560- 2 2 6 22 22 22 116 116 116 116 116 116
53561- 22 22 22 2 2 6 74 74 74 70 70 70
53562- 30 30 30 10 10 10 0 0 0 0 0 0
53563- 0 0 0 0 0 0 0 0 0 0 0 0
53564- 0 0 0 0 0 0 0 0 0 0 0 0
53565- 0 0 0 0 0 0 0 0 0 0 0 0
53566- 0 0 0 0 0 0 0 0 0 0 0 0
53567- 0 0 0 0 0 0 0 0 0 0 0 0
53568- 0 0 0 0 0 0 0 0 0 0 0 0
53569- 0 0 0 0 0 0 0 0 0 0 0 0
53570- 0 0 0 0 0 0 0 0 0 0 0 0
53571- 0 0 0 0 0 0 0 0 0 0 0 0
53572- 0 0 0 0 0 0 0 0 0 0 0 0
53573- 0 0 0 0 0 0 0 0 0 0 0 0
53574- 0 0 0 0 0 0 6 6 6 18 18 18
53575- 50 50 50 101 101 101 26 26 26 10 10 10
53576-138 138 138 190 190 190 174 154 114 156 107 11
53577-197 138 11 200 144 11 197 138 11 192 133 9
53578-180 123 7 190 142 34 190 178 144 187 187 187
53579-202 202 202 221 221 221 214 214 214 66 66 66
53580- 2 2 6 2 2 6 50 50 50 62 62 62
53581- 6 6 6 2 2 6 10 10 10 90 90 90
53582- 50 50 50 18 18 18 6 6 6 0 0 0
53583- 0 0 0 0 0 0 0 0 0 0 0 0
53584- 0 0 0 0 0 0 0 0 0 0 0 0
53585- 0 0 0 0 0 0 0 0 0 0 0 0
53586- 0 0 0 0 0 0 0 0 0 0 0 0
53587- 0 0 0 0 0 0 0 0 0 0 0 0
53588- 0 0 0 0 0 0 0 0 0 0 0 0
53589- 0 0 0 0 0 0 0 0 0 0 0 0
53590- 0 0 0 0 0 0 0 0 0 0 0 0
53591- 0 0 0 0 0 0 0 0 0 0 0 0
53592- 0 0 0 0 0 0 0 0 0 0 0 0
53593- 0 0 0 0 0 0 0 0 0 0 0 0
53594- 0 0 0 0 0 0 10 10 10 34 34 34
53595- 74 74 74 74 74 74 2 2 6 6 6 6
53596-144 144 144 198 198 198 190 190 190 178 166 146
53597-154 121 60 156 107 11 156 107 11 168 124 44
53598-174 154 114 187 187 187 190 190 190 210 210 210
53599-246 246 246 253 253 253 253 253 253 182 182 182
53600- 6 6 6 2 2 6 2 2 6 2 2 6
53601- 2 2 6 2 2 6 2 2 6 62 62 62
53602- 74 74 74 34 34 34 14 14 14 0 0 0
53603- 0 0 0 0 0 0 0 0 0 0 0 0
53604- 0 0 0 0 0 0 0 0 0 0 0 0
53605- 0 0 0 0 0 0 0 0 0 0 0 0
53606- 0 0 0 0 0 0 0 0 0 0 0 0
53607- 0 0 0 0 0 0 0 0 0 0 0 0
53608- 0 0 0 0 0 0 0 0 0 0 0 0
53609- 0 0 0 0 0 0 0 0 0 0 0 0
53610- 0 0 0 0 0 0 0 0 0 0 0 0
53611- 0 0 0 0 0 0 0 0 0 0 0 0
53612- 0 0 0 0 0 0 0 0 0 0 0 0
53613- 0 0 0 0 0 0 0 0 0 0 0 0
53614- 0 0 0 10 10 10 22 22 22 54 54 54
53615- 94 94 94 18 18 18 2 2 6 46 46 46
53616-234 234 234 221 221 221 190 190 190 190 190 190
53617-190 190 190 187 187 187 187 187 187 190 190 190
53618-190 190 190 195 195 195 214 214 214 242 242 242
53619-253 253 253 253 253 253 253 253 253 253 253 253
53620- 82 82 82 2 2 6 2 2 6 2 2 6
53621- 2 2 6 2 2 6 2 2 6 14 14 14
53622- 86 86 86 54 54 54 22 22 22 6 6 6
53623- 0 0 0 0 0 0 0 0 0 0 0 0
53624- 0 0 0 0 0 0 0 0 0 0 0 0
53625- 0 0 0 0 0 0 0 0 0 0 0 0
53626- 0 0 0 0 0 0 0 0 0 0 0 0
53627- 0 0 0 0 0 0 0 0 0 0 0 0
53628- 0 0 0 0 0 0 0 0 0 0 0 0
53629- 0 0 0 0 0 0 0 0 0 0 0 0
53630- 0 0 0 0 0 0 0 0 0 0 0 0
53631- 0 0 0 0 0 0 0 0 0 0 0 0
53632- 0 0 0 0 0 0 0 0 0 0 0 0
53633- 0 0 0 0 0 0 0 0 0 0 0 0
53634- 6 6 6 18 18 18 46 46 46 90 90 90
53635- 46 46 46 18 18 18 6 6 6 182 182 182
53636-253 253 253 246 246 246 206 206 206 190 190 190
53637-190 190 190 190 190 190 190 190 190 190 190 190
53638-206 206 206 231 231 231 250 250 250 253 253 253
53639-253 253 253 253 253 253 253 253 253 253 253 253
53640-202 202 202 14 14 14 2 2 6 2 2 6
53641- 2 2 6 2 2 6 2 2 6 2 2 6
53642- 42 42 42 86 86 86 42 42 42 18 18 18
53643- 6 6 6 0 0 0 0 0 0 0 0 0
53644- 0 0 0 0 0 0 0 0 0 0 0 0
53645- 0 0 0 0 0 0 0 0 0 0 0 0
53646- 0 0 0 0 0 0 0 0 0 0 0 0
53647- 0 0 0 0 0 0 0 0 0 0 0 0
53648- 0 0 0 0 0 0 0 0 0 0 0 0
53649- 0 0 0 0 0 0 0 0 0 0 0 0
53650- 0 0 0 0 0 0 0 0 0 0 0 0
53651- 0 0 0 0 0 0 0 0 0 0 0 0
53652- 0 0 0 0 0 0 0 0 0 0 0 0
53653- 0 0 0 0 0 0 0 0 0 6 6 6
53654- 14 14 14 38 38 38 74 74 74 66 66 66
53655- 2 2 6 6 6 6 90 90 90 250 250 250
53656-253 253 253 253 253 253 238 238 238 198 198 198
53657-190 190 190 190 190 190 195 195 195 221 221 221
53658-246 246 246 253 253 253 253 253 253 253 253 253
53659-253 253 253 253 253 253 253 253 253 253 253 253
53660-253 253 253 82 82 82 2 2 6 2 2 6
53661- 2 2 6 2 2 6 2 2 6 2 2 6
53662- 2 2 6 78 78 78 70 70 70 34 34 34
53663- 14 14 14 6 6 6 0 0 0 0 0 0
53664- 0 0 0 0 0 0 0 0 0 0 0 0
53665- 0 0 0 0 0 0 0 0 0 0 0 0
53666- 0 0 0 0 0 0 0 0 0 0 0 0
53667- 0 0 0 0 0 0 0 0 0 0 0 0
53668- 0 0 0 0 0 0 0 0 0 0 0 0
53669- 0 0 0 0 0 0 0 0 0 0 0 0
53670- 0 0 0 0 0 0 0 0 0 0 0 0
53671- 0 0 0 0 0 0 0 0 0 0 0 0
53672- 0 0 0 0 0 0 0 0 0 0 0 0
53673- 0 0 0 0 0 0 0 0 0 14 14 14
53674- 34 34 34 66 66 66 78 78 78 6 6 6
53675- 2 2 6 18 18 18 218 218 218 253 253 253
53676-253 253 253 253 253 253 253 253 253 246 246 246
53677-226 226 226 231 231 231 246 246 246 253 253 253
53678-253 253 253 253 253 253 253 253 253 253 253 253
53679-253 253 253 253 253 253 253 253 253 253 253 253
53680-253 253 253 178 178 178 2 2 6 2 2 6
53681- 2 2 6 2 2 6 2 2 6 2 2 6
53682- 2 2 6 18 18 18 90 90 90 62 62 62
53683- 30 30 30 10 10 10 0 0 0 0 0 0
53684- 0 0 0 0 0 0 0 0 0 0 0 0
53685- 0 0 0 0 0 0 0 0 0 0 0 0
53686- 0 0 0 0 0 0 0 0 0 0 0 0
53687- 0 0 0 0 0 0 0 0 0 0 0 0
53688- 0 0 0 0 0 0 0 0 0 0 0 0
53689- 0 0 0 0 0 0 0 0 0 0 0 0
53690- 0 0 0 0 0 0 0 0 0 0 0 0
53691- 0 0 0 0 0 0 0 0 0 0 0 0
53692- 0 0 0 0 0 0 0 0 0 0 0 0
53693- 0 0 0 0 0 0 10 10 10 26 26 26
53694- 58 58 58 90 90 90 18 18 18 2 2 6
53695- 2 2 6 110 110 110 253 253 253 253 253 253
53696-253 253 253 253 253 253 253 253 253 253 253 253
53697-250 250 250 253 253 253 253 253 253 253 253 253
53698-253 253 253 253 253 253 253 253 253 253 253 253
53699-253 253 253 253 253 253 253 253 253 253 253 253
53700-253 253 253 231 231 231 18 18 18 2 2 6
53701- 2 2 6 2 2 6 2 2 6 2 2 6
53702- 2 2 6 2 2 6 18 18 18 94 94 94
53703- 54 54 54 26 26 26 10 10 10 0 0 0
53704- 0 0 0 0 0 0 0 0 0 0 0 0
53705- 0 0 0 0 0 0 0 0 0 0 0 0
53706- 0 0 0 0 0 0 0 0 0 0 0 0
53707- 0 0 0 0 0 0 0 0 0 0 0 0
53708- 0 0 0 0 0 0 0 0 0 0 0 0
53709- 0 0 0 0 0 0 0 0 0 0 0 0
53710- 0 0 0 0 0 0 0 0 0 0 0 0
53711- 0 0 0 0 0 0 0 0 0 0 0 0
53712- 0 0 0 0 0 0 0 0 0 0 0 0
53713- 0 0 0 6 6 6 22 22 22 50 50 50
53714- 90 90 90 26 26 26 2 2 6 2 2 6
53715- 14 14 14 195 195 195 250 250 250 253 253 253
53716-253 253 253 253 253 253 253 253 253 253 253 253
53717-253 253 253 253 253 253 253 253 253 253 253 253
53718-253 253 253 253 253 253 253 253 253 253 253 253
53719-253 253 253 253 253 253 253 253 253 253 253 253
53720-250 250 250 242 242 242 54 54 54 2 2 6
53721- 2 2 6 2 2 6 2 2 6 2 2 6
53722- 2 2 6 2 2 6 2 2 6 38 38 38
53723- 86 86 86 50 50 50 22 22 22 6 6 6
53724- 0 0 0 0 0 0 0 0 0 0 0 0
53725- 0 0 0 0 0 0 0 0 0 0 0 0
53726- 0 0 0 0 0 0 0 0 0 0 0 0
53727- 0 0 0 0 0 0 0 0 0 0 0 0
53728- 0 0 0 0 0 0 0 0 0 0 0 0
53729- 0 0 0 0 0 0 0 0 0 0 0 0
53730- 0 0 0 0 0 0 0 0 0 0 0 0
53731- 0 0 0 0 0 0 0 0 0 0 0 0
53732- 0 0 0 0 0 0 0 0 0 0 0 0
53733- 6 6 6 14 14 14 38 38 38 82 82 82
53734- 34 34 34 2 2 6 2 2 6 2 2 6
53735- 42 42 42 195 195 195 246 246 246 253 253 253
53736-253 253 253 253 253 253 253 253 253 250 250 250
53737-242 242 242 242 242 242 250 250 250 253 253 253
53738-253 253 253 253 253 253 253 253 253 253 253 253
53739-253 253 253 250 250 250 246 246 246 238 238 238
53740-226 226 226 231 231 231 101 101 101 6 6 6
53741- 2 2 6 2 2 6 2 2 6 2 2 6
53742- 2 2 6 2 2 6 2 2 6 2 2 6
53743- 38 38 38 82 82 82 42 42 42 14 14 14
53744- 6 6 6 0 0 0 0 0 0 0 0 0
53745- 0 0 0 0 0 0 0 0 0 0 0 0
53746- 0 0 0 0 0 0 0 0 0 0 0 0
53747- 0 0 0 0 0 0 0 0 0 0 0 0
53748- 0 0 0 0 0 0 0 0 0 0 0 0
53749- 0 0 0 0 0 0 0 0 0 0 0 0
53750- 0 0 0 0 0 0 0 0 0 0 0 0
53751- 0 0 0 0 0 0 0 0 0 0 0 0
53752- 0 0 0 0 0 0 0 0 0 0 0 0
53753- 10 10 10 26 26 26 62 62 62 66 66 66
53754- 2 2 6 2 2 6 2 2 6 6 6 6
53755- 70 70 70 170 170 170 206 206 206 234 234 234
53756-246 246 246 250 250 250 250 250 250 238 238 238
53757-226 226 226 231 231 231 238 238 238 250 250 250
53758-250 250 250 250 250 250 246 246 246 231 231 231
53759-214 214 214 206 206 206 202 202 202 202 202 202
53760-198 198 198 202 202 202 182 182 182 18 18 18
53761- 2 2 6 2 2 6 2 2 6 2 2 6
53762- 2 2 6 2 2 6 2 2 6 2 2 6
53763- 2 2 6 62 62 62 66 66 66 30 30 30
53764- 10 10 10 0 0 0 0 0 0 0 0 0
53765- 0 0 0 0 0 0 0 0 0 0 0 0
53766- 0 0 0 0 0 0 0 0 0 0 0 0
53767- 0 0 0 0 0 0 0 0 0 0 0 0
53768- 0 0 0 0 0 0 0 0 0 0 0 0
53769- 0 0 0 0 0 0 0 0 0 0 0 0
53770- 0 0 0 0 0 0 0 0 0 0 0 0
53771- 0 0 0 0 0 0 0 0 0 0 0 0
53772- 0 0 0 0 0 0 0 0 0 0 0 0
53773- 14 14 14 42 42 42 82 82 82 18 18 18
53774- 2 2 6 2 2 6 2 2 6 10 10 10
53775- 94 94 94 182 182 182 218 218 218 242 242 242
53776-250 250 250 253 253 253 253 253 253 250 250 250
53777-234 234 234 253 253 253 253 253 253 253 253 253
53778-253 253 253 253 253 253 253 253 253 246 246 246
53779-238 238 238 226 226 226 210 210 210 202 202 202
53780-195 195 195 195 195 195 210 210 210 158 158 158
53781- 6 6 6 14 14 14 50 50 50 14 14 14
53782- 2 2 6 2 2 6 2 2 6 2 2 6
53783- 2 2 6 6 6 6 86 86 86 46 46 46
53784- 18 18 18 6 6 6 0 0 0 0 0 0
53785- 0 0 0 0 0 0 0 0 0 0 0 0
53786- 0 0 0 0 0 0 0 0 0 0 0 0
53787- 0 0 0 0 0 0 0 0 0 0 0 0
53788- 0 0 0 0 0 0 0 0 0 0 0 0
53789- 0 0 0 0 0 0 0 0 0 0 0 0
53790- 0 0 0 0 0 0 0 0 0 0 0 0
53791- 0 0 0 0 0 0 0 0 0 0 0 0
53792- 0 0 0 0 0 0 0 0 0 6 6 6
53793- 22 22 22 54 54 54 70 70 70 2 2 6
53794- 2 2 6 10 10 10 2 2 6 22 22 22
53795-166 166 166 231 231 231 250 250 250 253 253 253
53796-253 253 253 253 253 253 253 253 253 250 250 250
53797-242 242 242 253 253 253 253 253 253 253 253 253
53798-253 253 253 253 253 253 253 253 253 253 253 253
53799-253 253 253 253 253 253 253 253 253 246 246 246
53800-231 231 231 206 206 206 198 198 198 226 226 226
53801- 94 94 94 2 2 6 6 6 6 38 38 38
53802- 30 30 30 2 2 6 2 2 6 2 2 6
53803- 2 2 6 2 2 6 62 62 62 66 66 66
53804- 26 26 26 10 10 10 0 0 0 0 0 0
53805- 0 0 0 0 0 0 0 0 0 0 0 0
53806- 0 0 0 0 0 0 0 0 0 0 0 0
53807- 0 0 0 0 0 0 0 0 0 0 0 0
53808- 0 0 0 0 0 0 0 0 0 0 0 0
53809- 0 0 0 0 0 0 0 0 0 0 0 0
53810- 0 0 0 0 0 0 0 0 0 0 0 0
53811- 0 0 0 0 0 0 0 0 0 0 0 0
53812- 0 0 0 0 0 0 0 0 0 10 10 10
53813- 30 30 30 74 74 74 50 50 50 2 2 6
53814- 26 26 26 26 26 26 2 2 6 106 106 106
53815-238 238 238 253 253 253 253 253 253 253 253 253
53816-253 253 253 253 253 253 253 253 253 253 253 253
53817-253 253 253 253 253 253 253 253 253 253 253 253
53818-253 253 253 253 253 253 253 253 253 253 253 253
53819-253 253 253 253 253 253 253 253 253 253 253 253
53820-253 253 253 246 246 246 218 218 218 202 202 202
53821-210 210 210 14 14 14 2 2 6 2 2 6
53822- 30 30 30 22 22 22 2 2 6 2 2 6
53823- 2 2 6 2 2 6 18 18 18 86 86 86
53824- 42 42 42 14 14 14 0 0 0 0 0 0
53825- 0 0 0 0 0 0 0 0 0 0 0 0
53826- 0 0 0 0 0 0 0 0 0 0 0 0
53827- 0 0 0 0 0 0 0 0 0 0 0 0
53828- 0 0 0 0 0 0 0 0 0 0 0 0
53829- 0 0 0 0 0 0 0 0 0 0 0 0
53830- 0 0 0 0 0 0 0 0 0 0 0 0
53831- 0 0 0 0 0 0 0 0 0 0 0 0
53832- 0 0 0 0 0 0 0 0 0 14 14 14
53833- 42 42 42 90 90 90 22 22 22 2 2 6
53834- 42 42 42 2 2 6 18 18 18 218 218 218
53835-253 253 253 253 253 253 253 253 253 253 253 253
53836-253 253 253 253 253 253 253 253 253 253 253 253
53837-253 253 253 253 253 253 253 253 253 253 253 253
53838-253 253 253 253 253 253 253 253 253 253 253 253
53839-253 253 253 253 253 253 253 253 253 253 253 253
53840-253 253 253 253 253 253 250 250 250 221 221 221
53841-218 218 218 101 101 101 2 2 6 14 14 14
53842- 18 18 18 38 38 38 10 10 10 2 2 6
53843- 2 2 6 2 2 6 2 2 6 78 78 78
53844- 58 58 58 22 22 22 6 6 6 0 0 0
53845- 0 0 0 0 0 0 0 0 0 0 0 0
53846- 0 0 0 0 0 0 0 0 0 0 0 0
53847- 0 0 0 0 0 0 0 0 0 0 0 0
53848- 0 0 0 0 0 0 0 0 0 0 0 0
53849- 0 0 0 0 0 0 0 0 0 0 0 0
53850- 0 0 0 0 0 0 0 0 0 0 0 0
53851- 0 0 0 0 0 0 0 0 0 0 0 0
53852- 0 0 0 0 0 0 6 6 6 18 18 18
53853- 54 54 54 82 82 82 2 2 6 26 26 26
53854- 22 22 22 2 2 6 123 123 123 253 253 253
53855-253 253 253 253 253 253 253 253 253 253 253 253
53856-253 253 253 253 253 253 253 253 253 253 253 253
53857-253 253 253 253 253 253 253 253 253 253 253 253
53858-253 253 253 253 253 253 253 253 253 253 253 253
53859-253 253 253 253 253 253 253 253 253 253 253 253
53860-253 253 253 253 253 253 253 253 253 250 250 250
53861-238 238 238 198 198 198 6 6 6 38 38 38
53862- 58 58 58 26 26 26 38 38 38 2 2 6
53863- 2 2 6 2 2 6 2 2 6 46 46 46
53864- 78 78 78 30 30 30 10 10 10 0 0 0
53865- 0 0 0 0 0 0 0 0 0 0 0 0
53866- 0 0 0 0 0 0 0 0 0 0 0 0
53867- 0 0 0 0 0 0 0 0 0 0 0 0
53868- 0 0 0 0 0 0 0 0 0 0 0 0
53869- 0 0 0 0 0 0 0 0 0 0 0 0
53870- 0 0 0 0 0 0 0 0 0 0 0 0
53871- 0 0 0 0 0 0 0 0 0 0 0 0
53872- 0 0 0 0 0 0 10 10 10 30 30 30
53873- 74 74 74 58 58 58 2 2 6 42 42 42
53874- 2 2 6 22 22 22 231 231 231 253 253 253
53875-253 253 253 253 253 253 253 253 253 253 253 253
53876-253 253 253 253 253 253 253 253 253 250 250 250
53877-253 253 253 253 253 253 253 253 253 253 253 253
53878-253 253 253 253 253 253 253 253 253 253 253 253
53879-253 253 253 253 253 253 253 253 253 253 253 253
53880-253 253 253 253 253 253 253 253 253 253 253 253
53881-253 253 253 246 246 246 46 46 46 38 38 38
53882- 42 42 42 14 14 14 38 38 38 14 14 14
53883- 2 2 6 2 2 6 2 2 6 6 6 6
53884- 86 86 86 46 46 46 14 14 14 0 0 0
53885- 0 0 0 0 0 0 0 0 0 0 0 0
53886- 0 0 0 0 0 0 0 0 0 0 0 0
53887- 0 0 0 0 0 0 0 0 0 0 0 0
53888- 0 0 0 0 0 0 0 0 0 0 0 0
53889- 0 0 0 0 0 0 0 0 0 0 0 0
53890- 0 0 0 0 0 0 0 0 0 0 0 0
53891- 0 0 0 0 0 0 0 0 0 0 0 0
53892- 0 0 0 6 6 6 14 14 14 42 42 42
53893- 90 90 90 18 18 18 18 18 18 26 26 26
53894- 2 2 6 116 116 116 253 253 253 253 253 253
53895-253 253 253 253 253 253 253 253 253 253 253 253
53896-253 253 253 253 253 253 250 250 250 238 238 238
53897-253 253 253 253 253 253 253 253 253 253 253 253
53898-253 253 253 253 253 253 253 253 253 253 253 253
53899-253 253 253 253 253 253 253 253 253 253 253 253
53900-253 253 253 253 253 253 253 253 253 253 253 253
53901-253 253 253 253 253 253 94 94 94 6 6 6
53902- 2 2 6 2 2 6 10 10 10 34 34 34
53903- 2 2 6 2 2 6 2 2 6 2 2 6
53904- 74 74 74 58 58 58 22 22 22 6 6 6
53905- 0 0 0 0 0 0 0 0 0 0 0 0
53906- 0 0 0 0 0 0 0 0 0 0 0 0
53907- 0 0 0 0 0 0 0 0 0 0 0 0
53908- 0 0 0 0 0 0 0 0 0 0 0 0
53909- 0 0 0 0 0 0 0 0 0 0 0 0
53910- 0 0 0 0 0 0 0 0 0 0 0 0
53911- 0 0 0 0 0 0 0 0 0 0 0 0
53912- 0 0 0 10 10 10 26 26 26 66 66 66
53913- 82 82 82 2 2 6 38 38 38 6 6 6
53914- 14 14 14 210 210 210 253 253 253 253 253 253
53915-253 253 253 253 253 253 253 253 253 253 253 253
53916-253 253 253 253 253 253 246 246 246 242 242 242
53917-253 253 253 253 253 253 253 253 253 253 253 253
53918-253 253 253 253 253 253 253 253 253 253 253 253
53919-253 253 253 253 253 253 253 253 253 253 253 253
53920-253 253 253 253 253 253 253 253 253 253 253 253
53921-253 253 253 253 253 253 144 144 144 2 2 6
53922- 2 2 6 2 2 6 2 2 6 46 46 46
53923- 2 2 6 2 2 6 2 2 6 2 2 6
53924- 42 42 42 74 74 74 30 30 30 10 10 10
53925- 0 0 0 0 0 0 0 0 0 0 0 0
53926- 0 0 0 0 0 0 0 0 0 0 0 0
53927- 0 0 0 0 0 0 0 0 0 0 0 0
53928- 0 0 0 0 0 0 0 0 0 0 0 0
53929- 0 0 0 0 0 0 0 0 0 0 0 0
53930- 0 0 0 0 0 0 0 0 0 0 0 0
53931- 0 0 0 0 0 0 0 0 0 0 0 0
53932- 6 6 6 14 14 14 42 42 42 90 90 90
53933- 26 26 26 6 6 6 42 42 42 2 2 6
53934- 74 74 74 250 250 250 253 253 253 253 253 253
53935-253 253 253 253 253 253 253 253 253 253 253 253
53936-253 253 253 253 253 253 242 242 242 242 242 242
53937-253 253 253 253 253 253 253 253 253 253 253 253
53938-253 253 253 253 253 253 253 253 253 253 253 253
53939-253 253 253 253 253 253 253 253 253 253 253 253
53940-253 253 253 253 253 253 253 253 253 253 253 253
53941-253 253 253 253 253 253 182 182 182 2 2 6
53942- 2 2 6 2 2 6 2 2 6 46 46 46
53943- 2 2 6 2 2 6 2 2 6 2 2 6
53944- 10 10 10 86 86 86 38 38 38 10 10 10
53945- 0 0 0 0 0 0 0 0 0 0 0 0
53946- 0 0 0 0 0 0 0 0 0 0 0 0
53947- 0 0 0 0 0 0 0 0 0 0 0 0
53948- 0 0 0 0 0 0 0 0 0 0 0 0
53949- 0 0 0 0 0 0 0 0 0 0 0 0
53950- 0 0 0 0 0 0 0 0 0 0 0 0
53951- 0 0 0 0 0 0 0 0 0 0 0 0
53952- 10 10 10 26 26 26 66 66 66 82 82 82
53953- 2 2 6 22 22 22 18 18 18 2 2 6
53954-149 149 149 253 253 253 253 253 253 253 253 253
53955-253 253 253 253 253 253 253 253 253 253 253 253
53956-253 253 253 253 253 253 234 234 234 242 242 242
53957-253 253 253 253 253 253 253 253 253 253 253 253
53958-253 253 253 253 253 253 253 253 253 253 253 253
53959-253 253 253 253 253 253 253 253 253 253 253 253
53960-253 253 253 253 253 253 253 253 253 253 253 253
53961-253 253 253 253 253 253 206 206 206 2 2 6
53962- 2 2 6 2 2 6 2 2 6 38 38 38
53963- 2 2 6 2 2 6 2 2 6 2 2 6
53964- 6 6 6 86 86 86 46 46 46 14 14 14
53965- 0 0 0 0 0 0 0 0 0 0 0 0
53966- 0 0 0 0 0 0 0 0 0 0 0 0
53967- 0 0 0 0 0 0 0 0 0 0 0 0
53968- 0 0 0 0 0 0 0 0 0 0 0 0
53969- 0 0 0 0 0 0 0 0 0 0 0 0
53970- 0 0 0 0 0 0 0 0 0 0 0 0
53971- 0 0 0 0 0 0 0 0 0 6 6 6
53972- 18 18 18 46 46 46 86 86 86 18 18 18
53973- 2 2 6 34 34 34 10 10 10 6 6 6
53974-210 210 210 253 253 253 253 253 253 253 253 253
53975-253 253 253 253 253 253 253 253 253 253 253 253
53976-253 253 253 253 253 253 234 234 234 242 242 242
53977-253 253 253 253 253 253 253 253 253 253 253 253
53978-253 253 253 253 253 253 253 253 253 253 253 253
53979-253 253 253 253 253 253 253 253 253 253 253 253
53980-253 253 253 253 253 253 253 253 253 253 253 253
53981-253 253 253 253 253 253 221 221 221 6 6 6
53982- 2 2 6 2 2 6 6 6 6 30 30 30
53983- 2 2 6 2 2 6 2 2 6 2 2 6
53984- 2 2 6 82 82 82 54 54 54 18 18 18
53985- 6 6 6 0 0 0 0 0 0 0 0 0
53986- 0 0 0 0 0 0 0 0 0 0 0 0
53987- 0 0 0 0 0 0 0 0 0 0 0 0
53988- 0 0 0 0 0 0 0 0 0 0 0 0
53989- 0 0 0 0 0 0 0 0 0 0 0 0
53990- 0 0 0 0 0 0 0 0 0 0 0 0
53991- 0 0 0 0 0 0 0 0 0 10 10 10
53992- 26 26 26 66 66 66 62 62 62 2 2 6
53993- 2 2 6 38 38 38 10 10 10 26 26 26
53994-238 238 238 253 253 253 253 253 253 253 253 253
53995-253 253 253 253 253 253 253 253 253 253 253 253
53996-253 253 253 253 253 253 231 231 231 238 238 238
53997-253 253 253 253 253 253 253 253 253 253 253 253
53998-253 253 253 253 253 253 253 253 253 253 253 253
53999-253 253 253 253 253 253 253 253 253 253 253 253
54000-253 253 253 253 253 253 253 253 253 253 253 253
54001-253 253 253 253 253 253 231 231 231 6 6 6
54002- 2 2 6 2 2 6 10 10 10 30 30 30
54003- 2 2 6 2 2 6 2 2 6 2 2 6
54004- 2 2 6 66 66 66 58 58 58 22 22 22
54005- 6 6 6 0 0 0 0 0 0 0 0 0
54006- 0 0 0 0 0 0 0 0 0 0 0 0
54007- 0 0 0 0 0 0 0 0 0 0 0 0
54008- 0 0 0 0 0 0 0 0 0 0 0 0
54009- 0 0 0 0 0 0 0 0 0 0 0 0
54010- 0 0 0 0 0 0 0 0 0 0 0 0
54011- 0 0 0 0 0 0 0 0 0 10 10 10
54012- 38 38 38 78 78 78 6 6 6 2 2 6
54013- 2 2 6 46 46 46 14 14 14 42 42 42
54014-246 246 246 253 253 253 253 253 253 253 253 253
54015-253 253 253 253 253 253 253 253 253 253 253 253
54016-253 253 253 253 253 253 231 231 231 242 242 242
54017-253 253 253 253 253 253 253 253 253 253 253 253
54018-253 253 253 253 253 253 253 253 253 253 253 253
54019-253 253 253 253 253 253 253 253 253 253 253 253
54020-253 253 253 253 253 253 253 253 253 253 253 253
54021-253 253 253 253 253 253 234 234 234 10 10 10
54022- 2 2 6 2 2 6 22 22 22 14 14 14
54023- 2 2 6 2 2 6 2 2 6 2 2 6
54024- 2 2 6 66 66 66 62 62 62 22 22 22
54025- 6 6 6 0 0 0 0 0 0 0 0 0
54026- 0 0 0 0 0 0 0 0 0 0 0 0
54027- 0 0 0 0 0 0 0 0 0 0 0 0
54028- 0 0 0 0 0 0 0 0 0 0 0 0
54029- 0 0 0 0 0 0 0 0 0 0 0 0
54030- 0 0 0 0 0 0 0 0 0 0 0 0
54031- 0 0 0 0 0 0 6 6 6 18 18 18
54032- 50 50 50 74 74 74 2 2 6 2 2 6
54033- 14 14 14 70 70 70 34 34 34 62 62 62
54034-250 250 250 253 253 253 253 253 253 253 253 253
54035-253 253 253 253 253 253 253 253 253 253 253 253
54036-253 253 253 253 253 253 231 231 231 246 246 246
54037-253 253 253 253 253 253 253 253 253 253 253 253
54038-253 253 253 253 253 253 253 253 253 253 253 253
54039-253 253 253 253 253 253 253 253 253 253 253 253
54040-253 253 253 253 253 253 253 253 253 253 253 253
54041-253 253 253 253 253 253 234 234 234 14 14 14
54042- 2 2 6 2 2 6 30 30 30 2 2 6
54043- 2 2 6 2 2 6 2 2 6 2 2 6
54044- 2 2 6 66 66 66 62 62 62 22 22 22
54045- 6 6 6 0 0 0 0 0 0 0 0 0
54046- 0 0 0 0 0 0 0 0 0 0 0 0
54047- 0 0 0 0 0 0 0 0 0 0 0 0
54048- 0 0 0 0 0 0 0 0 0 0 0 0
54049- 0 0 0 0 0 0 0 0 0 0 0 0
54050- 0 0 0 0 0 0 0 0 0 0 0 0
54051- 0 0 0 0 0 0 6 6 6 18 18 18
54052- 54 54 54 62 62 62 2 2 6 2 2 6
54053- 2 2 6 30 30 30 46 46 46 70 70 70
54054-250 250 250 253 253 253 253 253 253 253 253 253
54055-253 253 253 253 253 253 253 253 253 253 253 253
54056-253 253 253 253 253 253 231 231 231 246 246 246
54057-253 253 253 253 253 253 253 253 253 253 253 253
54058-253 253 253 253 253 253 253 253 253 253 253 253
54059-253 253 253 253 253 253 253 253 253 253 253 253
54060-253 253 253 253 253 253 253 253 253 253 253 253
54061-253 253 253 253 253 253 226 226 226 10 10 10
54062- 2 2 6 6 6 6 30 30 30 2 2 6
54063- 2 2 6 2 2 6 2 2 6 2 2 6
54064- 2 2 6 66 66 66 58 58 58 22 22 22
54065- 6 6 6 0 0 0 0 0 0 0 0 0
54066- 0 0 0 0 0 0 0 0 0 0 0 0
54067- 0 0 0 0 0 0 0 0 0 0 0 0
54068- 0 0 0 0 0 0 0 0 0 0 0 0
54069- 0 0 0 0 0 0 0 0 0 0 0 0
54070- 0 0 0 0 0 0 0 0 0 0 0 0
54071- 0 0 0 0 0 0 6 6 6 22 22 22
54072- 58 58 58 62 62 62 2 2 6 2 2 6
54073- 2 2 6 2 2 6 30 30 30 78 78 78
54074-250 250 250 253 253 253 253 253 253 253 253 253
54075-253 253 253 253 253 253 253 253 253 253 253 253
54076-253 253 253 253 253 253 231 231 231 246 246 246
54077-253 253 253 253 253 253 253 253 253 253 253 253
54078-253 253 253 253 253 253 253 253 253 253 253 253
54079-253 253 253 253 253 253 253 253 253 253 253 253
54080-253 253 253 253 253 253 253 253 253 253 253 253
54081-253 253 253 253 253 253 206 206 206 2 2 6
54082- 22 22 22 34 34 34 18 14 6 22 22 22
54083- 26 26 26 18 18 18 6 6 6 2 2 6
54084- 2 2 6 82 82 82 54 54 54 18 18 18
54085- 6 6 6 0 0 0 0 0 0 0 0 0
54086- 0 0 0 0 0 0 0 0 0 0 0 0
54087- 0 0 0 0 0 0 0 0 0 0 0 0
54088- 0 0 0 0 0 0 0 0 0 0 0 0
54089- 0 0 0 0 0 0 0 0 0 0 0 0
54090- 0 0 0 0 0 0 0 0 0 0 0 0
54091- 0 0 0 0 0 0 6 6 6 26 26 26
54092- 62 62 62 106 106 106 74 54 14 185 133 11
54093-210 162 10 121 92 8 6 6 6 62 62 62
54094-238 238 238 253 253 253 253 253 253 253 253 253
54095-253 253 253 253 253 253 253 253 253 253 253 253
54096-253 253 253 253 253 253 231 231 231 246 246 246
54097-253 253 253 253 253 253 253 253 253 253 253 253
54098-253 253 253 253 253 253 253 253 253 253 253 253
54099-253 253 253 253 253 253 253 253 253 253 253 253
54100-253 253 253 253 253 253 253 253 253 253 253 253
54101-253 253 253 253 253 253 158 158 158 18 18 18
54102- 14 14 14 2 2 6 2 2 6 2 2 6
54103- 6 6 6 18 18 18 66 66 66 38 38 38
54104- 6 6 6 94 94 94 50 50 50 18 18 18
54105- 6 6 6 0 0 0 0 0 0 0 0 0
54106- 0 0 0 0 0 0 0 0 0 0 0 0
54107- 0 0 0 0 0 0 0 0 0 0 0 0
54108- 0 0 0 0 0 0 0 0 0 0 0 0
54109- 0 0 0 0 0 0 0 0 0 0 0 0
54110- 0 0 0 0 0 0 0 0 0 6 6 6
54111- 10 10 10 10 10 10 18 18 18 38 38 38
54112- 78 78 78 142 134 106 216 158 10 242 186 14
54113-246 190 14 246 190 14 156 118 10 10 10 10
54114- 90 90 90 238 238 238 253 253 253 253 253 253
54115-253 253 253 253 253 253 253 253 253 253 253 253
54116-253 253 253 253 253 253 231 231 231 250 250 250
54117-253 253 253 253 253 253 253 253 253 253 253 253
54118-253 253 253 253 253 253 253 253 253 253 253 253
54119-253 253 253 253 253 253 253 253 253 253 253 253
54120-253 253 253 253 253 253 253 253 253 246 230 190
54121-238 204 91 238 204 91 181 142 44 37 26 9
54122- 2 2 6 2 2 6 2 2 6 2 2 6
54123- 2 2 6 2 2 6 38 38 38 46 46 46
54124- 26 26 26 106 106 106 54 54 54 18 18 18
54125- 6 6 6 0 0 0 0 0 0 0 0 0
54126- 0 0 0 0 0 0 0 0 0 0 0 0
54127- 0 0 0 0 0 0 0 0 0 0 0 0
54128- 0 0 0 0 0 0 0 0 0 0 0 0
54129- 0 0 0 0 0 0 0 0 0 0 0 0
54130- 0 0 0 6 6 6 14 14 14 22 22 22
54131- 30 30 30 38 38 38 50 50 50 70 70 70
54132-106 106 106 190 142 34 226 170 11 242 186 14
54133-246 190 14 246 190 14 246 190 14 154 114 10
54134- 6 6 6 74 74 74 226 226 226 253 253 253
54135-253 253 253 253 253 253 253 253 253 253 253 253
54136-253 253 253 253 253 253 231 231 231 250 250 250
54137-253 253 253 253 253 253 253 253 253 253 253 253
54138-253 253 253 253 253 253 253 253 253 253 253 253
54139-253 253 253 253 253 253 253 253 253 253 253 253
54140-253 253 253 253 253 253 253 253 253 228 184 62
54141-241 196 14 241 208 19 232 195 16 38 30 10
54142- 2 2 6 2 2 6 2 2 6 2 2 6
54143- 2 2 6 6 6 6 30 30 30 26 26 26
54144-203 166 17 154 142 90 66 66 66 26 26 26
54145- 6 6 6 0 0 0 0 0 0 0 0 0
54146- 0 0 0 0 0 0 0 0 0 0 0 0
54147- 0 0 0 0 0 0 0 0 0 0 0 0
54148- 0 0 0 0 0 0 0 0 0 0 0 0
54149- 0 0 0 0 0 0 0 0 0 0 0 0
54150- 6 6 6 18 18 18 38 38 38 58 58 58
54151- 78 78 78 86 86 86 101 101 101 123 123 123
54152-175 146 61 210 150 10 234 174 13 246 186 14
54153-246 190 14 246 190 14 246 190 14 238 190 10
54154-102 78 10 2 2 6 46 46 46 198 198 198
54155-253 253 253 253 253 253 253 253 253 253 253 253
54156-253 253 253 253 253 253 234 234 234 242 242 242
54157-253 253 253 253 253 253 253 253 253 253 253 253
54158-253 253 253 253 253 253 253 253 253 253 253 253
54159-253 253 253 253 253 253 253 253 253 253 253 253
54160-253 253 253 253 253 253 253 253 253 224 178 62
54161-242 186 14 241 196 14 210 166 10 22 18 6
54162- 2 2 6 2 2 6 2 2 6 2 2 6
54163- 2 2 6 2 2 6 6 6 6 121 92 8
54164-238 202 15 232 195 16 82 82 82 34 34 34
54165- 10 10 10 0 0 0 0 0 0 0 0 0
54166- 0 0 0 0 0 0 0 0 0 0 0 0
54167- 0 0 0 0 0 0 0 0 0 0 0 0
54168- 0 0 0 0 0 0 0 0 0 0 0 0
54169- 0 0 0 0 0 0 0 0 0 0 0 0
54170- 14 14 14 38 38 38 70 70 70 154 122 46
54171-190 142 34 200 144 11 197 138 11 197 138 11
54172-213 154 11 226 170 11 242 186 14 246 190 14
54173-246 190 14 246 190 14 246 190 14 246 190 14
54174-225 175 15 46 32 6 2 2 6 22 22 22
54175-158 158 158 250 250 250 253 253 253 253 253 253
54176-253 253 253 253 253 253 253 253 253 253 253 253
54177-253 253 253 253 253 253 253 253 253 253 253 253
54178-253 253 253 253 253 253 253 253 253 253 253 253
54179-253 253 253 253 253 253 253 253 253 253 253 253
54180-253 253 253 250 250 250 242 242 242 224 178 62
54181-239 182 13 236 186 11 213 154 11 46 32 6
54182- 2 2 6 2 2 6 2 2 6 2 2 6
54183- 2 2 6 2 2 6 61 42 6 225 175 15
54184-238 190 10 236 186 11 112 100 78 42 42 42
54185- 14 14 14 0 0 0 0 0 0 0 0 0
54186- 0 0 0 0 0 0 0 0 0 0 0 0
54187- 0 0 0 0 0 0 0 0 0 0 0 0
54188- 0 0 0 0 0 0 0 0 0 0 0 0
54189- 0 0 0 0 0 0 0 0 0 6 6 6
54190- 22 22 22 54 54 54 154 122 46 213 154 11
54191-226 170 11 230 174 11 226 170 11 226 170 11
54192-236 178 12 242 186 14 246 190 14 246 190 14
54193-246 190 14 246 190 14 246 190 14 246 190 14
54194-241 196 14 184 144 12 10 10 10 2 2 6
54195- 6 6 6 116 116 116 242 242 242 253 253 253
54196-253 253 253 253 253 253 253 253 253 253 253 253
54197-253 253 253 253 253 253 253 253 253 253 253 253
54198-253 253 253 253 253 253 253 253 253 253 253 253
54199-253 253 253 253 253 253 253 253 253 253 253 253
54200-253 253 253 231 231 231 198 198 198 214 170 54
54201-236 178 12 236 178 12 210 150 10 137 92 6
54202- 18 14 6 2 2 6 2 2 6 2 2 6
54203- 6 6 6 70 47 6 200 144 11 236 178 12
54204-239 182 13 239 182 13 124 112 88 58 58 58
54205- 22 22 22 6 6 6 0 0 0 0 0 0
54206- 0 0 0 0 0 0 0 0 0 0 0 0
54207- 0 0 0 0 0 0 0 0 0 0 0 0
54208- 0 0 0 0 0 0 0 0 0 0 0 0
54209- 0 0 0 0 0 0 0 0 0 10 10 10
54210- 30 30 30 70 70 70 180 133 36 226 170 11
54211-239 182 13 242 186 14 242 186 14 246 186 14
54212-246 190 14 246 190 14 246 190 14 246 190 14
54213-246 190 14 246 190 14 246 190 14 246 190 14
54214-246 190 14 232 195 16 98 70 6 2 2 6
54215- 2 2 6 2 2 6 66 66 66 221 221 221
54216-253 253 253 253 253 253 253 253 253 253 253 253
54217-253 253 253 253 253 253 253 253 253 253 253 253
54218-253 253 253 253 253 253 253 253 253 253 253 253
54219-253 253 253 253 253 253 253 253 253 253 253 253
54220-253 253 253 206 206 206 198 198 198 214 166 58
54221-230 174 11 230 174 11 216 158 10 192 133 9
54222-163 110 8 116 81 8 102 78 10 116 81 8
54223-167 114 7 197 138 11 226 170 11 239 182 13
54224-242 186 14 242 186 14 162 146 94 78 78 78
54225- 34 34 34 14 14 14 6 6 6 0 0 0
54226- 0 0 0 0 0 0 0 0 0 0 0 0
54227- 0 0 0 0 0 0 0 0 0 0 0 0
54228- 0 0 0 0 0 0 0 0 0 0 0 0
54229- 0 0 0 0 0 0 0 0 0 6 6 6
54230- 30 30 30 78 78 78 190 142 34 226 170 11
54231-239 182 13 246 190 14 246 190 14 246 190 14
54232-246 190 14 246 190 14 246 190 14 246 190 14
54233-246 190 14 246 190 14 246 190 14 246 190 14
54234-246 190 14 241 196 14 203 166 17 22 18 6
54235- 2 2 6 2 2 6 2 2 6 38 38 38
54236-218 218 218 253 253 253 253 253 253 253 253 253
54237-253 253 253 253 253 253 253 253 253 253 253 253
54238-253 253 253 253 253 253 253 253 253 253 253 253
54239-253 253 253 253 253 253 253 253 253 253 253 253
54240-250 250 250 206 206 206 198 198 198 202 162 69
54241-226 170 11 236 178 12 224 166 10 210 150 10
54242-200 144 11 197 138 11 192 133 9 197 138 11
54243-210 150 10 226 170 11 242 186 14 246 190 14
54244-246 190 14 246 186 14 225 175 15 124 112 88
54245- 62 62 62 30 30 30 14 14 14 6 6 6
54246- 0 0 0 0 0 0 0 0 0 0 0 0
54247- 0 0 0 0 0 0 0 0 0 0 0 0
54248- 0 0 0 0 0 0 0 0 0 0 0 0
54249- 0 0 0 0 0 0 0 0 0 10 10 10
54250- 30 30 30 78 78 78 174 135 50 224 166 10
54251-239 182 13 246 190 14 246 190 14 246 190 14
54252-246 190 14 246 190 14 246 190 14 246 190 14
54253-246 190 14 246 190 14 246 190 14 246 190 14
54254-246 190 14 246 190 14 241 196 14 139 102 15
54255- 2 2 6 2 2 6 2 2 6 2 2 6
54256- 78 78 78 250 250 250 253 253 253 253 253 253
54257-253 253 253 253 253 253 253 253 253 253 253 253
54258-253 253 253 253 253 253 253 253 253 253 253 253
54259-253 253 253 253 253 253 253 253 253 253 253 253
54260-250 250 250 214 214 214 198 198 198 190 150 46
54261-219 162 10 236 178 12 234 174 13 224 166 10
54262-216 158 10 213 154 11 213 154 11 216 158 10
54263-226 170 11 239 182 13 246 190 14 246 190 14
54264-246 190 14 246 190 14 242 186 14 206 162 42
54265-101 101 101 58 58 58 30 30 30 14 14 14
54266- 6 6 6 0 0 0 0 0 0 0 0 0
54267- 0 0 0 0 0 0 0 0 0 0 0 0
54268- 0 0 0 0 0 0 0 0 0 0 0 0
54269- 0 0 0 0 0 0 0 0 0 10 10 10
54270- 30 30 30 74 74 74 174 135 50 216 158 10
54271-236 178 12 246 190 14 246 190 14 246 190 14
54272-246 190 14 246 190 14 246 190 14 246 190 14
54273-246 190 14 246 190 14 246 190 14 246 190 14
54274-246 190 14 246 190 14 241 196 14 226 184 13
54275- 61 42 6 2 2 6 2 2 6 2 2 6
54276- 22 22 22 238 238 238 253 253 253 253 253 253
54277-253 253 253 253 253 253 253 253 253 253 253 253
54278-253 253 253 253 253 253 253 253 253 253 253 253
54279-253 253 253 253 253 253 253 253 253 253 253 253
54280-253 253 253 226 226 226 187 187 187 180 133 36
54281-216 158 10 236 178 12 239 182 13 236 178 12
54282-230 174 11 226 170 11 226 170 11 230 174 11
54283-236 178 12 242 186 14 246 190 14 246 190 14
54284-246 190 14 246 190 14 246 186 14 239 182 13
54285-206 162 42 106 106 106 66 66 66 34 34 34
54286- 14 14 14 6 6 6 0 0 0 0 0 0
54287- 0 0 0 0 0 0 0 0 0 0 0 0
54288- 0 0 0 0 0 0 0 0 0 0 0 0
54289- 0 0 0 0 0 0 0 0 0 6 6 6
54290- 26 26 26 70 70 70 163 133 67 213 154 11
54291-236 178 12 246 190 14 246 190 14 246 190 14
54292-246 190 14 246 190 14 246 190 14 246 190 14
54293-246 190 14 246 190 14 246 190 14 246 190 14
54294-246 190 14 246 190 14 246 190 14 241 196 14
54295-190 146 13 18 14 6 2 2 6 2 2 6
54296- 46 46 46 246 246 246 253 253 253 253 253 253
54297-253 253 253 253 253 253 253 253 253 253 253 253
54298-253 253 253 253 253 253 253 253 253 253 253 253
54299-253 253 253 253 253 253 253 253 253 253 253 253
54300-253 253 253 221 221 221 86 86 86 156 107 11
54301-216 158 10 236 178 12 242 186 14 246 186 14
54302-242 186 14 239 182 13 239 182 13 242 186 14
54303-242 186 14 246 186 14 246 190 14 246 190 14
54304-246 190 14 246 190 14 246 190 14 246 190 14
54305-242 186 14 225 175 15 142 122 72 66 66 66
54306- 30 30 30 10 10 10 0 0 0 0 0 0
54307- 0 0 0 0 0 0 0 0 0 0 0 0
54308- 0 0 0 0 0 0 0 0 0 0 0 0
54309- 0 0 0 0 0 0 0 0 0 6 6 6
54310- 26 26 26 70 70 70 163 133 67 210 150 10
54311-236 178 12 246 190 14 246 190 14 246 190 14
54312-246 190 14 246 190 14 246 190 14 246 190 14
54313-246 190 14 246 190 14 246 190 14 246 190 14
54314-246 190 14 246 190 14 246 190 14 246 190 14
54315-232 195 16 121 92 8 34 34 34 106 106 106
54316-221 221 221 253 253 253 253 253 253 253 253 253
54317-253 253 253 253 253 253 253 253 253 253 253 253
54318-253 253 253 253 253 253 253 253 253 253 253 253
54319-253 253 253 253 253 253 253 253 253 253 253 253
54320-242 242 242 82 82 82 18 14 6 163 110 8
54321-216 158 10 236 178 12 242 186 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 246 190 14 246 190 14
54325-246 190 14 246 190 14 242 186 14 163 133 67
54326- 46 46 46 18 18 18 6 6 6 0 0 0
54327- 0 0 0 0 0 0 0 0 0 0 0 0
54328- 0 0 0 0 0 0 0 0 0 0 0 0
54329- 0 0 0 0 0 0 0 0 0 10 10 10
54330- 30 30 30 78 78 78 163 133 67 210 150 10
54331-236 178 12 246 186 14 246 190 14 246 190 14
54332-246 190 14 246 190 14 246 190 14 246 190 14
54333-246 190 14 246 190 14 246 190 14 246 190 14
54334-246 190 14 246 190 14 246 190 14 246 190 14
54335-241 196 14 215 174 15 190 178 144 253 253 253
54336-253 253 253 253 253 253 253 253 253 253 253 253
54337-253 253 253 253 253 253 253 253 253 253 253 253
54338-253 253 253 253 253 253 253 253 253 253 253 253
54339-253 253 253 253 253 253 253 253 253 218 218 218
54340- 58 58 58 2 2 6 22 18 6 167 114 7
54341-216 158 10 236 178 12 246 186 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 246 190 14 246 190 14
54345-246 190 14 246 186 14 242 186 14 190 150 46
54346- 54 54 54 22 22 22 6 6 6 0 0 0
54347- 0 0 0 0 0 0 0 0 0 0 0 0
54348- 0 0 0 0 0 0 0 0 0 0 0 0
54349- 0 0 0 0 0 0 0 0 0 14 14 14
54350- 38 38 38 86 86 86 180 133 36 213 154 11
54351-236 178 12 246 186 14 246 190 14 246 190 14
54352-246 190 14 246 190 14 246 190 14 246 190 14
54353-246 190 14 246 190 14 246 190 14 246 190 14
54354-246 190 14 246 190 14 246 190 14 246 190 14
54355-246 190 14 232 195 16 190 146 13 214 214 214
54356-253 253 253 253 253 253 253 253 253 253 253 253
54357-253 253 253 253 253 253 253 253 253 253 253 253
54358-253 253 253 253 253 253 253 253 253 253 253 253
54359-253 253 253 250 250 250 170 170 170 26 26 26
54360- 2 2 6 2 2 6 37 26 9 163 110 8
54361-219 162 10 239 182 13 246 186 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 246 190 14
54365-246 186 14 236 178 12 224 166 10 142 122 72
54366- 46 46 46 18 18 18 6 6 6 0 0 0
54367- 0 0 0 0 0 0 0 0 0 0 0 0
54368- 0 0 0 0 0 0 0 0 0 0 0 0
54369- 0 0 0 0 0 0 6 6 6 18 18 18
54370- 50 50 50 109 106 95 192 133 9 224 166 10
54371-242 186 14 246 190 14 246 190 14 246 190 14
54372-246 190 14 246 190 14 246 190 14 246 190 14
54373-246 190 14 246 190 14 246 190 14 246 190 14
54374-246 190 14 246 190 14 246 190 14 246 190 14
54375-242 186 14 226 184 13 210 162 10 142 110 46
54376-226 226 226 253 253 253 253 253 253 253 253 253
54377-253 253 253 253 253 253 253 253 253 253 253 253
54378-253 253 253 253 253 253 253 253 253 253 253 253
54379-198 198 198 66 66 66 2 2 6 2 2 6
54380- 2 2 6 2 2 6 50 34 6 156 107 11
54381-219 162 10 239 182 13 246 186 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 242 186 14
54385-234 174 13 213 154 11 154 122 46 66 66 66
54386- 30 30 30 10 10 10 0 0 0 0 0 0
54387- 0 0 0 0 0 0 0 0 0 0 0 0
54388- 0 0 0 0 0 0 0 0 0 0 0 0
54389- 0 0 0 0 0 0 6 6 6 22 22 22
54390- 58 58 58 154 121 60 206 145 10 234 174 13
54391-242 186 14 246 186 14 246 190 14 246 190 14
54392-246 190 14 246 190 14 246 190 14 246 190 14
54393-246 190 14 246 190 14 246 190 14 246 190 14
54394-246 190 14 246 190 14 246 190 14 246 190 14
54395-246 186 14 236 178 12 210 162 10 163 110 8
54396- 61 42 6 138 138 138 218 218 218 250 250 250
54397-253 253 253 253 253 253 253 253 253 250 250 250
54398-242 242 242 210 210 210 144 144 144 66 66 66
54399- 6 6 6 2 2 6 2 2 6 2 2 6
54400- 2 2 6 2 2 6 61 42 6 163 110 8
54401-216 158 10 236 178 12 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 239 182 13 230 174 11 216 158 10
54405-190 142 34 124 112 88 70 70 70 38 38 38
54406- 18 18 18 6 6 6 0 0 0 0 0 0
54407- 0 0 0 0 0 0 0 0 0 0 0 0
54408- 0 0 0 0 0 0 0 0 0 0 0 0
54409- 0 0 0 0 0 0 6 6 6 22 22 22
54410- 62 62 62 168 124 44 206 145 10 224 166 10
54411-236 178 12 239 182 13 242 186 14 242 186 14
54412-246 186 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 236 178 12 216 158 10 175 118 6
54416- 80 54 7 2 2 6 6 6 6 30 30 30
54417- 54 54 54 62 62 62 50 50 50 38 38 38
54418- 14 14 14 2 2 6 2 2 6 2 2 6
54419- 2 2 6 2 2 6 2 2 6 2 2 6
54420- 2 2 6 6 6 6 80 54 7 167 114 7
54421-213 154 11 236 178 12 246 190 14 246 190 14
54422-246 190 14 246 190 14 246 190 14 246 190 14
54423-246 190 14 242 186 14 239 182 13 239 182 13
54424-230 174 11 210 150 10 174 135 50 124 112 88
54425- 82 82 82 54 54 54 34 34 34 18 18 18
54426- 6 6 6 0 0 0 0 0 0 0 0 0
54427- 0 0 0 0 0 0 0 0 0 0 0 0
54428- 0 0 0 0 0 0 0 0 0 0 0 0
54429- 0 0 0 0 0 0 6 6 6 18 18 18
54430- 50 50 50 158 118 36 192 133 9 200 144 11
54431-216 158 10 219 162 10 224 166 10 226 170 11
54432-230 174 11 236 178 12 239 182 13 239 182 13
54433-242 186 14 246 186 14 246 190 14 246 190 14
54434-246 190 14 246 190 14 246 190 14 246 190 14
54435-246 186 14 230 174 11 210 150 10 163 110 8
54436-104 69 6 10 10 10 2 2 6 2 2 6
54437- 2 2 6 2 2 6 2 2 6 2 2 6
54438- 2 2 6 2 2 6 2 2 6 2 2 6
54439- 2 2 6 2 2 6 2 2 6 2 2 6
54440- 2 2 6 6 6 6 91 60 6 167 114 7
54441-206 145 10 230 174 11 242 186 14 246 190 14
54442-246 190 14 246 190 14 246 186 14 242 186 14
54443-239 182 13 230 174 11 224 166 10 213 154 11
54444-180 133 36 124 112 88 86 86 86 58 58 58
54445- 38 38 38 22 22 22 10 10 10 6 6 6
54446- 0 0 0 0 0 0 0 0 0 0 0 0
54447- 0 0 0 0 0 0 0 0 0 0 0 0
54448- 0 0 0 0 0 0 0 0 0 0 0 0
54449- 0 0 0 0 0 0 0 0 0 14 14 14
54450- 34 34 34 70 70 70 138 110 50 158 118 36
54451-167 114 7 180 123 7 192 133 9 197 138 11
54452-200 144 11 206 145 10 213 154 11 219 162 10
54453-224 166 10 230 174 11 239 182 13 242 186 14
54454-246 186 14 246 186 14 246 186 14 246 186 14
54455-239 182 13 216 158 10 185 133 11 152 99 6
54456-104 69 6 18 14 6 2 2 6 2 2 6
54457- 2 2 6 2 2 6 2 2 6 2 2 6
54458- 2 2 6 2 2 6 2 2 6 2 2 6
54459- 2 2 6 2 2 6 2 2 6 2 2 6
54460- 2 2 6 6 6 6 80 54 7 152 99 6
54461-192 133 9 219 162 10 236 178 12 239 182 13
54462-246 186 14 242 186 14 239 182 13 236 178 12
54463-224 166 10 206 145 10 192 133 9 154 121 60
54464- 94 94 94 62 62 62 42 42 42 22 22 22
54465- 14 14 14 6 6 6 0 0 0 0 0 0
54466- 0 0 0 0 0 0 0 0 0 0 0 0
54467- 0 0 0 0 0 0 0 0 0 0 0 0
54468- 0 0 0 0 0 0 0 0 0 0 0 0
54469- 0 0 0 0 0 0 0 0 0 6 6 6
54470- 18 18 18 34 34 34 58 58 58 78 78 78
54471-101 98 89 124 112 88 142 110 46 156 107 11
54472-163 110 8 167 114 7 175 118 6 180 123 7
54473-185 133 11 197 138 11 210 150 10 219 162 10
54474-226 170 11 236 178 12 236 178 12 234 174 13
54475-219 162 10 197 138 11 163 110 8 130 83 6
54476- 91 60 6 10 10 10 2 2 6 2 2 6
54477- 18 18 18 38 38 38 38 38 38 38 38 38
54478- 38 38 38 38 38 38 38 38 38 38 38 38
54479- 38 38 38 38 38 38 26 26 26 2 2 6
54480- 2 2 6 6 6 6 70 47 6 137 92 6
54481-175 118 6 200 144 11 219 162 10 230 174 11
54482-234 174 13 230 174 11 219 162 10 210 150 10
54483-192 133 9 163 110 8 124 112 88 82 82 82
54484- 50 50 50 30 30 30 14 14 14 6 6 6
54485- 0 0 0 0 0 0 0 0 0 0 0 0
54486- 0 0 0 0 0 0 0 0 0 0 0 0
54487- 0 0 0 0 0 0 0 0 0 0 0 0
54488- 0 0 0 0 0 0 0 0 0 0 0 0
54489- 0 0 0 0 0 0 0 0 0 0 0 0
54490- 6 6 6 14 14 14 22 22 22 34 34 34
54491- 42 42 42 58 58 58 74 74 74 86 86 86
54492-101 98 89 122 102 70 130 98 46 121 87 25
54493-137 92 6 152 99 6 163 110 8 180 123 7
54494-185 133 11 197 138 11 206 145 10 200 144 11
54495-180 123 7 156 107 11 130 83 6 104 69 6
54496- 50 34 6 54 54 54 110 110 110 101 98 89
54497- 86 86 86 82 82 82 78 78 78 78 78 78
54498- 78 78 78 78 78 78 78 78 78 78 78 78
54499- 78 78 78 82 82 82 86 86 86 94 94 94
54500-106 106 106 101 101 101 86 66 34 124 80 6
54501-156 107 11 180 123 7 192 133 9 200 144 11
54502-206 145 10 200 144 11 192 133 9 175 118 6
54503-139 102 15 109 106 95 70 70 70 42 42 42
54504- 22 22 22 10 10 10 0 0 0 0 0 0
54505- 0 0 0 0 0 0 0 0 0 0 0 0
54506- 0 0 0 0 0 0 0 0 0 0 0 0
54507- 0 0 0 0 0 0 0 0 0 0 0 0
54508- 0 0 0 0 0 0 0 0 0 0 0 0
54509- 0 0 0 0 0 0 0 0 0 0 0 0
54510- 0 0 0 0 0 0 6 6 6 10 10 10
54511- 14 14 14 22 22 22 30 30 30 38 38 38
54512- 50 50 50 62 62 62 74 74 74 90 90 90
54513-101 98 89 112 100 78 121 87 25 124 80 6
54514-137 92 6 152 99 6 152 99 6 152 99 6
54515-138 86 6 124 80 6 98 70 6 86 66 30
54516-101 98 89 82 82 82 58 58 58 46 46 46
54517- 38 38 38 34 34 34 34 34 34 34 34 34
54518- 34 34 34 34 34 34 34 34 34 34 34 34
54519- 34 34 34 34 34 34 38 38 38 42 42 42
54520- 54 54 54 82 82 82 94 86 76 91 60 6
54521-134 86 6 156 107 11 167 114 7 175 118 6
54522-175 118 6 167 114 7 152 99 6 121 87 25
54523-101 98 89 62 62 62 34 34 34 18 18 18
54524- 6 6 6 0 0 0 0 0 0 0 0 0
54525- 0 0 0 0 0 0 0 0 0 0 0 0
54526- 0 0 0 0 0 0 0 0 0 0 0 0
54527- 0 0 0 0 0 0 0 0 0 0 0 0
54528- 0 0 0 0 0 0 0 0 0 0 0 0
54529- 0 0 0 0 0 0 0 0 0 0 0 0
54530- 0 0 0 0 0 0 0 0 0 0 0 0
54531- 0 0 0 6 6 6 6 6 6 10 10 10
54532- 18 18 18 22 22 22 30 30 30 42 42 42
54533- 50 50 50 66 66 66 86 86 86 101 98 89
54534-106 86 58 98 70 6 104 69 6 104 69 6
54535-104 69 6 91 60 6 82 62 34 90 90 90
54536- 62 62 62 38 38 38 22 22 22 14 14 14
54537- 10 10 10 10 10 10 10 10 10 10 10 10
54538- 10 10 10 10 10 10 6 6 6 10 10 10
54539- 10 10 10 10 10 10 10 10 10 14 14 14
54540- 22 22 22 42 42 42 70 70 70 89 81 66
54541- 80 54 7 104 69 6 124 80 6 137 92 6
54542-134 86 6 116 81 8 100 82 52 86 86 86
54543- 58 58 58 30 30 30 14 14 14 6 6 6
54544- 0 0 0 0 0 0 0 0 0 0 0 0
54545- 0 0 0 0 0 0 0 0 0 0 0 0
54546- 0 0 0 0 0 0 0 0 0 0 0 0
54547- 0 0 0 0 0 0 0 0 0 0 0 0
54548- 0 0 0 0 0 0 0 0 0 0 0 0
54549- 0 0 0 0 0 0 0 0 0 0 0 0
54550- 0 0 0 0 0 0 0 0 0 0 0 0
54551- 0 0 0 0 0 0 0 0 0 0 0 0
54552- 0 0 0 6 6 6 10 10 10 14 14 14
54553- 18 18 18 26 26 26 38 38 38 54 54 54
54554- 70 70 70 86 86 86 94 86 76 89 81 66
54555- 89 81 66 86 86 86 74 74 74 50 50 50
54556- 30 30 30 14 14 14 6 6 6 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 18 18 18 34 34 34 58 58 58
54561- 82 82 82 89 81 66 89 81 66 89 81 66
54562- 94 86 66 94 86 76 74 74 74 50 50 50
54563- 26 26 26 14 14 14 6 6 6 0 0 0
54564- 0 0 0 0 0 0 0 0 0 0 0 0
54565- 0 0 0 0 0 0 0 0 0 0 0 0
54566- 0 0 0 0 0 0 0 0 0 0 0 0
54567- 0 0 0 0 0 0 0 0 0 0 0 0
54568- 0 0 0 0 0 0 0 0 0 0 0 0
54569- 0 0 0 0 0 0 0 0 0 0 0 0
54570- 0 0 0 0 0 0 0 0 0 0 0 0
54571- 0 0 0 0 0 0 0 0 0 0 0 0
54572- 0 0 0 0 0 0 0 0 0 0 0 0
54573- 6 6 6 6 6 6 14 14 14 18 18 18
54574- 30 30 30 38 38 38 46 46 46 54 54 54
54575- 50 50 50 42 42 42 30 30 30 18 18 18
54576- 10 10 10 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 6 6 6 14 14 14 26 26 26
54581- 38 38 38 50 50 50 58 58 58 58 58 58
54582- 54 54 54 42 42 42 30 30 30 18 18 18
54583- 10 10 10 0 0 0 0 0 0 0 0 0
54584- 0 0 0 0 0 0 0 0 0 0 0 0
54585- 0 0 0 0 0 0 0 0 0 0 0 0
54586- 0 0 0 0 0 0 0 0 0 0 0 0
54587- 0 0 0 0 0 0 0 0 0 0 0 0
54588- 0 0 0 0 0 0 0 0 0 0 0 0
54589- 0 0 0 0 0 0 0 0 0 0 0 0
54590- 0 0 0 0 0 0 0 0 0 0 0 0
54591- 0 0 0 0 0 0 0 0 0 0 0 0
54592- 0 0 0 0 0 0 0 0 0 0 0 0
54593- 0 0 0 0 0 0 0 0 0 6 6 6
54594- 6 6 6 10 10 10 14 14 14 18 18 18
54595- 18 18 18 14 14 14 10 10 10 6 6 6
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 6 6 6
54601- 14 14 14 18 18 18 22 22 22 22 22 22
54602- 18 18 18 14 14 14 10 10 10 6 6 6
54603- 0 0 0 0 0 0 0 0 0 0 0 0
54604- 0 0 0 0 0 0 0 0 0 0 0 0
54605- 0 0 0 0 0 0 0 0 0 0 0 0
54606- 0 0 0 0 0 0 0 0 0 0 0 0
54607- 0 0 0 0 0 0 0 0 0 0 0 0
54608+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54609+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54610+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54611+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54612+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54613+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54614+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54615+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54616+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54617+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54618+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54619+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54620+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54621+4 4 4 4 4 4
54622+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54623+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54624+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54625+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54626+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54627+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54628+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54629+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54630+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54631+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54632+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54633+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54634+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54635+4 4 4 4 4 4
54636+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54637+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54638+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54639+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54640+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54641+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54642+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54643+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54644+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54645+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54646+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54647+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54648+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54649+4 4 4 4 4 4
54650+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54651+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54652+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54653+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54654+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54655+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54656+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54657+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54658+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54659+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54660+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54661+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54662+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54663+4 4 4 4 4 4
54664+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54665+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54666+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54667+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54668+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54669+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54670+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54671+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54672+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54673+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54674+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54675+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54676+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54677+4 4 4 4 4 4
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 3 3 3 0 0 0 0 0 0
54697+0 0 0 0 0 0 0 0 0 0 0 0 3 3 3 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 1 1 1 0 0 0
54702+0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
54703+4 4 4 4 4 4 4 4 4 2 1 0 2 1 0 3 2 2
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 2 2 2 0 0 0 3 4 3 26 28 28
54711+37 38 37 37 38 37 14 17 19 2 2 2 0 0 0 2 2 2
54712+5 5 5 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 3 3 3 0 0 0 1 1 1 6 6 6
54716+2 2 2 0 0 0 3 3 3 4 4 4 4 4 4 4 4 4
54717+4 4 5 3 3 3 1 0 0 0 0 0 1 0 0 0 0 0
54718+1 1 1 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+2 2 2 0 0 0 0 0 0 14 17 19 60 74 84 137 136 137
54725+153 152 153 137 136 137 125 124 125 60 73 81 6 6 6 3 1 0
54726+0 0 0 3 3 3 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 0 0 0 4 4 4 41 54 63 125 124 125
54730+60 73 81 6 6 6 4 0 0 3 3 3 4 4 4 4 4 4
54731+4 4 4 0 0 0 6 9 11 41 54 63 41 65 82 22 30 35
54732+2 2 2 2 1 0 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 5 5 5 5 5 5 2 2 2 0 0 0
54738+4 0 0 6 6 6 41 54 63 137 136 137 174 174 174 167 166 167
54739+165 164 165 165 164 165 163 162 163 163 162 163 125 124 125 41 54 63
54740+1 1 1 0 0 0 0 0 0 3 3 3 5 5 5 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 5 5 5 5 5 5
54743+3 3 3 2 0 0 4 0 0 60 73 81 156 155 156 167 166 167
54744+163 162 163 85 115 134 5 7 8 0 0 0 4 4 4 5 5 5
54745+0 0 0 2 5 5 55 98 126 90 154 193 90 154 193 72 125 159
54746+37 51 59 2 0 0 1 1 1 4 5 5 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 5 5 5 4 4 4 1 1 1 0 0 0 3 3 3
54752+37 38 37 125 124 125 163 162 163 174 174 174 158 157 158 158 157 158
54753+156 155 156 156 155 156 158 157 158 165 164 165 174 174 174 166 165 166
54754+125 124 125 16 19 21 1 0 0 0 0 0 0 0 0 4 4 4
54755+5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
54756+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 1 1 1
54757+0 0 0 0 0 0 37 38 37 153 152 153 174 174 174 158 157 158
54758+174 174 174 163 162 163 37 38 37 4 3 3 4 0 0 1 1 1
54759+0 0 0 22 40 52 101 161 196 101 161 196 90 154 193 101 161 196
54760+64 123 161 14 17 19 0 0 0 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 5 5 5
54765+5 5 5 2 2 2 0 0 0 4 0 0 24 26 27 85 115 134
54766+156 155 156 174 174 174 167 166 167 156 155 156 154 153 154 157 156 157
54767+156 155 156 156 155 156 155 154 155 153 152 153 158 157 158 167 166 167
54768+174 174 174 156 155 156 60 74 84 16 19 21 0 0 0 0 0 0
54769+1 1 1 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
54770+4 4 4 5 5 5 6 6 6 3 3 3 0 0 0 4 0 0
54771+13 16 17 60 73 81 137 136 137 165 164 165 156 155 156 153 152 153
54772+174 174 174 177 184 187 60 73 81 3 1 0 0 0 0 1 1 2
54773+22 30 35 64 123 161 136 185 209 90 154 193 90 154 193 90 154 193
54774+90 154 193 21 29 34 0 0 0 3 2 2 4 4 5 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 5 5 5 3 3 3
54779+0 0 0 0 0 0 10 13 16 60 74 84 157 156 157 174 174 174
54780+174 174 174 158 157 158 153 152 153 154 153 154 156 155 156 155 154 155
54781+156 155 156 155 154 155 154 153 154 157 156 157 154 153 154 153 152 153
54782+163 162 163 174 174 174 177 184 187 137 136 137 60 73 81 13 16 17
54783+4 0 0 0 0 0 3 3 3 5 5 5 4 4 4 4 4 4
54784+5 5 5 4 4 4 1 1 1 0 0 0 3 3 3 41 54 63
54785+131 129 131 174 174 174 174 174 174 174 174 174 167 166 167 174 174 174
54786+190 197 201 137 136 137 24 26 27 4 0 0 16 21 25 50 82 103
54787+90 154 193 136 185 209 90 154 193 101 161 196 101 161 196 101 161 196
54788+31 91 132 3 6 7 0 0 0 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 2 2 2 0 0 0 4 0 0
54793+4 0 0 43 57 68 137 136 137 177 184 187 174 174 174 163 162 163
54794+155 154 155 155 154 155 156 155 156 155 154 155 158 157 158 165 164 165
54795+167 166 167 166 165 166 163 162 163 157 156 157 155 154 155 155 154 155
54796+153 152 153 156 155 156 167 166 167 174 174 174 174 174 174 131 129 131
54797+41 54 63 5 5 5 0 0 0 0 0 0 3 3 3 4 4 4
54798+1 1 1 0 0 0 1 0 0 26 28 28 125 124 125 174 174 174
54799+177 184 187 174 174 174 174 174 174 156 155 156 131 129 131 137 136 137
54800+125 124 125 24 26 27 4 0 0 41 65 82 90 154 193 136 185 209
54801+136 185 209 101 161 196 53 118 160 37 112 160 90 154 193 34 86 122
54802+7 12 15 0 0 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 3 3 3 0 0 0 0 0 0 5 5 5 37 38 37
54807+125 124 125 167 166 167 174 174 174 167 166 167 158 157 158 155 154 155
54808+156 155 156 156 155 156 156 155 156 163 162 163 167 166 167 155 154 155
54809+137 136 137 153 152 153 156 155 156 165 164 165 163 162 163 156 155 156
54810+156 155 156 156 155 156 155 154 155 158 157 158 166 165 166 174 174 174
54811+167 166 167 125 124 125 37 38 37 1 0 0 0 0 0 0 0 0
54812+0 0 0 24 26 27 60 74 84 158 157 158 174 174 174 174 174 174
54813+166 165 166 158 157 158 125 124 125 41 54 63 13 16 17 6 6 6
54814+6 6 6 37 38 37 80 127 157 136 185 209 101 161 196 101 161 196
54815+90 154 193 28 67 93 6 10 14 13 20 25 13 20 25 6 10 14
54816+1 1 2 4 3 3 4 4 4 4 4 4 4 4 4 4 4 4
54817+4 4 4 4 4 4
54818+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54819+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54820+1 1 1 1 0 0 4 3 3 37 38 37 60 74 84 153 152 153
54821+167 166 167 167 166 167 158 157 158 154 153 154 155 154 155 156 155 156
54822+157 156 157 158 157 158 167 166 167 167 166 167 131 129 131 43 57 68
54823+26 28 28 37 38 37 60 73 81 131 129 131 165 164 165 166 165 166
54824+158 157 158 155 154 155 156 155 156 156 155 156 156 155 156 158 157 158
54825+165 164 165 174 174 174 163 162 163 60 74 84 16 19 21 13 16 17
54826+60 73 81 131 129 131 174 174 174 174 174 174 167 166 167 165 164 165
54827+137 136 137 60 73 81 24 26 27 4 0 0 4 0 0 16 19 21
54828+52 104 138 101 161 196 136 185 209 136 185 209 90 154 193 27 99 146
54829+13 20 25 4 5 7 2 5 5 4 5 7 1 1 2 0 0 0
54830+4 4 4 4 4 4 3 3 3 2 2 2 2 2 2 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 3 3 3 0 0 0
54834+0 0 0 13 16 17 60 73 81 137 136 137 174 174 174 166 165 166
54835+158 157 158 156 155 156 157 156 157 156 155 156 155 154 155 158 157 158
54836+167 166 167 174 174 174 153 152 153 60 73 81 16 19 21 4 0 0
54837+4 0 0 4 0 0 6 6 6 26 28 28 60 74 84 158 157 158
54838+174 174 174 166 165 166 157 156 157 155 154 155 156 155 156 156 155 156
54839+155 154 155 158 157 158 167 166 167 167 166 167 131 129 131 125 124 125
54840+137 136 137 167 166 167 167 166 167 174 174 174 158 157 158 125 124 125
54841+16 19 21 4 0 0 4 0 0 10 13 16 49 76 92 107 159 188
54842+136 185 209 136 185 209 90 154 193 26 108 161 22 40 52 6 10 14
54843+2 3 3 1 1 2 1 1 2 4 4 5 4 4 5 4 4 5
54844+4 4 5 2 2 1 0 0 0 0 0 0 0 0 0 2 2 2
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 5 5 5 3 3 3 0 0 0 1 0 0 4 0 0
54848+37 51 59 131 129 131 167 166 167 167 166 167 163 162 163 157 156 157
54849+157 156 157 155 154 155 153 152 153 157 156 157 167 166 167 174 174 174
54850+153 152 153 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
54851+4 3 3 4 3 3 4 0 0 6 6 6 4 0 0 37 38 37
54852+125 124 125 174 174 174 174 174 174 165 164 165 156 155 156 154 153 154
54853+156 155 156 156 155 156 155 154 155 163 162 163 158 157 158 163 162 163
54854+174 174 174 174 174 174 174 174 174 125 124 125 37 38 37 0 0 0
54855+4 0 0 6 9 11 41 54 63 90 154 193 136 185 209 146 190 211
54856+136 185 209 37 112 160 22 40 52 6 10 14 3 6 7 1 1 2
54857+1 1 2 3 3 3 1 1 2 3 3 3 4 4 4 4 4 4
54858+2 2 2 2 0 0 16 19 21 37 38 37 24 26 27 0 0 0
54859+0 0 0 4 4 4
54860+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
54861+4 4 4 0 0 0 0 0 0 0 0 0 26 28 28 120 125 127
54862+158 157 158 174 174 174 165 164 165 157 156 157 155 154 155 156 155 156
54863+153 152 153 153 152 153 167 166 167 174 174 174 174 174 174 125 124 125
54864+37 38 37 4 0 0 0 0 0 4 0 0 4 3 3 4 4 4
54865+4 4 4 4 4 4 5 5 5 4 0 0 4 0 0 4 0 0
54866+4 3 3 43 57 68 137 136 137 174 174 174 174 174 174 165 164 165
54867+154 153 154 153 152 153 153 152 153 153 152 153 163 162 163 174 174 174
54868+174 174 174 153 152 153 60 73 81 6 6 6 4 0 0 4 3 3
54869+32 43 50 80 127 157 136 185 209 146 190 211 146 190 211 90 154 193
54870+28 67 93 28 67 93 40 71 93 3 6 7 1 1 2 2 5 5
54871+50 82 103 79 117 143 26 37 45 0 0 0 3 3 3 1 1 1
54872+0 0 0 41 54 63 137 136 137 174 174 174 153 152 153 60 73 81
54873+2 0 0 0 0 0
54874+4 4 4 4 4 4 4 4 4 4 4 4 6 6 6 2 2 2
54875+0 0 0 2 0 0 24 26 27 60 74 84 153 152 153 174 174 174
54876+174 174 174 157 156 157 154 153 154 156 155 156 154 153 154 153 152 153
54877+165 164 165 174 174 174 177 184 187 137 136 137 43 57 68 6 6 6
54878+4 0 0 2 0 0 3 3 3 5 5 5 5 5 5 4 4 4
54879+4 4 4 4 4 4 4 4 4 5 5 5 6 6 6 4 3 3
54880+4 0 0 4 0 0 24 26 27 60 73 81 153 152 153 174 174 174
54881+174 174 174 158 157 158 158 157 158 174 174 174 174 174 174 158 157 158
54882+60 74 84 24 26 27 4 0 0 4 0 0 17 23 27 59 113 148
54883+136 185 209 191 222 234 146 190 211 136 185 209 31 91 132 7 11 13
54884+22 40 52 101 161 196 90 154 193 6 9 11 3 4 4 43 95 132
54885+136 185 209 172 205 220 55 98 126 0 0 0 0 0 0 2 0 0
54886+26 28 28 153 152 153 177 184 187 167 166 167 177 184 187 165 164 165
54887+37 38 37 0 0 0
54888+4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
54889+13 16 17 60 73 81 137 136 137 174 174 174 174 174 174 165 164 165
54890+153 152 153 153 152 153 155 154 155 154 153 154 158 157 158 174 174 174
54891+177 184 187 163 162 163 60 73 81 16 19 21 4 0 0 4 0 0
54892+4 3 3 4 4 4 5 5 5 5 5 5 4 4 4 5 5 5
54893+5 5 5 5 5 5 5 5 5 4 4 4 4 4 4 5 5 5
54894+6 6 6 4 0 0 4 0 0 4 0 0 24 26 27 60 74 84
54895+166 165 166 174 174 174 177 184 187 165 164 165 125 124 125 24 26 27
54896+4 0 0 4 0 0 5 5 5 50 82 103 136 185 209 172 205 220
54897+146 190 211 136 185 209 26 108 161 22 40 52 7 12 15 44 81 103
54898+71 116 144 28 67 93 37 51 59 41 65 82 100 139 164 101 161 196
54899+90 154 193 90 154 193 28 67 93 0 0 0 0 0 0 26 28 28
54900+125 124 125 167 166 167 163 162 163 153 152 153 163 162 163 174 174 174
54901+85 115 134 4 0 0
54902+4 4 4 5 5 5 4 4 4 1 0 0 4 0 0 34 47 55
54903+125 124 125 174 174 174 174 174 174 167 166 167 157 156 157 153 152 153
54904+155 154 155 155 154 155 158 157 158 166 165 166 167 166 167 154 153 154
54905+125 124 125 26 28 28 4 0 0 4 0 0 4 0 0 5 5 5
54906+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 1 1 1
54907+0 0 0 0 0 0 1 1 1 4 4 4 4 4 4 4 4 4
54908+5 5 5 5 5 5 4 3 3 4 0 0 4 0 0 6 6 6
54909+37 38 37 131 129 131 137 136 137 37 38 37 0 0 0 4 0 0
54910+4 5 5 43 61 72 90 154 193 172 205 220 146 190 211 136 185 209
54911+90 154 193 28 67 93 13 20 25 43 61 72 71 116 144 44 81 103
54912+2 5 5 7 11 13 59 113 148 101 161 196 90 154 193 28 67 93
54913+13 20 25 6 10 14 0 0 0 13 16 17 60 73 81 137 136 137
54914+166 165 166 158 157 158 156 155 156 154 153 154 167 166 167 174 174 174
54915+60 73 81 4 0 0
54916+4 4 4 4 4 4 0 0 0 3 3 3 60 74 84 174 174 174
54917+174 174 174 167 166 167 163 162 163 155 154 155 157 156 157 155 154 155
54918+156 155 156 163 162 163 167 166 167 158 157 158 125 124 125 37 38 37
54919+4 3 3 4 0 0 4 0 0 6 6 6 6 6 6 5 5 5
54920+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 2 3 3
54921+10 13 16 7 11 13 1 0 0 0 0 0 2 2 1 4 4 4
54922+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 4 0 0
54923+4 0 0 7 11 13 13 16 17 4 0 0 3 3 3 34 47 55
54924+80 127 157 146 190 211 172 205 220 136 185 209 136 185 209 136 185 209
54925+28 67 93 22 40 52 55 98 126 55 98 126 21 29 34 7 11 13
54926+50 82 103 101 161 196 101 161 196 35 83 115 13 20 25 2 2 1
54927+1 1 2 1 1 2 37 51 59 131 129 131 174 174 174 174 174 174
54928+167 166 167 163 162 163 163 162 163 167 166 167 174 174 174 125 124 125
54929+16 19 21 4 0 0
54930+4 4 4 4 0 0 4 0 0 60 74 84 174 174 174 174 174 174
54931+158 157 158 155 154 155 155 154 155 156 155 156 155 154 155 158 157 158
54932+167 166 167 165 164 165 131 129 131 60 73 81 13 16 17 4 0 0
54933+4 0 0 4 3 3 6 6 6 4 3 3 5 5 5 4 4 4
54934+4 4 4 3 2 2 0 0 0 0 0 0 7 11 13 45 69 86
54935+80 127 157 71 116 144 43 61 72 7 11 13 0 0 0 1 1 1
54936+4 3 3 4 4 4 4 4 4 4 4 4 6 6 6 5 5 5
54937+3 2 2 4 0 0 1 0 0 21 29 34 59 113 148 136 185 209
54938+146 190 211 136 185 209 136 185 209 136 185 209 136 185 209 136 185 209
54939+68 124 159 44 81 103 22 40 52 13 16 17 43 61 72 90 154 193
54940+136 185 209 59 113 148 21 29 34 3 4 3 1 1 1 0 0 0
54941+24 26 27 125 124 125 163 162 163 174 174 174 166 165 166 165 164 165
54942+163 162 163 125 124 125 125 124 125 125 124 125 125 124 125 26 28 28
54943+4 0 0 4 3 3
54944+3 3 3 0 0 0 24 26 27 153 152 153 177 184 187 158 157 158
54945+156 155 156 156 155 156 155 154 155 155 154 155 165 164 165 174 174 174
54946+155 154 155 60 74 84 26 28 28 4 0 0 4 0 0 3 1 0
54947+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 3 3
54948+2 0 0 0 0 0 0 0 0 32 43 50 72 125 159 101 161 196
54949+136 185 209 101 161 196 101 161 196 79 117 143 32 43 50 0 0 0
54950+0 0 0 2 2 2 4 4 4 4 4 4 3 3 3 1 0 0
54951+0 0 0 4 5 5 49 76 92 101 161 196 146 190 211 146 190 211
54952+136 185 209 136 185 209 136 185 209 136 185 209 136 185 209 90 154 193
54953+28 67 93 13 16 17 37 51 59 80 127 157 136 185 209 90 154 193
54954+22 40 52 6 9 11 3 4 3 2 2 1 16 19 21 60 73 81
54955+137 136 137 163 162 163 158 157 158 166 165 166 167 166 167 153 152 153
54956+60 74 84 37 38 37 6 6 6 13 16 17 4 0 0 1 0 0
54957+3 2 2 4 4 4
54958+3 2 2 4 0 0 37 38 37 137 136 137 167 166 167 158 157 158
54959+157 156 157 154 153 154 157 156 157 167 166 167 174 174 174 125 124 125
54960+37 38 37 4 0 0 4 0 0 4 0 0 4 3 3 4 4 4
54961+4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
54962+0 0 0 16 21 25 55 98 126 90 154 193 136 185 209 101 161 196
54963+101 161 196 101 161 196 136 185 209 136 185 209 101 161 196 55 98 126
54964+14 17 19 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
54965+22 40 52 90 154 193 146 190 211 146 190 211 136 185 209 136 185 209
54966+136 185 209 136 185 209 136 185 209 101 161 196 35 83 115 7 11 13
54967+17 23 27 59 113 148 136 185 209 101 161 196 34 86 122 7 12 15
54968+2 5 5 3 4 3 6 6 6 60 73 81 131 129 131 163 162 163
54969+166 165 166 174 174 174 174 174 174 163 162 163 125 124 125 41 54 63
54970+13 16 17 4 0 0 4 0 0 4 0 0 1 0 0 2 2 2
54971+4 4 4 4 4 4
54972+1 1 1 2 1 0 43 57 68 137 136 137 153 152 153 153 152 153
54973+163 162 163 156 155 156 165 164 165 167 166 167 60 74 84 6 6 6
54974+4 0 0 4 0 0 5 5 5 4 4 4 4 4 4 4 4 4
54975+4 5 5 6 6 6 4 3 3 0 0 0 0 0 0 11 15 18
54976+40 71 93 100 139 164 101 161 196 101 161 196 101 161 196 101 161 196
54977+101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 136 185 209
54978+101 161 196 45 69 86 6 6 6 0 0 0 17 23 27 55 98 126
54979+136 185 209 146 190 211 136 185 209 136 185 209 136 185 209 136 185 209
54980+136 185 209 136 185 209 90 154 193 22 40 52 7 11 13 50 82 103
54981+136 185 209 136 185 209 53 118 160 22 40 52 7 11 13 2 5 5
54982+3 4 3 37 38 37 125 124 125 157 156 157 166 165 166 167 166 167
54983+174 174 174 174 174 174 137 136 137 60 73 81 4 0 0 4 0 0
54984+4 0 0 4 0 0 5 5 5 3 3 3 3 3 3 4 4 4
54985+4 4 4 4 4 4
54986+4 0 0 4 0 0 41 54 63 137 136 137 125 124 125 131 129 131
54987+155 154 155 167 166 167 174 174 174 60 74 84 6 6 6 4 0 0
54988+4 3 3 6 6 6 4 4 4 4 4 4 4 4 4 5 5 5
54989+4 4 4 1 1 1 0 0 0 3 6 7 41 65 82 72 125 159
54990+101 161 196 101 161 196 101 161 196 90 154 193 90 154 193 101 161 196
54991+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
54992+136 185 209 136 185 209 80 127 157 55 98 126 101 161 196 146 190 211
54993+136 185 209 136 185 209 136 185 209 101 161 196 136 185 209 101 161 196
54994+136 185 209 101 161 196 35 83 115 22 30 35 101 161 196 172 205 220
54995+90 154 193 28 67 93 7 11 13 2 5 5 3 4 3 13 16 17
54996+85 115 134 167 166 167 174 174 174 174 174 174 174 174 174 174 174 174
54997+167 166 167 60 74 84 13 16 17 4 0 0 4 0 0 4 3 3
54998+6 6 6 5 5 5 4 4 4 5 5 5 4 4 4 5 5 5
54999+5 5 5 5 5 5
55000+1 1 1 4 0 0 41 54 63 137 136 137 137 136 137 125 124 125
55001+131 129 131 167 166 167 157 156 157 37 38 37 6 6 6 4 0 0
55002+6 6 6 5 5 5 4 4 4 4 4 4 4 5 5 2 2 1
55003+0 0 0 0 0 0 26 37 45 58 111 146 101 161 196 101 161 196
55004+101 161 196 90 154 193 90 154 193 90 154 193 101 161 196 101 161 196
55005+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
55006+101 161 196 136 185 209 136 185 209 136 185 209 146 190 211 136 185 209
55007+136 185 209 101 161 196 136 185 209 136 185 209 101 161 196 136 185 209
55008+101 161 196 136 185 209 136 185 209 136 185 209 136 185 209 16 89 141
55009+7 11 13 2 5 5 2 5 5 13 16 17 60 73 81 154 154 154
55010+174 174 174 174 174 174 174 174 174 174 174 174 163 162 163 125 124 125
55011+24 26 27 4 0 0 4 0 0 4 0 0 5 5 5 5 5 5
55012+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
55013+5 5 5 4 4 4
55014+4 0 0 6 6 6 37 38 37 137 136 137 137 136 137 131 129 131
55015+131 129 131 153 152 153 131 129 131 26 28 28 4 0 0 4 3 3
55016+6 6 6 4 4 4 4 4 4 4 4 4 0 0 0 0 0 0
55017+13 20 25 51 88 114 90 154 193 101 161 196 101 161 196 90 154 193
55018+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
55019+101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 101 161 196
55020+101 161 196 136 185 209 101 161 196 136 185 209 136 185 209 101 161 196
55021+136 185 209 101 161 196 136 185 209 101 161 196 101 161 196 101 161 196
55022+136 185 209 136 185 209 136 185 209 37 112 160 21 29 34 5 7 8
55023+2 5 5 13 16 17 43 57 68 131 129 131 174 174 174 174 174 174
55024+174 174 174 167 166 167 157 156 157 125 124 125 37 38 37 4 0 0
55025+4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
55026+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55027+4 4 4 4 4 4
55028+1 1 1 4 0 0 41 54 63 153 152 153 137 136 137 137 136 137
55029+137 136 137 153 152 153 125 124 125 24 26 27 4 0 0 3 2 2
55030+4 4 4 4 4 4 4 3 3 4 0 0 3 6 7 43 61 72
55031+64 123 161 101 161 196 90 154 193 90 154 193 90 154 193 90 154 193
55032+90 154 193 90 154 193 90 154 193 90 154 193 101 161 196 90 154 193
55033+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
55034+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
55035+136 185 209 101 161 196 101 161 196 136 185 209 136 185 209 101 161 196
55036+101 161 196 90 154 193 28 67 93 13 16 17 7 11 13 3 6 7
55037+37 51 59 125 124 125 163 162 163 174 174 174 167 166 167 166 165 166
55038+167 166 167 131 129 131 60 73 81 4 0 0 4 0 0 4 0 0
55039+3 3 3 5 5 5 6 6 6 4 4 4 4 4 4 4 4 4
55040+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55041+4 4 4 4 4 4
55042+4 0 0 4 0 0 41 54 63 137 136 137 153 152 153 137 136 137
55043+153 152 153 157 156 157 125 124 125 24 26 27 0 0 0 2 2 2
55044+4 4 4 4 4 4 2 0 0 0 0 0 28 67 93 90 154 193
55045+90 154 193 90 154 193 90 154 193 90 154 193 64 123 161 90 154 193
55046+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
55047+90 154 193 101 161 196 101 161 196 101 161 196 90 154 193 136 185 209
55048+101 161 196 101 161 196 136 185 209 101 161 196 136 185 209 101 161 196
55049+101 161 196 101 161 196 136 185 209 101 161 196 101 161 196 90 154 193
55050+35 83 115 13 16 17 3 6 7 2 5 5 13 16 17 60 74 84
55051+154 154 154 166 165 166 165 164 165 158 157 158 163 162 163 157 156 157
55052+60 74 84 13 16 17 4 0 0 4 0 0 3 2 2 4 4 4
55053+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55054+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55055+4 4 4 4 4 4
55056+1 1 1 4 0 0 41 54 63 157 156 157 155 154 155 137 136 137
55057+153 152 153 158 157 158 137 136 137 26 28 28 2 0 0 2 2 2
55058+4 4 4 4 4 4 1 0 0 6 10 14 34 86 122 90 154 193
55059+64 123 161 90 154 193 64 123 161 90 154 193 90 154 193 90 154 193
55060+64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
55061+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
55062+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
55063+136 185 209 101 161 196 136 185 209 90 154 193 26 108 161 22 40 52
55064+13 16 17 5 7 8 2 5 5 2 5 5 37 38 37 165 164 165
55065+174 174 174 163 162 163 154 154 154 165 164 165 167 166 167 60 73 81
55066+6 6 6 4 0 0 4 0 0 4 4 4 4 4 4 4 4 4
55067+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55068+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55069+4 4 4 4 4 4
55070+4 0 0 6 6 6 41 54 63 156 155 156 158 157 158 153 152 153
55071+156 155 156 165 164 165 137 136 137 26 28 28 0 0 0 2 2 2
55072+4 4 5 4 4 4 2 0 0 7 12 15 31 96 139 64 123 161
55073+90 154 193 64 123 161 90 154 193 90 154 193 64 123 161 90 154 193
55074+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
55075+90 154 193 90 154 193 90 154 193 101 161 196 101 161 196 101 161 196
55076+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
55077+101 161 196 136 185 209 26 108 161 22 40 52 7 11 13 5 7 8
55078+2 5 5 2 5 5 2 5 5 2 2 1 37 38 37 158 157 158
55079+174 174 174 154 154 154 156 155 156 167 166 167 165 164 165 37 38 37
55080+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55081+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55082+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55083+4 4 4 4 4 4
55084+3 1 0 4 0 0 60 73 81 157 156 157 163 162 163 153 152 153
55085+158 157 158 167 166 167 137 136 137 26 28 28 2 0 0 2 2 2
55086+4 5 5 4 4 4 4 0 0 7 12 15 24 86 132 26 108 161
55087+37 112 160 64 123 161 90 154 193 64 123 161 90 154 193 90 154 193
55088+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
55089+90 154 193 101 161 196 90 154 193 101 161 196 101 161 196 101 161 196
55090+101 161 196 101 161 196 101 161 196 136 185 209 101 161 196 136 185 209
55091+90 154 193 35 83 115 13 16 17 13 16 17 7 11 13 3 6 7
55092+5 7 8 6 6 6 3 4 3 2 2 1 30 32 34 154 154 154
55093+167 166 167 154 154 154 154 154 154 174 174 174 165 164 165 37 38 37
55094+6 6 6 4 0 0 6 6 6 4 4 4 4 4 4 4 4 4
55095+4 4 4 4 4 4 4 4 4 4 4 4 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+4 0 0 4 0 0 41 54 63 163 162 163 166 165 166 154 154 154
55099+163 162 163 174 174 174 137 136 137 26 28 28 0 0 0 2 2 2
55100+4 5 5 4 4 5 1 1 2 6 10 14 28 67 93 18 97 151
55101+18 97 151 18 97 151 26 108 161 37 112 160 37 112 160 90 154 193
55102+64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
55103+90 154 193 101 161 196 101 161 196 90 154 193 101 161 196 101 161 196
55104+101 161 196 101 161 196 101 161 196 136 185 209 90 154 193 16 89 141
55105+13 20 25 7 11 13 5 7 8 5 7 8 2 5 5 4 5 5
55106+3 4 3 4 5 5 3 4 3 0 0 0 37 38 37 158 157 158
55107+174 174 174 158 157 158 158 157 158 167 166 167 174 174 174 41 54 63
55108+4 0 0 3 2 2 5 5 5 4 4 4 4 4 4 4 4 4
55109+4 4 4 4 4 4 4 4 4 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+1 1 1 4 0 0 60 73 81 165 164 165 174 174 174 158 157 158
55113+167 166 167 174 174 174 153 152 153 26 28 28 2 0 0 2 2 2
55114+4 5 5 4 4 4 4 0 0 7 12 15 10 87 144 10 87 144
55115+18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
55116+26 108 161 37 112 160 53 118 160 90 154 193 90 154 193 90 154 193
55117+90 154 193 90 154 193 101 161 196 101 161 196 101 161 196 101 161 196
55118+101 161 196 136 185 209 90 154 193 26 108 161 22 40 52 13 16 17
55119+7 11 13 3 6 7 5 7 8 5 7 8 2 5 5 4 5 5
55120+4 5 5 6 6 6 3 4 3 0 0 0 30 32 34 158 157 158
55121+174 174 174 156 155 156 155 154 155 165 164 165 154 153 154 37 38 37
55122+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 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+4 0 0 4 0 0 60 73 81 167 166 167 174 174 174 163 162 163
55127+174 174 174 174 174 174 153 152 153 26 28 28 0 0 0 3 3 3
55128+5 5 5 4 4 4 1 1 2 7 12 15 28 67 93 18 97 151
55129+18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
55130+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
55131+90 154 193 26 108 161 90 154 193 90 154 193 90 154 193 101 161 196
55132+101 161 196 26 108 161 22 40 52 13 16 17 7 11 13 2 5 5
55133+2 5 5 6 6 6 2 5 5 4 5 5 4 5 5 4 5 5
55134+3 4 3 5 5 5 3 4 3 2 0 0 30 32 34 137 136 137
55135+153 152 153 137 136 137 131 129 131 137 136 137 131 129 131 37 38 37
55136+4 0 0 4 3 3 5 5 5 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+1 1 1 4 0 0 60 73 81 167 166 167 174 174 174 166 165 166
55141+174 174 174 177 184 187 153 152 153 30 32 34 1 0 0 3 3 3
55142+5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
55143+18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
55144+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
55145+26 108 161 26 108 161 26 108 161 90 154 193 90 154 193 26 108 161
55146+35 83 115 13 16 17 7 11 13 5 7 8 3 6 7 5 7 8
55147+2 5 5 6 6 6 4 5 5 4 5 5 3 4 3 4 5 5
55148+3 4 3 6 6 6 3 4 3 0 0 0 26 28 28 125 124 125
55149+131 129 131 125 124 125 125 124 125 131 129 131 131 129 131 37 38 37
55150+4 0 0 3 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 174 174 174 177 184 187 167 166 167
55155+174 174 174 177 184 187 153 152 153 30 32 34 0 0 0 3 3 3
55156+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
55157+18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
55158+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
55159+26 108 161 90 154 193 26 108 161 26 108 161 24 86 132 13 20 25
55160+7 11 13 13 20 25 22 40 52 5 7 8 3 4 3 3 4 3
55161+4 5 5 3 4 3 4 5 5 3 4 3 4 5 5 3 4 3
55162+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
55163+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55164+0 0 0 3 3 3 5 5 5 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+1 1 1 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
55169+174 174 174 190 197 201 157 156 157 30 32 34 1 0 0 3 3 3
55170+5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
55171+18 97 151 19 95 150 19 95 150 18 97 151 18 97 151 26 108 161
55172+18 97 151 26 108 161 26 108 161 26 108 161 26 108 161 90 154 193
55173+26 108 161 26 108 161 26 108 161 22 40 52 2 5 5 3 4 3
55174+28 67 93 37 112 160 34 86 122 2 5 5 3 4 3 3 4 3
55175+3 4 3 3 4 3 3 4 3 2 2 1 3 4 3 4 4 4
55176+4 5 5 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
55177+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55178+0 0 0 3 3 3 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+4 0 0 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
55183+174 174 174 190 197 201 158 157 158 30 32 34 0 0 0 2 2 2
55184+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
55185+10 87 144 19 95 150 19 95 150 18 97 151 18 97 151 18 97 151
55186+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
55187+18 97 151 22 40 52 2 5 5 2 2 1 22 40 52 26 108 161
55188+90 154 193 37 112 160 22 40 52 3 4 3 13 20 25 22 30 35
55189+3 6 7 1 1 1 2 2 2 6 9 11 5 5 5 4 3 3
55190+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
55191+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55192+0 0 0 3 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+1 1 1 4 0 0 60 73 81 177 184 187 193 200 203 174 174 174
55197+177 184 187 193 200 203 163 162 163 30 32 34 4 0 0 2 2 2
55198+5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
55199+10 87 144 10 87 144 19 95 150 19 95 150 19 95 150 18 97 151
55200+26 108 161 26 108 161 26 108 161 90 154 193 26 108 161 28 67 93
55201+6 10 14 2 5 5 13 20 25 24 86 132 37 112 160 90 154 193
55202+10 87 144 7 12 15 2 5 5 28 67 93 37 112 160 28 67 93
55203+2 2 1 7 12 15 35 83 115 28 67 93 3 6 7 1 0 0
55204+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
55205+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55206+0 0 0 3 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+4 0 0 4 0 0 60 73 81 174 174 174 190 197 201 174 174 174
55211+177 184 187 193 200 203 163 162 163 30 32 34 0 0 0 2 2 2
55212+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
55213+10 87 144 16 89 141 19 95 150 10 87 144 26 108 161 26 108 161
55214+26 108 161 26 108 161 26 108 161 28 67 93 6 10 14 1 1 2
55215+7 12 15 28 67 93 26 108 161 16 89 141 24 86 132 21 29 34
55216+3 4 3 21 29 34 37 112 160 37 112 160 27 99 146 21 29 34
55217+21 29 34 26 108 161 90 154 193 35 83 115 1 1 2 2 0 0
55218+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
55219+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55220+0 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 193 200 203 193 200 203 174 174 174
55225+190 197 201 193 200 203 165 164 165 37 38 37 4 0 0 2 2 2
55226+5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
55227+10 87 144 10 87 144 16 89 141 18 97 151 18 97 151 10 87 144
55228+24 86 132 24 86 132 13 20 25 4 5 7 4 5 7 22 40 52
55229+18 97 151 37 112 160 26 108 161 7 12 15 1 1 1 0 0 0
55230+28 67 93 37 112 160 26 108 161 28 67 93 22 40 52 28 67 93
55231+26 108 161 90 154 193 26 108 161 10 87 144 0 0 0 2 0 0
55232+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
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+4 0 0 6 6 6 60 73 81 174 174 174 193 200 203 174 174 174
55239+190 197 201 193 200 203 165 164 165 30 32 34 0 0 0 2 2 2
55240+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
55241+10 87 144 10 87 144 10 87 144 18 97 151 28 67 93 6 10 14
55242+0 0 0 1 1 2 4 5 7 13 20 25 16 89 141 26 108 161
55243+26 108 161 26 108 161 24 86 132 6 9 11 2 3 3 22 40 52
55244+37 112 160 16 89 141 22 40 52 28 67 93 26 108 161 26 108 161
55245+90 154 193 26 108 161 26 108 161 28 67 93 1 1 1 4 0 0
55246+4 4 4 5 5 5 3 3 3 4 0 0 26 28 28 124 126 130
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 193 200 203 193 200 203 174 174 174
55253+193 200 203 193 200 203 167 166 167 37 38 37 4 0 0 2 2 2
55254+5 5 5 4 4 4 4 0 0 6 10 14 28 67 93 10 87 144
55255+10 87 144 10 87 144 18 97 151 10 87 144 13 20 25 4 5 7
55256+1 1 2 1 1 1 22 40 52 26 108 161 26 108 161 26 108 161
55257+26 108 161 26 108 161 26 108 161 24 86 132 22 40 52 22 40 52
55258+22 40 52 22 40 52 10 87 144 26 108 161 26 108 161 26 108 161
55259+26 108 161 26 108 161 90 154 193 10 87 144 0 0 0 4 0 0
55260+4 4 4 5 5 5 3 3 3 0 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+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
55267+190 197 201 205 212 215 167 166 167 30 32 34 0 0 0 2 2 2
55268+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
55269+10 87 144 10 87 144 10 87 144 10 87 144 22 40 52 1 1 2
55270+2 0 0 1 1 2 24 86 132 26 108 161 26 108 161 26 108 161
55271+26 108 161 19 95 150 16 89 141 10 87 144 22 40 52 22 40 52
55272+10 87 144 26 108 161 37 112 160 26 108 161 26 108 161 26 108 161
55273+26 108 161 26 108 161 26 108 161 28 67 93 2 0 0 3 1 0
55274+4 4 4 5 5 5 3 3 3 2 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 220 221 221 190 197 201 174 174 174
55281+193 200 203 193 200 203 174 174 174 37 38 37 4 0 0 2 2 2
55282+5 5 5 4 4 4 3 2 2 1 1 2 13 20 25 10 87 144
55283+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 13 20 25
55284+13 20 25 22 40 52 10 87 144 18 97 151 18 97 151 26 108 161
55285+10 87 144 13 20 25 6 10 14 21 29 34 24 86 132 18 97 151
55286+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
55287+26 108 161 90 154 193 18 97 151 13 20 25 0 0 0 4 3 3
55288+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
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+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
55295+190 197 201 220 221 221 167 166 167 30 32 34 1 0 0 2 2 2
55296+5 5 5 4 4 4 4 4 5 2 5 5 4 5 7 13 20 25
55297+28 67 93 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
55298+10 87 144 10 87 144 18 97 151 10 87 144 18 97 151 18 97 151
55299+28 67 93 2 3 3 0 0 0 28 67 93 26 108 161 26 108 161
55300+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
55301+26 108 161 10 87 144 13 20 25 1 1 2 3 2 2 4 4 4
55302+4 4 4 5 5 5 3 3 3 2 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 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
55309+193 200 203 193 200 203 174 174 174 26 28 28 4 0 0 4 3 3
55310+5 5 5 4 4 4 4 4 4 4 4 5 1 1 2 2 5 5
55311+4 5 7 22 40 52 10 87 144 10 87 144 18 97 151 10 87 144
55312+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 18 97 151
55313+10 87 144 28 67 93 22 40 52 10 87 144 26 108 161 18 97 151
55314+18 97 151 18 97 151 26 108 161 26 108 161 26 108 161 26 108 161
55315+22 40 52 1 1 2 0 0 0 2 3 3 4 4 4 4 4 4
55316+4 4 4 5 5 5 4 4 4 0 0 0 26 28 28 131 129 131
55317+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55318+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55319+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55320+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55321+4 4 4 4 4 4
55322+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
55323+190 197 201 220 221 221 190 197 201 41 54 63 4 0 0 2 2 2
55324+6 6 6 4 4 4 4 4 4 4 4 5 4 4 5 3 3 3
55325+1 1 2 1 1 2 6 10 14 22 40 52 10 87 144 18 97 151
55326+18 97 151 10 87 144 10 87 144 10 87 144 18 97 151 10 87 144
55327+10 87 144 18 97 151 26 108 161 18 97 151 18 97 151 10 87 144
55328+26 108 161 26 108 161 26 108 161 10 87 144 28 67 93 6 10 14
55329+1 1 2 1 1 2 4 3 3 4 4 5 4 4 4 4 4 4
55330+5 5 5 5 5 5 1 1 1 4 0 0 37 51 59 137 136 137
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 4 0 0 60 73 81 220 221 221 193 200 203 174 174 174
55337+193 200 203 193 200 203 220 221 221 137 136 137 13 16 17 4 0 0
55338+2 2 2 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5
55339+4 4 5 4 3 3 1 1 2 4 5 7 13 20 25 28 67 93
55340+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
55341+10 87 144 18 97 151 18 97 151 10 87 144 18 97 151 26 108 161
55342+26 108 161 18 97 151 28 67 93 6 10 14 0 0 0 0 0 0
55343+2 3 3 4 5 5 4 4 5 4 4 4 4 4 4 5 5 5
55344+3 3 3 1 1 1 0 0 0 16 19 21 125 124 125 137 136 137
55345+131 129 131 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 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
55351+193 200 203 190 197 201 220 221 221 220 221 221 153 152 153 30 32 34
55352+0 0 0 0 0 0 2 2 2 4 4 4 4 4 4 4 4 4
55353+4 4 4 4 5 5 4 5 7 1 1 2 1 1 2 4 5 7
55354+13 20 25 28 67 93 10 87 144 18 97 151 10 87 144 10 87 144
55355+10 87 144 10 87 144 10 87 144 18 97 151 26 108 161 18 97 151
55356+28 67 93 7 12 15 0 0 0 0 0 0 2 2 1 4 4 4
55357+4 5 5 4 5 5 4 4 4 4 4 4 3 3 3 0 0 0
55358+0 0 0 0 0 0 37 38 37 125 124 125 158 157 158 131 129 131
55359+125 124 125 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 3 3 4 0 0 41 54 63 193 200 203 220 221 221 174 174 174
55365+193 200 203 193 200 203 193 200 203 220 221 221 244 246 246 193 200 203
55366+120 125 127 5 5 5 1 0 0 0 0 0 1 1 1 4 4 4
55367+4 4 4 4 4 4 4 5 5 4 5 5 4 4 5 1 1 2
55368+4 5 7 4 5 7 22 40 52 10 87 144 10 87 144 10 87 144
55369+10 87 144 10 87 144 18 97 151 10 87 144 10 87 144 13 20 25
55370+4 5 7 2 3 3 1 1 2 4 4 4 4 5 5 4 4 4
55371+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 1 2
55372+24 26 27 60 74 84 153 152 153 163 162 163 137 136 137 125 124 125
55373+125 124 125 125 124 125 125 124 125 137 136 137 125 124 125 26 28 28
55374+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55375+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55376+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55377+4 4 4 4 4 4
55378+4 0 0 6 6 6 26 28 28 156 155 156 220 221 221 220 221 221
55379+174 174 174 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
55380+220 221 221 167 166 167 60 73 81 7 11 13 0 0 0 0 0 0
55381+3 3 3 4 4 4 4 4 4 4 4 4 4 4 5 4 4 5
55382+4 4 5 1 1 2 1 1 2 4 5 7 22 40 52 10 87 144
55383+10 87 144 10 87 144 10 87 144 22 40 52 4 5 7 1 1 2
55384+1 1 2 4 4 5 4 4 4 4 4 4 4 4 4 4 4 4
55385+5 5 5 2 2 2 0 0 0 4 0 0 16 19 21 60 73 81
55386+137 136 137 167 166 167 158 157 158 137 136 137 131 129 131 131 129 131
55387+125 124 125 125 124 125 131 129 131 155 154 155 60 74 84 5 7 8
55388+0 0 0 4 4 4 4 4 4 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+5 5 5 4 0 0 4 0 0 60 73 81 193 200 203 220 221 221
55393+193 200 203 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
55394+220 221 221 220 221 221 220 221 221 137 136 137 43 57 68 6 6 6
55395+4 0 0 1 1 1 4 4 4 4 4 4 4 4 4 4 4 4
55396+4 4 5 4 4 5 3 2 2 1 1 2 2 5 5 13 20 25
55397+22 40 52 22 40 52 13 20 25 2 3 3 1 1 2 3 3 3
55398+4 5 7 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55399+1 1 1 0 0 0 2 3 3 41 54 63 131 129 131 166 165 166
55400+166 165 166 155 154 155 153 152 153 137 136 137 137 136 137 125 124 125
55401+125 124 125 137 136 137 137 136 137 125 124 125 37 38 37 4 3 3
55402+4 3 3 5 5 5 4 4 4 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 3 3 6 6 6 6 6 6 13 16 17 60 73 81 167 166 167
55407+220 221 221 220 221 221 220 221 221 193 200 203 193 200 203 193 200 203
55408+205 212 215 220 221 221 220 221 221 244 246 246 205 212 215 125 124 125
55409+24 26 27 0 0 0 0 0 0 2 2 2 5 5 5 5 5 5
55410+4 4 4 4 4 4 4 4 4 4 4 5 1 1 2 4 5 7
55411+4 5 7 4 5 7 1 1 2 3 2 2 4 4 5 4 4 4
55412+4 4 4 4 4 4 5 5 5 4 4 4 0 0 0 0 0 0
55413+2 0 0 26 28 28 125 124 125 174 174 174 174 174 174 166 165 166
55414+156 155 156 153 152 153 137 136 137 137 136 137 131 129 131 137 136 137
55415+137 136 137 137 136 137 60 74 84 30 32 34 4 0 0 4 0 0
55416+5 5 5 4 4 4 4 4 4 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+5 5 5 6 6 6 4 0 0 4 0 0 6 6 6 26 28 28
55421+125 124 125 174 174 174 220 221 221 220 221 221 220 221 221 193 200 203
55422+205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
55423+193 200 203 60 74 84 13 16 17 4 0 0 0 0 0 3 3 3
55424+5 5 5 5 5 5 4 4 4 4 4 4 4 4 5 3 3 3
55425+1 1 2 3 3 3 4 4 5 4 4 5 4 4 4 4 4 4
55426+5 5 5 5 5 5 2 2 2 0 0 0 0 0 0 13 16 17
55427+60 74 84 174 174 174 193 200 203 174 174 174 167 166 167 163 162 163
55428+153 152 153 153 152 153 137 136 137 137 136 137 153 152 153 137 136 137
55429+125 124 125 41 54 63 24 26 27 4 0 0 4 0 0 5 5 5
55430+4 4 4 4 4 4 4 4 4 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 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
55435+6 6 6 37 38 37 131 129 131 220 221 221 220 221 221 220 221 221
55436+193 200 203 193 200 203 220 221 221 205 212 215 220 221 221 244 246 246
55437+244 246 246 244 246 246 174 174 174 41 54 63 0 0 0 0 0 0
55438+0 0 0 4 4 4 5 5 5 5 5 5 4 4 4 4 4 5
55439+4 4 5 4 4 5 4 4 4 4 4 4 6 6 6 6 6 6
55440+3 3 3 0 0 0 2 0 0 13 16 17 60 73 81 156 155 156
55441+220 221 221 193 200 203 174 174 174 165 164 165 163 162 163 154 153 154
55442+153 152 153 153 152 153 158 157 158 163 162 163 137 136 137 60 73 81
55443+13 16 17 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
55444+4 4 4 4 4 4 4 4 4 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+5 5 5 4 3 3 4 3 3 6 6 6 6 6 6 6 6 6
55449+6 6 6 6 6 6 6 6 6 37 38 37 167 166 167 244 246 246
55450+244 246 246 220 221 221 205 212 215 205 212 215 220 221 221 193 200 203
55451+220 221 221 244 246 246 244 246 246 244 246 246 137 136 137 37 38 37
55452+3 2 2 0 0 0 1 1 1 5 5 5 5 5 5 4 4 4
55453+4 4 4 4 4 4 4 4 4 5 5 5 4 4 4 1 1 1
55454+0 0 0 5 5 5 43 57 68 153 152 153 193 200 203 220 221 221
55455+177 184 187 174 174 174 167 166 167 166 165 166 158 157 158 157 156 157
55456+158 157 158 166 165 166 156 155 156 85 115 134 13 16 17 4 0 0
55457+4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
55458+4 4 4 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 3 3 6 6 6 6 6 6 4 0 0 6 6 6
55463+6 6 6 6 6 6 6 6 6 6 6 6 13 16 17 60 73 81
55464+177 184 187 220 221 221 220 221 221 220 221 221 205 212 215 220 221 221
55465+220 221 221 205 212 215 220 221 221 244 246 246 244 246 246 205 212 215
55466+125 124 125 30 32 34 0 0 0 0 0 0 2 2 2 5 5 5
55467+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 0 0
55468+37 38 37 131 129 131 205 212 215 220 221 221 193 200 203 174 174 174
55469+174 174 174 174 174 174 167 166 167 165 164 165 166 165 166 167 166 167
55470+158 157 158 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
55471+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
55472+4 4 4 4 4 4 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 4 4 5 5 5 4 3 3 4 3 3 6 6 6 6 6 6
55477+4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
55478+26 28 28 125 124 125 205 212 215 220 221 221 220 221 221 220 221 221
55479+205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
55480+244 246 246 190 197 201 60 74 84 16 19 21 4 0 0 0 0 0
55481+0 0 0 0 0 0 0 0 0 0 0 0 16 19 21 120 125 127
55482+177 184 187 220 221 221 205 212 215 177 184 187 174 174 174 177 184 187
55483+174 174 174 174 174 174 167 166 167 174 174 174 166 165 166 137 136 137
55484+60 73 81 13 16 17 4 0 0 4 0 0 4 3 3 6 6 6
55485+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55486+4 4 4 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 4 3 3 5 5 5 4 3 3 6 6 6 4 0 0
55491+6 6 6 6 6 6 4 0 0 6 6 6 4 0 0 6 6 6
55492+6 6 6 6 6 6 37 38 37 137 136 137 193 200 203 220 221 221
55493+220 221 221 205 212 215 220 221 221 205 212 215 205 212 215 220 221 221
55494+220 221 221 220 221 221 244 246 246 166 165 166 43 57 68 2 2 2
55495+0 0 0 4 0 0 16 19 21 60 73 81 157 156 157 202 210 214
55496+220 221 221 193 200 203 177 184 187 177 184 187 177 184 187 174 174 174
55497+174 174 174 174 174 174 174 174 174 157 156 157 60 74 84 24 26 27
55498+4 0 0 4 0 0 4 0 0 6 6 6 4 4 4 4 4 4
55499+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
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 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
55505+6 6 6 4 0 0 6 6 6 6 6 6 6 6 6 4 0 0
55506+4 0 0 4 0 0 6 6 6 24 26 27 60 73 81 167 166 167
55507+220 221 221 220 221 221 220 221 221 205 212 215 205 212 215 205 212 215
55508+205 212 215 220 221 221 220 221 221 220 221 221 205 212 215 137 136 137
55509+60 74 84 125 124 125 137 136 137 190 197 201 220 221 221 193 200 203
55510+177 184 187 177 184 187 177 184 187 174 174 174 174 174 174 177 184 187
55511+190 197 201 174 174 174 125 124 125 37 38 37 6 6 6 4 0 0
55512+4 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55513+4 4 4 4 4 4 4 4 4 4 4 4 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+4 4 4 4 4 4 5 5 5 5 5 5 4 3 3 6 6 6
55519+4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 6 6 6
55520+6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
55521+125 124 125 193 200 203 244 246 246 220 221 221 205 212 215 205 212 215
55522+205 212 215 193 200 203 205 212 215 205 212 215 220 221 221 220 221 221
55523+193 200 203 193 200 203 205 212 215 193 200 203 193 200 203 177 184 187
55524+190 197 201 190 197 201 174 174 174 190 197 201 193 200 203 190 197 201
55525+153 152 153 60 73 81 4 0 0 4 0 0 4 0 0 3 2 2
55526+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55527+4 4 4 4 4 4 4 4 4 4 4 4 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+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
55533+6 6 6 4 3 3 4 3 3 4 3 3 6 6 6 6 6 6
55534+4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 4 0 0
55535+4 0 0 26 28 28 131 129 131 220 221 221 244 246 246 220 221 221
55536+205 212 215 193 200 203 205 212 215 193 200 203 193 200 203 205 212 215
55537+220 221 221 193 200 203 193 200 203 193 200 203 190 197 201 174 174 174
55538+174 174 174 190 197 201 193 200 203 193 200 203 167 166 167 125 124 125
55539+6 6 6 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
55540+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55541+4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
55547+5 5 5 4 3 3 5 5 5 6 6 6 4 3 3 5 5 5
55548+6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
55549+4 0 0 4 0 0 6 6 6 41 54 63 158 157 158 220 221 221
55550+220 221 221 220 221 221 193 200 203 193 200 203 193 200 203 190 197 201
55551+190 197 201 190 197 201 190 197 201 190 197 201 174 174 174 193 200 203
55552+193 200 203 220 221 221 174 174 174 125 124 125 37 38 37 4 0 0
55553+4 0 0 4 3 3 6 6 6 4 4 4 4 4 4 4 4 4
55554+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
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+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55561+4 4 4 5 5 5 4 3 3 4 3 3 4 3 3 5 5 5
55562+4 3 3 6 6 6 5 5 5 4 3 3 6 6 6 6 6 6
55563+6 6 6 6 6 6 4 0 0 4 0 0 13 16 17 60 73 81
55564+174 174 174 220 221 221 220 221 221 205 212 215 190 197 201 174 174 174
55565+193 200 203 174 174 174 190 197 201 174 174 174 193 200 203 220 221 221
55566+193 200 203 131 129 131 37 38 37 6 6 6 4 0 0 4 0 0
55567+6 6 6 6 6 6 4 3 3 5 5 5 4 4 4 4 4 4
55568+4 4 4 4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4
55575+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
55576+5 5 5 4 3 3 4 3 3 5 5 5 4 3 3 4 3 3
55577+5 5 5 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
55578+6 6 6 125 124 125 174 174 174 220 221 221 220 221 221 193 200 203
55579+193 200 203 193 200 203 193 200 203 193 200 203 220 221 221 158 157 158
55580+60 73 81 6 6 6 4 0 0 4 0 0 5 5 5 6 6 6
55581+5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
55582+4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4
55589+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55590+4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
55591+5 5 5 5 5 5 6 6 6 6 6 6 4 0 0 4 0 0
55592+4 0 0 4 0 0 26 28 28 125 124 125 174 174 174 193 200 203
55593+193 200 203 174 174 174 193 200 203 167 166 167 125 124 125 6 6 6
55594+6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 5 5 5
55595+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
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 4 4 4 4 4 4
55603+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55604+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
55605+4 3 3 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
55606+6 6 6 4 0 0 4 0 0 6 6 6 37 38 37 125 124 125
55607+153 152 153 131 129 131 125 124 125 37 38 37 6 6 6 6 6 6
55608+6 6 6 4 0 0 6 6 6 6 6 6 4 3 3 5 5 5
55609+4 4 4 4 4 4 4 4 4 4 4 4 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 4 4 4
55617+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55618+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55619+4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
55620+6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
55621+24 26 27 24 26 27 6 6 6 6 6 6 6 6 6 4 0 0
55622+6 6 6 6 6 6 4 0 0 6 6 6 5 5 5 4 3 3
55623+4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55632+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55633+4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
55634+4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
55635+6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
55636+4 0 0 6 6 6 6 6 6 4 3 3 5 5 5 4 4 4
55637+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55638+4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4
55646+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55647+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 5 5 5
55648+5 5 5 5 5 5 4 0 0 6 6 6 4 0 0 6 6 6
55649+6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 4 0 0
55650+6 6 6 4 3 3 5 5 5 4 3 3 5 5 5 4 4 4
55651+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55652+4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55661+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
55662+4 3 3 6 6 6 4 3 3 6 6 6 6 6 6 6 6 6
55663+4 0 0 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
55664+6 6 6 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55665+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55666+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 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 4 4 4
55675+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55676+4 4 4 5 5 5 4 3 3 5 5 5 4 0 0 6 6 6
55677+6 6 6 4 0 0 6 6 6 6 6 6 4 0 0 6 6 6
55678+4 3 3 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
55679+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55680+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55681+4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55690+4 4 4 5 5 5 4 3 3 5 5 5 6 6 6 4 3 3
55691+4 3 3 6 6 6 6 6 6 4 3 3 6 6 6 4 3 3
55692+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55693+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55694+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55695+4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4
55704+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 6 6 6
55705+5 5 5 4 3 3 4 3 3 4 3 3 5 5 5 5 5 5
55706+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55707+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55708+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55709+4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4
55718+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
55719+5 5 5 4 3 3 5 5 5 5 5 5 4 4 4 4 4 4
55720+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55721+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55722+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55723+4 4 4 4 4 4 4 4 4 4 4 4 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
55728diff --git a/drivers/video/matrox/matroxfb_DAC1064.c b/drivers/video/matrox/matroxfb_DAC1064.c
55729index a01147f..5d896f8 100644
55730--- a/drivers/video/matrox/matroxfb_DAC1064.c
55731+++ b/drivers/video/matrox/matroxfb_DAC1064.c
55732@@ -1088,14 +1088,20 @@ static void MGAG100_restore(struct matrox_fb_info *minfo)
55733
55734 #ifdef CONFIG_FB_MATROX_MYSTIQUE
55735 struct matrox_switch matrox_mystique = {
55736- MGA1064_preinit, MGA1064_reset, MGA1064_init, MGA1064_restore,
55737+ .preinit = MGA1064_preinit,
55738+ .reset = MGA1064_reset,
55739+ .init = MGA1064_init,
55740+ .restore = MGA1064_restore,
55741 };
55742 EXPORT_SYMBOL(matrox_mystique);
55743 #endif
55744
55745 #ifdef CONFIG_FB_MATROX_G
55746 struct matrox_switch matrox_G100 = {
55747- MGAG100_preinit, MGAG100_reset, MGAG100_init, MGAG100_restore,
55748+ .preinit = MGAG100_preinit,
55749+ .reset = MGAG100_reset,
55750+ .init = MGAG100_init,
55751+ .restore = MGAG100_restore,
55752 };
55753 EXPORT_SYMBOL(matrox_G100);
55754 #endif
55755diff --git a/drivers/video/matrox/matroxfb_Ti3026.c b/drivers/video/matrox/matroxfb_Ti3026.c
55756index 195ad7c..09743fc 100644
55757--- a/drivers/video/matrox/matroxfb_Ti3026.c
55758+++ b/drivers/video/matrox/matroxfb_Ti3026.c
55759@@ -738,7 +738,10 @@ static int Ti3026_preinit(struct matrox_fb_info *minfo)
55760 }
55761
55762 struct matrox_switch matrox_millennium = {
55763- Ti3026_preinit, Ti3026_reset, Ti3026_init, Ti3026_restore
55764+ .preinit = Ti3026_preinit,
55765+ .reset = Ti3026_reset,
55766+ .init = Ti3026_init,
55767+ .restore = Ti3026_restore
55768 };
55769 EXPORT_SYMBOL(matrox_millennium);
55770 #endif
55771diff --git a/drivers/video/mb862xx/mb862xxfb_accel.c b/drivers/video/mb862xx/mb862xxfb_accel.c
55772index fe92eed..106e085 100644
55773--- a/drivers/video/mb862xx/mb862xxfb_accel.c
55774+++ b/drivers/video/mb862xx/mb862xxfb_accel.c
55775@@ -312,14 +312,18 @@ void mb862xxfb_init_accel(struct fb_info *info, int xres)
55776 struct mb862xxfb_par *par = info->par;
55777
55778 if (info->var.bits_per_pixel == 32) {
55779- info->fbops->fb_fillrect = cfb_fillrect;
55780- info->fbops->fb_copyarea = cfb_copyarea;
55781- info->fbops->fb_imageblit = cfb_imageblit;
55782+ pax_open_kernel();
55783+ *(void **)&info->fbops->fb_fillrect = cfb_fillrect;
55784+ *(void **)&info->fbops->fb_copyarea = cfb_copyarea;
55785+ *(void **)&info->fbops->fb_imageblit = cfb_imageblit;
55786+ pax_close_kernel();
55787 } else {
55788 outreg(disp, GC_L0EM, 3);
55789- info->fbops->fb_fillrect = mb86290fb_fillrect;
55790- info->fbops->fb_copyarea = mb86290fb_copyarea;
55791- info->fbops->fb_imageblit = mb86290fb_imageblit;
55792+ pax_open_kernel();
55793+ *(void **)&info->fbops->fb_fillrect = mb86290fb_fillrect;
55794+ *(void **)&info->fbops->fb_copyarea = mb86290fb_copyarea;
55795+ *(void **)&info->fbops->fb_imageblit = mb86290fb_imageblit;
55796+ pax_close_kernel();
55797 }
55798 outreg(draw, GDC_REG_DRAW_BASE, 0);
55799 outreg(draw, GDC_REG_MODE_MISC, 0x8000);
55800diff --git a/drivers/video/nvidia/nvidia.c b/drivers/video/nvidia/nvidia.c
55801index def0412..fed6529 100644
55802--- a/drivers/video/nvidia/nvidia.c
55803+++ b/drivers/video/nvidia/nvidia.c
55804@@ -669,19 +669,23 @@ static int nvidiafb_set_par(struct fb_info *info)
55805 info->fix.line_length = (info->var.xres_virtual *
55806 info->var.bits_per_pixel) >> 3;
55807 if (info->var.accel_flags) {
55808- info->fbops->fb_imageblit = nvidiafb_imageblit;
55809- info->fbops->fb_fillrect = nvidiafb_fillrect;
55810- info->fbops->fb_copyarea = nvidiafb_copyarea;
55811- info->fbops->fb_sync = nvidiafb_sync;
55812+ pax_open_kernel();
55813+ *(void **)&info->fbops->fb_imageblit = nvidiafb_imageblit;
55814+ *(void **)&info->fbops->fb_fillrect = nvidiafb_fillrect;
55815+ *(void **)&info->fbops->fb_copyarea = nvidiafb_copyarea;
55816+ *(void **)&info->fbops->fb_sync = nvidiafb_sync;
55817+ pax_close_kernel();
55818 info->pixmap.scan_align = 4;
55819 info->flags &= ~FBINFO_HWACCEL_DISABLED;
55820 info->flags |= FBINFO_READS_FAST;
55821 NVResetGraphics(info);
55822 } else {
55823- info->fbops->fb_imageblit = cfb_imageblit;
55824- info->fbops->fb_fillrect = cfb_fillrect;
55825- info->fbops->fb_copyarea = cfb_copyarea;
55826- info->fbops->fb_sync = NULL;
55827+ pax_open_kernel();
55828+ *(void **)&info->fbops->fb_imageblit = cfb_imageblit;
55829+ *(void **)&info->fbops->fb_fillrect = cfb_fillrect;
55830+ *(void **)&info->fbops->fb_copyarea = cfb_copyarea;
55831+ *(void **)&info->fbops->fb_sync = NULL;
55832+ pax_close_kernel();
55833 info->pixmap.scan_align = 1;
55834 info->flags |= FBINFO_HWACCEL_DISABLED;
55835 info->flags &= ~FBINFO_READS_FAST;
55836@@ -1173,8 +1177,11 @@ static int nvidia_set_fbinfo(struct fb_info *info)
55837 info->pixmap.size = 8 * 1024;
55838 info->pixmap.flags = FB_PIXMAP_SYSTEM;
55839
55840- if (!hwcur)
55841- info->fbops->fb_cursor = NULL;
55842+ if (!hwcur) {
55843+ pax_open_kernel();
55844+ *(void **)&info->fbops->fb_cursor = NULL;
55845+ pax_close_kernel();
55846+ }
55847
55848 info->var.accel_flags = (!noaccel);
55849
55850diff --git a/drivers/video/omap2/dss/display.c b/drivers/video/omap2/dss/display.c
55851index 669a81f..e216d76 100644
55852--- a/drivers/video/omap2/dss/display.c
55853+++ b/drivers/video/omap2/dss/display.c
55854@@ -137,12 +137,14 @@ int omapdss_register_display(struct omap_dss_device *dssdev)
55855 snprintf(dssdev->alias, sizeof(dssdev->alias),
55856 "display%d", disp_num_counter++);
55857
55858+ pax_open_kernel();
55859 if (drv && drv->get_resolution == NULL)
55860- drv->get_resolution = omapdss_default_get_resolution;
55861+ *(void **)&drv->get_resolution = omapdss_default_get_resolution;
55862 if (drv && drv->get_recommended_bpp == NULL)
55863- drv->get_recommended_bpp = omapdss_default_get_recommended_bpp;
55864+ *(void **)&drv->get_recommended_bpp = omapdss_default_get_recommended_bpp;
55865 if (drv && drv->get_timings == NULL)
55866- drv->get_timings = omapdss_default_get_timings;
55867+ *(void **)&drv->get_timings = omapdss_default_get_timings;
55868+ pax_close_kernel();
55869
55870 mutex_lock(&panel_list_mutex);
55871 list_add_tail(&dssdev->panel_list, &panel_list);
55872diff --git a/drivers/video/s1d13xxxfb.c b/drivers/video/s1d13xxxfb.c
55873index 83433cb..71e9b98 100644
55874--- a/drivers/video/s1d13xxxfb.c
55875+++ b/drivers/video/s1d13xxxfb.c
55876@@ -881,8 +881,10 @@ static int s1d13xxxfb_probe(struct platform_device *pdev)
55877
55878 switch(prod_id) {
55879 case S1D13506_PROD_ID: /* activate acceleration */
55880- s1d13xxxfb_fbops.fb_fillrect = s1d13xxxfb_bitblt_solidfill;
55881- s1d13xxxfb_fbops.fb_copyarea = s1d13xxxfb_bitblt_copyarea;
55882+ pax_open_kernel();
55883+ *(void **)&s1d13xxxfb_fbops.fb_fillrect = s1d13xxxfb_bitblt_solidfill;
55884+ *(void **)&s1d13xxxfb_fbops.fb_copyarea = s1d13xxxfb_bitblt_copyarea;
55885+ pax_close_kernel();
55886 info->flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN |
55887 FBINFO_HWACCEL_FILLRECT | FBINFO_HWACCEL_COPYAREA;
55888 break;
55889diff --git a/drivers/video/sh_mobile_lcdcfb.c b/drivers/video/sh_mobile_lcdcfb.c
55890index 2bcc84a..29dd1ea 100644
55891--- a/drivers/video/sh_mobile_lcdcfb.c
55892+++ b/drivers/video/sh_mobile_lcdcfb.c
55893@@ -439,9 +439,9 @@ static unsigned long lcdc_sys_read_data(void *handle)
55894 }
55895
55896 static struct sh_mobile_lcdc_sys_bus_ops sh_mobile_lcdc_sys_bus_ops = {
55897- lcdc_sys_write_index,
55898- lcdc_sys_write_data,
55899- lcdc_sys_read_data,
55900+ .write_index = lcdc_sys_write_index,
55901+ .write_data = lcdc_sys_write_data,
55902+ .read_data = lcdc_sys_read_data,
55903 };
55904
55905 static int sh_mobile_lcdc_sginit(struct fb_info *info,
55906diff --git a/drivers/video/smscufx.c b/drivers/video/smscufx.c
55907index d513ed6..90b0de9 100644
55908--- a/drivers/video/smscufx.c
55909+++ b/drivers/video/smscufx.c
55910@@ -1175,7 +1175,9 @@ static int ufx_ops_release(struct fb_info *info, int user)
55911 fb_deferred_io_cleanup(info);
55912 kfree(info->fbdefio);
55913 info->fbdefio = NULL;
55914- info->fbops->fb_mmap = ufx_ops_mmap;
55915+ pax_open_kernel();
55916+ *(void **)&info->fbops->fb_mmap = ufx_ops_mmap;
55917+ pax_close_kernel();
55918 }
55919
55920 pr_debug("released /dev/fb%d user=%d count=%d",
55921diff --git a/drivers/video/udlfb.c b/drivers/video/udlfb.c
55922index 77b890e..458e666 100644
55923--- a/drivers/video/udlfb.c
55924+++ b/drivers/video/udlfb.c
55925@@ -623,11 +623,11 @@ static int dlfb_handle_damage(struct dlfb_data *dev, int x, int y,
55926 dlfb_urb_completion(urb);
55927
55928 error:
55929- atomic_add(bytes_sent, &dev->bytes_sent);
55930- atomic_add(bytes_identical, &dev->bytes_identical);
55931- atomic_add(width*height*2, &dev->bytes_rendered);
55932+ atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
55933+ atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
55934+ atomic_add_unchecked(width*height*2, &dev->bytes_rendered);
55935 end_cycles = get_cycles();
55936- atomic_add(((unsigned int) ((end_cycles - start_cycles)
55937+ atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
55938 >> 10)), /* Kcycles */
55939 &dev->cpu_kcycles_used);
55940
55941@@ -748,11 +748,11 @@ static void dlfb_dpy_deferred_io(struct fb_info *info,
55942 dlfb_urb_completion(urb);
55943
55944 error:
55945- atomic_add(bytes_sent, &dev->bytes_sent);
55946- atomic_add(bytes_identical, &dev->bytes_identical);
55947- atomic_add(bytes_rendered, &dev->bytes_rendered);
55948+ atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
55949+ atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
55950+ atomic_add_unchecked(bytes_rendered, &dev->bytes_rendered);
55951 end_cycles = get_cycles();
55952- atomic_add(((unsigned int) ((end_cycles - start_cycles)
55953+ atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
55954 >> 10)), /* Kcycles */
55955 &dev->cpu_kcycles_used);
55956 }
55957@@ -993,7 +993,9 @@ static int dlfb_ops_release(struct fb_info *info, int user)
55958 fb_deferred_io_cleanup(info);
55959 kfree(info->fbdefio);
55960 info->fbdefio = NULL;
55961- info->fbops->fb_mmap = dlfb_ops_mmap;
55962+ pax_open_kernel();
55963+ *(void **)&info->fbops->fb_mmap = dlfb_ops_mmap;
55964+ pax_close_kernel();
55965 }
55966
55967 pr_warn("released /dev/fb%d user=%d count=%d\n",
55968@@ -1376,7 +1378,7 @@ static ssize_t metrics_bytes_rendered_show(struct device *fbdev,
55969 struct fb_info *fb_info = dev_get_drvdata(fbdev);
55970 struct dlfb_data *dev = fb_info->par;
55971 return snprintf(buf, PAGE_SIZE, "%u\n",
55972- atomic_read(&dev->bytes_rendered));
55973+ atomic_read_unchecked(&dev->bytes_rendered));
55974 }
55975
55976 static ssize_t metrics_bytes_identical_show(struct device *fbdev,
55977@@ -1384,7 +1386,7 @@ static ssize_t metrics_bytes_identical_show(struct device *fbdev,
55978 struct fb_info *fb_info = dev_get_drvdata(fbdev);
55979 struct dlfb_data *dev = fb_info->par;
55980 return snprintf(buf, PAGE_SIZE, "%u\n",
55981- atomic_read(&dev->bytes_identical));
55982+ atomic_read_unchecked(&dev->bytes_identical));
55983 }
55984
55985 static ssize_t metrics_bytes_sent_show(struct device *fbdev,
55986@@ -1392,7 +1394,7 @@ static ssize_t metrics_bytes_sent_show(struct device *fbdev,
55987 struct fb_info *fb_info = dev_get_drvdata(fbdev);
55988 struct dlfb_data *dev = fb_info->par;
55989 return snprintf(buf, PAGE_SIZE, "%u\n",
55990- atomic_read(&dev->bytes_sent));
55991+ atomic_read_unchecked(&dev->bytes_sent));
55992 }
55993
55994 static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
55995@@ -1400,7 +1402,7 @@ static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
55996 struct fb_info *fb_info = dev_get_drvdata(fbdev);
55997 struct dlfb_data *dev = fb_info->par;
55998 return snprintf(buf, PAGE_SIZE, "%u\n",
55999- atomic_read(&dev->cpu_kcycles_used));
56000+ atomic_read_unchecked(&dev->cpu_kcycles_used));
56001 }
56002
56003 static ssize_t edid_show(
56004@@ -1460,10 +1462,10 @@ static ssize_t metrics_reset_store(struct device *fbdev,
56005 struct fb_info *fb_info = dev_get_drvdata(fbdev);
56006 struct dlfb_data *dev = fb_info->par;
56007
56008- atomic_set(&dev->bytes_rendered, 0);
56009- atomic_set(&dev->bytes_identical, 0);
56010- atomic_set(&dev->bytes_sent, 0);
56011- atomic_set(&dev->cpu_kcycles_used, 0);
56012+ atomic_set_unchecked(&dev->bytes_rendered, 0);
56013+ atomic_set_unchecked(&dev->bytes_identical, 0);
56014+ atomic_set_unchecked(&dev->bytes_sent, 0);
56015+ atomic_set_unchecked(&dev->cpu_kcycles_used, 0);
56016
56017 return count;
56018 }
56019diff --git a/drivers/video/uvesafb.c b/drivers/video/uvesafb.c
56020index 256fba7..6e75516 100644
56021--- a/drivers/video/uvesafb.c
56022+++ b/drivers/video/uvesafb.c
56023@@ -19,6 +19,7 @@
56024 #include <linux/io.h>
56025 #include <linux/mutex.h>
56026 #include <linux/slab.h>
56027+#include <linux/moduleloader.h>
56028 #include <video/edid.h>
56029 #include <video/uvesafb.h>
56030 #ifdef CONFIG_X86
56031@@ -565,10 +566,32 @@ static int uvesafb_vbe_getpmi(struct uvesafb_ktask *task,
56032 if ((task->t.regs.eax & 0xffff) != 0x4f || task->t.regs.es < 0xc000) {
56033 par->pmi_setpal = par->ypan = 0;
56034 } else {
56035+
56036+#ifdef CONFIG_PAX_KERNEXEC
56037+#ifdef CONFIG_MODULES
56038+ par->pmi_code = module_alloc_exec((u16)task->t.regs.ecx);
56039+#endif
56040+ if (!par->pmi_code) {
56041+ par->pmi_setpal = par->ypan = 0;
56042+ return 0;
56043+ }
56044+#endif
56045+
56046 par->pmi_base = (u16 *)phys_to_virt(((u32)task->t.regs.es << 4)
56047 + task->t.regs.edi);
56048+
56049+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
56050+ pax_open_kernel();
56051+ memcpy(par->pmi_code, par->pmi_base, (u16)task->t.regs.ecx);
56052+ pax_close_kernel();
56053+
56054+ par->pmi_start = ktva_ktla(par->pmi_code + par->pmi_base[1]);
56055+ par->pmi_pal = ktva_ktla(par->pmi_code + par->pmi_base[2]);
56056+#else
56057 par->pmi_start = (u8 *)par->pmi_base + par->pmi_base[1];
56058 par->pmi_pal = (u8 *)par->pmi_base + par->pmi_base[2];
56059+#endif
56060+
56061 printk(KERN_INFO "uvesafb: protected mode interface info at "
56062 "%04x:%04x\n",
56063 (u16)task->t.regs.es, (u16)task->t.regs.edi);
56064@@ -813,13 +836,14 @@ static int uvesafb_vbe_init(struct fb_info *info)
56065 par->ypan = ypan;
56066
56067 if (par->pmi_setpal || par->ypan) {
56068+#if !defined(CONFIG_MODULES) || !defined(CONFIG_PAX_KERNEXEC)
56069 if (__supported_pte_mask & _PAGE_NX) {
56070 par->pmi_setpal = par->ypan = 0;
56071 printk(KERN_WARNING "uvesafb: NX protection is active, "
56072 "better not use the PMI.\n");
56073- } else {
56074+ } else
56075+#endif
56076 uvesafb_vbe_getpmi(task, par);
56077- }
56078 }
56079 #else
56080 /* The protected mode interface is not available on non-x86. */
56081@@ -1453,8 +1477,11 @@ static void uvesafb_init_info(struct fb_info *info, struct vbe_mode_ib *mode)
56082 info->fix.ywrapstep = (par->ypan > 1) ? 1 : 0;
56083
56084 /* Disable blanking if the user requested so. */
56085- if (!blank)
56086- info->fbops->fb_blank = NULL;
56087+ if (!blank) {
56088+ pax_open_kernel();
56089+ *(void **)&info->fbops->fb_blank = NULL;
56090+ pax_close_kernel();
56091+ }
56092
56093 /*
56094 * Find out how much IO memory is required for the mode with
56095@@ -1530,8 +1557,11 @@ static void uvesafb_init_info(struct fb_info *info, struct vbe_mode_ib *mode)
56096 info->flags = FBINFO_FLAG_DEFAULT |
56097 (par->ypan ? FBINFO_HWACCEL_YPAN : 0);
56098
56099- if (!par->ypan)
56100- info->fbops->fb_pan_display = NULL;
56101+ if (!par->ypan) {
56102+ pax_open_kernel();
56103+ *(void **)&info->fbops->fb_pan_display = NULL;
56104+ pax_close_kernel();
56105+ }
56106 }
56107
56108 static void uvesafb_init_mtrr(struct fb_info *info)
56109@@ -1792,6 +1822,11 @@ out_mode:
56110 out:
56111 kfree(par->vbe_modes);
56112
56113+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
56114+ if (par->pmi_code)
56115+ module_free_exec(NULL, par->pmi_code);
56116+#endif
56117+
56118 framebuffer_release(info);
56119 return err;
56120 }
56121@@ -1816,6 +1851,12 @@ static int uvesafb_remove(struct platform_device *dev)
56122 kfree(par->vbe_modes);
56123 kfree(par->vbe_state_orig);
56124 kfree(par->vbe_state_saved);
56125+
56126+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
56127+ if (par->pmi_code)
56128+ module_free_exec(NULL, par->pmi_code);
56129+#endif
56130+
56131 }
56132
56133 framebuffer_release(info);
56134diff --git a/drivers/video/vesafb.c b/drivers/video/vesafb.c
56135index 1c7da3b..56ea0bd 100644
56136--- a/drivers/video/vesafb.c
56137+++ b/drivers/video/vesafb.c
56138@@ -9,6 +9,7 @@
56139 */
56140
56141 #include <linux/module.h>
56142+#include <linux/moduleloader.h>
56143 #include <linux/kernel.h>
56144 #include <linux/errno.h>
56145 #include <linux/string.h>
56146@@ -52,8 +53,8 @@ static int vram_remap; /* Set amount of memory to be used */
56147 static int vram_total; /* Set total amount of memory */
56148 static int pmi_setpal __read_mostly = 1; /* pmi for palette changes ??? */
56149 static int ypan __read_mostly; /* 0..nothing, 1..ypan, 2..ywrap */
56150-static void (*pmi_start)(void) __read_mostly;
56151-static void (*pmi_pal) (void) __read_mostly;
56152+static void (*pmi_start)(void) __read_only;
56153+static void (*pmi_pal) (void) __read_only;
56154 static int depth __read_mostly;
56155 static int vga_compat __read_mostly;
56156 /* --------------------------------------------------------------------- */
56157@@ -234,6 +235,7 @@ static int vesafb_probe(struct platform_device *dev)
56158 unsigned int size_remap;
56159 unsigned int size_total;
56160 char *option = NULL;
56161+ void *pmi_code = NULL;
56162
56163 /* ignore error return of fb_get_options */
56164 fb_get_options("vesafb", &option);
56165@@ -280,10 +282,6 @@ static int vesafb_probe(struct platform_device *dev)
56166 size_remap = size_total;
56167 vesafb_fix.smem_len = size_remap;
56168
56169-#ifndef __i386__
56170- screen_info.vesapm_seg = 0;
56171-#endif
56172-
56173 if (!request_mem_region(vesafb_fix.smem_start, size_total, "vesafb")) {
56174 printk(KERN_WARNING
56175 "vesafb: cannot reserve video memory at 0x%lx\n",
56176@@ -312,9 +310,21 @@ static int vesafb_probe(struct platform_device *dev)
56177 printk(KERN_INFO "vesafb: mode is %dx%dx%d, linelength=%d, pages=%d\n",
56178 vesafb_defined.xres, vesafb_defined.yres, vesafb_defined.bits_per_pixel, vesafb_fix.line_length, screen_info.pages);
56179
56180+#ifdef __i386__
56181+
56182+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
56183+ pmi_code = module_alloc_exec(screen_info.vesapm_size);
56184+ if (!pmi_code)
56185+#elif !defined(CONFIG_PAX_KERNEXEC)
56186+ if (0)
56187+#endif
56188+
56189+#endif
56190+ screen_info.vesapm_seg = 0;
56191+
56192 if (screen_info.vesapm_seg) {
56193- printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x\n",
56194- screen_info.vesapm_seg,screen_info.vesapm_off);
56195+ printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x %04x bytes\n",
56196+ screen_info.vesapm_seg,screen_info.vesapm_off,screen_info.vesapm_size);
56197 }
56198
56199 if (screen_info.vesapm_seg < 0xc000)
56200@@ -322,9 +332,25 @@ static int vesafb_probe(struct platform_device *dev)
56201
56202 if (ypan || pmi_setpal) {
56203 unsigned short *pmi_base;
56204+
56205 pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off);
56206- pmi_start = (void*)((char*)pmi_base + pmi_base[1]);
56207- pmi_pal = (void*)((char*)pmi_base + pmi_base[2]);
56208+
56209+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
56210+ pax_open_kernel();
56211+ memcpy(pmi_code, pmi_base, screen_info.vesapm_size);
56212+#else
56213+ pmi_code = pmi_base;
56214+#endif
56215+
56216+ pmi_start = (void*)((char*)pmi_code + pmi_base[1]);
56217+ pmi_pal = (void*)((char*)pmi_code + pmi_base[2]);
56218+
56219+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
56220+ pmi_start = ktva_ktla(pmi_start);
56221+ pmi_pal = ktva_ktla(pmi_pal);
56222+ pax_close_kernel();
56223+#endif
56224+
56225 printk(KERN_INFO "vesafb: pmi: set display start = %p, set palette = %p\n",pmi_start,pmi_pal);
56226 if (pmi_base[3]) {
56227 printk(KERN_INFO "vesafb: pmi: ports = ");
56228@@ -477,8 +503,11 @@ static int vesafb_probe(struct platform_device *dev)
56229 info->flags = FBINFO_FLAG_DEFAULT | FBINFO_MISC_FIRMWARE |
56230 (ypan ? FBINFO_HWACCEL_YPAN : 0);
56231
56232- if (!ypan)
56233- info->fbops->fb_pan_display = NULL;
56234+ if (!ypan) {
56235+ pax_open_kernel();
56236+ *(void **)&info->fbops->fb_pan_display = NULL;
56237+ pax_close_kernel();
56238+ }
56239
56240 if (fb_alloc_cmap(&info->cmap, 256, 0) < 0) {
56241 err = -ENOMEM;
56242@@ -492,6 +521,11 @@ static int vesafb_probe(struct platform_device *dev)
56243 fb_info(info, "%s frame buffer device\n", info->fix.id);
56244 return 0;
56245 err:
56246+
56247+#if defined(__i386__) && defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
56248+ module_free_exec(NULL, pmi_code);
56249+#endif
56250+
56251 if (info->screen_base)
56252 iounmap(info->screen_base);
56253 framebuffer_release(info);
56254diff --git a/drivers/video/via/via_clock.h b/drivers/video/via/via_clock.h
56255index 88714ae..16c2e11 100644
56256--- a/drivers/video/via/via_clock.h
56257+++ b/drivers/video/via/via_clock.h
56258@@ -56,7 +56,7 @@ struct via_clock {
56259
56260 void (*set_engine_pll_state)(u8 state);
56261 void (*set_engine_pll)(struct via_pll_config config);
56262-};
56263+} __no_const;
56264
56265
56266 static inline u32 get_pll_internal_frequency(u32 ref_freq,
56267diff --git a/drivers/xen/xenfs/xenstored.c b/drivers/xen/xenfs/xenstored.c
56268index fef20db..d28b1ab 100644
56269--- a/drivers/xen/xenfs/xenstored.c
56270+++ b/drivers/xen/xenfs/xenstored.c
56271@@ -24,7 +24,12 @@ static int xsd_release(struct inode *inode, struct file *file)
56272 static int xsd_kva_open(struct inode *inode, struct file *file)
56273 {
56274 file->private_data = (void *)kasprintf(GFP_KERNEL, "0x%p",
56275+#ifdef CONFIG_GRKERNSEC_HIDESYM
56276+ NULL);
56277+#else
56278 xen_store_interface);
56279+#endif
56280+
56281 if (!file->private_data)
56282 return -ENOMEM;
56283 return 0;
56284diff --git a/fs/9p/vfs_addr.c b/fs/9p/vfs_addr.c
56285index c71e886..61d3d44b 100644
56286--- a/fs/9p/vfs_addr.c
56287+++ b/fs/9p/vfs_addr.c
56288@@ -187,7 +187,7 @@ static int v9fs_vfs_writepage_locked(struct page *page)
56289
56290 retval = v9fs_file_write_internal(inode,
56291 v9inode->writeback_fid,
56292- (__force const char __user *)buffer,
56293+ (const char __force_user *)buffer,
56294 len, &offset, 0);
56295 if (retval > 0)
56296 retval = 0;
56297diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c
56298index bb7991c..481e21a 100644
56299--- a/fs/9p/vfs_inode.c
56300+++ b/fs/9p/vfs_inode.c
56301@@ -1312,7 +1312,7 @@ static void *v9fs_vfs_follow_link(struct dentry *dentry, struct nameidata *nd)
56302 void
56303 v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
56304 {
56305- char *s = nd_get_link(nd);
56306+ const char *s = nd_get_link(nd);
56307
56308 p9_debug(P9_DEBUG_VFS, " %s %s\n",
56309 dentry->d_name.name, IS_ERR(s) ? "<error>" : s);
56310diff --git a/fs/Kconfig.binfmt b/fs/Kconfig.binfmt
56311index 370b24c..ff0be7b 100644
56312--- a/fs/Kconfig.binfmt
56313+++ b/fs/Kconfig.binfmt
56314@@ -103,7 +103,7 @@ config HAVE_AOUT
56315
56316 config BINFMT_AOUT
56317 tristate "Kernel support for a.out and ECOFF binaries"
56318- depends on HAVE_AOUT
56319+ depends on HAVE_AOUT && BROKEN
56320 ---help---
56321 A.out (Assembler.OUTput) is a set of formats for libraries and
56322 executables used in the earliest versions of UNIX. Linux used
56323diff --git a/fs/affs/super.c b/fs/affs/super.c
56324index d098731..9a5b19d 100644
56325--- a/fs/affs/super.c
56326+++ b/fs/affs/super.c
56327@@ -336,8 +336,6 @@ static int affs_fill_super(struct super_block *sb, void *data, int silent)
56328 &blocksize,&sbi->s_prefix,
56329 sbi->s_volume, &mount_flags)) {
56330 printk(KERN_ERR "AFFS: Error parsing options\n");
56331- kfree(sbi->s_prefix);
56332- kfree(sbi);
56333 return -EINVAL;
56334 }
56335 /* N.B. after this point s_prefix must be released */
56336diff --git a/fs/afs/inode.c b/fs/afs/inode.c
56337index ce25d75..dc09eeb 100644
56338--- a/fs/afs/inode.c
56339+++ b/fs/afs/inode.c
56340@@ -141,7 +141,7 @@ struct inode *afs_iget_autocell(struct inode *dir, const char *dev_name,
56341 struct afs_vnode *vnode;
56342 struct super_block *sb;
56343 struct inode *inode;
56344- static atomic_t afs_autocell_ino;
56345+ static atomic_unchecked_t afs_autocell_ino;
56346
56347 _enter("{%x:%u},%*.*s,",
56348 AFS_FS_I(dir)->fid.vid, AFS_FS_I(dir)->fid.vnode,
56349@@ -154,7 +154,7 @@ struct inode *afs_iget_autocell(struct inode *dir, const char *dev_name,
56350 data.fid.unique = 0;
56351 data.fid.vnode = 0;
56352
56353- inode = iget5_locked(sb, atomic_inc_return(&afs_autocell_ino),
56354+ inode = iget5_locked(sb, atomic_inc_return_unchecked(&afs_autocell_ino),
56355 afs_iget5_autocell_test, afs_iget5_set,
56356 &data);
56357 if (!inode) {
56358diff --git a/fs/aio.c b/fs/aio.c
56359index 12a3de0e..25949c1 100644
56360--- a/fs/aio.c
56361+++ b/fs/aio.c
56362@@ -375,7 +375,7 @@ static int aio_setup_ring(struct kioctx *ctx)
56363 size += sizeof(struct io_event) * nr_events;
56364
56365 nr_pages = PFN_UP(size);
56366- if (nr_pages < 0)
56367+ if (nr_pages <= 0)
56368 return -EINVAL;
56369
56370 file = aio_private_file(ctx, nr_pages);
56371@@ -1299,10 +1299,8 @@ rw_common:
56372 &iovec, compat)
56373 : aio_setup_single_vector(req, rw, buf, &nr_segs,
56374 iovec);
56375- if (ret)
56376- return ret;
56377-
56378- ret = rw_verify_area(rw, file, &req->ki_pos, req->ki_nbytes);
56379+ if (!ret)
56380+ ret = rw_verify_area(rw, file, &req->ki_pos, req->ki_nbytes);
56381 if (ret < 0) {
56382 if (iovec != &inline_vec)
56383 kfree(iovec);
56384diff --git a/fs/attr.c b/fs/attr.c
56385index 5d4e59d..fd02418 100644
56386--- a/fs/attr.c
56387+++ b/fs/attr.c
56388@@ -102,6 +102,7 @@ int inode_newsize_ok(const struct inode *inode, loff_t offset)
56389 unsigned long limit;
56390
56391 limit = rlimit(RLIMIT_FSIZE);
56392+ gr_learn_resource(current, RLIMIT_FSIZE, (unsigned long)offset, 1);
56393 if (limit != RLIM_INFINITY && offset > limit)
56394 goto out_sig;
56395 if (offset > inode->i_sb->s_maxbytes)
56396diff --git a/fs/autofs4/waitq.c b/fs/autofs4/waitq.c
56397index 116fd38..c04182da 100644
56398--- a/fs/autofs4/waitq.c
56399+++ b/fs/autofs4/waitq.c
56400@@ -59,7 +59,7 @@ static int autofs4_write(struct autofs_sb_info *sbi,
56401 {
56402 unsigned long sigpipe, flags;
56403 mm_segment_t fs;
56404- const char *data = (const char *)addr;
56405+ const char __user *data = (const char __force_user *)addr;
56406 ssize_t wr = 0;
56407
56408 sigpipe = sigismember(&current->pending.signal, SIGPIPE);
56409@@ -340,6 +340,10 @@ static int validate_request(struct autofs_wait_queue **wait,
56410 return 1;
56411 }
56412
56413+#ifdef CONFIG_GRKERNSEC_HIDESYM
56414+static atomic_unchecked_t autofs_dummy_name_id = ATOMIC_INIT(0);
56415+#endif
56416+
56417 int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
56418 enum autofs_notify notify)
56419 {
56420@@ -385,7 +389,12 @@ int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
56421
56422 /* If this is a direct mount request create a dummy name */
56423 if (IS_ROOT(dentry) && autofs_type_trigger(sbi->type))
56424+#ifdef CONFIG_GRKERNSEC_HIDESYM
56425+ /* this name does get written to userland via autofs4_write() */
56426+ qstr.len = sprintf(name, "%08x", atomic_inc_return_unchecked(&autofs_dummy_name_id));
56427+#else
56428 qstr.len = sprintf(name, "%p", dentry);
56429+#endif
56430 else {
56431 qstr.len = autofs4_getpath(sbi, dentry, &name);
56432 if (!qstr.len) {
56433diff --git a/fs/befs/endian.h b/fs/befs/endian.h
56434index 2722387..56059b5 100644
56435--- a/fs/befs/endian.h
56436+++ b/fs/befs/endian.h
56437@@ -11,7 +11,7 @@
56438
56439 #include <asm/byteorder.h>
56440
56441-static inline u64
56442+static inline u64 __intentional_overflow(-1)
56443 fs64_to_cpu(const struct super_block *sb, fs64 n)
56444 {
56445 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
56446@@ -29,7 +29,7 @@ cpu_to_fs64(const struct super_block *sb, u64 n)
56447 return (__force fs64)cpu_to_be64(n);
56448 }
56449
56450-static inline u32
56451+static inline u32 __intentional_overflow(-1)
56452 fs32_to_cpu(const struct super_block *sb, fs32 n)
56453 {
56454 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
56455@@ -47,7 +47,7 @@ cpu_to_fs32(const struct super_block *sb, u32 n)
56456 return (__force fs32)cpu_to_be32(n);
56457 }
56458
56459-static inline u16
56460+static inline u16 __intentional_overflow(-1)
56461 fs16_to_cpu(const struct super_block *sb, fs16 n)
56462 {
56463 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
56464diff --git a/fs/binfmt_aout.c b/fs/binfmt_aout.c
56465index ca0ba15..0fa3257 100644
56466--- a/fs/binfmt_aout.c
56467+++ b/fs/binfmt_aout.c
56468@@ -16,6 +16,7 @@
56469 #include <linux/string.h>
56470 #include <linux/fs.h>
56471 #include <linux/file.h>
56472+#include <linux/security.h>
56473 #include <linux/stat.h>
56474 #include <linux/fcntl.h>
56475 #include <linux/ptrace.h>
56476@@ -58,6 +59,8 @@ static int aout_core_dump(struct coredump_params *cprm)
56477 #endif
56478 # define START_STACK(u) ((void __user *)u.start_stack)
56479
56480+ memset(&dump, 0, sizeof(dump));
56481+
56482 fs = get_fs();
56483 set_fs(KERNEL_DS);
56484 has_dumped = 1;
56485@@ -68,10 +71,12 @@ static int aout_core_dump(struct coredump_params *cprm)
56486
56487 /* If the size of the dump file exceeds the rlimit, then see what would happen
56488 if we wrote the stack, but not the data area. */
56489+ gr_learn_resource(current, RLIMIT_CORE, (dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE, 1);
56490 if ((dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE > cprm->limit)
56491 dump.u_dsize = 0;
56492
56493 /* Make sure we have enough room to write the stack and data areas. */
56494+ gr_learn_resource(current, RLIMIT_CORE, (dump.u_ssize + 1) * PAGE_SIZE, 1);
56495 if ((dump.u_ssize + 1) * PAGE_SIZE > cprm->limit)
56496 dump.u_ssize = 0;
56497
56498@@ -232,6 +237,8 @@ static int load_aout_binary(struct linux_binprm * bprm)
56499 rlim = rlimit(RLIMIT_DATA);
56500 if (rlim >= RLIM_INFINITY)
56501 rlim = ~0;
56502+
56503+ gr_learn_resource(current, RLIMIT_DATA, ex.a_data + ex.a_bss, 1);
56504 if (ex.a_data + ex.a_bss > rlim)
56505 return -ENOMEM;
56506
56507@@ -264,6 +271,27 @@ static int load_aout_binary(struct linux_binprm * bprm)
56508
56509 install_exec_creds(bprm);
56510
56511+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
56512+ current->mm->pax_flags = 0UL;
56513+#endif
56514+
56515+#ifdef CONFIG_PAX_PAGEEXEC
56516+ if (!(N_FLAGS(ex) & F_PAX_PAGEEXEC)) {
56517+ current->mm->pax_flags |= MF_PAX_PAGEEXEC;
56518+
56519+#ifdef CONFIG_PAX_EMUTRAMP
56520+ if (N_FLAGS(ex) & F_PAX_EMUTRAMP)
56521+ current->mm->pax_flags |= MF_PAX_EMUTRAMP;
56522+#endif
56523+
56524+#ifdef CONFIG_PAX_MPROTECT
56525+ if (!(N_FLAGS(ex) & F_PAX_MPROTECT))
56526+ current->mm->pax_flags |= MF_PAX_MPROTECT;
56527+#endif
56528+
56529+ }
56530+#endif
56531+
56532 if (N_MAGIC(ex) == OMAGIC) {
56533 unsigned long text_addr, map_size;
56534 loff_t pos;
56535@@ -321,7 +349,7 @@ static int load_aout_binary(struct linux_binprm * bprm)
56536 }
56537
56538 error = vm_mmap(bprm->file, N_DATADDR(ex), ex.a_data,
56539- PROT_READ | PROT_WRITE | PROT_EXEC,
56540+ PROT_READ | PROT_WRITE,
56541 MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE,
56542 fd_offset + ex.a_text);
56543 if (error != N_DATADDR(ex)) {
56544diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
56545index 67be295..83e2f86 100644
56546--- a/fs/binfmt_elf.c
56547+++ b/fs/binfmt_elf.c
56548@@ -34,6 +34,7 @@
56549 #include <linux/utsname.h>
56550 #include <linux/coredump.h>
56551 #include <linux/sched.h>
56552+#include <linux/xattr.h>
56553 #include <asm/uaccess.h>
56554 #include <asm/param.h>
56555 #include <asm/page.h>
56556@@ -48,7 +49,7 @@
56557 static int load_elf_binary(struct linux_binprm *bprm);
56558 static int load_elf_library(struct file *);
56559 static unsigned long elf_map(struct file *, unsigned long, struct elf_phdr *,
56560- int, int, unsigned long);
56561+ int, int, unsigned long) __intentional_overflow(-1);
56562
56563 /*
56564 * If we don't support core dumping, then supply a NULL so we
56565@@ -60,6 +61,14 @@ static int elf_core_dump(struct coredump_params *cprm);
56566 #define elf_core_dump NULL
56567 #endif
56568
56569+#ifdef CONFIG_PAX_MPROTECT
56570+static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags);
56571+#endif
56572+
56573+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
56574+static void elf_handle_mmap(struct file *file);
56575+#endif
56576+
56577 #if ELF_EXEC_PAGESIZE > PAGE_SIZE
56578 #define ELF_MIN_ALIGN ELF_EXEC_PAGESIZE
56579 #else
56580@@ -79,6 +88,15 @@ static struct linux_binfmt elf_format = {
56581 .load_binary = load_elf_binary,
56582 .load_shlib = load_elf_library,
56583 .core_dump = elf_core_dump,
56584+
56585+#ifdef CONFIG_PAX_MPROTECT
56586+ .handle_mprotect= elf_handle_mprotect,
56587+#endif
56588+
56589+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
56590+ .handle_mmap = elf_handle_mmap,
56591+#endif
56592+
56593 .min_coredump = ELF_EXEC_PAGESIZE,
56594 };
56595
56596@@ -86,6 +104,8 @@ static struct linux_binfmt elf_format = {
56597
56598 static int set_brk(unsigned long start, unsigned long end)
56599 {
56600+ unsigned long e = end;
56601+
56602 start = ELF_PAGEALIGN(start);
56603 end = ELF_PAGEALIGN(end);
56604 if (end > start) {
56605@@ -94,7 +114,7 @@ static int set_brk(unsigned long start, unsigned long end)
56606 if (BAD_ADDR(addr))
56607 return addr;
56608 }
56609- current->mm->start_brk = current->mm->brk = end;
56610+ current->mm->start_brk = current->mm->brk = e;
56611 return 0;
56612 }
56613
56614@@ -155,12 +175,13 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
56615 elf_addr_t __user *u_rand_bytes;
56616 const char *k_platform = ELF_PLATFORM;
56617 const char *k_base_platform = ELF_BASE_PLATFORM;
56618- unsigned char k_rand_bytes[16];
56619+ u32 k_rand_bytes[4];
56620 int items;
56621 elf_addr_t *elf_info;
56622 int ei_index = 0;
56623 const struct cred *cred = current_cred();
56624 struct vm_area_struct *vma;
56625+ unsigned long saved_auxv[AT_VECTOR_SIZE];
56626
56627 /*
56628 * In some cases (e.g. Hyper-Threading), we want to avoid L1
56629@@ -202,8 +223,12 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
56630 * Generate 16 random bytes for userspace PRNG seeding.
56631 */
56632 get_random_bytes(k_rand_bytes, sizeof(k_rand_bytes));
56633- u_rand_bytes = (elf_addr_t __user *)
56634- STACK_ALLOC(p, sizeof(k_rand_bytes));
56635+ prandom_seed(k_rand_bytes[0] ^ prandom_u32());
56636+ prandom_seed(k_rand_bytes[1] ^ prandom_u32());
56637+ prandom_seed(k_rand_bytes[2] ^ prandom_u32());
56638+ prandom_seed(k_rand_bytes[3] ^ prandom_u32());
56639+ p = STACK_ROUND(p, sizeof(k_rand_bytes));
56640+ u_rand_bytes = (elf_addr_t __user *) p;
56641 if (__copy_to_user(u_rand_bytes, k_rand_bytes, sizeof(k_rand_bytes)))
56642 return -EFAULT;
56643
56644@@ -318,9 +343,11 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
56645 return -EFAULT;
56646 current->mm->env_end = p;
56647
56648+ memcpy(saved_auxv, elf_info, ei_index * sizeof(elf_addr_t));
56649+
56650 /* Put the elf_info on the stack in the right place. */
56651 sp = (elf_addr_t __user *)envp + 1;
56652- if (copy_to_user(sp, elf_info, ei_index * sizeof(elf_addr_t)))
56653+ if (copy_to_user(sp, saved_auxv, ei_index * sizeof(elf_addr_t)))
56654 return -EFAULT;
56655 return 0;
56656 }
56657@@ -388,15 +415,14 @@ static unsigned long total_mapping_size(struct elf_phdr *cmds, int nr)
56658 an ELF header */
56659
56660 static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
56661- struct file *interpreter, unsigned long *interp_map_addr,
56662- unsigned long no_base)
56663+ struct file *interpreter, unsigned long no_base)
56664 {
56665 struct elf_phdr *elf_phdata;
56666 struct elf_phdr *eppnt;
56667- unsigned long load_addr = 0;
56668+ unsigned long load_addr = 0, pax_task_size = TASK_SIZE;
56669 int load_addr_set = 0;
56670 unsigned long last_bss = 0, elf_bss = 0;
56671- unsigned long error = ~0UL;
56672+ unsigned long error = -EINVAL;
56673 unsigned long total_size;
56674 int retval, i, size;
56675
56676@@ -442,6 +468,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
56677 goto out_close;
56678 }
56679
56680+#ifdef CONFIG_PAX_SEGMEXEC
56681+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
56682+ pax_task_size = SEGMEXEC_TASK_SIZE;
56683+#endif
56684+
56685 eppnt = elf_phdata;
56686 for (i = 0; i < interp_elf_ex->e_phnum; i++, eppnt++) {
56687 if (eppnt->p_type == PT_LOAD) {
56688@@ -465,8 +496,6 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
56689 map_addr = elf_map(interpreter, load_addr + vaddr,
56690 eppnt, elf_prot, elf_type, total_size);
56691 total_size = 0;
56692- if (!*interp_map_addr)
56693- *interp_map_addr = map_addr;
56694 error = map_addr;
56695 if (BAD_ADDR(map_addr))
56696 goto out_close;
56697@@ -485,8 +514,8 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
56698 k = load_addr + eppnt->p_vaddr;
56699 if (BAD_ADDR(k) ||
56700 eppnt->p_filesz > eppnt->p_memsz ||
56701- eppnt->p_memsz > TASK_SIZE ||
56702- TASK_SIZE - eppnt->p_memsz < k) {
56703+ eppnt->p_memsz > pax_task_size ||
56704+ pax_task_size - eppnt->p_memsz < k) {
56705 error = -ENOMEM;
56706 goto out_close;
56707 }
56708@@ -525,9 +554,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
56709 elf_bss = ELF_PAGESTART(elf_bss + ELF_MIN_ALIGN - 1);
56710
56711 /* Map the last of the bss segment */
56712- error = vm_brk(elf_bss, last_bss - elf_bss);
56713- if (BAD_ADDR(error))
56714- goto out_close;
56715+ if (last_bss > elf_bss) {
56716+ error = vm_brk(elf_bss, last_bss - elf_bss);
56717+ if (BAD_ADDR(error))
56718+ goto out_close;
56719+ }
56720 }
56721
56722 error = load_addr;
56723@@ -538,6 +569,336 @@ out:
56724 return error;
56725 }
56726
56727+#ifdef CONFIG_PAX_PT_PAX_FLAGS
56728+#ifdef CONFIG_PAX_SOFTMODE
56729+static unsigned long pax_parse_pt_pax_softmode(const struct elf_phdr * const elf_phdata)
56730+{
56731+ unsigned long pax_flags = 0UL;
56732+
56733+#ifdef CONFIG_PAX_PAGEEXEC
56734+ if (elf_phdata->p_flags & PF_PAGEEXEC)
56735+ pax_flags |= MF_PAX_PAGEEXEC;
56736+#endif
56737+
56738+#ifdef CONFIG_PAX_SEGMEXEC
56739+ if (elf_phdata->p_flags & PF_SEGMEXEC)
56740+ pax_flags |= MF_PAX_SEGMEXEC;
56741+#endif
56742+
56743+#ifdef CONFIG_PAX_EMUTRAMP
56744+ if ((elf_phdata->p_flags & PF_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
56745+ pax_flags |= MF_PAX_EMUTRAMP;
56746+#endif
56747+
56748+#ifdef CONFIG_PAX_MPROTECT
56749+ if (elf_phdata->p_flags & PF_MPROTECT)
56750+ pax_flags |= MF_PAX_MPROTECT;
56751+#endif
56752+
56753+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
56754+ if (randomize_va_space && (elf_phdata->p_flags & PF_RANDMMAP))
56755+ pax_flags |= MF_PAX_RANDMMAP;
56756+#endif
56757+
56758+ return pax_flags;
56759+}
56760+#endif
56761+
56762+static unsigned long pax_parse_pt_pax_hardmode(const struct elf_phdr * const elf_phdata)
56763+{
56764+ unsigned long pax_flags = 0UL;
56765+
56766+#ifdef CONFIG_PAX_PAGEEXEC
56767+ if (!(elf_phdata->p_flags & PF_NOPAGEEXEC))
56768+ pax_flags |= MF_PAX_PAGEEXEC;
56769+#endif
56770+
56771+#ifdef CONFIG_PAX_SEGMEXEC
56772+ if (!(elf_phdata->p_flags & PF_NOSEGMEXEC))
56773+ pax_flags |= MF_PAX_SEGMEXEC;
56774+#endif
56775+
56776+#ifdef CONFIG_PAX_EMUTRAMP
56777+ if (!(elf_phdata->p_flags & PF_NOEMUTRAMP))
56778+ pax_flags |= MF_PAX_EMUTRAMP;
56779+#endif
56780+
56781+#ifdef CONFIG_PAX_MPROTECT
56782+ if (!(elf_phdata->p_flags & PF_NOMPROTECT))
56783+ pax_flags |= MF_PAX_MPROTECT;
56784+#endif
56785+
56786+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
56787+ if (randomize_va_space && !(elf_phdata->p_flags & PF_NORANDMMAP))
56788+ pax_flags |= MF_PAX_RANDMMAP;
56789+#endif
56790+
56791+ return pax_flags;
56792+}
56793+#endif
56794+
56795+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
56796+#ifdef CONFIG_PAX_SOFTMODE
56797+static unsigned long pax_parse_xattr_pax_softmode(unsigned long pax_flags_softmode)
56798+{
56799+ unsigned long pax_flags = 0UL;
56800+
56801+#ifdef CONFIG_PAX_PAGEEXEC
56802+ if (pax_flags_softmode & MF_PAX_PAGEEXEC)
56803+ pax_flags |= MF_PAX_PAGEEXEC;
56804+#endif
56805+
56806+#ifdef CONFIG_PAX_SEGMEXEC
56807+ if (pax_flags_softmode & MF_PAX_SEGMEXEC)
56808+ pax_flags |= MF_PAX_SEGMEXEC;
56809+#endif
56810+
56811+#ifdef CONFIG_PAX_EMUTRAMP
56812+ if ((pax_flags_softmode & MF_PAX_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
56813+ pax_flags |= MF_PAX_EMUTRAMP;
56814+#endif
56815+
56816+#ifdef CONFIG_PAX_MPROTECT
56817+ if (pax_flags_softmode & MF_PAX_MPROTECT)
56818+ pax_flags |= MF_PAX_MPROTECT;
56819+#endif
56820+
56821+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
56822+ if (randomize_va_space && (pax_flags_softmode & MF_PAX_RANDMMAP))
56823+ pax_flags |= MF_PAX_RANDMMAP;
56824+#endif
56825+
56826+ return pax_flags;
56827+}
56828+#endif
56829+
56830+static unsigned long pax_parse_xattr_pax_hardmode(unsigned long pax_flags_hardmode)
56831+{
56832+ unsigned long pax_flags = 0UL;
56833+
56834+#ifdef CONFIG_PAX_PAGEEXEC
56835+ if (!(pax_flags_hardmode & MF_PAX_PAGEEXEC))
56836+ pax_flags |= MF_PAX_PAGEEXEC;
56837+#endif
56838+
56839+#ifdef CONFIG_PAX_SEGMEXEC
56840+ if (!(pax_flags_hardmode & MF_PAX_SEGMEXEC))
56841+ pax_flags |= MF_PAX_SEGMEXEC;
56842+#endif
56843+
56844+#ifdef CONFIG_PAX_EMUTRAMP
56845+ if (!(pax_flags_hardmode & MF_PAX_EMUTRAMP))
56846+ pax_flags |= MF_PAX_EMUTRAMP;
56847+#endif
56848+
56849+#ifdef CONFIG_PAX_MPROTECT
56850+ if (!(pax_flags_hardmode & MF_PAX_MPROTECT))
56851+ pax_flags |= MF_PAX_MPROTECT;
56852+#endif
56853+
56854+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
56855+ if (randomize_va_space && !(pax_flags_hardmode & MF_PAX_RANDMMAP))
56856+ pax_flags |= MF_PAX_RANDMMAP;
56857+#endif
56858+
56859+ return pax_flags;
56860+}
56861+#endif
56862+
56863+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
56864+static unsigned long pax_parse_defaults(void)
56865+{
56866+ unsigned long pax_flags = 0UL;
56867+
56868+#ifdef CONFIG_PAX_SOFTMODE
56869+ if (pax_softmode)
56870+ return pax_flags;
56871+#endif
56872+
56873+#ifdef CONFIG_PAX_PAGEEXEC
56874+ pax_flags |= MF_PAX_PAGEEXEC;
56875+#endif
56876+
56877+#ifdef CONFIG_PAX_SEGMEXEC
56878+ pax_flags |= MF_PAX_SEGMEXEC;
56879+#endif
56880+
56881+#ifdef CONFIG_PAX_MPROTECT
56882+ pax_flags |= MF_PAX_MPROTECT;
56883+#endif
56884+
56885+#ifdef CONFIG_PAX_RANDMMAP
56886+ if (randomize_va_space)
56887+ pax_flags |= MF_PAX_RANDMMAP;
56888+#endif
56889+
56890+ return pax_flags;
56891+}
56892+
56893+static unsigned long pax_parse_ei_pax(const struct elfhdr * const elf_ex)
56894+{
56895+ unsigned long pax_flags = PAX_PARSE_FLAGS_FALLBACK;
56896+
56897+#ifdef CONFIG_PAX_EI_PAX
56898+
56899+#ifdef CONFIG_PAX_SOFTMODE
56900+ if (pax_softmode)
56901+ return pax_flags;
56902+#endif
56903+
56904+ pax_flags = 0UL;
56905+
56906+#ifdef CONFIG_PAX_PAGEEXEC
56907+ if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_PAGEEXEC))
56908+ pax_flags |= MF_PAX_PAGEEXEC;
56909+#endif
56910+
56911+#ifdef CONFIG_PAX_SEGMEXEC
56912+ if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_SEGMEXEC))
56913+ pax_flags |= MF_PAX_SEGMEXEC;
56914+#endif
56915+
56916+#ifdef CONFIG_PAX_EMUTRAMP
56917+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && (elf_ex->e_ident[EI_PAX] & EF_PAX_EMUTRAMP))
56918+ pax_flags |= MF_PAX_EMUTRAMP;
56919+#endif
56920+
56921+#ifdef CONFIG_PAX_MPROTECT
56922+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && !(elf_ex->e_ident[EI_PAX] & EF_PAX_MPROTECT))
56923+ pax_flags |= MF_PAX_MPROTECT;
56924+#endif
56925+
56926+#ifdef CONFIG_PAX_ASLR
56927+ if (randomize_va_space && !(elf_ex->e_ident[EI_PAX] & EF_PAX_RANDMMAP))
56928+ pax_flags |= MF_PAX_RANDMMAP;
56929+#endif
56930+
56931+#endif
56932+
56933+ return pax_flags;
56934+
56935+}
56936+
56937+static unsigned long pax_parse_pt_pax(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata)
56938+{
56939+
56940+#ifdef CONFIG_PAX_PT_PAX_FLAGS
56941+ unsigned long i;
56942+
56943+ for (i = 0UL; i < elf_ex->e_phnum; i++)
56944+ if (elf_phdata[i].p_type == PT_PAX_FLAGS) {
56945+ if (((elf_phdata[i].p_flags & PF_PAGEEXEC) && (elf_phdata[i].p_flags & PF_NOPAGEEXEC)) ||
56946+ ((elf_phdata[i].p_flags & PF_SEGMEXEC) && (elf_phdata[i].p_flags & PF_NOSEGMEXEC)) ||
56947+ ((elf_phdata[i].p_flags & PF_EMUTRAMP) && (elf_phdata[i].p_flags & PF_NOEMUTRAMP)) ||
56948+ ((elf_phdata[i].p_flags & PF_MPROTECT) && (elf_phdata[i].p_flags & PF_NOMPROTECT)) ||
56949+ ((elf_phdata[i].p_flags & PF_RANDMMAP) && (elf_phdata[i].p_flags & PF_NORANDMMAP)))
56950+ return PAX_PARSE_FLAGS_FALLBACK;
56951+
56952+#ifdef CONFIG_PAX_SOFTMODE
56953+ if (pax_softmode)
56954+ return pax_parse_pt_pax_softmode(&elf_phdata[i]);
56955+ else
56956+#endif
56957+
56958+ return pax_parse_pt_pax_hardmode(&elf_phdata[i]);
56959+ break;
56960+ }
56961+#endif
56962+
56963+ return PAX_PARSE_FLAGS_FALLBACK;
56964+}
56965+
56966+static unsigned long pax_parse_xattr_pax(struct file * const file)
56967+{
56968+
56969+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
56970+ ssize_t xattr_size, i;
56971+ unsigned char xattr_value[sizeof("pemrs") - 1];
56972+ unsigned long pax_flags_hardmode = 0UL, pax_flags_softmode = 0UL;
56973+
56974+ xattr_size = pax_getxattr(file->f_path.dentry, xattr_value, sizeof xattr_value);
56975+ if (xattr_size < 0 || xattr_size > sizeof xattr_value)
56976+ return PAX_PARSE_FLAGS_FALLBACK;
56977+
56978+ for (i = 0; i < xattr_size; i++)
56979+ switch (xattr_value[i]) {
56980+ default:
56981+ return PAX_PARSE_FLAGS_FALLBACK;
56982+
56983+#define parse_flag(option1, option2, flag) \
56984+ case option1: \
56985+ if (pax_flags_hardmode & MF_PAX_##flag) \
56986+ return PAX_PARSE_FLAGS_FALLBACK;\
56987+ pax_flags_hardmode |= MF_PAX_##flag; \
56988+ break; \
56989+ case option2: \
56990+ if (pax_flags_softmode & MF_PAX_##flag) \
56991+ return PAX_PARSE_FLAGS_FALLBACK;\
56992+ pax_flags_softmode |= MF_PAX_##flag; \
56993+ break;
56994+
56995+ parse_flag('p', 'P', PAGEEXEC);
56996+ parse_flag('e', 'E', EMUTRAMP);
56997+ parse_flag('m', 'M', MPROTECT);
56998+ parse_flag('r', 'R', RANDMMAP);
56999+ parse_flag('s', 'S', SEGMEXEC);
57000+
57001+#undef parse_flag
57002+ }
57003+
57004+ if (pax_flags_hardmode & pax_flags_softmode)
57005+ return PAX_PARSE_FLAGS_FALLBACK;
57006+
57007+#ifdef CONFIG_PAX_SOFTMODE
57008+ if (pax_softmode)
57009+ return pax_parse_xattr_pax_softmode(pax_flags_softmode);
57010+ else
57011+#endif
57012+
57013+ return pax_parse_xattr_pax_hardmode(pax_flags_hardmode);
57014+#else
57015+ return PAX_PARSE_FLAGS_FALLBACK;
57016+#endif
57017+
57018+}
57019+
57020+static long pax_parse_pax_flags(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata, struct file * const file)
57021+{
57022+ unsigned long pax_flags, ei_pax_flags, pt_pax_flags, xattr_pax_flags;
57023+
57024+ pax_flags = pax_parse_defaults();
57025+ ei_pax_flags = pax_parse_ei_pax(elf_ex);
57026+ pt_pax_flags = pax_parse_pt_pax(elf_ex, elf_phdata);
57027+ xattr_pax_flags = pax_parse_xattr_pax(file);
57028+
57029+ if (pt_pax_flags != PAX_PARSE_FLAGS_FALLBACK &&
57030+ xattr_pax_flags != PAX_PARSE_FLAGS_FALLBACK &&
57031+ pt_pax_flags != xattr_pax_flags)
57032+ return -EINVAL;
57033+ if (xattr_pax_flags != PAX_PARSE_FLAGS_FALLBACK)
57034+ pax_flags = xattr_pax_flags;
57035+ else if (pt_pax_flags != PAX_PARSE_FLAGS_FALLBACK)
57036+ pax_flags = pt_pax_flags;
57037+ else if (ei_pax_flags != PAX_PARSE_FLAGS_FALLBACK)
57038+ pax_flags = ei_pax_flags;
57039+
57040+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
57041+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
57042+ if ((__supported_pte_mask & _PAGE_NX))
57043+ pax_flags &= ~MF_PAX_SEGMEXEC;
57044+ else
57045+ pax_flags &= ~MF_PAX_PAGEEXEC;
57046+ }
57047+#endif
57048+
57049+ if (0 > pax_check_flags(&pax_flags))
57050+ return -EINVAL;
57051+
57052+ current->mm->pax_flags = pax_flags;
57053+ return 0;
57054+}
57055+#endif
57056+
57057 /*
57058 * These are the functions used to load ELF style executables and shared
57059 * libraries. There is no binary dependent code anywhere else.
57060@@ -551,6 +912,11 @@ static unsigned long randomize_stack_top(unsigned long stack_top)
57061 {
57062 unsigned int random_variable = 0;
57063
57064+#ifdef CONFIG_PAX_RANDUSTACK
57065+ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
57066+ return stack_top - current->mm->delta_stack;
57067+#endif
57068+
57069 if ((current->flags & PF_RANDOMIZE) &&
57070 !(current->personality & ADDR_NO_RANDOMIZE)) {
57071 random_variable = get_random_int() & STACK_RND_MASK;
57072@@ -569,7 +935,7 @@ static int load_elf_binary(struct linux_binprm *bprm)
57073 unsigned long load_addr = 0, load_bias = 0;
57074 int load_addr_set = 0;
57075 char * elf_interpreter = NULL;
57076- unsigned long error;
57077+ unsigned long error = 0;
57078 struct elf_phdr *elf_ppnt, *elf_phdata;
57079 unsigned long elf_bss, elf_brk;
57080 int retval, i;
57081@@ -579,12 +945,12 @@ static int load_elf_binary(struct linux_binprm *bprm)
57082 unsigned long start_code, end_code, start_data, end_data;
57083 unsigned long reloc_func_desc __maybe_unused = 0;
57084 int executable_stack = EXSTACK_DEFAULT;
57085- unsigned long def_flags = 0;
57086 struct pt_regs *regs = current_pt_regs();
57087 struct {
57088 struct elfhdr elf_ex;
57089 struct elfhdr interp_elf_ex;
57090 } *loc;
57091+ unsigned long pax_task_size;
57092
57093 loc = kmalloc(sizeof(*loc), GFP_KERNEL);
57094 if (!loc) {
57095@@ -720,11 +1086,82 @@ static int load_elf_binary(struct linux_binprm *bprm)
57096 goto out_free_dentry;
57097
57098 /* OK, This is the point of no return */
57099- current->mm->def_flags = def_flags;
57100+ current->mm->def_flags = 0;
57101
57102 /* Do this immediately, since STACK_TOP as used in setup_arg_pages
57103 may depend on the personality. */
57104 SET_PERSONALITY(loc->elf_ex);
57105+
57106+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
57107+ current->mm->pax_flags = 0UL;
57108+#endif
57109+
57110+#ifdef CONFIG_PAX_DLRESOLVE
57111+ current->mm->call_dl_resolve = 0UL;
57112+#endif
57113+
57114+#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
57115+ current->mm->call_syscall = 0UL;
57116+#endif
57117+
57118+#ifdef CONFIG_PAX_ASLR
57119+ current->mm->delta_mmap = 0UL;
57120+ current->mm->delta_stack = 0UL;
57121+#endif
57122+
57123+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
57124+ if (0 > pax_parse_pax_flags(&loc->elf_ex, elf_phdata, bprm->file)) {
57125+ send_sig(SIGKILL, current, 0);
57126+ goto out_free_dentry;
57127+ }
57128+#endif
57129+
57130+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
57131+ pax_set_initial_flags(bprm);
57132+#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
57133+ if (pax_set_initial_flags_func)
57134+ (pax_set_initial_flags_func)(bprm);
57135+#endif
57136+
57137+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
57138+ if ((current->mm->pax_flags & MF_PAX_PAGEEXEC) && !(__supported_pte_mask & _PAGE_NX)) {
57139+ current->mm->context.user_cs_limit = PAGE_SIZE;
57140+ current->mm->def_flags |= VM_PAGEEXEC | VM_NOHUGEPAGE;
57141+ }
57142+#endif
57143+
57144+#ifdef CONFIG_PAX_SEGMEXEC
57145+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
57146+ current->mm->context.user_cs_base = SEGMEXEC_TASK_SIZE;
57147+ current->mm->context.user_cs_limit = TASK_SIZE-SEGMEXEC_TASK_SIZE;
57148+ pax_task_size = SEGMEXEC_TASK_SIZE;
57149+ current->mm->def_flags |= VM_NOHUGEPAGE;
57150+ } else
57151+#endif
57152+
57153+ pax_task_size = TASK_SIZE;
57154+
57155+#if defined(CONFIG_ARCH_TRACK_EXEC_LIMIT) || defined(CONFIG_PAX_SEGMEXEC)
57156+ if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
57157+ set_user_cs(current->mm->context.user_cs_base, current->mm->context.user_cs_limit, get_cpu());
57158+ put_cpu();
57159+ }
57160+#endif
57161+
57162+#ifdef CONFIG_PAX_ASLR
57163+ if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
57164+ current->mm->delta_mmap = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN)-1)) << PAGE_SHIFT;
57165+ current->mm->delta_stack = (pax_get_random_long() & ((1UL << PAX_DELTA_STACK_LEN)-1)) << PAGE_SHIFT;
57166+ }
57167+#endif
57168+
57169+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
57170+ if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
57171+ executable_stack = EXSTACK_DISABLE_X;
57172+ current->personality &= ~READ_IMPLIES_EXEC;
57173+ } else
57174+#endif
57175+
57176 if (elf_read_implies_exec(loc->elf_ex, executable_stack))
57177 current->personality |= READ_IMPLIES_EXEC;
57178
57179@@ -814,6 +1251,20 @@ static int load_elf_binary(struct linux_binprm *bprm)
57180 #else
57181 load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr);
57182 #endif
57183+
57184+#ifdef CONFIG_PAX_RANDMMAP
57185+ /* PaX: randomize base address at the default exe base if requested */
57186+ if ((current->mm->pax_flags & MF_PAX_RANDMMAP) && elf_interpreter) {
57187+#ifdef CONFIG_SPARC64
57188+ load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << (PAGE_SHIFT+1);
57189+#else
57190+ load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << PAGE_SHIFT;
57191+#endif
57192+ load_bias = ELF_PAGESTART(PAX_ELF_ET_DYN_BASE - vaddr + load_bias);
57193+ elf_flags |= MAP_FIXED;
57194+ }
57195+#endif
57196+
57197 }
57198
57199 error = elf_map(bprm->file, load_bias + vaddr, elf_ppnt,
57200@@ -846,9 +1297,9 @@ static int load_elf_binary(struct linux_binprm *bprm)
57201 * allowed task size. Note that p_filesz must always be
57202 * <= p_memsz so it is only necessary to check p_memsz.
57203 */
57204- if (BAD_ADDR(k) || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
57205- elf_ppnt->p_memsz > TASK_SIZE ||
57206- TASK_SIZE - elf_ppnt->p_memsz < k) {
57207+ if (k >= pax_task_size || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
57208+ elf_ppnt->p_memsz > pax_task_size ||
57209+ pax_task_size - elf_ppnt->p_memsz < k) {
57210 /* set_brk can never work. Avoid overflows. */
57211 send_sig(SIGKILL, current, 0);
57212 retval = -EINVAL;
57213@@ -887,17 +1338,45 @@ static int load_elf_binary(struct linux_binprm *bprm)
57214 goto out_free_dentry;
57215 }
57216 if (likely(elf_bss != elf_brk) && unlikely(padzero(elf_bss))) {
57217- send_sig(SIGSEGV, current, 0);
57218- retval = -EFAULT; /* Nobody gets to see this, but.. */
57219- goto out_free_dentry;
57220+ /*
57221+ * This bss-zeroing can fail if the ELF
57222+ * file specifies odd protections. So
57223+ * we don't check the return value
57224+ */
57225 }
57226
57227+#ifdef CONFIG_PAX_RANDMMAP
57228+ if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
57229+ unsigned long start, size, flags;
57230+ vm_flags_t vm_flags;
57231+
57232+ start = ELF_PAGEALIGN(elf_brk);
57233+ size = PAGE_SIZE + ((pax_get_random_long() & ((1UL << 22) - 1UL)) << 4);
57234+ flags = MAP_FIXED | MAP_PRIVATE;
57235+ vm_flags = VM_DONTEXPAND | VM_DONTDUMP;
57236+
57237+ down_write(&current->mm->mmap_sem);
57238+ start = get_unmapped_area(NULL, start, PAGE_ALIGN(size), 0, flags);
57239+ retval = -ENOMEM;
57240+ if (!IS_ERR_VALUE(start) && !find_vma_intersection(current->mm, start, start + size + PAGE_SIZE)) {
57241+// if (current->personality & ADDR_NO_RANDOMIZE)
57242+// vm_flags |= VM_READ | VM_MAYREAD;
57243+ start = mmap_region(NULL, start, PAGE_ALIGN(size), vm_flags, 0);
57244+ retval = IS_ERR_VALUE(start) ? start : 0;
57245+ }
57246+ up_write(&current->mm->mmap_sem);
57247+ if (retval == 0)
57248+ retval = set_brk(start + size, start + size + PAGE_SIZE);
57249+ if (retval < 0) {
57250+ send_sig(SIGKILL, current, 0);
57251+ goto out_free_dentry;
57252+ }
57253+ }
57254+#endif
57255+
57256 if (elf_interpreter) {
57257- unsigned long interp_map_addr = 0;
57258-
57259 elf_entry = load_elf_interp(&loc->interp_elf_ex,
57260 interpreter,
57261- &interp_map_addr,
57262 load_bias);
57263 if (!IS_ERR((void *)elf_entry)) {
57264 /*
57265@@ -1119,7 +1598,7 @@ static bool always_dump_vma(struct vm_area_struct *vma)
57266 * Decide what to dump of a segment, part, all or none.
57267 */
57268 static unsigned long vma_dump_size(struct vm_area_struct *vma,
57269- unsigned long mm_flags)
57270+ unsigned long mm_flags, long signr)
57271 {
57272 #define FILTER(type) (mm_flags & (1UL << MMF_DUMP_##type))
57273
57274@@ -1157,7 +1636,7 @@ static unsigned long vma_dump_size(struct vm_area_struct *vma,
57275 if (vma->vm_file == NULL)
57276 return 0;
57277
57278- if (FILTER(MAPPED_PRIVATE))
57279+ if (signr == SIGKILL || FILTER(MAPPED_PRIVATE))
57280 goto whole;
57281
57282 /*
57283@@ -1364,9 +1843,9 @@ static void fill_auxv_note(struct memelfnote *note, struct mm_struct *mm)
57284 {
57285 elf_addr_t *auxv = (elf_addr_t *) mm->saved_auxv;
57286 int i = 0;
57287- do
57288+ do {
57289 i += 2;
57290- while (auxv[i - 2] != AT_NULL);
57291+ } while (auxv[i - 2] != AT_NULL);
57292 fill_note(note, "CORE", NT_AUXV, i * sizeof(elf_addr_t), auxv);
57293 }
57294
57295@@ -1375,7 +1854,7 @@ static void fill_siginfo_note(struct memelfnote *note, user_siginfo_t *csigdata,
57296 {
57297 mm_segment_t old_fs = get_fs();
57298 set_fs(KERNEL_DS);
57299- copy_siginfo_to_user((user_siginfo_t __user *) csigdata, siginfo);
57300+ copy_siginfo_to_user((user_siginfo_t __force_user *) csigdata, siginfo);
57301 set_fs(old_fs);
57302 fill_note(note, "CORE", NT_SIGINFO, sizeof(*csigdata), csigdata);
57303 }
57304@@ -1999,14 +2478,14 @@ static void fill_extnum_info(struct elfhdr *elf, struct elf_shdr *shdr4extnum,
57305 }
57306
57307 static size_t elf_core_vma_data_size(struct vm_area_struct *gate_vma,
57308- unsigned long mm_flags)
57309+ struct coredump_params *cprm)
57310 {
57311 struct vm_area_struct *vma;
57312 size_t size = 0;
57313
57314 for (vma = first_vma(current, gate_vma); vma != NULL;
57315 vma = next_vma(vma, gate_vma))
57316- size += vma_dump_size(vma, mm_flags);
57317+ size += vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
57318 return size;
57319 }
57320
57321@@ -2097,7 +2576,7 @@ static int elf_core_dump(struct coredump_params *cprm)
57322
57323 dataoff = offset = roundup(offset, ELF_EXEC_PAGESIZE);
57324
57325- offset += elf_core_vma_data_size(gate_vma, cprm->mm_flags);
57326+ offset += elf_core_vma_data_size(gate_vma, cprm);
57327 offset += elf_core_extra_data_size();
57328 e_shoff = offset;
57329
57330@@ -2125,7 +2604,7 @@ static int elf_core_dump(struct coredump_params *cprm)
57331 phdr.p_offset = offset;
57332 phdr.p_vaddr = vma->vm_start;
57333 phdr.p_paddr = 0;
57334- phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags);
57335+ phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
57336 phdr.p_memsz = vma->vm_end - vma->vm_start;
57337 offset += phdr.p_filesz;
57338 phdr.p_flags = vma->vm_flags & VM_READ ? PF_R : 0;
57339@@ -2158,7 +2637,7 @@ static int elf_core_dump(struct coredump_params *cprm)
57340 unsigned long addr;
57341 unsigned long end;
57342
57343- end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags);
57344+ end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
57345
57346 for (addr = vma->vm_start; addr < end; addr += PAGE_SIZE) {
57347 struct page *page;
57348@@ -2199,6 +2678,167 @@ out:
57349
57350 #endif /* CONFIG_ELF_CORE */
57351
57352+#ifdef CONFIG_PAX_MPROTECT
57353+/* PaX: non-PIC ELF libraries need relocations on their executable segments
57354+ * therefore we'll grant them VM_MAYWRITE once during their life. Similarly
57355+ * we'll remove VM_MAYWRITE for good on RELRO segments.
57356+ *
57357+ * The checks favour ld-linux.so behaviour which operates on a per ELF segment
57358+ * basis because we want to allow the common case and not the special ones.
57359+ */
57360+static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags)
57361+{
57362+ struct elfhdr elf_h;
57363+ struct elf_phdr elf_p;
57364+ unsigned long i;
57365+ unsigned long oldflags;
57366+ bool is_textrel_rw, is_textrel_rx, is_relro;
57367+
57368+ if (!(vma->vm_mm->pax_flags & MF_PAX_MPROTECT) || !vma->vm_file)
57369+ return;
57370+
57371+ oldflags = vma->vm_flags & (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ);
57372+ newflags &= VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ;
57373+
57374+#ifdef CONFIG_PAX_ELFRELOCS
57375+ /* possible TEXTREL */
57376+ is_textrel_rw = !vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYREAD | VM_EXEC | VM_READ) && newflags == (VM_WRITE | VM_READ);
57377+ is_textrel_rx = vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_WRITE | VM_READ) && newflags == (VM_EXEC | VM_READ);
57378+#else
57379+ is_textrel_rw = false;
57380+ is_textrel_rx = false;
57381+#endif
57382+
57383+ /* possible RELRO */
57384+ is_relro = vma->anon_vma && oldflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ) && newflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ);
57385+
57386+ if (!is_textrel_rw && !is_textrel_rx && !is_relro)
57387+ return;
57388+
57389+ if (sizeof(elf_h) != kernel_read(vma->vm_file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
57390+ memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
57391+
57392+#ifdef CONFIG_PAX_ETEXECRELOCS
57393+ ((is_textrel_rw || is_textrel_rx) && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
57394+#else
57395+ ((is_textrel_rw || is_textrel_rx) && elf_h.e_type != ET_DYN) ||
57396+#endif
57397+
57398+ (is_relro && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
57399+ !elf_check_arch(&elf_h) ||
57400+ elf_h.e_phentsize != sizeof(struct elf_phdr) ||
57401+ elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
57402+ return;
57403+
57404+ for (i = 0UL; i < elf_h.e_phnum; i++) {
57405+ if (sizeof(elf_p) != kernel_read(vma->vm_file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
57406+ return;
57407+ switch (elf_p.p_type) {
57408+ case PT_DYNAMIC:
57409+ if (!is_textrel_rw && !is_textrel_rx)
57410+ continue;
57411+ i = 0UL;
57412+ while ((i+1) * sizeof(elf_dyn) <= elf_p.p_filesz) {
57413+ elf_dyn dyn;
57414+
57415+ if (sizeof(dyn) != kernel_read(vma->vm_file, elf_p.p_offset + i*sizeof(dyn), (char *)&dyn, sizeof(dyn)))
57416+ break;
57417+ if (dyn.d_tag == DT_NULL)
57418+ break;
57419+ if (dyn.d_tag == DT_TEXTREL || (dyn.d_tag == DT_FLAGS && (dyn.d_un.d_val & DF_TEXTREL))) {
57420+ gr_log_textrel(vma);
57421+ if (is_textrel_rw)
57422+ vma->vm_flags |= VM_MAYWRITE;
57423+ else
57424+ /* PaX: disallow write access after relocs are done, hopefully noone else needs it... */
57425+ vma->vm_flags &= ~VM_MAYWRITE;
57426+ break;
57427+ }
57428+ i++;
57429+ }
57430+ is_textrel_rw = false;
57431+ is_textrel_rx = false;
57432+ continue;
57433+
57434+ case PT_GNU_RELRO:
57435+ if (!is_relro)
57436+ continue;
57437+ if ((elf_p.p_offset >> PAGE_SHIFT) == vma->vm_pgoff && ELF_PAGEALIGN(elf_p.p_memsz) == vma->vm_end - vma->vm_start)
57438+ vma->vm_flags &= ~VM_MAYWRITE;
57439+ is_relro = false;
57440+ continue;
57441+
57442+#ifdef CONFIG_PAX_PT_PAX_FLAGS
57443+ case PT_PAX_FLAGS: {
57444+ const char *msg_mprotect = "", *msg_emutramp = "";
57445+ char *buffer_lib, *buffer_exe;
57446+
57447+ if (elf_p.p_flags & PF_NOMPROTECT)
57448+ msg_mprotect = "MPROTECT disabled";
57449+
57450+#ifdef CONFIG_PAX_EMUTRAMP
57451+ if (!(vma->vm_mm->pax_flags & MF_PAX_EMUTRAMP) && !(elf_p.p_flags & PF_NOEMUTRAMP))
57452+ msg_emutramp = "EMUTRAMP enabled";
57453+#endif
57454+
57455+ if (!msg_mprotect[0] && !msg_emutramp[0])
57456+ continue;
57457+
57458+ if (!printk_ratelimit())
57459+ continue;
57460+
57461+ buffer_lib = (char *)__get_free_page(GFP_KERNEL);
57462+ buffer_exe = (char *)__get_free_page(GFP_KERNEL);
57463+ if (buffer_lib && buffer_exe) {
57464+ char *path_lib, *path_exe;
57465+
57466+ path_lib = pax_get_path(&vma->vm_file->f_path, buffer_lib, PAGE_SIZE);
57467+ path_exe = pax_get_path(&vma->vm_mm->exe_file->f_path, buffer_exe, PAGE_SIZE);
57468+
57469+ pr_info("PAX: %s wants %s%s%s on %s\n", path_lib, msg_mprotect,
57470+ (msg_mprotect[0] && msg_emutramp[0] ? " and " : ""), msg_emutramp, path_exe);
57471+
57472+ }
57473+ free_page((unsigned long)buffer_exe);
57474+ free_page((unsigned long)buffer_lib);
57475+ continue;
57476+ }
57477+#endif
57478+
57479+ }
57480+ }
57481+}
57482+#endif
57483+
57484+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
57485+
57486+extern int grsec_enable_log_rwxmaps;
57487+
57488+static void elf_handle_mmap(struct file *file)
57489+{
57490+ struct elfhdr elf_h;
57491+ struct elf_phdr elf_p;
57492+ unsigned long i;
57493+
57494+ if (!grsec_enable_log_rwxmaps)
57495+ return;
57496+
57497+ if (sizeof(elf_h) != kernel_read(file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
57498+ memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
57499+ (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC) || !elf_check_arch(&elf_h) ||
57500+ elf_h.e_phentsize != sizeof(struct elf_phdr) ||
57501+ elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
57502+ return;
57503+
57504+ for (i = 0UL; i < elf_h.e_phnum; i++) {
57505+ if (sizeof(elf_p) != kernel_read(file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
57506+ return;
57507+ if (elf_p.p_type == PT_GNU_STACK && (elf_p.p_flags & PF_X))
57508+ gr_log_ptgnustack(file);
57509+ }
57510+}
57511+#endif
57512+
57513 static int __init init_elf_binfmt(void)
57514 {
57515 register_binfmt(&elf_format);
57516diff --git a/fs/bio.c b/fs/bio.c
57517index 8754e7b..0669094 100644
57518--- a/fs/bio.c
57519+++ b/fs/bio.c
57520@@ -1145,7 +1145,7 @@ struct bio *bio_copy_user_iov(struct request_queue *q,
57521 /*
57522 * Overflow, abort
57523 */
57524- if (end < start)
57525+ if (end < start || end - start > INT_MAX - nr_pages)
57526 return ERR_PTR(-EINVAL);
57527
57528 nr_pages += end - start;
57529@@ -1279,7 +1279,7 @@ static struct bio *__bio_map_user_iov(struct request_queue *q,
57530 /*
57531 * Overflow, abort
57532 */
57533- if (end < start)
57534+ if (end < start || end - start > INT_MAX - nr_pages)
57535 return ERR_PTR(-EINVAL);
57536
57537 nr_pages += end - start;
57538@@ -1541,7 +1541,7 @@ static void bio_copy_kern_endio(struct bio *bio, int err)
57539 const int read = bio_data_dir(bio) == READ;
57540 struct bio_map_data *bmd = bio->bi_private;
57541 int i;
57542- char *p = bmd->sgvecs[0].iov_base;
57543+ char *p = (char __force_kernel *)bmd->sgvecs[0].iov_base;
57544
57545 bio_for_each_segment_all(bvec, bio, i) {
57546 char *addr = page_address(bvec->bv_page);
57547diff --git a/fs/block_dev.c b/fs/block_dev.c
57548index 1e86823..8e34695 100644
57549--- a/fs/block_dev.c
57550+++ b/fs/block_dev.c
57551@@ -637,7 +637,7 @@ static bool bd_may_claim(struct block_device *bdev, struct block_device *whole,
57552 else if (bdev->bd_contains == bdev)
57553 return true; /* is a whole device which isn't held */
57554
57555- else if (whole->bd_holder == bd_may_claim)
57556+ else if (whole->bd_holder == (void *)bd_may_claim)
57557 return true; /* is a partition of a device that is being partitioned */
57558 else if (whole->bd_holder != NULL)
57559 return false; /* is a partition of a held device */
57560diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
57561index cbd3a7d..c6a2881 100644
57562--- a/fs/btrfs/ctree.c
57563+++ b/fs/btrfs/ctree.c
57564@@ -1216,9 +1216,12 @@ static noinline int __btrfs_cow_block(struct btrfs_trans_handle *trans,
57565 free_extent_buffer(buf);
57566 add_root_to_dirty_list(root);
57567 } else {
57568- if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID)
57569- parent_start = parent->start;
57570- else
57571+ if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) {
57572+ if (parent)
57573+ parent_start = parent->start;
57574+ else
57575+ parent_start = 0;
57576+ } else
57577 parent_start = 0;
57578
57579 WARN_ON(trans->transid != btrfs_header_generation(parent));
57580diff --git a/fs/btrfs/delayed-inode.c b/fs/btrfs/delayed-inode.c
57581index 451b00c..a2cccee 100644
57582--- a/fs/btrfs/delayed-inode.c
57583+++ b/fs/btrfs/delayed-inode.c
57584@@ -459,7 +459,7 @@ static int __btrfs_add_delayed_deletion_item(struct btrfs_delayed_node *node,
57585
57586 static void finish_one_item(struct btrfs_delayed_root *delayed_root)
57587 {
57588- int seq = atomic_inc_return(&delayed_root->items_seq);
57589+ int seq = atomic_inc_return_unchecked(&delayed_root->items_seq);
57590 if ((atomic_dec_return(&delayed_root->items) <
57591 BTRFS_DELAYED_BACKGROUND || seq % BTRFS_DELAYED_BATCH == 0) &&
57592 waitqueue_active(&delayed_root->wait))
57593@@ -1409,7 +1409,7 @@ void btrfs_assert_delayed_root_empty(struct btrfs_root *root)
57594
57595 static int could_end_wait(struct btrfs_delayed_root *delayed_root, int seq)
57596 {
57597- int val = atomic_read(&delayed_root->items_seq);
57598+ int val = atomic_read_unchecked(&delayed_root->items_seq);
57599
57600 if (val < seq || val >= seq + BTRFS_DELAYED_BATCH)
57601 return 1;
57602@@ -1433,7 +1433,7 @@ void btrfs_balance_delayed_items(struct btrfs_root *root)
57603 int seq;
57604 int ret;
57605
57606- seq = atomic_read(&delayed_root->items_seq);
57607+ seq = atomic_read_unchecked(&delayed_root->items_seq);
57608
57609 ret = btrfs_wq_run_delayed_node(delayed_root, root, 0);
57610 if (ret)
57611diff --git a/fs/btrfs/delayed-inode.h b/fs/btrfs/delayed-inode.h
57612index f70119f..ab5894d 100644
57613--- a/fs/btrfs/delayed-inode.h
57614+++ b/fs/btrfs/delayed-inode.h
57615@@ -43,7 +43,7 @@ struct btrfs_delayed_root {
57616 */
57617 struct list_head prepare_list;
57618 atomic_t items; /* for delayed items */
57619- atomic_t items_seq; /* for delayed items */
57620+ atomic_unchecked_t items_seq; /* for delayed items */
57621 int nodes; /* for delayed nodes */
57622 wait_queue_head_t wait;
57623 };
57624@@ -90,7 +90,7 @@ static inline void btrfs_init_delayed_root(
57625 struct btrfs_delayed_root *delayed_root)
57626 {
57627 atomic_set(&delayed_root->items, 0);
57628- atomic_set(&delayed_root->items_seq, 0);
57629+ atomic_set_unchecked(&delayed_root->items_seq, 0);
57630 delayed_root->nodes = 0;
57631 spin_lock_init(&delayed_root->lock);
57632 init_waitqueue_head(&delayed_root->wait);
57633diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
57634index a6d8efa..2f062cf 100644
57635--- a/fs/btrfs/ioctl.c
57636+++ b/fs/btrfs/ioctl.c
57637@@ -3491,9 +3491,12 @@ static long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
57638 for (i = 0; i < num_types; i++) {
57639 struct btrfs_space_info *tmp;
57640
57641+ /* Don't copy in more than we allocated */
57642 if (!slot_count)
57643 break;
57644
57645+ slot_count--;
57646+
57647 info = NULL;
57648 rcu_read_lock();
57649 list_for_each_entry_rcu(tmp, &root->fs_info->space_info,
57650@@ -3515,10 +3518,7 @@ static long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
57651 memcpy(dest, &space, sizeof(space));
57652 dest++;
57653 space_args.total_spaces++;
57654- slot_count--;
57655 }
57656- if (!slot_count)
57657- break;
57658 }
57659 up_read(&info->groups_sem);
57660 }
57661diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
57662index d04db81..96e54f1 100644
57663--- a/fs/btrfs/super.c
57664+++ b/fs/btrfs/super.c
57665@@ -268,7 +268,7 @@ void __btrfs_abort_transaction(struct btrfs_trans_handle *trans,
57666 function, line, errstr);
57667 return;
57668 }
57669- ACCESS_ONCE(trans->transaction->aborted) = errno;
57670+ ACCESS_ONCE_RW(trans->transaction->aborted) = errno;
57671 /* Wake up anybody who may be waiting on this transaction */
57672 wake_up(&root->fs_info->transaction_wait);
57673 wake_up(&root->fs_info->transaction_blocked_wait);
57674diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c
57675index 865f4cf..f321e86 100644
57676--- a/fs/btrfs/sysfs.c
57677+++ b/fs/btrfs/sysfs.c
57678@@ -436,7 +436,7 @@ static int addrm_unknown_feature_attrs(struct btrfs_fs_info *fs_info, bool add)
57679 for (set = 0; set < FEAT_MAX; set++) {
57680 int i;
57681 struct attribute *attrs[2];
57682- struct attribute_group agroup = {
57683+ attribute_group_no_const agroup = {
57684 .name = "features",
57685 .attrs = attrs,
57686 };
57687diff --git a/fs/buffer.c b/fs/buffer.c
57688index 27265a8..289f488 100644
57689--- a/fs/buffer.c
57690+++ b/fs/buffer.c
57691@@ -3428,7 +3428,7 @@ void __init buffer_init(void)
57692 bh_cachep = kmem_cache_create("buffer_head",
57693 sizeof(struct buffer_head), 0,
57694 (SLAB_RECLAIM_ACCOUNT|SLAB_PANIC|
57695- SLAB_MEM_SPREAD),
57696+ SLAB_MEM_SPREAD|SLAB_NO_SANITIZE),
57697 NULL);
57698
57699 /*
57700diff --git a/fs/cachefiles/bind.c b/fs/cachefiles/bind.c
57701index 622f469..e8d2d55 100644
57702--- a/fs/cachefiles/bind.c
57703+++ b/fs/cachefiles/bind.c
57704@@ -39,13 +39,11 @@ int cachefiles_daemon_bind(struct cachefiles_cache *cache, char *args)
57705 args);
57706
57707 /* start by checking things over */
57708- ASSERT(cache->fstop_percent >= 0 &&
57709- cache->fstop_percent < cache->fcull_percent &&
57710+ ASSERT(cache->fstop_percent < cache->fcull_percent &&
57711 cache->fcull_percent < cache->frun_percent &&
57712 cache->frun_percent < 100);
57713
57714- ASSERT(cache->bstop_percent >= 0 &&
57715- cache->bstop_percent < cache->bcull_percent &&
57716+ ASSERT(cache->bstop_percent < cache->bcull_percent &&
57717 cache->bcull_percent < cache->brun_percent &&
57718 cache->brun_percent < 100);
57719
57720diff --git a/fs/cachefiles/daemon.c b/fs/cachefiles/daemon.c
57721index 0a1467b..6a53245 100644
57722--- a/fs/cachefiles/daemon.c
57723+++ b/fs/cachefiles/daemon.c
57724@@ -196,7 +196,7 @@ static ssize_t cachefiles_daemon_read(struct file *file, char __user *_buffer,
57725 if (n > buflen)
57726 return -EMSGSIZE;
57727
57728- if (copy_to_user(_buffer, buffer, n) != 0)
57729+ if (n > sizeof(buffer) || copy_to_user(_buffer, buffer, n) != 0)
57730 return -EFAULT;
57731
57732 return n;
57733@@ -222,7 +222,7 @@ static ssize_t cachefiles_daemon_write(struct file *file,
57734 if (test_bit(CACHEFILES_DEAD, &cache->flags))
57735 return -EIO;
57736
57737- if (datalen < 0 || datalen > PAGE_SIZE - 1)
57738+ if (datalen > PAGE_SIZE - 1)
57739 return -EOPNOTSUPP;
57740
57741 /* drag the command string into the kernel so we can parse it */
57742@@ -386,7 +386,7 @@ static int cachefiles_daemon_fstop(struct cachefiles_cache *cache, char *args)
57743 if (args[0] != '%' || args[1] != '\0')
57744 return -EINVAL;
57745
57746- if (fstop < 0 || fstop >= cache->fcull_percent)
57747+ if (fstop >= cache->fcull_percent)
57748 return cachefiles_daemon_range_error(cache, args);
57749
57750 cache->fstop_percent = fstop;
57751@@ -458,7 +458,7 @@ static int cachefiles_daemon_bstop(struct cachefiles_cache *cache, char *args)
57752 if (args[0] != '%' || args[1] != '\0')
57753 return -EINVAL;
57754
57755- if (bstop < 0 || bstop >= cache->bcull_percent)
57756+ if (bstop >= cache->bcull_percent)
57757 return cachefiles_daemon_range_error(cache, args);
57758
57759 cache->bstop_percent = bstop;
57760diff --git a/fs/cachefiles/internal.h b/fs/cachefiles/internal.h
57761index 5349473..d6c0b93 100644
57762--- a/fs/cachefiles/internal.h
57763+++ b/fs/cachefiles/internal.h
57764@@ -59,7 +59,7 @@ struct cachefiles_cache {
57765 wait_queue_head_t daemon_pollwq; /* poll waitqueue for daemon */
57766 struct rb_root active_nodes; /* active nodes (can't be culled) */
57767 rwlock_t active_lock; /* lock for active_nodes */
57768- atomic_t gravecounter; /* graveyard uniquifier */
57769+ atomic_unchecked_t gravecounter; /* graveyard uniquifier */
57770 unsigned frun_percent; /* when to stop culling (% files) */
57771 unsigned fcull_percent; /* when to start culling (% files) */
57772 unsigned fstop_percent; /* when to stop allocating (% files) */
57773@@ -171,19 +171,19 @@ extern int cachefiles_check_in_use(struct cachefiles_cache *cache,
57774 * proc.c
57775 */
57776 #ifdef CONFIG_CACHEFILES_HISTOGRAM
57777-extern atomic_t cachefiles_lookup_histogram[HZ];
57778-extern atomic_t cachefiles_mkdir_histogram[HZ];
57779-extern atomic_t cachefiles_create_histogram[HZ];
57780+extern atomic_unchecked_t cachefiles_lookup_histogram[HZ];
57781+extern atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
57782+extern atomic_unchecked_t cachefiles_create_histogram[HZ];
57783
57784 extern int __init cachefiles_proc_init(void);
57785 extern void cachefiles_proc_cleanup(void);
57786 static inline
57787-void cachefiles_hist(atomic_t histogram[], unsigned long start_jif)
57788+void cachefiles_hist(atomic_unchecked_t histogram[], unsigned long start_jif)
57789 {
57790 unsigned long jif = jiffies - start_jif;
57791 if (jif >= HZ)
57792 jif = HZ - 1;
57793- atomic_inc(&histogram[jif]);
57794+ atomic_inc_unchecked(&histogram[jif]);
57795 }
57796
57797 #else
57798diff --git a/fs/cachefiles/namei.c b/fs/cachefiles/namei.c
57799index ca65f39..48921e3 100644
57800--- a/fs/cachefiles/namei.c
57801+++ b/fs/cachefiles/namei.c
57802@@ -317,7 +317,7 @@ try_again:
57803 /* first step is to make up a grave dentry in the graveyard */
57804 sprintf(nbuffer, "%08x%08x",
57805 (uint32_t) get_seconds(),
57806- (uint32_t) atomic_inc_return(&cache->gravecounter));
57807+ (uint32_t) atomic_inc_return_unchecked(&cache->gravecounter));
57808
57809 /* do the multiway lock magic */
57810 trap = lock_rename(cache->graveyard, dir);
57811diff --git a/fs/cachefiles/proc.c b/fs/cachefiles/proc.c
57812index eccd339..4c1d995 100644
57813--- a/fs/cachefiles/proc.c
57814+++ b/fs/cachefiles/proc.c
57815@@ -14,9 +14,9 @@
57816 #include <linux/seq_file.h>
57817 #include "internal.h"
57818
57819-atomic_t cachefiles_lookup_histogram[HZ];
57820-atomic_t cachefiles_mkdir_histogram[HZ];
57821-atomic_t cachefiles_create_histogram[HZ];
57822+atomic_unchecked_t cachefiles_lookup_histogram[HZ];
57823+atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
57824+atomic_unchecked_t cachefiles_create_histogram[HZ];
57825
57826 /*
57827 * display the latency histogram
57828@@ -35,9 +35,9 @@ static int cachefiles_histogram_show(struct seq_file *m, void *v)
57829 return 0;
57830 default:
57831 index = (unsigned long) v - 3;
57832- x = atomic_read(&cachefiles_lookup_histogram[index]);
57833- y = atomic_read(&cachefiles_mkdir_histogram[index]);
57834- z = atomic_read(&cachefiles_create_histogram[index]);
57835+ x = atomic_read_unchecked(&cachefiles_lookup_histogram[index]);
57836+ y = atomic_read_unchecked(&cachefiles_mkdir_histogram[index]);
57837+ z = atomic_read_unchecked(&cachefiles_create_histogram[index]);
57838 if (x == 0 && y == 0 && z == 0)
57839 return 0;
57840
57841diff --git a/fs/cachefiles/rdwr.c b/fs/cachefiles/rdwr.c
57842index ebaff36..7e3ea26 100644
57843--- a/fs/cachefiles/rdwr.c
57844+++ b/fs/cachefiles/rdwr.c
57845@@ -950,7 +950,7 @@ int cachefiles_write_page(struct fscache_storage *op, struct page *page)
57846 old_fs = get_fs();
57847 set_fs(KERNEL_DS);
57848 ret = file->f_op->write(
57849- file, (const void __user *) data, len, &pos);
57850+ file, (const void __force_user *) data, len, &pos);
57851 set_fs(old_fs);
57852 kunmap(page);
57853 file_end_write(file);
57854diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c
57855index 45eda6d..9126f7f 100644
57856--- a/fs/ceph/dir.c
57857+++ b/fs/ceph/dir.c
57858@@ -248,7 +248,7 @@ static int ceph_readdir(struct file *file, struct dir_context *ctx)
57859 struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
57860 struct ceph_mds_client *mdsc = fsc->mdsc;
57861 unsigned frag = fpos_frag(ctx->pos);
57862- int off = fpos_off(ctx->pos);
57863+ unsigned int off = fpos_off(ctx->pos);
57864 int err;
57865 u32 ftype;
57866 struct ceph_mds_reply_info_parsed *rinfo;
57867diff --git a/fs/ceph/super.c b/fs/ceph/super.c
57868index 10a4ccb..92dbc5e 100644
57869--- a/fs/ceph/super.c
57870+++ b/fs/ceph/super.c
57871@@ -895,7 +895,7 @@ static int ceph_compare_super(struct super_block *sb, void *data)
57872 /*
57873 * construct our own bdi so we can control readahead, etc.
57874 */
57875-static atomic_long_t bdi_seq = ATOMIC_LONG_INIT(0);
57876+static atomic_long_unchecked_t bdi_seq = ATOMIC_LONG_INIT(0);
57877
57878 static int ceph_register_bdi(struct super_block *sb,
57879 struct ceph_fs_client *fsc)
57880@@ -912,7 +912,7 @@ static int ceph_register_bdi(struct super_block *sb,
57881 default_backing_dev_info.ra_pages;
57882
57883 err = bdi_register(&fsc->backing_dev_info, NULL, "ceph-%ld",
57884- atomic_long_inc_return(&bdi_seq));
57885+ atomic_long_inc_return_unchecked(&bdi_seq));
57886 if (!err)
57887 sb->s_bdi = &fsc->backing_dev_info;
57888 return err;
57889diff --git a/fs/cifs/cifs_debug.c b/fs/cifs/cifs_debug.c
57890index f3ac415..3d2420c 100644
57891--- a/fs/cifs/cifs_debug.c
57892+++ b/fs/cifs/cifs_debug.c
57893@@ -286,8 +286,8 @@ static ssize_t cifs_stats_proc_write(struct file *file,
57894
57895 if (c == '1' || c == 'y' || c == 'Y' || c == '0') {
57896 #ifdef CONFIG_CIFS_STATS2
57897- atomic_set(&totBufAllocCount, 0);
57898- atomic_set(&totSmBufAllocCount, 0);
57899+ atomic_set_unchecked(&totBufAllocCount, 0);
57900+ atomic_set_unchecked(&totSmBufAllocCount, 0);
57901 #endif /* CONFIG_CIFS_STATS2 */
57902 spin_lock(&cifs_tcp_ses_lock);
57903 list_for_each(tmp1, &cifs_tcp_ses_list) {
57904@@ -300,7 +300,7 @@ static ssize_t cifs_stats_proc_write(struct file *file,
57905 tcon = list_entry(tmp3,
57906 struct cifs_tcon,
57907 tcon_list);
57908- atomic_set(&tcon->num_smbs_sent, 0);
57909+ atomic_set_unchecked(&tcon->num_smbs_sent, 0);
57910 if (server->ops->clear_stats)
57911 server->ops->clear_stats(tcon);
57912 }
57913@@ -332,8 +332,8 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
57914 smBufAllocCount.counter, cifs_min_small);
57915 #ifdef CONFIG_CIFS_STATS2
57916 seq_printf(m, "Total Large %d Small %d Allocations\n",
57917- atomic_read(&totBufAllocCount),
57918- atomic_read(&totSmBufAllocCount));
57919+ atomic_read_unchecked(&totBufAllocCount),
57920+ atomic_read_unchecked(&totSmBufAllocCount));
57921 #endif /* CONFIG_CIFS_STATS2 */
57922
57923 seq_printf(m, "Operations (MIDs): %d\n", atomic_read(&midCount));
57924@@ -362,7 +362,7 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
57925 if (tcon->need_reconnect)
57926 seq_puts(m, "\tDISCONNECTED ");
57927 seq_printf(m, "\nSMBs: %d",
57928- atomic_read(&tcon->num_smbs_sent));
57929+ atomic_read_unchecked(&tcon->num_smbs_sent));
57930 if (server->ops->print_stats)
57931 server->ops->print_stats(m, tcon);
57932 }
57933diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
57934index 849f613..eae6dec 100644
57935--- a/fs/cifs/cifsfs.c
57936+++ b/fs/cifs/cifsfs.c
57937@@ -1056,7 +1056,7 @@ cifs_init_request_bufs(void)
57938 */
57939 cifs_req_cachep = kmem_cache_create("cifs_request",
57940 CIFSMaxBufSize + max_hdr_size, 0,
57941- SLAB_HWCACHE_ALIGN, NULL);
57942+ SLAB_HWCACHE_ALIGN | SLAB_USERCOPY, NULL);
57943 if (cifs_req_cachep == NULL)
57944 return -ENOMEM;
57945
57946@@ -1083,7 +1083,7 @@ cifs_init_request_bufs(void)
57947 efficient to alloc 1 per page off the slab compared to 17K (5page)
57948 alloc of large cifs buffers even when page debugging is on */
57949 cifs_sm_req_cachep = kmem_cache_create("cifs_small_rq",
57950- MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN,
57951+ MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN | SLAB_USERCOPY,
57952 NULL);
57953 if (cifs_sm_req_cachep == NULL) {
57954 mempool_destroy(cifs_req_poolp);
57955@@ -1168,8 +1168,8 @@ init_cifs(void)
57956 atomic_set(&bufAllocCount, 0);
57957 atomic_set(&smBufAllocCount, 0);
57958 #ifdef CONFIG_CIFS_STATS2
57959- atomic_set(&totBufAllocCount, 0);
57960- atomic_set(&totSmBufAllocCount, 0);
57961+ atomic_set_unchecked(&totBufAllocCount, 0);
57962+ atomic_set_unchecked(&totSmBufAllocCount, 0);
57963 #endif /* CONFIG_CIFS_STATS2 */
57964
57965 atomic_set(&midCount, 0);
57966diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
57967index c0f3718..6afed7d 100644
57968--- a/fs/cifs/cifsglob.h
57969+++ b/fs/cifs/cifsglob.h
57970@@ -804,35 +804,35 @@ struct cifs_tcon {
57971 __u16 Flags; /* optional support bits */
57972 enum statusEnum tidStatus;
57973 #ifdef CONFIG_CIFS_STATS
57974- atomic_t num_smbs_sent;
57975+ atomic_unchecked_t num_smbs_sent;
57976 union {
57977 struct {
57978- atomic_t num_writes;
57979- atomic_t num_reads;
57980- atomic_t num_flushes;
57981- atomic_t num_oplock_brks;
57982- atomic_t num_opens;
57983- atomic_t num_closes;
57984- atomic_t num_deletes;
57985- atomic_t num_mkdirs;
57986- atomic_t num_posixopens;
57987- atomic_t num_posixmkdirs;
57988- atomic_t num_rmdirs;
57989- atomic_t num_renames;
57990- atomic_t num_t2renames;
57991- atomic_t num_ffirst;
57992- atomic_t num_fnext;
57993- atomic_t num_fclose;
57994- atomic_t num_hardlinks;
57995- atomic_t num_symlinks;
57996- atomic_t num_locks;
57997- atomic_t num_acl_get;
57998- atomic_t num_acl_set;
57999+ atomic_unchecked_t num_writes;
58000+ atomic_unchecked_t num_reads;
58001+ atomic_unchecked_t num_flushes;
58002+ atomic_unchecked_t num_oplock_brks;
58003+ atomic_unchecked_t num_opens;
58004+ atomic_unchecked_t num_closes;
58005+ atomic_unchecked_t num_deletes;
58006+ atomic_unchecked_t num_mkdirs;
58007+ atomic_unchecked_t num_posixopens;
58008+ atomic_unchecked_t num_posixmkdirs;
58009+ atomic_unchecked_t num_rmdirs;
58010+ atomic_unchecked_t num_renames;
58011+ atomic_unchecked_t num_t2renames;
58012+ atomic_unchecked_t num_ffirst;
58013+ atomic_unchecked_t num_fnext;
58014+ atomic_unchecked_t num_fclose;
58015+ atomic_unchecked_t num_hardlinks;
58016+ atomic_unchecked_t num_symlinks;
58017+ atomic_unchecked_t num_locks;
58018+ atomic_unchecked_t num_acl_get;
58019+ atomic_unchecked_t num_acl_set;
58020 } cifs_stats;
58021 #ifdef CONFIG_CIFS_SMB2
58022 struct {
58023- atomic_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
58024- atomic_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
58025+ atomic_unchecked_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
58026+ atomic_unchecked_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
58027 } smb2_stats;
58028 #endif /* CONFIG_CIFS_SMB2 */
58029 } stats;
58030@@ -1162,7 +1162,7 @@ convert_delimiter(char *path, char delim)
58031 }
58032
58033 #ifdef CONFIG_CIFS_STATS
58034-#define cifs_stats_inc atomic_inc
58035+#define cifs_stats_inc atomic_inc_unchecked
58036
58037 static inline void cifs_stats_bytes_written(struct cifs_tcon *tcon,
58038 unsigned int bytes)
58039@@ -1528,8 +1528,8 @@ GLOBAL_EXTERN atomic_t tconInfoReconnectCount;
58040 /* Various Debug counters */
58041 GLOBAL_EXTERN atomic_t bufAllocCount; /* current number allocated */
58042 #ifdef CONFIG_CIFS_STATS2
58043-GLOBAL_EXTERN atomic_t totBufAllocCount; /* total allocated over all time */
58044-GLOBAL_EXTERN atomic_t totSmBufAllocCount;
58045+GLOBAL_EXTERN atomic_unchecked_t totBufAllocCount; /* total allocated over all time */
58046+GLOBAL_EXTERN atomic_unchecked_t totSmBufAllocCount;
58047 #endif
58048 GLOBAL_EXTERN atomic_t smBufAllocCount;
58049 GLOBAL_EXTERN atomic_t midCount;
58050diff --git a/fs/cifs/file.c b/fs/cifs/file.c
58051index 834fce7..8a314b5 100644
58052--- a/fs/cifs/file.c
58053+++ b/fs/cifs/file.c
58054@@ -1900,10 +1900,14 @@ static int cifs_writepages(struct address_space *mapping,
58055 index = mapping->writeback_index; /* Start from prev offset */
58056 end = -1;
58057 } else {
58058- index = wbc->range_start >> PAGE_CACHE_SHIFT;
58059- end = wbc->range_end >> PAGE_CACHE_SHIFT;
58060- if (wbc->range_start == 0 && wbc->range_end == LLONG_MAX)
58061+ if (wbc->range_start == 0 && wbc->range_end == LLONG_MAX) {
58062 range_whole = true;
58063+ index = 0;
58064+ end = ULONG_MAX;
58065+ } else {
58066+ index = wbc->range_start >> PAGE_CACHE_SHIFT;
58067+ end = wbc->range_end >> PAGE_CACHE_SHIFT;
58068+ }
58069 scanned = true;
58070 }
58071 retry:
58072diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c
58073index 2f9f379..43f8025 100644
58074--- a/fs/cifs/misc.c
58075+++ b/fs/cifs/misc.c
58076@@ -170,7 +170,7 @@ cifs_buf_get(void)
58077 memset(ret_buf, 0, buf_size + 3);
58078 atomic_inc(&bufAllocCount);
58079 #ifdef CONFIG_CIFS_STATS2
58080- atomic_inc(&totBufAllocCount);
58081+ atomic_inc_unchecked(&totBufAllocCount);
58082 #endif /* CONFIG_CIFS_STATS2 */
58083 }
58084
58085@@ -205,7 +205,7 @@ cifs_small_buf_get(void)
58086 /* memset(ret_buf, 0, sizeof(struct smb_hdr) + 27);*/
58087 atomic_inc(&smBufAllocCount);
58088 #ifdef CONFIG_CIFS_STATS2
58089- atomic_inc(&totSmBufAllocCount);
58090+ atomic_inc_unchecked(&totSmBufAllocCount);
58091 #endif /* CONFIG_CIFS_STATS2 */
58092
58093 }
58094diff --git a/fs/cifs/smb1ops.c b/fs/cifs/smb1ops.c
58095index 526fb89..ecdbf5a 100644
58096--- a/fs/cifs/smb1ops.c
58097+++ b/fs/cifs/smb1ops.c
58098@@ -616,27 +616,27 @@ static void
58099 cifs_clear_stats(struct cifs_tcon *tcon)
58100 {
58101 #ifdef CONFIG_CIFS_STATS
58102- atomic_set(&tcon->stats.cifs_stats.num_writes, 0);
58103- atomic_set(&tcon->stats.cifs_stats.num_reads, 0);
58104- atomic_set(&tcon->stats.cifs_stats.num_flushes, 0);
58105- atomic_set(&tcon->stats.cifs_stats.num_oplock_brks, 0);
58106- atomic_set(&tcon->stats.cifs_stats.num_opens, 0);
58107- atomic_set(&tcon->stats.cifs_stats.num_posixopens, 0);
58108- atomic_set(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
58109- atomic_set(&tcon->stats.cifs_stats.num_closes, 0);
58110- atomic_set(&tcon->stats.cifs_stats.num_deletes, 0);
58111- atomic_set(&tcon->stats.cifs_stats.num_mkdirs, 0);
58112- atomic_set(&tcon->stats.cifs_stats.num_rmdirs, 0);
58113- atomic_set(&tcon->stats.cifs_stats.num_renames, 0);
58114- atomic_set(&tcon->stats.cifs_stats.num_t2renames, 0);
58115- atomic_set(&tcon->stats.cifs_stats.num_ffirst, 0);
58116- atomic_set(&tcon->stats.cifs_stats.num_fnext, 0);
58117- atomic_set(&tcon->stats.cifs_stats.num_fclose, 0);
58118- atomic_set(&tcon->stats.cifs_stats.num_hardlinks, 0);
58119- atomic_set(&tcon->stats.cifs_stats.num_symlinks, 0);
58120- atomic_set(&tcon->stats.cifs_stats.num_locks, 0);
58121- atomic_set(&tcon->stats.cifs_stats.num_acl_get, 0);
58122- atomic_set(&tcon->stats.cifs_stats.num_acl_set, 0);
58123+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_writes, 0);
58124+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_reads, 0);
58125+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_flushes, 0);
58126+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_oplock_brks, 0);
58127+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_opens, 0);
58128+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixopens, 0);
58129+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
58130+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_closes, 0);
58131+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_deletes, 0);
58132+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_mkdirs, 0);
58133+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_rmdirs, 0);
58134+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_renames, 0);
58135+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_t2renames, 0);
58136+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_ffirst, 0);
58137+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_fnext, 0);
58138+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_fclose, 0);
58139+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_hardlinks, 0);
58140+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_symlinks, 0);
58141+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_locks, 0);
58142+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_get, 0);
58143+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_set, 0);
58144 #endif
58145 }
58146
58147@@ -645,36 +645,36 @@ cifs_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
58148 {
58149 #ifdef CONFIG_CIFS_STATS
58150 seq_printf(m, " Oplocks breaks: %d",
58151- atomic_read(&tcon->stats.cifs_stats.num_oplock_brks));
58152+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_oplock_brks));
58153 seq_printf(m, "\nReads: %d Bytes: %llu",
58154- atomic_read(&tcon->stats.cifs_stats.num_reads),
58155+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_reads),
58156 (long long)(tcon->bytes_read));
58157 seq_printf(m, "\nWrites: %d Bytes: %llu",
58158- atomic_read(&tcon->stats.cifs_stats.num_writes),
58159+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_writes),
58160 (long long)(tcon->bytes_written));
58161 seq_printf(m, "\nFlushes: %d",
58162- atomic_read(&tcon->stats.cifs_stats.num_flushes));
58163+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_flushes));
58164 seq_printf(m, "\nLocks: %d HardLinks: %d Symlinks: %d",
58165- atomic_read(&tcon->stats.cifs_stats.num_locks),
58166- atomic_read(&tcon->stats.cifs_stats.num_hardlinks),
58167- atomic_read(&tcon->stats.cifs_stats.num_symlinks));
58168+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_locks),
58169+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_hardlinks),
58170+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_symlinks));
58171 seq_printf(m, "\nOpens: %d Closes: %d Deletes: %d",
58172- atomic_read(&tcon->stats.cifs_stats.num_opens),
58173- atomic_read(&tcon->stats.cifs_stats.num_closes),
58174- atomic_read(&tcon->stats.cifs_stats.num_deletes));
58175+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_opens),
58176+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_closes),
58177+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_deletes));
58178 seq_printf(m, "\nPosix Opens: %d Posix Mkdirs: %d",
58179- atomic_read(&tcon->stats.cifs_stats.num_posixopens),
58180- atomic_read(&tcon->stats.cifs_stats.num_posixmkdirs));
58181+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixopens),
58182+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs));
58183 seq_printf(m, "\nMkdirs: %d Rmdirs: %d",
58184- atomic_read(&tcon->stats.cifs_stats.num_mkdirs),
58185- atomic_read(&tcon->stats.cifs_stats.num_rmdirs));
58186+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_mkdirs),
58187+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_rmdirs));
58188 seq_printf(m, "\nRenames: %d T2 Renames %d",
58189- atomic_read(&tcon->stats.cifs_stats.num_renames),
58190- atomic_read(&tcon->stats.cifs_stats.num_t2renames));
58191+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_renames),
58192+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_t2renames));
58193 seq_printf(m, "\nFindFirst: %d FNext %d FClose %d",
58194- atomic_read(&tcon->stats.cifs_stats.num_ffirst),
58195- atomic_read(&tcon->stats.cifs_stats.num_fnext),
58196- atomic_read(&tcon->stats.cifs_stats.num_fclose));
58197+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_ffirst),
58198+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_fnext),
58199+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_fclose));
58200 #endif
58201 }
58202
58203diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c
58204index 192f51a..539307e 100644
58205--- a/fs/cifs/smb2ops.c
58206+++ b/fs/cifs/smb2ops.c
58207@@ -364,8 +364,8 @@ smb2_clear_stats(struct cifs_tcon *tcon)
58208 #ifdef CONFIG_CIFS_STATS
58209 int i;
58210 for (i = 0; i < NUMBER_OF_SMB2_COMMANDS; i++) {
58211- atomic_set(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
58212- atomic_set(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
58213+ atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
58214+ atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
58215 }
58216 #endif
58217 }
58218@@ -405,65 +405,65 @@ static void
58219 smb2_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
58220 {
58221 #ifdef CONFIG_CIFS_STATS
58222- atomic_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
58223- atomic_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
58224+ atomic_unchecked_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
58225+ atomic_unchecked_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
58226 seq_printf(m, "\nNegotiates: %d sent %d failed",
58227- atomic_read(&sent[SMB2_NEGOTIATE_HE]),
58228- atomic_read(&failed[SMB2_NEGOTIATE_HE]));
58229+ atomic_read_unchecked(&sent[SMB2_NEGOTIATE_HE]),
58230+ atomic_read_unchecked(&failed[SMB2_NEGOTIATE_HE]));
58231 seq_printf(m, "\nSessionSetups: %d sent %d failed",
58232- atomic_read(&sent[SMB2_SESSION_SETUP_HE]),
58233- atomic_read(&failed[SMB2_SESSION_SETUP_HE]));
58234+ atomic_read_unchecked(&sent[SMB2_SESSION_SETUP_HE]),
58235+ atomic_read_unchecked(&failed[SMB2_SESSION_SETUP_HE]));
58236 seq_printf(m, "\nLogoffs: %d sent %d failed",
58237- atomic_read(&sent[SMB2_LOGOFF_HE]),
58238- atomic_read(&failed[SMB2_LOGOFF_HE]));
58239+ atomic_read_unchecked(&sent[SMB2_LOGOFF_HE]),
58240+ atomic_read_unchecked(&failed[SMB2_LOGOFF_HE]));
58241 seq_printf(m, "\nTreeConnects: %d sent %d failed",
58242- atomic_read(&sent[SMB2_TREE_CONNECT_HE]),
58243- atomic_read(&failed[SMB2_TREE_CONNECT_HE]));
58244+ atomic_read_unchecked(&sent[SMB2_TREE_CONNECT_HE]),
58245+ atomic_read_unchecked(&failed[SMB2_TREE_CONNECT_HE]));
58246 seq_printf(m, "\nTreeDisconnects: %d sent %d failed",
58247- atomic_read(&sent[SMB2_TREE_DISCONNECT_HE]),
58248- atomic_read(&failed[SMB2_TREE_DISCONNECT_HE]));
58249+ atomic_read_unchecked(&sent[SMB2_TREE_DISCONNECT_HE]),
58250+ atomic_read_unchecked(&failed[SMB2_TREE_DISCONNECT_HE]));
58251 seq_printf(m, "\nCreates: %d sent %d failed",
58252- atomic_read(&sent[SMB2_CREATE_HE]),
58253- atomic_read(&failed[SMB2_CREATE_HE]));
58254+ atomic_read_unchecked(&sent[SMB2_CREATE_HE]),
58255+ atomic_read_unchecked(&failed[SMB2_CREATE_HE]));
58256 seq_printf(m, "\nCloses: %d sent %d failed",
58257- atomic_read(&sent[SMB2_CLOSE_HE]),
58258- atomic_read(&failed[SMB2_CLOSE_HE]));
58259+ atomic_read_unchecked(&sent[SMB2_CLOSE_HE]),
58260+ atomic_read_unchecked(&failed[SMB2_CLOSE_HE]));
58261 seq_printf(m, "\nFlushes: %d sent %d failed",
58262- atomic_read(&sent[SMB2_FLUSH_HE]),
58263- atomic_read(&failed[SMB2_FLUSH_HE]));
58264+ atomic_read_unchecked(&sent[SMB2_FLUSH_HE]),
58265+ atomic_read_unchecked(&failed[SMB2_FLUSH_HE]));
58266 seq_printf(m, "\nReads: %d sent %d failed",
58267- atomic_read(&sent[SMB2_READ_HE]),
58268- atomic_read(&failed[SMB2_READ_HE]));
58269+ atomic_read_unchecked(&sent[SMB2_READ_HE]),
58270+ atomic_read_unchecked(&failed[SMB2_READ_HE]));
58271 seq_printf(m, "\nWrites: %d sent %d failed",
58272- atomic_read(&sent[SMB2_WRITE_HE]),
58273- atomic_read(&failed[SMB2_WRITE_HE]));
58274+ atomic_read_unchecked(&sent[SMB2_WRITE_HE]),
58275+ atomic_read_unchecked(&failed[SMB2_WRITE_HE]));
58276 seq_printf(m, "\nLocks: %d sent %d failed",
58277- atomic_read(&sent[SMB2_LOCK_HE]),
58278- atomic_read(&failed[SMB2_LOCK_HE]));
58279+ atomic_read_unchecked(&sent[SMB2_LOCK_HE]),
58280+ atomic_read_unchecked(&failed[SMB2_LOCK_HE]));
58281 seq_printf(m, "\nIOCTLs: %d sent %d failed",
58282- atomic_read(&sent[SMB2_IOCTL_HE]),
58283- atomic_read(&failed[SMB2_IOCTL_HE]));
58284+ atomic_read_unchecked(&sent[SMB2_IOCTL_HE]),
58285+ atomic_read_unchecked(&failed[SMB2_IOCTL_HE]));
58286 seq_printf(m, "\nCancels: %d sent %d failed",
58287- atomic_read(&sent[SMB2_CANCEL_HE]),
58288- atomic_read(&failed[SMB2_CANCEL_HE]));
58289+ atomic_read_unchecked(&sent[SMB2_CANCEL_HE]),
58290+ atomic_read_unchecked(&failed[SMB2_CANCEL_HE]));
58291 seq_printf(m, "\nEchos: %d sent %d failed",
58292- atomic_read(&sent[SMB2_ECHO_HE]),
58293- atomic_read(&failed[SMB2_ECHO_HE]));
58294+ atomic_read_unchecked(&sent[SMB2_ECHO_HE]),
58295+ atomic_read_unchecked(&failed[SMB2_ECHO_HE]));
58296 seq_printf(m, "\nQueryDirectories: %d sent %d failed",
58297- atomic_read(&sent[SMB2_QUERY_DIRECTORY_HE]),
58298- atomic_read(&failed[SMB2_QUERY_DIRECTORY_HE]));
58299+ atomic_read_unchecked(&sent[SMB2_QUERY_DIRECTORY_HE]),
58300+ atomic_read_unchecked(&failed[SMB2_QUERY_DIRECTORY_HE]));
58301 seq_printf(m, "\nChangeNotifies: %d sent %d failed",
58302- atomic_read(&sent[SMB2_CHANGE_NOTIFY_HE]),
58303- atomic_read(&failed[SMB2_CHANGE_NOTIFY_HE]));
58304+ atomic_read_unchecked(&sent[SMB2_CHANGE_NOTIFY_HE]),
58305+ atomic_read_unchecked(&failed[SMB2_CHANGE_NOTIFY_HE]));
58306 seq_printf(m, "\nQueryInfos: %d sent %d failed",
58307- atomic_read(&sent[SMB2_QUERY_INFO_HE]),
58308- atomic_read(&failed[SMB2_QUERY_INFO_HE]));
58309+ atomic_read_unchecked(&sent[SMB2_QUERY_INFO_HE]),
58310+ atomic_read_unchecked(&failed[SMB2_QUERY_INFO_HE]));
58311 seq_printf(m, "\nSetInfos: %d sent %d failed",
58312- atomic_read(&sent[SMB2_SET_INFO_HE]),
58313- atomic_read(&failed[SMB2_SET_INFO_HE]));
58314+ atomic_read_unchecked(&sent[SMB2_SET_INFO_HE]),
58315+ atomic_read_unchecked(&failed[SMB2_SET_INFO_HE]));
58316 seq_printf(m, "\nOplockBreaks: %d sent %d failed",
58317- atomic_read(&sent[SMB2_OPLOCK_BREAK_HE]),
58318- atomic_read(&failed[SMB2_OPLOCK_BREAK_HE]));
58319+ atomic_read_unchecked(&sent[SMB2_OPLOCK_BREAK_HE]),
58320+ atomic_read_unchecked(&failed[SMB2_OPLOCK_BREAK_HE]));
58321 #endif
58322 }
58323
58324diff --git a/fs/cifs/smb2pdu.c b/fs/cifs/smb2pdu.c
58325index 8603447..f9caeee 100644
58326--- a/fs/cifs/smb2pdu.c
58327+++ b/fs/cifs/smb2pdu.c
58328@@ -2094,8 +2094,7 @@ SMB2_query_directory(const unsigned int xid, struct cifs_tcon *tcon,
58329 default:
58330 cifs_dbg(VFS, "info level %u isn't supported\n",
58331 srch_inf->info_level);
58332- rc = -EINVAL;
58333- goto qdir_exit;
58334+ return -EINVAL;
58335 }
58336
58337 req->FileIndex = cpu_to_le32(index);
58338diff --git a/fs/coda/cache.c b/fs/coda/cache.c
58339index 1da168c..8bc7ff6 100644
58340--- a/fs/coda/cache.c
58341+++ b/fs/coda/cache.c
58342@@ -24,7 +24,7 @@
58343 #include "coda_linux.h"
58344 #include "coda_cache.h"
58345
58346-static atomic_t permission_epoch = ATOMIC_INIT(0);
58347+static atomic_unchecked_t permission_epoch = ATOMIC_INIT(0);
58348
58349 /* replace or extend an acl cache hit */
58350 void coda_cache_enter(struct inode *inode, int mask)
58351@@ -32,7 +32,7 @@ void coda_cache_enter(struct inode *inode, int mask)
58352 struct coda_inode_info *cii = ITOC(inode);
58353
58354 spin_lock(&cii->c_lock);
58355- cii->c_cached_epoch = atomic_read(&permission_epoch);
58356+ cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch);
58357 if (!uid_eq(cii->c_uid, current_fsuid())) {
58358 cii->c_uid = current_fsuid();
58359 cii->c_cached_perm = mask;
58360@@ -46,14 +46,14 @@ void coda_cache_clear_inode(struct inode *inode)
58361 {
58362 struct coda_inode_info *cii = ITOC(inode);
58363 spin_lock(&cii->c_lock);
58364- cii->c_cached_epoch = atomic_read(&permission_epoch) - 1;
58365+ cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch) - 1;
58366 spin_unlock(&cii->c_lock);
58367 }
58368
58369 /* remove all acl caches */
58370 void coda_cache_clear_all(struct super_block *sb)
58371 {
58372- atomic_inc(&permission_epoch);
58373+ atomic_inc_unchecked(&permission_epoch);
58374 }
58375
58376
58377@@ -66,7 +66,7 @@ int coda_cache_check(struct inode *inode, int mask)
58378 spin_lock(&cii->c_lock);
58379 hit = (mask & cii->c_cached_perm) == mask &&
58380 uid_eq(cii->c_uid, current_fsuid()) &&
58381- cii->c_cached_epoch == atomic_read(&permission_epoch);
58382+ cii->c_cached_epoch == atomic_read_unchecked(&permission_epoch);
58383 spin_unlock(&cii->c_lock);
58384
58385 return hit;
58386diff --git a/fs/compat.c b/fs/compat.c
58387index 6af20de..fec3fbb 100644
58388--- a/fs/compat.c
58389+++ b/fs/compat.c
58390@@ -54,7 +54,7 @@
58391 #include <asm/ioctls.h>
58392 #include "internal.h"
58393
58394-int compat_log = 1;
58395+int compat_log = 0;
58396
58397 int compat_printk(const char *fmt, ...)
58398 {
58399@@ -488,7 +488,7 @@ compat_sys_io_setup(unsigned nr_reqs, u32 __user *ctx32p)
58400
58401 set_fs(KERNEL_DS);
58402 /* The __user pointer cast is valid because of the set_fs() */
58403- ret = sys_io_setup(nr_reqs, (aio_context_t __user *) &ctx64);
58404+ ret = sys_io_setup(nr_reqs, (aio_context_t __force_user *) &ctx64);
58405 set_fs(oldfs);
58406 /* truncating is ok because it's a user address */
58407 if (!ret)
58408@@ -546,7 +546,7 @@ ssize_t compat_rw_copy_check_uvector(int type,
58409 goto out;
58410
58411 ret = -EINVAL;
58412- if (nr_segs > UIO_MAXIOV || nr_segs < 0)
58413+ if (nr_segs > UIO_MAXIOV)
58414 goto out;
58415 if (nr_segs > fast_segs) {
58416 ret = -ENOMEM;
58417@@ -834,6 +834,7 @@ struct compat_old_linux_dirent {
58418 struct compat_readdir_callback {
58419 struct dir_context ctx;
58420 struct compat_old_linux_dirent __user *dirent;
58421+ struct file * file;
58422 int result;
58423 };
58424
58425@@ -851,6 +852,10 @@ static int compat_fillonedir(void *__buf, const char *name, int namlen,
58426 buf->result = -EOVERFLOW;
58427 return -EOVERFLOW;
58428 }
58429+
58430+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
58431+ return 0;
58432+
58433 buf->result++;
58434 dirent = buf->dirent;
58435 if (!access_ok(VERIFY_WRITE, dirent,
58436@@ -882,6 +887,7 @@ asmlinkage long compat_sys_old_readdir(unsigned int fd,
58437 if (!f.file)
58438 return -EBADF;
58439
58440+ buf.file = f.file;
58441 error = iterate_dir(f.file, &buf.ctx);
58442 if (buf.result)
58443 error = buf.result;
58444@@ -901,6 +907,7 @@ struct compat_getdents_callback {
58445 struct dir_context ctx;
58446 struct compat_linux_dirent __user *current_dir;
58447 struct compat_linux_dirent __user *previous;
58448+ struct file * file;
58449 int count;
58450 int error;
58451 };
58452@@ -922,6 +929,10 @@ static int compat_filldir(void *__buf, const char *name, int namlen,
58453 buf->error = -EOVERFLOW;
58454 return -EOVERFLOW;
58455 }
58456+
58457+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
58458+ return 0;
58459+
58460 dirent = buf->previous;
58461 if (dirent) {
58462 if (__put_user(offset, &dirent->d_off))
58463@@ -967,6 +978,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
58464 if (!f.file)
58465 return -EBADF;
58466
58467+ buf.file = f.file;
58468 error = iterate_dir(f.file, &buf.ctx);
58469 if (error >= 0)
58470 error = buf.error;
58471@@ -987,6 +999,7 @@ struct compat_getdents_callback64 {
58472 struct dir_context ctx;
58473 struct linux_dirent64 __user *current_dir;
58474 struct linux_dirent64 __user *previous;
58475+ struct file * file;
58476 int count;
58477 int error;
58478 };
58479@@ -1003,6 +1016,10 @@ static int compat_filldir64(void * __buf, const char * name, int namlen, loff_t
58480 buf->error = -EINVAL; /* only used if we fail.. */
58481 if (reclen > buf->count)
58482 return -EINVAL;
58483+
58484+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
58485+ return 0;
58486+
58487 dirent = buf->previous;
58488
58489 if (dirent) {
58490@@ -1052,6 +1069,7 @@ asmlinkage long compat_sys_getdents64(unsigned int fd,
58491 if (!f.file)
58492 return -EBADF;
58493
58494+ buf.file = f.file;
58495 error = iterate_dir(f.file, &buf.ctx);
58496 if (error >= 0)
58497 error = buf.error;
58498diff --git a/fs/compat_binfmt_elf.c b/fs/compat_binfmt_elf.c
58499index a81147e..20bf2b5 100644
58500--- a/fs/compat_binfmt_elf.c
58501+++ b/fs/compat_binfmt_elf.c
58502@@ -30,11 +30,13 @@
58503 #undef elf_phdr
58504 #undef elf_shdr
58505 #undef elf_note
58506+#undef elf_dyn
58507 #undef elf_addr_t
58508 #define elfhdr elf32_hdr
58509 #define elf_phdr elf32_phdr
58510 #define elf_shdr elf32_shdr
58511 #define elf_note elf32_note
58512+#define elf_dyn Elf32_Dyn
58513 #define elf_addr_t Elf32_Addr
58514
58515 /*
58516diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c
58517index 3881610..ab3df0b 100644
58518--- a/fs/compat_ioctl.c
58519+++ b/fs/compat_ioctl.c
58520@@ -621,7 +621,7 @@ static int serial_struct_ioctl(unsigned fd, unsigned cmd,
58521 return -EFAULT;
58522 if (__get_user(udata, &ss32->iomem_base))
58523 return -EFAULT;
58524- ss.iomem_base = compat_ptr(udata);
58525+ ss.iomem_base = (unsigned char __force_kernel *)compat_ptr(udata);
58526 if (__get_user(ss.iomem_reg_shift, &ss32->iomem_reg_shift) ||
58527 __get_user(ss.port_high, &ss32->port_high))
58528 return -EFAULT;
58529@@ -703,8 +703,8 @@ static int do_i2c_rdwr_ioctl(unsigned int fd, unsigned int cmd,
58530 for (i = 0; i < nmsgs; i++) {
58531 if (copy_in_user(&tmsgs[i].addr, &umsgs[i].addr, 3*sizeof(u16)))
58532 return -EFAULT;
58533- if (get_user(datap, &umsgs[i].buf) ||
58534- put_user(compat_ptr(datap), &tmsgs[i].buf))
58535+ if (get_user(datap, (u8 __user * __user *)&umsgs[i].buf) ||
58536+ put_user(compat_ptr(datap), (u8 __user * __user *)&tmsgs[i].buf))
58537 return -EFAULT;
58538 }
58539 return sys_ioctl(fd, cmd, (unsigned long)tdata);
58540@@ -797,7 +797,7 @@ static int compat_ioctl_preallocate(struct file *file,
58541 copy_in_user(&p->l_len, &p32->l_len, sizeof(s64)) ||
58542 copy_in_user(&p->l_sysid, &p32->l_sysid, sizeof(s32)) ||
58543 copy_in_user(&p->l_pid, &p32->l_pid, sizeof(u32)) ||
58544- copy_in_user(&p->l_pad, &p32->l_pad, 4*sizeof(u32)))
58545+ copy_in_user(p->l_pad, p32->l_pad, 4*sizeof(u32)))
58546 return -EFAULT;
58547
58548 return ioctl_preallocate(file, p);
58549@@ -1617,8 +1617,8 @@ asmlinkage long compat_sys_ioctl(unsigned int fd, unsigned int cmd,
58550 static int __init init_sys32_ioctl_cmp(const void *p, const void *q)
58551 {
58552 unsigned int a, b;
58553- a = *(unsigned int *)p;
58554- b = *(unsigned int *)q;
58555+ a = *(const unsigned int *)p;
58556+ b = *(const unsigned int *)q;
58557 if (a > b)
58558 return 1;
58559 if (a < b)
58560diff --git a/fs/configfs/dir.c b/fs/configfs/dir.c
58561index e081acb..911df21 100644
58562--- a/fs/configfs/dir.c
58563+++ b/fs/configfs/dir.c
58564@@ -1548,7 +1548,8 @@ static int configfs_readdir(struct file *file, struct dir_context *ctx)
58565 }
58566 for (p = q->next; p != &parent_sd->s_children; p = p->next) {
58567 struct configfs_dirent *next;
58568- const char *name;
58569+ const unsigned char * name;
58570+ char d_name[sizeof(next->s_dentry->d_iname)];
58571 int len;
58572 struct inode *inode = NULL;
58573
58574@@ -1557,7 +1558,12 @@ static int configfs_readdir(struct file *file, struct dir_context *ctx)
58575 continue;
58576
58577 name = configfs_get_name(next);
58578- len = strlen(name);
58579+ if (next->s_dentry && name == next->s_dentry->d_iname) {
58580+ len = next->s_dentry->d_name.len;
58581+ memcpy(d_name, name, len);
58582+ name = d_name;
58583+ } else
58584+ len = strlen(name);
58585
58586 /*
58587 * We'll have a dentry and an inode for
58588diff --git a/fs/coredump.c b/fs/coredump.c
58589index e3ad709..836c55f 100644
58590--- a/fs/coredump.c
58591+++ b/fs/coredump.c
58592@@ -73,10 +73,15 @@ static int expand_corename(struct core_name *cn, int size)
58593 static int cn_vprintf(struct core_name *cn, const char *fmt, va_list arg)
58594 {
58595 int free, need;
58596+ va_list arg_copy;
58597
58598 again:
58599 free = cn->size - cn->used;
58600- need = vsnprintf(cn->corename + cn->used, free, fmt, arg);
58601+
58602+ va_copy(arg_copy, arg);
58603+ need = vsnprintf(cn->corename + cn->used, free, fmt, arg_copy);
58604+ va_end(arg_copy);
58605+
58606 if (need < free) {
58607 cn->used += need;
58608 return 0;
58609@@ -437,8 +442,8 @@ static void wait_for_dump_helpers(struct file *file)
58610 struct pipe_inode_info *pipe = file->private_data;
58611
58612 pipe_lock(pipe);
58613- pipe->readers++;
58614- pipe->writers--;
58615+ atomic_inc(&pipe->readers);
58616+ atomic_dec(&pipe->writers);
58617 wake_up_interruptible_sync(&pipe->wait);
58618 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
58619 pipe_unlock(pipe);
58620@@ -447,11 +452,11 @@ static void wait_for_dump_helpers(struct file *file)
58621 * We actually want wait_event_freezable() but then we need
58622 * to clear TIF_SIGPENDING and improve dump_interrupted().
58623 */
58624- wait_event_interruptible(pipe->wait, pipe->readers == 1);
58625+ wait_event_interruptible(pipe->wait, atomic_read(&pipe->readers) == 1);
58626
58627 pipe_lock(pipe);
58628- pipe->readers--;
58629- pipe->writers++;
58630+ atomic_dec(&pipe->readers);
58631+ atomic_inc(&pipe->writers);
58632 pipe_unlock(pipe);
58633 }
58634
58635@@ -498,7 +503,9 @@ void do_coredump(const siginfo_t *siginfo)
58636 struct files_struct *displaced;
58637 bool need_nonrelative = false;
58638 bool core_dumped = false;
58639- static atomic_t core_dump_count = ATOMIC_INIT(0);
58640+ static atomic_unchecked_t core_dump_count = ATOMIC_INIT(0);
58641+ long signr = siginfo->si_signo;
58642+ int dumpable;
58643 struct coredump_params cprm = {
58644 .siginfo = siginfo,
58645 .regs = signal_pt_regs(),
58646@@ -511,12 +518,17 @@ void do_coredump(const siginfo_t *siginfo)
58647 .mm_flags = mm->flags,
58648 };
58649
58650- audit_core_dumps(siginfo->si_signo);
58651+ audit_core_dumps(signr);
58652+
58653+ dumpable = __get_dumpable(cprm.mm_flags);
58654+
58655+ if (signr == SIGSEGV || signr == SIGBUS || signr == SIGKILL || signr == SIGILL)
58656+ gr_handle_brute_attach(dumpable);
58657
58658 binfmt = mm->binfmt;
58659 if (!binfmt || !binfmt->core_dump)
58660 goto fail;
58661- if (!__get_dumpable(cprm.mm_flags))
58662+ if (!dumpable)
58663 goto fail;
58664
58665 cred = prepare_creds();
58666@@ -535,7 +547,7 @@ void do_coredump(const siginfo_t *siginfo)
58667 need_nonrelative = true;
58668 }
58669
58670- retval = coredump_wait(siginfo->si_signo, &core_state);
58671+ retval = coredump_wait(signr, &core_state);
58672 if (retval < 0)
58673 goto fail_creds;
58674
58675@@ -578,7 +590,7 @@ void do_coredump(const siginfo_t *siginfo)
58676 }
58677 cprm.limit = RLIM_INFINITY;
58678
58679- dump_count = atomic_inc_return(&core_dump_count);
58680+ dump_count = atomic_inc_return_unchecked(&core_dump_count);
58681 if (core_pipe_limit && (core_pipe_limit < dump_count)) {
58682 printk(KERN_WARNING "Pid %d(%s) over core_pipe_limit\n",
58683 task_tgid_vnr(current), current->comm);
58684@@ -610,6 +622,8 @@ void do_coredump(const siginfo_t *siginfo)
58685 } else {
58686 struct inode *inode;
58687
58688+ gr_learn_resource(current, RLIMIT_CORE, binfmt->min_coredump, 1);
58689+
58690 if (cprm.limit < binfmt->min_coredump)
58691 goto fail_unlock;
58692
58693@@ -668,7 +682,7 @@ close_fail:
58694 filp_close(cprm.file, NULL);
58695 fail_dropcount:
58696 if (ispipe)
58697- atomic_dec(&core_dump_count);
58698+ atomic_dec_unchecked(&core_dump_count);
58699 fail_unlock:
58700 kfree(cn.corename);
58701 coredump_finish(mm, core_dumped);
58702@@ -689,6 +703,8 @@ int dump_emit(struct coredump_params *cprm, const void *addr, int nr)
58703 struct file *file = cprm->file;
58704 loff_t pos = file->f_pos;
58705 ssize_t n;
58706+
58707+ gr_learn_resource(current, RLIMIT_CORE, cprm->written + nr, 1);
58708 if (cprm->written + nr > cprm->limit)
58709 return 0;
58710 while (nr) {
58711diff --git a/fs/dcache.c b/fs/dcache.c
58712index ca02c13..7e2b581 100644
58713--- a/fs/dcache.c
58714+++ b/fs/dcache.c
58715@@ -1495,7 +1495,7 @@ struct dentry *__d_alloc(struct super_block *sb, const struct qstr *name)
58716 */
58717 dentry->d_iname[DNAME_INLINE_LEN-1] = 0;
58718 if (name->len > DNAME_INLINE_LEN-1) {
58719- dname = kmalloc(name->len + 1, GFP_KERNEL);
58720+ dname = kmalloc(round_up(name->len + 1, sizeof(unsigned long)), GFP_KERNEL);
58721 if (!dname) {
58722 kmem_cache_free(dentry_cache, dentry);
58723 return NULL;
58724@@ -3431,7 +3431,8 @@ void __init vfs_caches_init(unsigned long mempages)
58725 mempages -= reserve;
58726
58727 names_cachep = kmem_cache_create("names_cache", PATH_MAX, 0,
58728- SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
58729+ SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_USERCOPY|
58730+ SLAB_NO_SANITIZE, NULL);
58731
58732 dcache_init();
58733 inode_init();
58734diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c
58735index 9c0444c..628490c 100644
58736--- a/fs/debugfs/inode.c
58737+++ b/fs/debugfs/inode.c
58738@@ -415,7 +415,11 @@ EXPORT_SYMBOL_GPL(debugfs_create_file);
58739 */
58740 struct dentry *debugfs_create_dir(const char *name, struct dentry *parent)
58741 {
58742+#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
58743+ return __create_file(name, S_IFDIR | S_IRWXU,
58744+#else
58745 return __create_file(name, S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO,
58746+#endif
58747 parent, NULL, NULL);
58748 }
58749 EXPORT_SYMBOL_GPL(debugfs_create_dir);
58750diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c
58751index b167ca4..a224e19 100644
58752--- a/fs/ecryptfs/inode.c
58753+++ b/fs/ecryptfs/inode.c
58754@@ -673,7 +673,7 @@ static char *ecryptfs_readlink_lower(struct dentry *dentry, size_t *bufsiz)
58755 old_fs = get_fs();
58756 set_fs(get_ds());
58757 rc = lower_dentry->d_inode->i_op->readlink(lower_dentry,
58758- (char __user *)lower_buf,
58759+ (char __force_user *)lower_buf,
58760 PATH_MAX);
58761 set_fs(old_fs);
58762 if (rc < 0)
58763diff --git a/fs/ecryptfs/miscdev.c b/fs/ecryptfs/miscdev.c
58764index e4141f2..d8263e8 100644
58765--- a/fs/ecryptfs/miscdev.c
58766+++ b/fs/ecryptfs/miscdev.c
58767@@ -304,7 +304,7 @@ check_list:
58768 goto out_unlock_msg_ctx;
58769 i = PKT_TYPE_SIZE + PKT_CTR_SIZE;
58770 if (msg_ctx->msg) {
58771- if (copy_to_user(&buf[i], packet_length, packet_length_size))
58772+ if (packet_length_size > sizeof(packet_length) || copy_to_user(&buf[i], packet_length, packet_length_size))
58773 goto out_unlock_msg_ctx;
58774 i += packet_length_size;
58775 if (copy_to_user(&buf[i], msg_ctx->msg, msg_ctx->msg_size))
58776diff --git a/fs/exec.c b/fs/exec.c
58777index 3d78fcc..460e2a0 100644
58778--- a/fs/exec.c
58779+++ b/fs/exec.c
58780@@ -55,8 +55,20 @@
58781 #include <linux/pipe_fs_i.h>
58782 #include <linux/oom.h>
58783 #include <linux/compat.h>
58784+#include <linux/random.h>
58785+#include <linux/seq_file.h>
58786+#include <linux/coredump.h>
58787+#include <linux/mman.h>
58788+
58789+#ifdef CONFIG_PAX_REFCOUNT
58790+#include <linux/kallsyms.h>
58791+#include <linux/kdebug.h>
58792+#endif
58793+
58794+#include <trace/events/fs.h>
58795
58796 #include <asm/uaccess.h>
58797+#include <asm/sections.h>
58798 #include <asm/mmu_context.h>
58799 #include <asm/tlb.h>
58800
58801@@ -65,19 +77,34 @@
58802
58803 #include <trace/events/sched.h>
58804
58805+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
58806+void __weak pax_set_initial_flags(struct linux_binprm *bprm)
58807+{
58808+ 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");
58809+}
58810+#endif
58811+
58812+#ifdef CONFIG_PAX_HOOK_ACL_FLAGS
58813+void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
58814+EXPORT_SYMBOL(pax_set_initial_flags_func);
58815+#endif
58816+
58817 int suid_dumpable = 0;
58818
58819 static LIST_HEAD(formats);
58820 static DEFINE_RWLOCK(binfmt_lock);
58821
58822+extern int gr_process_kernel_exec_ban(void);
58823+extern int gr_process_suid_exec_ban(const struct linux_binprm *bprm);
58824+
58825 void __register_binfmt(struct linux_binfmt * fmt, int insert)
58826 {
58827 BUG_ON(!fmt);
58828 if (WARN_ON(!fmt->load_binary))
58829 return;
58830 write_lock(&binfmt_lock);
58831- insert ? list_add(&fmt->lh, &formats) :
58832- list_add_tail(&fmt->lh, &formats);
58833+ insert ? pax_list_add((struct list_head *)&fmt->lh, &formats) :
58834+ pax_list_add_tail((struct list_head *)&fmt->lh, &formats);
58835 write_unlock(&binfmt_lock);
58836 }
58837
58838@@ -86,7 +113,7 @@ EXPORT_SYMBOL(__register_binfmt);
58839 void unregister_binfmt(struct linux_binfmt * fmt)
58840 {
58841 write_lock(&binfmt_lock);
58842- list_del(&fmt->lh);
58843+ pax_list_del((struct list_head *)&fmt->lh);
58844 write_unlock(&binfmt_lock);
58845 }
58846
58847@@ -180,18 +207,10 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
58848 int write)
58849 {
58850 struct page *page;
58851- int ret;
58852
58853-#ifdef CONFIG_STACK_GROWSUP
58854- if (write) {
58855- ret = expand_downwards(bprm->vma, pos);
58856- if (ret < 0)
58857- return NULL;
58858- }
58859-#endif
58860- ret = get_user_pages(current, bprm->mm, pos,
58861- 1, write, 1, &page, NULL);
58862- if (ret <= 0)
58863+ if (0 > expand_downwards(bprm->vma, pos))
58864+ return NULL;
58865+ if (0 >= get_user_pages(current, bprm->mm, pos, 1, write, 1, &page, NULL))
58866 return NULL;
58867
58868 if (write) {
58869@@ -207,6 +226,17 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
58870 if (size <= ARG_MAX)
58871 return page;
58872
58873+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
58874+ // only allow 512KB for argv+env on suid/sgid binaries
58875+ // to prevent easy ASLR exhaustion
58876+ if (((!uid_eq(bprm->cred->euid, current_euid())) ||
58877+ (!gid_eq(bprm->cred->egid, current_egid()))) &&
58878+ (size > (512 * 1024))) {
58879+ put_page(page);
58880+ return NULL;
58881+ }
58882+#endif
58883+
58884 /*
58885 * Limit to 1/4-th the stack size for the argv+env strings.
58886 * This ensures that:
58887@@ -266,6 +296,11 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
58888 vma->vm_end = STACK_TOP_MAX;
58889 vma->vm_start = vma->vm_end - PAGE_SIZE;
58890 vma->vm_flags = VM_SOFTDIRTY | VM_STACK_FLAGS | VM_STACK_INCOMPLETE_SETUP;
58891+
58892+#ifdef CONFIG_PAX_SEGMEXEC
58893+ vma->vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
58894+#endif
58895+
58896 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
58897 INIT_LIST_HEAD(&vma->anon_vma_chain);
58898
58899@@ -276,6 +311,12 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
58900 mm->stack_vm = mm->total_vm = 1;
58901 up_write(&mm->mmap_sem);
58902 bprm->p = vma->vm_end - sizeof(void *);
58903+
58904+#ifdef CONFIG_PAX_RANDUSTACK
58905+ if (randomize_va_space)
58906+ bprm->p ^= prandom_u32() & ~PAGE_MASK;
58907+#endif
58908+
58909 return 0;
58910 err:
58911 up_write(&mm->mmap_sem);
58912@@ -396,7 +437,7 @@ struct user_arg_ptr {
58913 } ptr;
58914 };
58915
58916-static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
58917+const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
58918 {
58919 const char __user *native;
58920
58921@@ -405,14 +446,14 @@ static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
58922 compat_uptr_t compat;
58923
58924 if (get_user(compat, argv.ptr.compat + nr))
58925- return ERR_PTR(-EFAULT);
58926+ return (const char __force_user *)ERR_PTR(-EFAULT);
58927
58928 return compat_ptr(compat);
58929 }
58930 #endif
58931
58932 if (get_user(native, argv.ptr.native + nr))
58933- return ERR_PTR(-EFAULT);
58934+ return (const char __force_user *)ERR_PTR(-EFAULT);
58935
58936 return native;
58937 }
58938@@ -431,7 +472,7 @@ static int count(struct user_arg_ptr argv, int max)
58939 if (!p)
58940 break;
58941
58942- if (IS_ERR(p))
58943+ if (IS_ERR((const char __force_kernel *)p))
58944 return -EFAULT;
58945
58946 if (i >= max)
58947@@ -466,7 +507,7 @@ static int copy_strings(int argc, struct user_arg_ptr argv,
58948
58949 ret = -EFAULT;
58950 str = get_user_arg_ptr(argv, argc);
58951- if (IS_ERR(str))
58952+ if (IS_ERR((const char __force_kernel *)str))
58953 goto out;
58954
58955 len = strnlen_user(str, MAX_ARG_STRLEN);
58956@@ -548,7 +589,7 @@ int copy_strings_kernel(int argc, const char *const *__argv,
58957 int r;
58958 mm_segment_t oldfs = get_fs();
58959 struct user_arg_ptr argv = {
58960- .ptr.native = (const char __user *const __user *)__argv,
58961+ .ptr.native = (const char __user * const __force_user *)__argv,
58962 };
58963
58964 set_fs(KERNEL_DS);
58965@@ -583,7 +624,8 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
58966 unsigned long new_end = old_end - shift;
58967 struct mmu_gather tlb;
58968
58969- BUG_ON(new_start > new_end);
58970+ if (new_start >= new_end || new_start < mmap_min_addr)
58971+ return -ENOMEM;
58972
58973 /*
58974 * ensure there are no vmas between where we want to go
58975@@ -592,6 +634,10 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
58976 if (vma != find_vma(mm, new_start))
58977 return -EFAULT;
58978
58979+#ifdef CONFIG_PAX_SEGMEXEC
58980+ BUG_ON(pax_find_mirror_vma(vma));
58981+#endif
58982+
58983 /*
58984 * cover the whole range: [new_start, old_end)
58985 */
58986@@ -672,10 +718,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
58987 stack_top = arch_align_stack(stack_top);
58988 stack_top = PAGE_ALIGN(stack_top);
58989
58990- if (unlikely(stack_top < mmap_min_addr) ||
58991- unlikely(vma->vm_end - vma->vm_start >= stack_top - mmap_min_addr))
58992- return -ENOMEM;
58993-
58994 stack_shift = vma->vm_end - stack_top;
58995
58996 bprm->p -= stack_shift;
58997@@ -687,8 +729,28 @@ int setup_arg_pages(struct linux_binprm *bprm,
58998 bprm->exec -= stack_shift;
58999
59000 down_write(&mm->mmap_sem);
59001+
59002+ /* Move stack pages down in memory. */
59003+ if (stack_shift) {
59004+ ret = shift_arg_pages(vma, stack_shift);
59005+ if (ret)
59006+ goto out_unlock;
59007+ }
59008+
59009 vm_flags = VM_STACK_FLAGS;
59010
59011+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
59012+ if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
59013+ vm_flags &= ~VM_EXEC;
59014+
59015+#ifdef CONFIG_PAX_MPROTECT
59016+ if (mm->pax_flags & MF_PAX_MPROTECT)
59017+ vm_flags &= ~VM_MAYEXEC;
59018+#endif
59019+
59020+ }
59021+#endif
59022+
59023 /*
59024 * Adjust stack execute permissions; explicitly enable for
59025 * EXSTACK_ENABLE_X, disable for EXSTACK_DISABLE_X and leave alone
59026@@ -707,13 +769,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
59027 goto out_unlock;
59028 BUG_ON(prev != vma);
59029
59030- /* Move stack pages down in memory. */
59031- if (stack_shift) {
59032- ret = shift_arg_pages(vma, stack_shift);
59033- if (ret)
59034- goto out_unlock;
59035- }
59036-
59037 /* mprotect_fixup is overkill to remove the temporary stack flags */
59038 vma->vm_flags &= ~VM_STACK_INCOMPLETE_SETUP;
59039
59040@@ -737,6 +792,27 @@ int setup_arg_pages(struct linux_binprm *bprm,
59041 #endif
59042 current->mm->start_stack = bprm->p;
59043 ret = expand_stack(vma, stack_base);
59044+
59045+#if !defined(CONFIG_STACK_GROWSUP) && defined(CONFIG_PAX_RANDMMAP)
59046+ if (!ret && (mm->pax_flags & MF_PAX_RANDMMAP) && STACK_TOP <= 0xFFFFFFFFU && STACK_TOP > vma->vm_end) {
59047+ unsigned long size;
59048+ vm_flags_t vm_flags;
59049+
59050+ size = STACK_TOP - vma->vm_end;
59051+ vm_flags = VM_NONE | VM_DONTEXPAND | VM_DONTDUMP;
59052+
59053+ ret = vma->vm_end != mmap_region(NULL, vma->vm_end, size, vm_flags, 0);
59054+
59055+#ifdef CONFIG_X86
59056+ if (!ret) {
59057+ size = PAGE_SIZE + mmap_min_addr + ((mm->delta_mmap ^ mm->delta_stack) & (0xFFUL << PAGE_SHIFT));
59058+ ret = 0 != mmap_region(NULL, 0, PAGE_ALIGN(size), vm_flags, 0);
59059+ }
59060+#endif
59061+
59062+ }
59063+#endif
59064+
59065 if (ret)
59066 ret = -EFAULT;
59067
59068@@ -772,6 +848,8 @@ static struct file *do_open_exec(struct filename *name)
59069
59070 fsnotify_open(file);
59071
59072+ trace_open_exec(name->name);
59073+
59074 err = deny_write_access(file);
59075 if (err)
59076 goto exit;
59077@@ -801,7 +879,7 @@ int kernel_read(struct file *file, loff_t offset,
59078 old_fs = get_fs();
59079 set_fs(get_ds());
59080 /* The cast to a user pointer is valid due to the set_fs() */
59081- result = vfs_read(file, (void __user *)addr, count, &pos);
59082+ result = vfs_read(file, (void __force_user *)addr, count, &pos);
59083 set_fs(old_fs);
59084 return result;
59085 }
59086@@ -1258,7 +1336,7 @@ static void check_unsafe_exec(struct linux_binprm *bprm)
59087 }
59088 rcu_read_unlock();
59089
59090- if (p->fs->users > n_fs)
59091+ if (atomic_read(&p->fs->users) > n_fs)
59092 bprm->unsafe |= LSM_UNSAFE_SHARE;
59093 else
59094 p->fs->in_exec = 1;
59095@@ -1434,6 +1512,31 @@ static int exec_binprm(struct linux_binprm *bprm)
59096 return ret;
59097 }
59098
59099+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
59100+static DEFINE_PER_CPU(u64, exec_counter);
59101+static int __init init_exec_counters(void)
59102+{
59103+ unsigned int cpu;
59104+
59105+ for_each_possible_cpu(cpu) {
59106+ per_cpu(exec_counter, cpu) = (u64)cpu;
59107+ }
59108+
59109+ return 0;
59110+}
59111+early_initcall(init_exec_counters);
59112+static inline void increment_exec_counter(void)
59113+{
59114+ BUILD_BUG_ON(NR_CPUS > (1 << 16));
59115+ current->exec_id = this_cpu_add_return(exec_counter, 1 << 16);
59116+}
59117+#else
59118+static inline void increment_exec_counter(void) {}
59119+#endif
59120+
59121+extern void gr_handle_exec_args(struct linux_binprm *bprm,
59122+ struct user_arg_ptr argv);
59123+
59124 /*
59125 * sys_execve() executes a new program.
59126 */
59127@@ -1441,6 +1544,11 @@ static int do_execve_common(struct filename *filename,
59128 struct user_arg_ptr argv,
59129 struct user_arg_ptr envp)
59130 {
59131+#ifdef CONFIG_GRKERNSEC
59132+ struct file *old_exec_file;
59133+ struct acl_subject_label *old_acl;
59134+ struct rlimit old_rlim[RLIM_NLIMITS];
59135+#endif
59136 struct linux_binprm *bprm;
59137 struct file *file;
59138 struct files_struct *displaced;
59139@@ -1449,6 +1557,8 @@ static int do_execve_common(struct filename *filename,
59140 if (IS_ERR(filename))
59141 return PTR_ERR(filename);
59142
59143+ gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&current_user()->processes), 1);
59144+
59145 /*
59146 * We move the actual failure in case of RLIMIT_NPROC excess from
59147 * set*uid() to execve() because too many poorly written programs
59148@@ -1486,11 +1596,21 @@ static int do_execve_common(struct filename *filename,
59149 if (IS_ERR(file))
59150 goto out_unmark;
59151
59152+ if (gr_ptrace_readexec(file, bprm->unsafe)) {
59153+ retval = -EPERM;
59154+ goto out_unmark;
59155+ }
59156+
59157 sched_exec();
59158
59159 bprm->file = file;
59160 bprm->filename = bprm->interp = filename->name;
59161
59162+ if (!gr_acl_handle_execve(file->f_path.dentry, file->f_path.mnt)) {
59163+ retval = -EACCES;
59164+ goto out_unmark;
59165+ }
59166+
59167 retval = bprm_mm_init(bprm);
59168 if (retval)
59169 goto out_unmark;
59170@@ -1507,24 +1627,70 @@ static int do_execve_common(struct filename *filename,
59171 if (retval < 0)
59172 goto out;
59173
59174+#ifdef CONFIG_GRKERNSEC
59175+ old_acl = current->acl;
59176+ memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
59177+ old_exec_file = current->exec_file;
59178+ get_file(file);
59179+ current->exec_file = file;
59180+#endif
59181+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
59182+ /* limit suid stack to 8MB
59183+ * we saved the old limits above and will restore them if this exec fails
59184+ */
59185+ if (((!uid_eq(bprm->cred->euid, current_euid())) || (!gid_eq(bprm->cred->egid, current_egid()))) &&
59186+ (old_rlim[RLIMIT_STACK].rlim_cur > (8 * 1024 * 1024)))
59187+ current->signal->rlim[RLIMIT_STACK].rlim_cur = 8 * 1024 * 1024;
59188+#endif
59189+
59190+ if (gr_process_kernel_exec_ban() || gr_process_suid_exec_ban(bprm)) {
59191+ retval = -EPERM;
59192+ goto out_fail;
59193+ }
59194+
59195+ if (!gr_tpe_allow(file)) {
59196+ retval = -EACCES;
59197+ goto out_fail;
59198+ }
59199+
59200+ if (gr_check_crash_exec(file)) {
59201+ retval = -EACCES;
59202+ goto out_fail;
59203+ }
59204+
59205+ retval = gr_set_proc_label(file->f_path.dentry, file->f_path.mnt,
59206+ bprm->unsafe);
59207+ if (retval < 0)
59208+ goto out_fail;
59209+
59210 retval = copy_strings_kernel(1, &bprm->filename, bprm);
59211 if (retval < 0)
59212- goto out;
59213+ goto out_fail;
59214
59215 bprm->exec = bprm->p;
59216 retval = copy_strings(bprm->envc, envp, bprm);
59217 if (retval < 0)
59218- goto out;
59219+ goto out_fail;
59220
59221 retval = copy_strings(bprm->argc, argv, bprm);
59222 if (retval < 0)
59223- goto out;
59224+ goto out_fail;
59225+
59226+ gr_log_chroot_exec(file->f_path.dentry, file->f_path.mnt);
59227+
59228+ gr_handle_exec_args(bprm, argv);
59229
59230 retval = exec_binprm(bprm);
59231 if (retval < 0)
59232- goto out;
59233+ goto out_fail;
59234+#ifdef CONFIG_GRKERNSEC
59235+ if (old_exec_file)
59236+ fput(old_exec_file);
59237+#endif
59238
59239 /* execve succeeded */
59240+
59241+ increment_exec_counter();
59242 current->fs->in_exec = 0;
59243 current->in_execve = 0;
59244 acct_update_integrals(current);
59245@@ -1535,6 +1701,14 @@ static int do_execve_common(struct filename *filename,
59246 put_files_struct(displaced);
59247 return retval;
59248
59249+out_fail:
59250+#ifdef CONFIG_GRKERNSEC
59251+ current->acl = old_acl;
59252+ memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
59253+ fput(current->exec_file);
59254+ current->exec_file = old_exec_file;
59255+#endif
59256+
59257 out:
59258 if (bprm->mm) {
59259 acct_arg_size(bprm, 0);
59260@@ -1626,3 +1800,296 @@ asmlinkage long compat_sys_execve(const char __user * filename,
59261 return compat_do_execve(getname(filename), argv, envp);
59262 }
59263 #endif
59264+
59265+int pax_check_flags(unsigned long *flags)
59266+{
59267+ int retval = 0;
59268+
59269+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_SEGMEXEC)
59270+ if (*flags & MF_PAX_SEGMEXEC)
59271+ {
59272+ *flags &= ~MF_PAX_SEGMEXEC;
59273+ retval = -EINVAL;
59274+ }
59275+#endif
59276+
59277+ if ((*flags & MF_PAX_PAGEEXEC)
59278+
59279+#ifdef CONFIG_PAX_PAGEEXEC
59280+ && (*flags & MF_PAX_SEGMEXEC)
59281+#endif
59282+
59283+ )
59284+ {
59285+ *flags &= ~MF_PAX_PAGEEXEC;
59286+ retval = -EINVAL;
59287+ }
59288+
59289+ if ((*flags & MF_PAX_MPROTECT)
59290+
59291+#ifdef CONFIG_PAX_MPROTECT
59292+ && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
59293+#endif
59294+
59295+ )
59296+ {
59297+ *flags &= ~MF_PAX_MPROTECT;
59298+ retval = -EINVAL;
59299+ }
59300+
59301+ if ((*flags & MF_PAX_EMUTRAMP)
59302+
59303+#ifdef CONFIG_PAX_EMUTRAMP
59304+ && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
59305+#endif
59306+
59307+ )
59308+ {
59309+ *flags &= ~MF_PAX_EMUTRAMP;
59310+ retval = -EINVAL;
59311+ }
59312+
59313+ return retval;
59314+}
59315+
59316+EXPORT_SYMBOL(pax_check_flags);
59317+
59318+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
59319+char *pax_get_path(const struct path *path, char *buf, int buflen)
59320+{
59321+ char *pathname = d_path(path, buf, buflen);
59322+
59323+ if (IS_ERR(pathname))
59324+ goto toolong;
59325+
59326+ pathname = mangle_path(buf, pathname, "\t\n\\");
59327+ if (!pathname)
59328+ goto toolong;
59329+
59330+ *pathname = 0;
59331+ return buf;
59332+
59333+toolong:
59334+ return "<path too long>";
59335+}
59336+EXPORT_SYMBOL(pax_get_path);
59337+
59338+void pax_report_fault(struct pt_regs *regs, void *pc, void *sp)
59339+{
59340+ struct task_struct *tsk = current;
59341+ struct mm_struct *mm = current->mm;
59342+ char *buffer_exec = (char *)__get_free_page(GFP_KERNEL);
59343+ char *buffer_fault = (char *)__get_free_page(GFP_KERNEL);
59344+ char *path_exec = NULL;
59345+ char *path_fault = NULL;
59346+ unsigned long start = 0UL, end = 0UL, offset = 0UL;
59347+ siginfo_t info = { };
59348+
59349+ if (buffer_exec && buffer_fault) {
59350+ struct vm_area_struct *vma, *vma_exec = NULL, *vma_fault = NULL;
59351+
59352+ down_read(&mm->mmap_sem);
59353+ vma = mm->mmap;
59354+ while (vma && (!vma_exec || !vma_fault)) {
59355+ if (vma->vm_file && mm->exe_file == vma->vm_file && (vma->vm_flags & VM_EXEC))
59356+ vma_exec = vma;
59357+ if (vma->vm_start <= (unsigned long)pc && (unsigned long)pc < vma->vm_end)
59358+ vma_fault = vma;
59359+ vma = vma->vm_next;
59360+ }
59361+ if (vma_exec)
59362+ path_exec = pax_get_path(&vma_exec->vm_file->f_path, buffer_exec, PAGE_SIZE);
59363+ if (vma_fault) {
59364+ start = vma_fault->vm_start;
59365+ end = vma_fault->vm_end;
59366+ offset = vma_fault->vm_pgoff << PAGE_SHIFT;
59367+ if (vma_fault->vm_file)
59368+ path_fault = pax_get_path(&vma_fault->vm_file->f_path, buffer_fault, PAGE_SIZE);
59369+ else if ((unsigned long)pc >= mm->start_brk && (unsigned long)pc < mm->brk)
59370+ path_fault = "<heap>";
59371+ else if (vma_fault->vm_flags & (VM_GROWSDOWN | VM_GROWSUP))
59372+ path_fault = "<stack>";
59373+ else
59374+ path_fault = "<anonymous mapping>";
59375+ }
59376+ up_read(&mm->mmap_sem);
59377+ }
59378+ if (tsk->signal->curr_ip)
59379+ printk(KERN_ERR "PAX: From %pI4: execution attempt in: %s, %08lx-%08lx %08lx\n", &tsk->signal->curr_ip, path_fault, start, end, offset);
59380+ else
59381+ printk(KERN_ERR "PAX: execution attempt in: %s, %08lx-%08lx %08lx\n", path_fault, start, end, offset);
59382+ 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),
59383+ from_kuid_munged(&init_user_ns, task_uid(tsk)), from_kuid_munged(&init_user_ns, task_euid(tsk)), pc, sp);
59384+ free_page((unsigned long)buffer_exec);
59385+ free_page((unsigned long)buffer_fault);
59386+ pax_report_insns(regs, pc, sp);
59387+ info.si_signo = SIGKILL;
59388+ info.si_errno = 0;
59389+ info.si_code = SI_KERNEL;
59390+ info.si_pid = 0;
59391+ info.si_uid = 0;
59392+ do_coredump(&info);
59393+}
59394+#endif
59395+
59396+#ifdef CONFIG_PAX_REFCOUNT
59397+void pax_report_refcount_overflow(struct pt_regs *regs)
59398+{
59399+ if (current->signal->curr_ip)
59400+ printk(KERN_ERR "PAX: From %pI4: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
59401+ &current->signal->curr_ip, current->comm, task_pid_nr(current),
59402+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
59403+ else
59404+ printk(KERN_ERR "PAX: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n", current->comm, task_pid_nr(current),
59405+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
59406+ print_symbol(KERN_ERR "PAX: refcount overflow occured at: %s\n", instruction_pointer(regs));
59407+ preempt_disable();
59408+ show_regs(regs);
59409+ preempt_enable();
59410+ force_sig_info(SIGKILL, SEND_SIG_FORCED, current);
59411+}
59412+#endif
59413+
59414+#ifdef CONFIG_PAX_USERCOPY
59415+/* 0: not at all, 1: fully, 2: fully inside frame, -1: partially (implies an error) */
59416+static noinline int check_stack_object(const void *obj, unsigned long len)
59417+{
59418+ const void * const stack = task_stack_page(current);
59419+ const void * const stackend = stack + THREAD_SIZE;
59420+
59421+#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
59422+ const void *frame = NULL;
59423+ const void *oldframe;
59424+#endif
59425+
59426+ if (obj + len < obj)
59427+ return -1;
59428+
59429+ if (obj + len <= stack || stackend <= obj)
59430+ return 0;
59431+
59432+ if (obj < stack || stackend < obj + len)
59433+ return -1;
59434+
59435+#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
59436+ oldframe = __builtin_frame_address(1);
59437+ if (oldframe)
59438+ frame = __builtin_frame_address(2);
59439+ /*
59440+ low ----------------------------------------------> high
59441+ [saved bp][saved ip][args][local vars][saved bp][saved ip]
59442+ ^----------------^
59443+ allow copies only within here
59444+ */
59445+ while (stack <= frame && frame < stackend) {
59446+ /* if obj + len extends past the last frame, this
59447+ check won't pass and the next frame will be 0,
59448+ causing us to bail out and correctly report
59449+ the copy as invalid
59450+ */
59451+ if (obj + len <= frame)
59452+ return obj >= oldframe + 2 * sizeof(void *) ? 2 : -1;
59453+ oldframe = frame;
59454+ frame = *(const void * const *)frame;
59455+ }
59456+ return -1;
59457+#else
59458+ return 1;
59459+#endif
59460+}
59461+
59462+static __noreturn void pax_report_usercopy(const void *ptr, unsigned long len, bool to_user, const char *type)
59463+{
59464+ if (current->signal->curr_ip)
59465+ printk(KERN_ERR "PAX: From %pI4: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
59466+ &current->signal->curr_ip, to_user ? "leak" : "overwrite", to_user ? "from" : "to", ptr, type ? : "unknown", len);
59467+ else
59468+ printk(KERN_ERR "PAX: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
59469+ to_user ? "leak" : "overwrite", to_user ? "from" : "to", ptr, type ? : "unknown", len);
59470+ dump_stack();
59471+ gr_handle_kernel_exploit();
59472+ do_group_exit(SIGKILL);
59473+}
59474+#endif
59475+
59476+#ifdef CONFIG_PAX_USERCOPY
59477+
59478+static inline bool check_kernel_text_object(unsigned long low, unsigned long high)
59479+{
59480+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
59481+ unsigned long textlow = ktla_ktva((unsigned long)_stext);
59482+#ifdef CONFIG_MODULES
59483+ unsigned long texthigh = (unsigned long)MODULES_EXEC_VADDR;
59484+#else
59485+ unsigned long texthigh = ktla_ktva((unsigned long)_etext);
59486+#endif
59487+
59488+#else
59489+ unsigned long textlow = (unsigned long)_stext;
59490+ unsigned long texthigh = (unsigned long)_etext;
59491+
59492+#ifdef CONFIG_X86_64
59493+ /* check against linear mapping as well */
59494+ if (high > (unsigned long)__va(__pa(textlow)) &&
59495+ low < (unsigned long)__va(__pa(texthigh)))
59496+ return true;
59497+#endif
59498+
59499+#endif
59500+
59501+ if (high <= textlow || low >= texthigh)
59502+ return false;
59503+ else
59504+ return true;
59505+}
59506+#endif
59507+
59508+void __check_object_size(const void *ptr, unsigned long n, bool to_user)
59509+{
59510+
59511+#ifdef CONFIG_PAX_USERCOPY
59512+ const char *type;
59513+
59514+ if (!n)
59515+ return;
59516+
59517+ type = check_heap_object(ptr, n);
59518+ if (!type) {
59519+ int ret = check_stack_object(ptr, n);
59520+ if (ret == 1 || ret == 2)
59521+ return;
59522+ if (ret == 0) {
59523+ if (check_kernel_text_object((unsigned long)ptr, (unsigned long)ptr + n))
59524+ type = "<kernel text>";
59525+ else
59526+ return;
59527+ } else
59528+ type = "<process stack>";
59529+ }
59530+
59531+ pax_report_usercopy(ptr, n, to_user, type);
59532+#endif
59533+
59534+}
59535+EXPORT_SYMBOL(__check_object_size);
59536+
59537+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
59538+void pax_track_stack(void)
59539+{
59540+ unsigned long sp = (unsigned long)&sp;
59541+ if (sp < current_thread_info()->lowest_stack &&
59542+ sp > (unsigned long)task_stack_page(current))
59543+ current_thread_info()->lowest_stack = sp;
59544+}
59545+EXPORT_SYMBOL(pax_track_stack);
59546+#endif
59547+
59548+#ifdef CONFIG_PAX_SIZE_OVERFLOW
59549+void report_size_overflow(const char *file, unsigned int line, const char *func, const char *ssa_name)
59550+{
59551+ printk(KERN_ERR "PAX: size overflow detected in function %s %s:%u %s", func, file, line, ssa_name);
59552+ dump_stack();
59553+ do_group_exit(SIGKILL);
59554+}
59555+EXPORT_SYMBOL(report_size_overflow);
59556+#endif
59557diff --git a/fs/ext2/balloc.c b/fs/ext2/balloc.c
59558index 9f9992b..8b59411 100644
59559--- a/fs/ext2/balloc.c
59560+++ b/fs/ext2/balloc.c
59561@@ -1184,10 +1184,10 @@ static int ext2_has_free_blocks(struct ext2_sb_info *sbi)
59562
59563 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
59564 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
59565- if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
59566+ if (free_blocks < root_blocks + 1 &&
59567 !uid_eq(sbi->s_resuid, current_fsuid()) &&
59568 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
59569- !in_group_p (sbi->s_resgid))) {
59570+ !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
59571 return 0;
59572 }
59573 return 1;
59574diff --git a/fs/ext2/xattr.c b/fs/ext2/xattr.c
59575index 9142614..97484fa 100644
59576--- a/fs/ext2/xattr.c
59577+++ b/fs/ext2/xattr.c
59578@@ -247,7 +247,7 @@ ext2_xattr_list(struct dentry *dentry, char *buffer, size_t buffer_size)
59579 struct buffer_head *bh = NULL;
59580 struct ext2_xattr_entry *entry;
59581 char *end;
59582- size_t rest = buffer_size;
59583+ size_t rest = buffer_size, total_size = 0;
59584 int error;
59585
59586 ea_idebug(inode, "buffer=%p, buffer_size=%ld",
59587@@ -305,9 +305,10 @@ bad_block: ext2_error(inode->i_sb, "ext2_xattr_list",
59588 buffer += size;
59589 }
59590 rest -= size;
59591+ total_size += size;
59592 }
59593 }
59594- error = buffer_size - rest; /* total size */
59595+ error = total_size;
59596
59597 cleanup:
59598 brelse(bh);
59599diff --git a/fs/ext3/balloc.c b/fs/ext3/balloc.c
59600index 22548f5..41521d8 100644
59601--- a/fs/ext3/balloc.c
59602+++ b/fs/ext3/balloc.c
59603@@ -1438,10 +1438,10 @@ static int ext3_has_free_blocks(struct ext3_sb_info *sbi, int use_reservation)
59604
59605 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
59606 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
59607- if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
59608+ if (free_blocks < root_blocks + 1 &&
59609 !use_reservation && !uid_eq(sbi->s_resuid, current_fsuid()) &&
59610 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
59611- !in_group_p (sbi->s_resgid))) {
59612+ !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
59613 return 0;
59614 }
59615 return 1;
59616diff --git a/fs/ext3/xattr.c b/fs/ext3/xattr.c
59617index c6874be..f8a6ae8 100644
59618--- a/fs/ext3/xattr.c
59619+++ b/fs/ext3/xattr.c
59620@@ -330,7 +330,7 @@ static int
59621 ext3_xattr_list_entries(struct dentry *dentry, struct ext3_xattr_entry *entry,
59622 char *buffer, size_t buffer_size)
59623 {
59624- size_t rest = buffer_size;
59625+ size_t rest = buffer_size, total_size = 0;
59626
59627 for (; !IS_LAST_ENTRY(entry); entry = EXT3_XATTR_NEXT(entry)) {
59628 const struct xattr_handler *handler =
59629@@ -347,9 +347,10 @@ ext3_xattr_list_entries(struct dentry *dentry, struct ext3_xattr_entry *entry,
59630 buffer += size;
59631 }
59632 rest -= size;
59633+ total_size += size;
59634 }
59635 }
59636- return buffer_size - rest;
59637+ return total_size;
59638 }
59639
59640 static int
59641diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
59642index 6ea7b14..8fa16d9 100644
59643--- a/fs/ext4/balloc.c
59644+++ b/fs/ext4/balloc.c
59645@@ -534,8 +534,8 @@ static int ext4_has_free_clusters(struct ext4_sb_info *sbi,
59646 /* Hm, nope. Are (enough) root reserved clusters available? */
59647 if (uid_eq(sbi->s_resuid, current_fsuid()) ||
59648 (!gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) && in_group_p(sbi->s_resgid)) ||
59649- capable(CAP_SYS_RESOURCE) ||
59650- (flags & EXT4_MB_USE_ROOT_BLOCKS)) {
59651+ (flags & EXT4_MB_USE_ROOT_BLOCKS) ||
59652+ capable_nolog(CAP_SYS_RESOURCE)) {
59653
59654 if (free_clusters >= (nclusters + dirty_clusters +
59655 resv_clusters))
59656diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
59657index 3a603a8..9b868ba 100644
59658--- a/fs/ext4/ext4.h
59659+++ b/fs/ext4/ext4.h
59660@@ -1269,19 +1269,19 @@ struct ext4_sb_info {
59661 unsigned long s_mb_last_start;
59662
59663 /* stats for buddy allocator */
59664- atomic_t s_bal_reqs; /* number of reqs with len > 1 */
59665- atomic_t s_bal_success; /* we found long enough chunks */
59666- atomic_t s_bal_allocated; /* in blocks */
59667- atomic_t s_bal_ex_scanned; /* total extents scanned */
59668- atomic_t s_bal_goals; /* goal hits */
59669- atomic_t s_bal_breaks; /* too long searches */
59670- atomic_t s_bal_2orders; /* 2^order hits */
59671+ atomic_unchecked_t s_bal_reqs; /* number of reqs with len > 1 */
59672+ atomic_unchecked_t s_bal_success; /* we found long enough chunks */
59673+ atomic_unchecked_t s_bal_allocated; /* in blocks */
59674+ atomic_unchecked_t s_bal_ex_scanned; /* total extents scanned */
59675+ atomic_unchecked_t s_bal_goals; /* goal hits */
59676+ atomic_unchecked_t s_bal_breaks; /* too long searches */
59677+ atomic_unchecked_t s_bal_2orders; /* 2^order hits */
59678 spinlock_t s_bal_lock;
59679 unsigned long s_mb_buddies_generated;
59680 unsigned long long s_mb_generation_time;
59681- atomic_t s_mb_lost_chunks;
59682- atomic_t s_mb_preallocated;
59683- atomic_t s_mb_discarded;
59684+ atomic_unchecked_t s_mb_lost_chunks;
59685+ atomic_unchecked_t s_mb_preallocated;
59686+ atomic_unchecked_t s_mb_discarded;
59687 atomic_t s_lock_busy;
59688
59689 /* locality groups */
59690diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
59691index 04a5c75..09894fa 100644
59692--- a/fs/ext4/mballoc.c
59693+++ b/fs/ext4/mballoc.c
59694@@ -1880,7 +1880,7 @@ void ext4_mb_simple_scan_group(struct ext4_allocation_context *ac,
59695 BUG_ON(ac->ac_b_ex.fe_len != ac->ac_g_ex.fe_len);
59696
59697 if (EXT4_SB(sb)->s_mb_stats)
59698- atomic_inc(&EXT4_SB(sb)->s_bal_2orders);
59699+ atomic_inc_unchecked(&EXT4_SB(sb)->s_bal_2orders);
59700
59701 break;
59702 }
59703@@ -2189,7 +2189,7 @@ repeat:
59704 ac->ac_status = AC_STATUS_CONTINUE;
59705 ac->ac_flags |= EXT4_MB_HINT_FIRST;
59706 cr = 3;
59707- atomic_inc(&sbi->s_mb_lost_chunks);
59708+ atomic_inc_unchecked(&sbi->s_mb_lost_chunks);
59709 goto repeat;
59710 }
59711 }
59712@@ -2697,25 +2697,25 @@ int ext4_mb_release(struct super_block *sb)
59713 if (sbi->s_mb_stats) {
59714 ext4_msg(sb, KERN_INFO,
59715 "mballoc: %u blocks %u reqs (%u success)",
59716- atomic_read(&sbi->s_bal_allocated),
59717- atomic_read(&sbi->s_bal_reqs),
59718- atomic_read(&sbi->s_bal_success));
59719+ atomic_read_unchecked(&sbi->s_bal_allocated),
59720+ atomic_read_unchecked(&sbi->s_bal_reqs),
59721+ atomic_read_unchecked(&sbi->s_bal_success));
59722 ext4_msg(sb, KERN_INFO,
59723 "mballoc: %u extents scanned, %u goal hits, "
59724 "%u 2^N hits, %u breaks, %u lost",
59725- atomic_read(&sbi->s_bal_ex_scanned),
59726- atomic_read(&sbi->s_bal_goals),
59727- atomic_read(&sbi->s_bal_2orders),
59728- atomic_read(&sbi->s_bal_breaks),
59729- atomic_read(&sbi->s_mb_lost_chunks));
59730+ atomic_read_unchecked(&sbi->s_bal_ex_scanned),
59731+ atomic_read_unchecked(&sbi->s_bal_goals),
59732+ atomic_read_unchecked(&sbi->s_bal_2orders),
59733+ atomic_read_unchecked(&sbi->s_bal_breaks),
59734+ atomic_read_unchecked(&sbi->s_mb_lost_chunks));
59735 ext4_msg(sb, KERN_INFO,
59736 "mballoc: %lu generated and it took %Lu",
59737 sbi->s_mb_buddies_generated,
59738 sbi->s_mb_generation_time);
59739 ext4_msg(sb, KERN_INFO,
59740 "mballoc: %u preallocated, %u discarded",
59741- atomic_read(&sbi->s_mb_preallocated),
59742- atomic_read(&sbi->s_mb_discarded));
59743+ atomic_read_unchecked(&sbi->s_mb_preallocated),
59744+ atomic_read_unchecked(&sbi->s_mb_discarded));
59745 }
59746
59747 free_percpu(sbi->s_locality_groups);
59748@@ -3169,16 +3169,16 @@ static void ext4_mb_collect_stats(struct ext4_allocation_context *ac)
59749 struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb);
59750
59751 if (sbi->s_mb_stats && ac->ac_g_ex.fe_len > 1) {
59752- atomic_inc(&sbi->s_bal_reqs);
59753- atomic_add(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
59754+ atomic_inc_unchecked(&sbi->s_bal_reqs);
59755+ atomic_add_unchecked(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
59756 if (ac->ac_b_ex.fe_len >= ac->ac_o_ex.fe_len)
59757- atomic_inc(&sbi->s_bal_success);
59758- atomic_add(ac->ac_found, &sbi->s_bal_ex_scanned);
59759+ atomic_inc_unchecked(&sbi->s_bal_success);
59760+ atomic_add_unchecked(ac->ac_found, &sbi->s_bal_ex_scanned);
59761 if (ac->ac_g_ex.fe_start == ac->ac_b_ex.fe_start &&
59762 ac->ac_g_ex.fe_group == ac->ac_b_ex.fe_group)
59763- atomic_inc(&sbi->s_bal_goals);
59764+ atomic_inc_unchecked(&sbi->s_bal_goals);
59765 if (ac->ac_found > sbi->s_mb_max_to_scan)
59766- atomic_inc(&sbi->s_bal_breaks);
59767+ atomic_inc_unchecked(&sbi->s_bal_breaks);
59768 }
59769
59770 if (ac->ac_op == EXT4_MB_HISTORY_ALLOC)
59771@@ -3583,7 +3583,7 @@ ext4_mb_new_inode_pa(struct ext4_allocation_context *ac)
59772 trace_ext4_mb_new_inode_pa(ac, pa);
59773
59774 ext4_mb_use_inode_pa(ac, pa);
59775- atomic_add(pa->pa_free, &sbi->s_mb_preallocated);
59776+ atomic_add_unchecked(pa->pa_free, &sbi->s_mb_preallocated);
59777
59778 ei = EXT4_I(ac->ac_inode);
59779 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
59780@@ -3643,7 +3643,7 @@ ext4_mb_new_group_pa(struct ext4_allocation_context *ac)
59781 trace_ext4_mb_new_group_pa(ac, pa);
59782
59783 ext4_mb_use_group_pa(ac, pa);
59784- atomic_add(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
59785+ atomic_add_unchecked(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
59786
59787 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
59788 lg = ac->ac_lg;
59789@@ -3732,7 +3732,7 @@ ext4_mb_release_inode_pa(struct ext4_buddy *e4b, struct buffer_head *bitmap_bh,
59790 * from the bitmap and continue.
59791 */
59792 }
59793- atomic_add(free, &sbi->s_mb_discarded);
59794+ atomic_add_unchecked(free, &sbi->s_mb_discarded);
59795
59796 return err;
59797 }
59798@@ -3750,7 +3750,7 @@ ext4_mb_release_group_pa(struct ext4_buddy *e4b,
59799 ext4_get_group_no_and_offset(sb, pa->pa_pstart, &group, &bit);
59800 BUG_ON(group != e4b->bd_group && pa->pa_len != 0);
59801 mb_free_blocks(pa->pa_inode, e4b, bit, pa->pa_len);
59802- atomic_add(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
59803+ atomic_add_unchecked(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
59804 trace_ext4_mballoc_discard(sb, NULL, group, bit, pa->pa_len);
59805
59806 return 0;
59807diff --git a/fs/ext4/mmp.c b/fs/ext4/mmp.c
59808index 04434ad..6404663 100644
59809--- a/fs/ext4/mmp.c
59810+++ b/fs/ext4/mmp.c
59811@@ -113,7 +113,7 @@ static int read_mmp_block(struct super_block *sb, struct buffer_head **bh,
59812 void __dump_mmp_msg(struct super_block *sb, struct mmp_struct *mmp,
59813 const char *function, unsigned int line, const char *msg)
59814 {
59815- __ext4_warning(sb, function, line, msg);
59816+ __ext4_warning(sb, function, line, "%s", msg);
59817 __ext4_warning(sb, function, line,
59818 "MMP failure info: last update time: %llu, last update "
59819 "node: %s, last update device: %s\n",
59820diff --git a/fs/ext4/super.c b/fs/ext4/super.c
59821index 710fed2..a82e4e8 100644
59822--- a/fs/ext4/super.c
59823+++ b/fs/ext4/super.c
59824@@ -1270,7 +1270,7 @@ static ext4_fsblk_t get_sb_block(void **data)
59825 }
59826
59827 #define DEFAULT_JOURNAL_IOPRIO (IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE, 3))
59828-static char deprecated_msg[] = "Mount option \"%s\" will be removed by %s\n"
59829+static const char deprecated_msg[] = "Mount option \"%s\" will be removed by %s\n"
59830 "Contact linux-ext4@vger.kernel.org if you think we should keep it.\n";
59831
59832 #ifdef CONFIG_QUOTA
59833@@ -2450,7 +2450,7 @@ struct ext4_attr {
59834 int offset;
59835 int deprecated_val;
59836 } u;
59837-};
59838+} __do_const;
59839
59840 static int parse_strtoull(const char *buf,
59841 unsigned long long max, unsigned long long *value)
59842diff --git a/fs/ext4/xattr.c b/fs/ext4/xattr.c
59843index 55e611c..cfad16d 100644
59844--- a/fs/ext4/xattr.c
59845+++ b/fs/ext4/xattr.c
59846@@ -381,7 +381,7 @@ static int
59847 ext4_xattr_list_entries(struct dentry *dentry, struct ext4_xattr_entry *entry,
59848 char *buffer, size_t buffer_size)
59849 {
59850- size_t rest = buffer_size;
59851+ size_t rest = buffer_size, total_size = 0;
59852
59853 for (; !IS_LAST_ENTRY(entry); entry = EXT4_XATTR_NEXT(entry)) {
59854 const struct xattr_handler *handler =
59855@@ -398,9 +398,10 @@ ext4_xattr_list_entries(struct dentry *dentry, struct ext4_xattr_entry *entry,
59856 buffer += size;
59857 }
59858 rest -= size;
59859+ total_size += size;
59860 }
59861 }
59862- return buffer_size - rest;
59863+ return total_size;
59864 }
59865
59866 static int
59867diff --git a/fs/fcntl.c b/fs/fcntl.c
59868index ef68665..5deacdc 100644
59869--- a/fs/fcntl.c
59870+++ b/fs/fcntl.c
59871@@ -106,6 +106,11 @@ int __f_setown(struct file *filp, struct pid *pid, enum pid_type type,
59872 if (err)
59873 return err;
59874
59875+ if (gr_handle_chroot_fowner(pid, type))
59876+ return -ENOENT;
59877+ if (gr_check_protected_task_fowner(pid, type))
59878+ return -EACCES;
59879+
59880 f_modown(filp, pid, type, force);
59881 return 0;
59882 }
59883diff --git a/fs/fhandle.c b/fs/fhandle.c
59884index 999ff5c..41f4109 100644
59885--- a/fs/fhandle.c
59886+++ b/fs/fhandle.c
59887@@ -67,8 +67,7 @@ static long do_sys_name_to_handle(struct path *path,
59888 } else
59889 retval = 0;
59890 /* copy the mount id */
59891- if (copy_to_user(mnt_id, &real_mount(path->mnt)->mnt_id,
59892- sizeof(*mnt_id)) ||
59893+ if (put_user(real_mount(path->mnt)->mnt_id, mnt_id) ||
59894 copy_to_user(ufh, handle,
59895 sizeof(struct file_handle) + handle_bytes))
59896 retval = -EFAULT;
59897diff --git a/fs/file.c b/fs/file.c
59898index eb56a13..ccee850 100644
59899--- a/fs/file.c
59900+++ b/fs/file.c
59901@@ -16,6 +16,7 @@
59902 #include <linux/slab.h>
59903 #include <linux/vmalloc.h>
59904 #include <linux/file.h>
59905+#include <linux/security.h>
59906 #include <linux/fdtable.h>
59907 #include <linux/bitops.h>
59908 #include <linux/interrupt.h>
59909@@ -141,7 +142,7 @@ out:
59910 * Return <0 error code on error; 1 on successful completion.
59911 * The files->file_lock should be held on entry, and will be held on exit.
59912 */
59913-static int expand_fdtable(struct files_struct *files, int nr)
59914+static int expand_fdtable(struct files_struct *files, unsigned int nr)
59915 __releases(files->file_lock)
59916 __acquires(files->file_lock)
59917 {
59918@@ -186,7 +187,7 @@ static int expand_fdtable(struct files_struct *files, int nr)
59919 * expanded and execution may have blocked.
59920 * The files->file_lock should be held on entry, and will be held on exit.
59921 */
59922-static int expand_files(struct files_struct *files, int nr)
59923+static int expand_files(struct files_struct *files, unsigned int nr)
59924 {
59925 struct fdtable *fdt;
59926
59927@@ -807,6 +808,7 @@ int replace_fd(unsigned fd, struct file *file, unsigned flags)
59928 if (!file)
59929 return __close_fd(files, fd);
59930
59931+ gr_learn_resource(current, RLIMIT_NOFILE, fd, 0);
59932 if (fd >= rlimit(RLIMIT_NOFILE))
59933 return -EBADF;
59934
59935@@ -833,6 +835,7 @@ SYSCALL_DEFINE3(dup3, unsigned int, oldfd, unsigned int, newfd, int, flags)
59936 if (unlikely(oldfd == newfd))
59937 return -EINVAL;
59938
59939+ gr_learn_resource(current, RLIMIT_NOFILE, newfd, 0);
59940 if (newfd >= rlimit(RLIMIT_NOFILE))
59941 return -EBADF;
59942
59943@@ -888,6 +891,7 @@ SYSCALL_DEFINE1(dup, unsigned int, fildes)
59944 int f_dupfd(unsigned int from, struct file *file, unsigned flags)
59945 {
59946 int err;
59947+ gr_learn_resource(current, RLIMIT_NOFILE, from, 0);
59948 if (from >= rlimit(RLIMIT_NOFILE))
59949 return -EINVAL;
59950 err = alloc_fd(from, flags);
59951diff --git a/fs/filesystems.c b/fs/filesystems.c
59952index 92567d9..fcd8cbf 100644
59953--- a/fs/filesystems.c
59954+++ b/fs/filesystems.c
59955@@ -273,7 +273,11 @@ struct file_system_type *get_fs_type(const char *name)
59956 int len = dot ? dot - name : strlen(name);
59957
59958 fs = __get_fs_type(name, len);
59959+#ifdef CONFIG_GRKERNSEC_MODHARDEN
59960+ if (!fs && (___request_module(true, "grsec_modharden_fs", "fs-%.*s", len, name) == 0))
59961+#else
59962 if (!fs && (request_module("fs-%.*s", len, name) == 0))
59963+#endif
59964 fs = __get_fs_type(name, len);
59965
59966 if (dot && fs && !(fs->fs_flags & FS_HAS_SUBTYPE)) {
59967diff --git a/fs/fs_struct.c b/fs/fs_struct.c
59968index 7dca743..543d620 100644
59969--- a/fs/fs_struct.c
59970+++ b/fs/fs_struct.c
59971@@ -4,6 +4,7 @@
59972 #include <linux/path.h>
59973 #include <linux/slab.h>
59974 #include <linux/fs_struct.h>
59975+#include <linux/grsecurity.h>
59976 #include "internal.h"
59977
59978 /*
59979@@ -19,6 +20,7 @@ void set_fs_root(struct fs_struct *fs, const struct path *path)
59980 write_seqcount_begin(&fs->seq);
59981 old_root = fs->root;
59982 fs->root = *path;
59983+ gr_set_chroot_entries(current, path);
59984 write_seqcount_end(&fs->seq);
59985 spin_unlock(&fs->lock);
59986 if (old_root.dentry)
59987@@ -67,6 +69,10 @@ void chroot_fs_refs(const struct path *old_root, const struct path *new_root)
59988 int hits = 0;
59989 spin_lock(&fs->lock);
59990 write_seqcount_begin(&fs->seq);
59991+ /* this root replacement is only done by pivot_root,
59992+ leave grsec's chroot tagging alone for this task
59993+ so that a pivoted root isn't treated as a chroot
59994+ */
59995 hits += replace_path(&fs->root, old_root, new_root);
59996 hits += replace_path(&fs->pwd, old_root, new_root);
59997 write_seqcount_end(&fs->seq);
59998@@ -99,7 +105,8 @@ void exit_fs(struct task_struct *tsk)
59999 task_lock(tsk);
60000 spin_lock(&fs->lock);
60001 tsk->fs = NULL;
60002- kill = !--fs->users;
60003+ gr_clear_chroot_entries(tsk);
60004+ kill = !atomic_dec_return(&fs->users);
60005 spin_unlock(&fs->lock);
60006 task_unlock(tsk);
60007 if (kill)
60008@@ -112,7 +119,7 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
60009 struct fs_struct *fs = kmem_cache_alloc(fs_cachep, GFP_KERNEL);
60010 /* We don't need to lock fs - think why ;-) */
60011 if (fs) {
60012- fs->users = 1;
60013+ atomic_set(&fs->users, 1);
60014 fs->in_exec = 0;
60015 spin_lock_init(&fs->lock);
60016 seqcount_init(&fs->seq);
60017@@ -121,6 +128,9 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
60018 spin_lock(&old->lock);
60019 fs->root = old->root;
60020 path_get(&fs->root);
60021+ /* instead of calling gr_set_chroot_entries here,
60022+ we call it from every caller of this function
60023+ */
60024 fs->pwd = old->pwd;
60025 path_get(&fs->pwd);
60026 spin_unlock(&old->lock);
60027@@ -139,8 +149,9 @@ int unshare_fs_struct(void)
60028
60029 task_lock(current);
60030 spin_lock(&fs->lock);
60031- kill = !--fs->users;
60032+ kill = !atomic_dec_return(&fs->users);
60033 current->fs = new_fs;
60034+ gr_set_chroot_entries(current, &new_fs->root);
60035 spin_unlock(&fs->lock);
60036 task_unlock(current);
60037
60038@@ -153,13 +164,13 @@ EXPORT_SYMBOL_GPL(unshare_fs_struct);
60039
60040 int current_umask(void)
60041 {
60042- return current->fs->umask;
60043+ return current->fs->umask | gr_acl_umask();
60044 }
60045 EXPORT_SYMBOL(current_umask);
60046
60047 /* to be mentioned only in INIT_TASK */
60048 struct fs_struct init_fs = {
60049- .users = 1,
60050+ .users = ATOMIC_INIT(1),
60051 .lock = __SPIN_LOCK_UNLOCKED(init_fs.lock),
60052 .seq = SEQCNT_ZERO(init_fs.seq),
60053 .umask = 0022,
60054diff --git a/fs/fscache/cookie.c b/fs/fscache/cookie.c
60055index 29d7feb..303644d 100644
60056--- a/fs/fscache/cookie.c
60057+++ b/fs/fscache/cookie.c
60058@@ -19,7 +19,7 @@
60059
60060 struct kmem_cache *fscache_cookie_jar;
60061
60062-static atomic_t fscache_object_debug_id = ATOMIC_INIT(0);
60063+static atomic_unchecked_t fscache_object_debug_id = ATOMIC_INIT(0);
60064
60065 static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie);
60066 static int fscache_alloc_object(struct fscache_cache *cache,
60067@@ -69,11 +69,11 @@ struct fscache_cookie *__fscache_acquire_cookie(
60068 parent ? (char *) parent->def->name : "<no-parent>",
60069 def->name, netfs_data, enable);
60070
60071- fscache_stat(&fscache_n_acquires);
60072+ fscache_stat_unchecked(&fscache_n_acquires);
60073
60074 /* if there's no parent cookie, then we don't create one here either */
60075 if (!parent) {
60076- fscache_stat(&fscache_n_acquires_null);
60077+ fscache_stat_unchecked(&fscache_n_acquires_null);
60078 _leave(" [no parent]");
60079 return NULL;
60080 }
60081@@ -88,7 +88,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
60082 /* allocate and initialise a cookie */
60083 cookie = kmem_cache_alloc(fscache_cookie_jar, GFP_KERNEL);
60084 if (!cookie) {
60085- fscache_stat(&fscache_n_acquires_oom);
60086+ fscache_stat_unchecked(&fscache_n_acquires_oom);
60087 _leave(" [ENOMEM]");
60088 return NULL;
60089 }
60090@@ -115,13 +115,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
60091
60092 switch (cookie->def->type) {
60093 case FSCACHE_COOKIE_TYPE_INDEX:
60094- fscache_stat(&fscache_n_cookie_index);
60095+ fscache_stat_unchecked(&fscache_n_cookie_index);
60096 break;
60097 case FSCACHE_COOKIE_TYPE_DATAFILE:
60098- fscache_stat(&fscache_n_cookie_data);
60099+ fscache_stat_unchecked(&fscache_n_cookie_data);
60100 break;
60101 default:
60102- fscache_stat(&fscache_n_cookie_special);
60103+ fscache_stat_unchecked(&fscache_n_cookie_special);
60104 break;
60105 }
60106
60107@@ -135,7 +135,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
60108 } else {
60109 atomic_dec(&parent->n_children);
60110 __fscache_cookie_put(cookie);
60111- fscache_stat(&fscache_n_acquires_nobufs);
60112+ fscache_stat_unchecked(&fscache_n_acquires_nobufs);
60113 _leave(" = NULL");
60114 return NULL;
60115 }
60116@@ -144,7 +144,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
60117 }
60118 }
60119
60120- fscache_stat(&fscache_n_acquires_ok);
60121+ fscache_stat_unchecked(&fscache_n_acquires_ok);
60122 _leave(" = %p", cookie);
60123 return cookie;
60124 }
60125@@ -213,7 +213,7 @@ static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie)
60126 cache = fscache_select_cache_for_object(cookie->parent);
60127 if (!cache) {
60128 up_read(&fscache_addremove_sem);
60129- fscache_stat(&fscache_n_acquires_no_cache);
60130+ fscache_stat_unchecked(&fscache_n_acquires_no_cache);
60131 _leave(" = -ENOMEDIUM [no cache]");
60132 return -ENOMEDIUM;
60133 }
60134@@ -297,14 +297,14 @@ static int fscache_alloc_object(struct fscache_cache *cache,
60135 object = cache->ops->alloc_object(cache, cookie);
60136 fscache_stat_d(&fscache_n_cop_alloc_object);
60137 if (IS_ERR(object)) {
60138- fscache_stat(&fscache_n_object_no_alloc);
60139+ fscache_stat_unchecked(&fscache_n_object_no_alloc);
60140 ret = PTR_ERR(object);
60141 goto error;
60142 }
60143
60144- fscache_stat(&fscache_n_object_alloc);
60145+ fscache_stat_unchecked(&fscache_n_object_alloc);
60146
60147- object->debug_id = atomic_inc_return(&fscache_object_debug_id);
60148+ object->debug_id = atomic_inc_return_unchecked(&fscache_object_debug_id);
60149
60150 _debug("ALLOC OBJ%x: %s {%lx}",
60151 object->debug_id, cookie->def->name, object->events);
60152@@ -418,7 +418,7 @@ void __fscache_invalidate(struct fscache_cookie *cookie)
60153
60154 _enter("{%s}", cookie->def->name);
60155
60156- fscache_stat(&fscache_n_invalidates);
60157+ fscache_stat_unchecked(&fscache_n_invalidates);
60158
60159 /* Only permit invalidation of data files. Invalidating an index will
60160 * require the caller to release all its attachments to the tree rooted
60161@@ -477,10 +477,10 @@ void __fscache_update_cookie(struct fscache_cookie *cookie)
60162 {
60163 struct fscache_object *object;
60164
60165- fscache_stat(&fscache_n_updates);
60166+ fscache_stat_unchecked(&fscache_n_updates);
60167
60168 if (!cookie) {
60169- fscache_stat(&fscache_n_updates_null);
60170+ fscache_stat_unchecked(&fscache_n_updates_null);
60171 _leave(" [no cookie]");
60172 return;
60173 }
60174@@ -581,12 +581,12 @@ EXPORT_SYMBOL(__fscache_disable_cookie);
60175 */
60176 void __fscache_relinquish_cookie(struct fscache_cookie *cookie, bool retire)
60177 {
60178- fscache_stat(&fscache_n_relinquishes);
60179+ fscache_stat_unchecked(&fscache_n_relinquishes);
60180 if (retire)
60181- fscache_stat(&fscache_n_relinquishes_retire);
60182+ fscache_stat_unchecked(&fscache_n_relinquishes_retire);
60183
60184 if (!cookie) {
60185- fscache_stat(&fscache_n_relinquishes_null);
60186+ fscache_stat_unchecked(&fscache_n_relinquishes_null);
60187 _leave(" [no cookie]");
60188 return;
60189 }
60190@@ -687,7 +687,7 @@ int __fscache_check_consistency(struct fscache_cookie *cookie)
60191 if (test_bit(FSCACHE_IOERROR, &object->cache->flags))
60192 goto inconsistent;
60193
60194- op->debug_id = atomic_inc_return(&fscache_op_debug_id);
60195+ op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
60196
60197 __fscache_use_cookie(cookie);
60198 if (fscache_submit_op(object, op) < 0)
60199diff --git a/fs/fscache/internal.h b/fs/fscache/internal.h
60200index 4226f66..0fb3f45 100644
60201--- a/fs/fscache/internal.h
60202+++ b/fs/fscache/internal.h
60203@@ -133,8 +133,8 @@ extern void fscache_operation_gc(struct work_struct *);
60204 extern int fscache_wait_for_deferred_lookup(struct fscache_cookie *);
60205 extern int fscache_wait_for_operation_activation(struct fscache_object *,
60206 struct fscache_operation *,
60207- atomic_t *,
60208- atomic_t *,
60209+ atomic_unchecked_t *,
60210+ atomic_unchecked_t *,
60211 void (*)(struct fscache_operation *));
60212 extern void fscache_invalidate_writes(struct fscache_cookie *);
60213
60214@@ -153,101 +153,101 @@ extern void fscache_proc_cleanup(void);
60215 * stats.c
60216 */
60217 #ifdef CONFIG_FSCACHE_STATS
60218-extern atomic_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
60219-extern atomic_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
60220+extern atomic_unchecked_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
60221+extern atomic_unchecked_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
60222
60223-extern atomic_t fscache_n_op_pend;
60224-extern atomic_t fscache_n_op_run;
60225-extern atomic_t fscache_n_op_enqueue;
60226-extern atomic_t fscache_n_op_deferred_release;
60227-extern atomic_t fscache_n_op_release;
60228-extern atomic_t fscache_n_op_gc;
60229-extern atomic_t fscache_n_op_cancelled;
60230-extern atomic_t fscache_n_op_rejected;
60231+extern atomic_unchecked_t fscache_n_op_pend;
60232+extern atomic_unchecked_t fscache_n_op_run;
60233+extern atomic_unchecked_t fscache_n_op_enqueue;
60234+extern atomic_unchecked_t fscache_n_op_deferred_release;
60235+extern atomic_unchecked_t fscache_n_op_release;
60236+extern atomic_unchecked_t fscache_n_op_gc;
60237+extern atomic_unchecked_t fscache_n_op_cancelled;
60238+extern atomic_unchecked_t fscache_n_op_rejected;
60239
60240-extern atomic_t fscache_n_attr_changed;
60241-extern atomic_t fscache_n_attr_changed_ok;
60242-extern atomic_t fscache_n_attr_changed_nobufs;
60243-extern atomic_t fscache_n_attr_changed_nomem;
60244-extern atomic_t fscache_n_attr_changed_calls;
60245+extern atomic_unchecked_t fscache_n_attr_changed;
60246+extern atomic_unchecked_t fscache_n_attr_changed_ok;
60247+extern atomic_unchecked_t fscache_n_attr_changed_nobufs;
60248+extern atomic_unchecked_t fscache_n_attr_changed_nomem;
60249+extern atomic_unchecked_t fscache_n_attr_changed_calls;
60250
60251-extern atomic_t fscache_n_allocs;
60252-extern atomic_t fscache_n_allocs_ok;
60253-extern atomic_t fscache_n_allocs_wait;
60254-extern atomic_t fscache_n_allocs_nobufs;
60255-extern atomic_t fscache_n_allocs_intr;
60256-extern atomic_t fscache_n_allocs_object_dead;
60257-extern atomic_t fscache_n_alloc_ops;
60258-extern atomic_t fscache_n_alloc_op_waits;
60259+extern atomic_unchecked_t fscache_n_allocs;
60260+extern atomic_unchecked_t fscache_n_allocs_ok;
60261+extern atomic_unchecked_t fscache_n_allocs_wait;
60262+extern atomic_unchecked_t fscache_n_allocs_nobufs;
60263+extern atomic_unchecked_t fscache_n_allocs_intr;
60264+extern atomic_unchecked_t fscache_n_allocs_object_dead;
60265+extern atomic_unchecked_t fscache_n_alloc_ops;
60266+extern atomic_unchecked_t fscache_n_alloc_op_waits;
60267
60268-extern atomic_t fscache_n_retrievals;
60269-extern atomic_t fscache_n_retrievals_ok;
60270-extern atomic_t fscache_n_retrievals_wait;
60271-extern atomic_t fscache_n_retrievals_nodata;
60272-extern atomic_t fscache_n_retrievals_nobufs;
60273-extern atomic_t fscache_n_retrievals_intr;
60274-extern atomic_t fscache_n_retrievals_nomem;
60275-extern atomic_t fscache_n_retrievals_object_dead;
60276-extern atomic_t fscache_n_retrieval_ops;
60277-extern atomic_t fscache_n_retrieval_op_waits;
60278+extern atomic_unchecked_t fscache_n_retrievals;
60279+extern atomic_unchecked_t fscache_n_retrievals_ok;
60280+extern atomic_unchecked_t fscache_n_retrievals_wait;
60281+extern atomic_unchecked_t fscache_n_retrievals_nodata;
60282+extern atomic_unchecked_t fscache_n_retrievals_nobufs;
60283+extern atomic_unchecked_t fscache_n_retrievals_intr;
60284+extern atomic_unchecked_t fscache_n_retrievals_nomem;
60285+extern atomic_unchecked_t fscache_n_retrievals_object_dead;
60286+extern atomic_unchecked_t fscache_n_retrieval_ops;
60287+extern atomic_unchecked_t fscache_n_retrieval_op_waits;
60288
60289-extern atomic_t fscache_n_stores;
60290-extern atomic_t fscache_n_stores_ok;
60291-extern atomic_t fscache_n_stores_again;
60292-extern atomic_t fscache_n_stores_nobufs;
60293-extern atomic_t fscache_n_stores_oom;
60294-extern atomic_t fscache_n_store_ops;
60295-extern atomic_t fscache_n_store_calls;
60296-extern atomic_t fscache_n_store_pages;
60297-extern atomic_t fscache_n_store_radix_deletes;
60298-extern atomic_t fscache_n_store_pages_over_limit;
60299+extern atomic_unchecked_t fscache_n_stores;
60300+extern atomic_unchecked_t fscache_n_stores_ok;
60301+extern atomic_unchecked_t fscache_n_stores_again;
60302+extern atomic_unchecked_t fscache_n_stores_nobufs;
60303+extern atomic_unchecked_t fscache_n_stores_oom;
60304+extern atomic_unchecked_t fscache_n_store_ops;
60305+extern atomic_unchecked_t fscache_n_store_calls;
60306+extern atomic_unchecked_t fscache_n_store_pages;
60307+extern atomic_unchecked_t fscache_n_store_radix_deletes;
60308+extern atomic_unchecked_t fscache_n_store_pages_over_limit;
60309
60310-extern atomic_t fscache_n_store_vmscan_not_storing;
60311-extern atomic_t fscache_n_store_vmscan_gone;
60312-extern atomic_t fscache_n_store_vmscan_busy;
60313-extern atomic_t fscache_n_store_vmscan_cancelled;
60314-extern atomic_t fscache_n_store_vmscan_wait;
60315+extern atomic_unchecked_t fscache_n_store_vmscan_not_storing;
60316+extern atomic_unchecked_t fscache_n_store_vmscan_gone;
60317+extern atomic_unchecked_t fscache_n_store_vmscan_busy;
60318+extern atomic_unchecked_t fscache_n_store_vmscan_cancelled;
60319+extern atomic_unchecked_t fscache_n_store_vmscan_wait;
60320
60321-extern atomic_t fscache_n_marks;
60322-extern atomic_t fscache_n_uncaches;
60323+extern atomic_unchecked_t fscache_n_marks;
60324+extern atomic_unchecked_t fscache_n_uncaches;
60325
60326-extern atomic_t fscache_n_acquires;
60327-extern atomic_t fscache_n_acquires_null;
60328-extern atomic_t fscache_n_acquires_no_cache;
60329-extern atomic_t fscache_n_acquires_ok;
60330-extern atomic_t fscache_n_acquires_nobufs;
60331-extern atomic_t fscache_n_acquires_oom;
60332+extern atomic_unchecked_t fscache_n_acquires;
60333+extern atomic_unchecked_t fscache_n_acquires_null;
60334+extern atomic_unchecked_t fscache_n_acquires_no_cache;
60335+extern atomic_unchecked_t fscache_n_acquires_ok;
60336+extern atomic_unchecked_t fscache_n_acquires_nobufs;
60337+extern atomic_unchecked_t fscache_n_acquires_oom;
60338
60339-extern atomic_t fscache_n_invalidates;
60340-extern atomic_t fscache_n_invalidates_run;
60341+extern atomic_unchecked_t fscache_n_invalidates;
60342+extern atomic_unchecked_t fscache_n_invalidates_run;
60343
60344-extern atomic_t fscache_n_updates;
60345-extern atomic_t fscache_n_updates_null;
60346-extern atomic_t fscache_n_updates_run;
60347+extern atomic_unchecked_t fscache_n_updates;
60348+extern atomic_unchecked_t fscache_n_updates_null;
60349+extern atomic_unchecked_t fscache_n_updates_run;
60350
60351-extern atomic_t fscache_n_relinquishes;
60352-extern atomic_t fscache_n_relinquishes_null;
60353-extern atomic_t fscache_n_relinquishes_waitcrt;
60354-extern atomic_t fscache_n_relinquishes_retire;
60355+extern atomic_unchecked_t fscache_n_relinquishes;
60356+extern atomic_unchecked_t fscache_n_relinquishes_null;
60357+extern atomic_unchecked_t fscache_n_relinquishes_waitcrt;
60358+extern atomic_unchecked_t fscache_n_relinquishes_retire;
60359
60360-extern atomic_t fscache_n_cookie_index;
60361-extern atomic_t fscache_n_cookie_data;
60362-extern atomic_t fscache_n_cookie_special;
60363+extern atomic_unchecked_t fscache_n_cookie_index;
60364+extern atomic_unchecked_t fscache_n_cookie_data;
60365+extern atomic_unchecked_t fscache_n_cookie_special;
60366
60367-extern atomic_t fscache_n_object_alloc;
60368-extern atomic_t fscache_n_object_no_alloc;
60369-extern atomic_t fscache_n_object_lookups;
60370-extern atomic_t fscache_n_object_lookups_negative;
60371-extern atomic_t fscache_n_object_lookups_positive;
60372-extern atomic_t fscache_n_object_lookups_timed_out;
60373-extern atomic_t fscache_n_object_created;
60374-extern atomic_t fscache_n_object_avail;
60375-extern atomic_t fscache_n_object_dead;
60376+extern atomic_unchecked_t fscache_n_object_alloc;
60377+extern atomic_unchecked_t fscache_n_object_no_alloc;
60378+extern atomic_unchecked_t fscache_n_object_lookups;
60379+extern atomic_unchecked_t fscache_n_object_lookups_negative;
60380+extern atomic_unchecked_t fscache_n_object_lookups_positive;
60381+extern atomic_unchecked_t fscache_n_object_lookups_timed_out;
60382+extern atomic_unchecked_t fscache_n_object_created;
60383+extern atomic_unchecked_t fscache_n_object_avail;
60384+extern atomic_unchecked_t fscache_n_object_dead;
60385
60386-extern atomic_t fscache_n_checkaux_none;
60387-extern atomic_t fscache_n_checkaux_okay;
60388-extern atomic_t fscache_n_checkaux_update;
60389-extern atomic_t fscache_n_checkaux_obsolete;
60390+extern atomic_unchecked_t fscache_n_checkaux_none;
60391+extern atomic_unchecked_t fscache_n_checkaux_okay;
60392+extern atomic_unchecked_t fscache_n_checkaux_update;
60393+extern atomic_unchecked_t fscache_n_checkaux_obsolete;
60394
60395 extern atomic_t fscache_n_cop_alloc_object;
60396 extern atomic_t fscache_n_cop_lookup_object;
60397@@ -272,6 +272,11 @@ static inline void fscache_stat(atomic_t *stat)
60398 atomic_inc(stat);
60399 }
60400
60401+static inline void fscache_stat_unchecked(atomic_unchecked_t *stat)
60402+{
60403+ atomic_inc_unchecked(stat);
60404+}
60405+
60406 static inline void fscache_stat_d(atomic_t *stat)
60407 {
60408 atomic_dec(stat);
60409@@ -284,6 +289,7 @@ extern const struct file_operations fscache_stats_fops;
60410
60411 #define __fscache_stat(stat) (NULL)
60412 #define fscache_stat(stat) do {} while (0)
60413+#define fscache_stat_unchecked(stat) do {} while (0)
60414 #define fscache_stat_d(stat) do {} while (0)
60415 #endif
60416
60417diff --git a/fs/fscache/object.c b/fs/fscache/object.c
60418index d3b4539..ed0c659 100644
60419--- a/fs/fscache/object.c
60420+++ b/fs/fscache/object.c
60421@@ -454,7 +454,7 @@ static const struct fscache_state *fscache_look_up_object(struct fscache_object
60422 _debug("LOOKUP \"%s\" in \"%s\"",
60423 cookie->def->name, object->cache->tag->name);
60424
60425- fscache_stat(&fscache_n_object_lookups);
60426+ fscache_stat_unchecked(&fscache_n_object_lookups);
60427 fscache_stat(&fscache_n_cop_lookup_object);
60428 ret = object->cache->ops->lookup_object(object);
60429 fscache_stat_d(&fscache_n_cop_lookup_object);
60430@@ -464,7 +464,7 @@ static const struct fscache_state *fscache_look_up_object(struct fscache_object
60431 if (ret == -ETIMEDOUT) {
60432 /* probably stuck behind another object, so move this one to
60433 * the back of the queue */
60434- fscache_stat(&fscache_n_object_lookups_timed_out);
60435+ fscache_stat_unchecked(&fscache_n_object_lookups_timed_out);
60436 _leave(" [timeout]");
60437 return NO_TRANSIT;
60438 }
60439@@ -492,7 +492,7 @@ void fscache_object_lookup_negative(struct fscache_object *object)
60440 _enter("{OBJ%x,%s}", object->debug_id, object->state->name);
60441
60442 if (!test_and_set_bit(FSCACHE_OBJECT_IS_LOOKED_UP, &object->flags)) {
60443- fscache_stat(&fscache_n_object_lookups_negative);
60444+ fscache_stat_unchecked(&fscache_n_object_lookups_negative);
60445
60446 /* Allow write requests to begin stacking up and read requests to begin
60447 * returning ENODATA.
60448@@ -527,7 +527,7 @@ void fscache_obtained_object(struct fscache_object *object)
60449 /* if we were still looking up, then we must have a positive lookup
60450 * result, in which case there may be data available */
60451 if (!test_and_set_bit(FSCACHE_OBJECT_IS_LOOKED_UP, &object->flags)) {
60452- fscache_stat(&fscache_n_object_lookups_positive);
60453+ fscache_stat_unchecked(&fscache_n_object_lookups_positive);
60454
60455 /* We do (presumably) have data */
60456 clear_bit_unlock(FSCACHE_COOKIE_NO_DATA_YET, &cookie->flags);
60457@@ -539,7 +539,7 @@ void fscache_obtained_object(struct fscache_object *object)
60458 clear_bit_unlock(FSCACHE_COOKIE_LOOKING_UP, &cookie->flags);
60459 wake_up_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP);
60460 } else {
60461- fscache_stat(&fscache_n_object_created);
60462+ fscache_stat_unchecked(&fscache_n_object_created);
60463 }
60464
60465 set_bit(FSCACHE_OBJECT_IS_AVAILABLE, &object->flags);
60466@@ -575,7 +575,7 @@ static const struct fscache_state *fscache_object_available(struct fscache_objec
60467 fscache_stat_d(&fscache_n_cop_lookup_complete);
60468
60469 fscache_hist(fscache_obj_instantiate_histogram, object->lookup_jif);
60470- fscache_stat(&fscache_n_object_avail);
60471+ fscache_stat_unchecked(&fscache_n_object_avail);
60472
60473 _leave("");
60474 return transit_to(JUMPSTART_DEPS);
60475@@ -722,7 +722,7 @@ static const struct fscache_state *fscache_drop_object(struct fscache_object *ob
60476
60477 /* this just shifts the object release to the work processor */
60478 fscache_put_object(object);
60479- fscache_stat(&fscache_n_object_dead);
60480+ fscache_stat_unchecked(&fscache_n_object_dead);
60481
60482 _leave("");
60483 return transit_to(OBJECT_DEAD);
60484@@ -887,7 +887,7 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
60485 enum fscache_checkaux result;
60486
60487 if (!object->cookie->def->check_aux) {
60488- fscache_stat(&fscache_n_checkaux_none);
60489+ fscache_stat_unchecked(&fscache_n_checkaux_none);
60490 return FSCACHE_CHECKAUX_OKAY;
60491 }
60492
60493@@ -896,17 +896,17 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
60494 switch (result) {
60495 /* entry okay as is */
60496 case FSCACHE_CHECKAUX_OKAY:
60497- fscache_stat(&fscache_n_checkaux_okay);
60498+ fscache_stat_unchecked(&fscache_n_checkaux_okay);
60499 break;
60500
60501 /* entry requires update */
60502 case FSCACHE_CHECKAUX_NEEDS_UPDATE:
60503- fscache_stat(&fscache_n_checkaux_update);
60504+ fscache_stat_unchecked(&fscache_n_checkaux_update);
60505 break;
60506
60507 /* entry requires deletion */
60508 case FSCACHE_CHECKAUX_OBSOLETE:
60509- fscache_stat(&fscache_n_checkaux_obsolete);
60510+ fscache_stat_unchecked(&fscache_n_checkaux_obsolete);
60511 break;
60512
60513 default:
60514@@ -992,7 +992,7 @@ static const struct fscache_state *fscache_invalidate_object(struct fscache_obje
60515 {
60516 const struct fscache_state *s;
60517
60518- fscache_stat(&fscache_n_invalidates_run);
60519+ fscache_stat_unchecked(&fscache_n_invalidates_run);
60520 fscache_stat(&fscache_n_cop_invalidate_object);
60521 s = _fscache_invalidate_object(object, event);
60522 fscache_stat_d(&fscache_n_cop_invalidate_object);
60523@@ -1007,7 +1007,7 @@ static const struct fscache_state *fscache_update_object(struct fscache_object *
60524 {
60525 _enter("{OBJ%x},%d", object->debug_id, event);
60526
60527- fscache_stat(&fscache_n_updates_run);
60528+ fscache_stat_unchecked(&fscache_n_updates_run);
60529 fscache_stat(&fscache_n_cop_update_object);
60530 object->cache->ops->update_object(object);
60531 fscache_stat_d(&fscache_n_cop_update_object);
60532diff --git a/fs/fscache/operation.c b/fs/fscache/operation.c
60533index 318071a..379938b 100644
60534--- a/fs/fscache/operation.c
60535+++ b/fs/fscache/operation.c
60536@@ -17,7 +17,7 @@
60537 #include <linux/slab.h>
60538 #include "internal.h"
60539
60540-atomic_t fscache_op_debug_id;
60541+atomic_unchecked_t fscache_op_debug_id;
60542 EXPORT_SYMBOL(fscache_op_debug_id);
60543
60544 /**
60545@@ -39,7 +39,7 @@ void fscache_enqueue_operation(struct fscache_operation *op)
60546 ASSERTCMP(atomic_read(&op->usage), >, 0);
60547 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_IN_PROGRESS);
60548
60549- fscache_stat(&fscache_n_op_enqueue);
60550+ fscache_stat_unchecked(&fscache_n_op_enqueue);
60551 switch (op->flags & FSCACHE_OP_TYPE) {
60552 case FSCACHE_OP_ASYNC:
60553 _debug("queue async");
60554@@ -73,7 +73,7 @@ static void fscache_run_op(struct fscache_object *object,
60555 wake_up_bit(&op->flags, FSCACHE_OP_WAITING);
60556 if (op->processor)
60557 fscache_enqueue_operation(op);
60558- fscache_stat(&fscache_n_op_run);
60559+ fscache_stat_unchecked(&fscache_n_op_run);
60560 }
60561
60562 /*
60563@@ -105,11 +105,11 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
60564 if (object->n_in_progress > 0) {
60565 atomic_inc(&op->usage);
60566 list_add_tail(&op->pend_link, &object->pending_ops);
60567- fscache_stat(&fscache_n_op_pend);
60568+ fscache_stat_unchecked(&fscache_n_op_pend);
60569 } else if (!list_empty(&object->pending_ops)) {
60570 atomic_inc(&op->usage);
60571 list_add_tail(&op->pend_link, &object->pending_ops);
60572- fscache_stat(&fscache_n_op_pend);
60573+ fscache_stat_unchecked(&fscache_n_op_pend);
60574 fscache_start_operations(object);
60575 } else {
60576 ASSERTCMP(object->n_in_progress, ==, 0);
60577@@ -125,7 +125,7 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
60578 object->n_exclusive++; /* reads and writes must wait */
60579 atomic_inc(&op->usage);
60580 list_add_tail(&op->pend_link, &object->pending_ops);
60581- fscache_stat(&fscache_n_op_pend);
60582+ fscache_stat_unchecked(&fscache_n_op_pend);
60583 ret = 0;
60584 } else {
60585 /* If we're in any other state, there must have been an I/O
60586@@ -212,11 +212,11 @@ int fscache_submit_op(struct fscache_object *object,
60587 if (object->n_exclusive > 0) {
60588 atomic_inc(&op->usage);
60589 list_add_tail(&op->pend_link, &object->pending_ops);
60590- fscache_stat(&fscache_n_op_pend);
60591+ fscache_stat_unchecked(&fscache_n_op_pend);
60592 } else if (!list_empty(&object->pending_ops)) {
60593 atomic_inc(&op->usage);
60594 list_add_tail(&op->pend_link, &object->pending_ops);
60595- fscache_stat(&fscache_n_op_pend);
60596+ fscache_stat_unchecked(&fscache_n_op_pend);
60597 fscache_start_operations(object);
60598 } else {
60599 ASSERTCMP(object->n_exclusive, ==, 0);
60600@@ -228,10 +228,10 @@ int fscache_submit_op(struct fscache_object *object,
60601 object->n_ops++;
60602 atomic_inc(&op->usage);
60603 list_add_tail(&op->pend_link, &object->pending_ops);
60604- fscache_stat(&fscache_n_op_pend);
60605+ fscache_stat_unchecked(&fscache_n_op_pend);
60606 ret = 0;
60607 } else if (fscache_object_is_dying(object)) {
60608- fscache_stat(&fscache_n_op_rejected);
60609+ fscache_stat_unchecked(&fscache_n_op_rejected);
60610 op->state = FSCACHE_OP_ST_CANCELLED;
60611 ret = -ENOBUFS;
60612 } else if (!test_bit(FSCACHE_IOERROR, &object->cache->flags)) {
60613@@ -310,7 +310,7 @@ int fscache_cancel_op(struct fscache_operation *op,
60614 ret = -EBUSY;
60615 if (op->state == FSCACHE_OP_ST_PENDING) {
60616 ASSERT(!list_empty(&op->pend_link));
60617- fscache_stat(&fscache_n_op_cancelled);
60618+ fscache_stat_unchecked(&fscache_n_op_cancelled);
60619 list_del_init(&op->pend_link);
60620 if (do_cancel)
60621 do_cancel(op);
60622@@ -342,7 +342,7 @@ void fscache_cancel_all_ops(struct fscache_object *object)
60623 while (!list_empty(&object->pending_ops)) {
60624 op = list_entry(object->pending_ops.next,
60625 struct fscache_operation, pend_link);
60626- fscache_stat(&fscache_n_op_cancelled);
60627+ fscache_stat_unchecked(&fscache_n_op_cancelled);
60628 list_del_init(&op->pend_link);
60629
60630 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_PENDING);
60631@@ -414,7 +414,7 @@ void fscache_put_operation(struct fscache_operation *op)
60632 op->state, ==, FSCACHE_OP_ST_CANCELLED);
60633 op->state = FSCACHE_OP_ST_DEAD;
60634
60635- fscache_stat(&fscache_n_op_release);
60636+ fscache_stat_unchecked(&fscache_n_op_release);
60637
60638 if (op->release) {
60639 op->release(op);
60640@@ -433,7 +433,7 @@ void fscache_put_operation(struct fscache_operation *op)
60641 * lock, and defer it otherwise */
60642 if (!spin_trylock(&object->lock)) {
60643 _debug("defer put");
60644- fscache_stat(&fscache_n_op_deferred_release);
60645+ fscache_stat_unchecked(&fscache_n_op_deferred_release);
60646
60647 cache = object->cache;
60648 spin_lock(&cache->op_gc_list_lock);
60649@@ -486,7 +486,7 @@ void fscache_operation_gc(struct work_struct *work)
60650
60651 _debug("GC DEFERRED REL OBJ%x OP%x",
60652 object->debug_id, op->debug_id);
60653- fscache_stat(&fscache_n_op_gc);
60654+ fscache_stat_unchecked(&fscache_n_op_gc);
60655
60656 ASSERTCMP(atomic_read(&op->usage), ==, 0);
60657 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_DEAD);
60658diff --git a/fs/fscache/page.c b/fs/fscache/page.c
60659index 7f5c658..6c1e164 100644
60660--- a/fs/fscache/page.c
60661+++ b/fs/fscache/page.c
60662@@ -61,7 +61,7 @@ try_again:
60663 val = radix_tree_lookup(&cookie->stores, page->index);
60664 if (!val) {
60665 rcu_read_unlock();
60666- fscache_stat(&fscache_n_store_vmscan_not_storing);
60667+ fscache_stat_unchecked(&fscache_n_store_vmscan_not_storing);
60668 __fscache_uncache_page(cookie, page);
60669 return true;
60670 }
60671@@ -91,11 +91,11 @@ try_again:
60672 spin_unlock(&cookie->stores_lock);
60673
60674 if (xpage) {
60675- fscache_stat(&fscache_n_store_vmscan_cancelled);
60676- fscache_stat(&fscache_n_store_radix_deletes);
60677+ fscache_stat_unchecked(&fscache_n_store_vmscan_cancelled);
60678+ fscache_stat_unchecked(&fscache_n_store_radix_deletes);
60679 ASSERTCMP(xpage, ==, page);
60680 } else {
60681- fscache_stat(&fscache_n_store_vmscan_gone);
60682+ fscache_stat_unchecked(&fscache_n_store_vmscan_gone);
60683 }
60684
60685 wake_up_bit(&cookie->flags, 0);
60686@@ -110,11 +110,11 @@ page_busy:
60687 * sleeping on memory allocation, so we may need to impose a timeout
60688 * too. */
60689 if (!(gfp & __GFP_WAIT) || !(gfp & __GFP_FS)) {
60690- fscache_stat(&fscache_n_store_vmscan_busy);
60691+ fscache_stat_unchecked(&fscache_n_store_vmscan_busy);
60692 return false;
60693 }
60694
60695- fscache_stat(&fscache_n_store_vmscan_wait);
60696+ fscache_stat_unchecked(&fscache_n_store_vmscan_wait);
60697 __fscache_wait_on_page_write(cookie, page);
60698 gfp &= ~__GFP_WAIT;
60699 goto try_again;
60700@@ -140,7 +140,7 @@ static void fscache_end_page_write(struct fscache_object *object,
60701 FSCACHE_COOKIE_STORING_TAG);
60702 if (!radix_tree_tag_get(&cookie->stores, page->index,
60703 FSCACHE_COOKIE_PENDING_TAG)) {
60704- fscache_stat(&fscache_n_store_radix_deletes);
60705+ fscache_stat_unchecked(&fscache_n_store_radix_deletes);
60706 xpage = radix_tree_delete(&cookie->stores, page->index);
60707 }
60708 spin_unlock(&cookie->stores_lock);
60709@@ -161,7 +161,7 @@ static void fscache_attr_changed_op(struct fscache_operation *op)
60710
60711 _enter("{OBJ%x OP%x}", object->debug_id, op->debug_id);
60712
60713- fscache_stat(&fscache_n_attr_changed_calls);
60714+ fscache_stat_unchecked(&fscache_n_attr_changed_calls);
60715
60716 if (fscache_object_is_active(object)) {
60717 fscache_stat(&fscache_n_cop_attr_changed);
60718@@ -188,11 +188,11 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
60719
60720 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
60721
60722- fscache_stat(&fscache_n_attr_changed);
60723+ fscache_stat_unchecked(&fscache_n_attr_changed);
60724
60725 op = kzalloc(sizeof(*op), GFP_KERNEL);
60726 if (!op) {
60727- fscache_stat(&fscache_n_attr_changed_nomem);
60728+ fscache_stat_unchecked(&fscache_n_attr_changed_nomem);
60729 _leave(" = -ENOMEM");
60730 return -ENOMEM;
60731 }
60732@@ -214,7 +214,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
60733 if (fscache_submit_exclusive_op(object, op) < 0)
60734 goto nobufs;
60735 spin_unlock(&cookie->lock);
60736- fscache_stat(&fscache_n_attr_changed_ok);
60737+ fscache_stat_unchecked(&fscache_n_attr_changed_ok);
60738 fscache_put_operation(op);
60739 _leave(" = 0");
60740 return 0;
60741@@ -225,7 +225,7 @@ nobufs:
60742 kfree(op);
60743 if (wake_cookie)
60744 __fscache_wake_unused_cookie(cookie);
60745- fscache_stat(&fscache_n_attr_changed_nobufs);
60746+ fscache_stat_unchecked(&fscache_n_attr_changed_nobufs);
60747 _leave(" = %d", -ENOBUFS);
60748 return -ENOBUFS;
60749 }
60750@@ -264,7 +264,7 @@ static struct fscache_retrieval *fscache_alloc_retrieval(
60751 /* allocate a retrieval operation and attempt to submit it */
60752 op = kzalloc(sizeof(*op), GFP_NOIO);
60753 if (!op) {
60754- fscache_stat(&fscache_n_retrievals_nomem);
60755+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
60756 return NULL;
60757 }
60758
60759@@ -294,13 +294,13 @@ int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
60760 return 0;
60761 }
60762
60763- fscache_stat(&fscache_n_retrievals_wait);
60764+ fscache_stat_unchecked(&fscache_n_retrievals_wait);
60765
60766 jif = jiffies;
60767 if (wait_on_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP,
60768 fscache_wait_bit_interruptible,
60769 TASK_INTERRUPTIBLE) != 0) {
60770- fscache_stat(&fscache_n_retrievals_intr);
60771+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
60772 _leave(" = -ERESTARTSYS");
60773 return -ERESTARTSYS;
60774 }
60775@@ -329,8 +329,8 @@ static void fscache_do_cancel_retrieval(struct fscache_operation *_op)
60776 */
60777 int fscache_wait_for_operation_activation(struct fscache_object *object,
60778 struct fscache_operation *op,
60779- atomic_t *stat_op_waits,
60780- atomic_t *stat_object_dead,
60781+ atomic_unchecked_t *stat_op_waits,
60782+ atomic_unchecked_t *stat_object_dead,
60783 void (*do_cancel)(struct fscache_operation *))
60784 {
60785 int ret;
60786@@ -340,7 +340,7 @@ int fscache_wait_for_operation_activation(struct fscache_object *object,
60787
60788 _debug(">>> WT");
60789 if (stat_op_waits)
60790- fscache_stat(stat_op_waits);
60791+ fscache_stat_unchecked(stat_op_waits);
60792 if (wait_on_bit(&op->flags, FSCACHE_OP_WAITING,
60793 fscache_wait_bit_interruptible,
60794 TASK_INTERRUPTIBLE) != 0) {
60795@@ -358,7 +358,7 @@ int fscache_wait_for_operation_activation(struct fscache_object *object,
60796 check_if_dead:
60797 if (op->state == FSCACHE_OP_ST_CANCELLED) {
60798 if (stat_object_dead)
60799- fscache_stat(stat_object_dead);
60800+ fscache_stat_unchecked(stat_object_dead);
60801 _leave(" = -ENOBUFS [cancelled]");
60802 return -ENOBUFS;
60803 }
60804@@ -366,7 +366,7 @@ check_if_dead:
60805 pr_err("%s() = -ENOBUFS [obj dead %d]\n", __func__, op->state);
60806 fscache_cancel_op(op, do_cancel);
60807 if (stat_object_dead)
60808- fscache_stat(stat_object_dead);
60809+ fscache_stat_unchecked(stat_object_dead);
60810 return -ENOBUFS;
60811 }
60812 return 0;
60813@@ -394,7 +394,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
60814
60815 _enter("%p,%p,,,", cookie, page);
60816
60817- fscache_stat(&fscache_n_retrievals);
60818+ fscache_stat_unchecked(&fscache_n_retrievals);
60819
60820 if (hlist_empty(&cookie->backing_objects))
60821 goto nobufs;
60822@@ -436,7 +436,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
60823 goto nobufs_unlock_dec;
60824 spin_unlock(&cookie->lock);
60825
60826- fscache_stat(&fscache_n_retrieval_ops);
60827+ fscache_stat_unchecked(&fscache_n_retrieval_ops);
60828
60829 /* pin the netfs read context in case we need to do the actual netfs
60830 * read because we've encountered a cache read failure */
60831@@ -467,15 +467,15 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
60832
60833 error:
60834 if (ret == -ENOMEM)
60835- fscache_stat(&fscache_n_retrievals_nomem);
60836+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
60837 else if (ret == -ERESTARTSYS)
60838- fscache_stat(&fscache_n_retrievals_intr);
60839+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
60840 else if (ret == -ENODATA)
60841- fscache_stat(&fscache_n_retrievals_nodata);
60842+ fscache_stat_unchecked(&fscache_n_retrievals_nodata);
60843 else if (ret < 0)
60844- fscache_stat(&fscache_n_retrievals_nobufs);
60845+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
60846 else
60847- fscache_stat(&fscache_n_retrievals_ok);
60848+ fscache_stat_unchecked(&fscache_n_retrievals_ok);
60849
60850 fscache_put_retrieval(op);
60851 _leave(" = %d", ret);
60852@@ -490,7 +490,7 @@ nobufs_unlock:
60853 __fscache_wake_unused_cookie(cookie);
60854 kfree(op);
60855 nobufs:
60856- fscache_stat(&fscache_n_retrievals_nobufs);
60857+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
60858 _leave(" = -ENOBUFS");
60859 return -ENOBUFS;
60860 }
60861@@ -529,7 +529,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
60862
60863 _enter("%p,,%d,,,", cookie, *nr_pages);
60864
60865- fscache_stat(&fscache_n_retrievals);
60866+ fscache_stat_unchecked(&fscache_n_retrievals);
60867
60868 if (hlist_empty(&cookie->backing_objects))
60869 goto nobufs;
60870@@ -567,7 +567,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
60871 goto nobufs_unlock_dec;
60872 spin_unlock(&cookie->lock);
60873
60874- fscache_stat(&fscache_n_retrieval_ops);
60875+ fscache_stat_unchecked(&fscache_n_retrieval_ops);
60876
60877 /* pin the netfs read context in case we need to do the actual netfs
60878 * read because we've encountered a cache read failure */
60879@@ -598,15 +598,15 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
60880
60881 error:
60882 if (ret == -ENOMEM)
60883- fscache_stat(&fscache_n_retrievals_nomem);
60884+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
60885 else if (ret == -ERESTARTSYS)
60886- fscache_stat(&fscache_n_retrievals_intr);
60887+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
60888 else if (ret == -ENODATA)
60889- fscache_stat(&fscache_n_retrievals_nodata);
60890+ fscache_stat_unchecked(&fscache_n_retrievals_nodata);
60891 else if (ret < 0)
60892- fscache_stat(&fscache_n_retrievals_nobufs);
60893+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
60894 else
60895- fscache_stat(&fscache_n_retrievals_ok);
60896+ fscache_stat_unchecked(&fscache_n_retrievals_ok);
60897
60898 fscache_put_retrieval(op);
60899 _leave(" = %d", ret);
60900@@ -621,7 +621,7 @@ nobufs_unlock:
60901 if (wake_cookie)
60902 __fscache_wake_unused_cookie(cookie);
60903 nobufs:
60904- fscache_stat(&fscache_n_retrievals_nobufs);
60905+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
60906 _leave(" = -ENOBUFS");
60907 return -ENOBUFS;
60908 }
60909@@ -646,7 +646,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
60910
60911 _enter("%p,%p,,,", cookie, page);
60912
60913- fscache_stat(&fscache_n_allocs);
60914+ fscache_stat_unchecked(&fscache_n_allocs);
60915
60916 if (hlist_empty(&cookie->backing_objects))
60917 goto nobufs;
60918@@ -680,7 +680,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
60919 goto nobufs_unlock_dec;
60920 spin_unlock(&cookie->lock);
60921
60922- fscache_stat(&fscache_n_alloc_ops);
60923+ fscache_stat_unchecked(&fscache_n_alloc_ops);
60924
60925 ret = fscache_wait_for_operation_activation(
60926 object, &op->op,
60927@@ -697,11 +697,11 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
60928
60929 error:
60930 if (ret == -ERESTARTSYS)
60931- fscache_stat(&fscache_n_allocs_intr);
60932+ fscache_stat_unchecked(&fscache_n_allocs_intr);
60933 else if (ret < 0)
60934- fscache_stat(&fscache_n_allocs_nobufs);
60935+ fscache_stat_unchecked(&fscache_n_allocs_nobufs);
60936 else
60937- fscache_stat(&fscache_n_allocs_ok);
60938+ fscache_stat_unchecked(&fscache_n_allocs_ok);
60939
60940 fscache_put_retrieval(op);
60941 _leave(" = %d", ret);
60942@@ -715,7 +715,7 @@ nobufs_unlock:
60943 if (wake_cookie)
60944 __fscache_wake_unused_cookie(cookie);
60945 nobufs:
60946- fscache_stat(&fscache_n_allocs_nobufs);
60947+ fscache_stat_unchecked(&fscache_n_allocs_nobufs);
60948 _leave(" = -ENOBUFS");
60949 return -ENOBUFS;
60950 }
60951@@ -791,7 +791,7 @@ static void fscache_write_op(struct fscache_operation *_op)
60952
60953 spin_lock(&cookie->stores_lock);
60954
60955- fscache_stat(&fscache_n_store_calls);
60956+ fscache_stat_unchecked(&fscache_n_store_calls);
60957
60958 /* find a page to store */
60959 page = NULL;
60960@@ -802,7 +802,7 @@ static void fscache_write_op(struct fscache_operation *_op)
60961 page = results[0];
60962 _debug("gang %d [%lx]", n, page->index);
60963 if (page->index > op->store_limit) {
60964- fscache_stat(&fscache_n_store_pages_over_limit);
60965+ fscache_stat_unchecked(&fscache_n_store_pages_over_limit);
60966 goto superseded;
60967 }
60968
60969@@ -814,7 +814,7 @@ static void fscache_write_op(struct fscache_operation *_op)
60970 spin_unlock(&cookie->stores_lock);
60971 spin_unlock(&object->lock);
60972
60973- fscache_stat(&fscache_n_store_pages);
60974+ fscache_stat_unchecked(&fscache_n_store_pages);
60975 fscache_stat(&fscache_n_cop_write_page);
60976 ret = object->cache->ops->write_page(op, page);
60977 fscache_stat_d(&fscache_n_cop_write_page);
60978@@ -918,7 +918,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
60979 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
60980 ASSERT(PageFsCache(page));
60981
60982- fscache_stat(&fscache_n_stores);
60983+ fscache_stat_unchecked(&fscache_n_stores);
60984
60985 if (test_bit(FSCACHE_COOKIE_INVALIDATING, &cookie->flags)) {
60986 _leave(" = -ENOBUFS [invalidating]");
60987@@ -977,7 +977,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
60988 spin_unlock(&cookie->stores_lock);
60989 spin_unlock(&object->lock);
60990
60991- op->op.debug_id = atomic_inc_return(&fscache_op_debug_id);
60992+ op->op.debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
60993 op->store_limit = object->store_limit;
60994
60995 __fscache_use_cookie(cookie);
60996@@ -986,8 +986,8 @@ int __fscache_write_page(struct fscache_cookie *cookie,
60997
60998 spin_unlock(&cookie->lock);
60999 radix_tree_preload_end();
61000- fscache_stat(&fscache_n_store_ops);
61001- fscache_stat(&fscache_n_stores_ok);
61002+ fscache_stat_unchecked(&fscache_n_store_ops);
61003+ fscache_stat_unchecked(&fscache_n_stores_ok);
61004
61005 /* the work queue now carries its own ref on the object */
61006 fscache_put_operation(&op->op);
61007@@ -995,14 +995,14 @@ int __fscache_write_page(struct fscache_cookie *cookie,
61008 return 0;
61009
61010 already_queued:
61011- fscache_stat(&fscache_n_stores_again);
61012+ fscache_stat_unchecked(&fscache_n_stores_again);
61013 already_pending:
61014 spin_unlock(&cookie->stores_lock);
61015 spin_unlock(&object->lock);
61016 spin_unlock(&cookie->lock);
61017 radix_tree_preload_end();
61018 kfree(op);
61019- fscache_stat(&fscache_n_stores_ok);
61020+ fscache_stat_unchecked(&fscache_n_stores_ok);
61021 _leave(" = 0");
61022 return 0;
61023
61024@@ -1024,14 +1024,14 @@ nobufs:
61025 kfree(op);
61026 if (wake_cookie)
61027 __fscache_wake_unused_cookie(cookie);
61028- fscache_stat(&fscache_n_stores_nobufs);
61029+ fscache_stat_unchecked(&fscache_n_stores_nobufs);
61030 _leave(" = -ENOBUFS");
61031 return -ENOBUFS;
61032
61033 nomem_free:
61034 kfree(op);
61035 nomem:
61036- fscache_stat(&fscache_n_stores_oom);
61037+ fscache_stat_unchecked(&fscache_n_stores_oom);
61038 _leave(" = -ENOMEM");
61039 return -ENOMEM;
61040 }
61041@@ -1049,7 +1049,7 @@ void __fscache_uncache_page(struct fscache_cookie *cookie, struct page *page)
61042 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
61043 ASSERTCMP(page, !=, NULL);
61044
61045- fscache_stat(&fscache_n_uncaches);
61046+ fscache_stat_unchecked(&fscache_n_uncaches);
61047
61048 /* cache withdrawal may beat us to it */
61049 if (!PageFsCache(page))
61050@@ -1100,7 +1100,7 @@ void fscache_mark_page_cached(struct fscache_retrieval *op, struct page *page)
61051 struct fscache_cookie *cookie = op->op.object->cookie;
61052
61053 #ifdef CONFIG_FSCACHE_STATS
61054- atomic_inc(&fscache_n_marks);
61055+ atomic_inc_unchecked(&fscache_n_marks);
61056 #endif
61057
61058 _debug("- mark %p{%lx}", page, page->index);
61059diff --git a/fs/fscache/stats.c b/fs/fscache/stats.c
61060index 40d13c7..ddf52b9 100644
61061--- a/fs/fscache/stats.c
61062+++ b/fs/fscache/stats.c
61063@@ -18,99 +18,99 @@
61064 /*
61065 * operation counters
61066 */
61067-atomic_t fscache_n_op_pend;
61068-atomic_t fscache_n_op_run;
61069-atomic_t fscache_n_op_enqueue;
61070-atomic_t fscache_n_op_requeue;
61071-atomic_t fscache_n_op_deferred_release;
61072-atomic_t fscache_n_op_release;
61073-atomic_t fscache_n_op_gc;
61074-atomic_t fscache_n_op_cancelled;
61075-atomic_t fscache_n_op_rejected;
61076+atomic_unchecked_t fscache_n_op_pend;
61077+atomic_unchecked_t fscache_n_op_run;
61078+atomic_unchecked_t fscache_n_op_enqueue;
61079+atomic_unchecked_t fscache_n_op_requeue;
61080+atomic_unchecked_t fscache_n_op_deferred_release;
61081+atomic_unchecked_t fscache_n_op_release;
61082+atomic_unchecked_t fscache_n_op_gc;
61083+atomic_unchecked_t fscache_n_op_cancelled;
61084+atomic_unchecked_t fscache_n_op_rejected;
61085
61086-atomic_t fscache_n_attr_changed;
61087-atomic_t fscache_n_attr_changed_ok;
61088-atomic_t fscache_n_attr_changed_nobufs;
61089-atomic_t fscache_n_attr_changed_nomem;
61090-atomic_t fscache_n_attr_changed_calls;
61091+atomic_unchecked_t fscache_n_attr_changed;
61092+atomic_unchecked_t fscache_n_attr_changed_ok;
61093+atomic_unchecked_t fscache_n_attr_changed_nobufs;
61094+atomic_unchecked_t fscache_n_attr_changed_nomem;
61095+atomic_unchecked_t fscache_n_attr_changed_calls;
61096
61097-atomic_t fscache_n_allocs;
61098-atomic_t fscache_n_allocs_ok;
61099-atomic_t fscache_n_allocs_wait;
61100-atomic_t fscache_n_allocs_nobufs;
61101-atomic_t fscache_n_allocs_intr;
61102-atomic_t fscache_n_allocs_object_dead;
61103-atomic_t fscache_n_alloc_ops;
61104-atomic_t fscache_n_alloc_op_waits;
61105+atomic_unchecked_t fscache_n_allocs;
61106+atomic_unchecked_t fscache_n_allocs_ok;
61107+atomic_unchecked_t fscache_n_allocs_wait;
61108+atomic_unchecked_t fscache_n_allocs_nobufs;
61109+atomic_unchecked_t fscache_n_allocs_intr;
61110+atomic_unchecked_t fscache_n_allocs_object_dead;
61111+atomic_unchecked_t fscache_n_alloc_ops;
61112+atomic_unchecked_t fscache_n_alloc_op_waits;
61113
61114-atomic_t fscache_n_retrievals;
61115-atomic_t fscache_n_retrievals_ok;
61116-atomic_t fscache_n_retrievals_wait;
61117-atomic_t fscache_n_retrievals_nodata;
61118-atomic_t fscache_n_retrievals_nobufs;
61119-atomic_t fscache_n_retrievals_intr;
61120-atomic_t fscache_n_retrievals_nomem;
61121-atomic_t fscache_n_retrievals_object_dead;
61122-atomic_t fscache_n_retrieval_ops;
61123-atomic_t fscache_n_retrieval_op_waits;
61124+atomic_unchecked_t fscache_n_retrievals;
61125+atomic_unchecked_t fscache_n_retrievals_ok;
61126+atomic_unchecked_t fscache_n_retrievals_wait;
61127+atomic_unchecked_t fscache_n_retrievals_nodata;
61128+atomic_unchecked_t fscache_n_retrievals_nobufs;
61129+atomic_unchecked_t fscache_n_retrievals_intr;
61130+atomic_unchecked_t fscache_n_retrievals_nomem;
61131+atomic_unchecked_t fscache_n_retrievals_object_dead;
61132+atomic_unchecked_t fscache_n_retrieval_ops;
61133+atomic_unchecked_t fscache_n_retrieval_op_waits;
61134
61135-atomic_t fscache_n_stores;
61136-atomic_t fscache_n_stores_ok;
61137-atomic_t fscache_n_stores_again;
61138-atomic_t fscache_n_stores_nobufs;
61139-atomic_t fscache_n_stores_oom;
61140-atomic_t fscache_n_store_ops;
61141-atomic_t fscache_n_store_calls;
61142-atomic_t fscache_n_store_pages;
61143-atomic_t fscache_n_store_radix_deletes;
61144-atomic_t fscache_n_store_pages_over_limit;
61145+atomic_unchecked_t fscache_n_stores;
61146+atomic_unchecked_t fscache_n_stores_ok;
61147+atomic_unchecked_t fscache_n_stores_again;
61148+atomic_unchecked_t fscache_n_stores_nobufs;
61149+atomic_unchecked_t fscache_n_stores_oom;
61150+atomic_unchecked_t fscache_n_store_ops;
61151+atomic_unchecked_t fscache_n_store_calls;
61152+atomic_unchecked_t fscache_n_store_pages;
61153+atomic_unchecked_t fscache_n_store_radix_deletes;
61154+atomic_unchecked_t fscache_n_store_pages_over_limit;
61155
61156-atomic_t fscache_n_store_vmscan_not_storing;
61157-atomic_t fscache_n_store_vmscan_gone;
61158-atomic_t fscache_n_store_vmscan_busy;
61159-atomic_t fscache_n_store_vmscan_cancelled;
61160-atomic_t fscache_n_store_vmscan_wait;
61161+atomic_unchecked_t fscache_n_store_vmscan_not_storing;
61162+atomic_unchecked_t fscache_n_store_vmscan_gone;
61163+atomic_unchecked_t fscache_n_store_vmscan_busy;
61164+atomic_unchecked_t fscache_n_store_vmscan_cancelled;
61165+atomic_unchecked_t fscache_n_store_vmscan_wait;
61166
61167-atomic_t fscache_n_marks;
61168-atomic_t fscache_n_uncaches;
61169+atomic_unchecked_t fscache_n_marks;
61170+atomic_unchecked_t fscache_n_uncaches;
61171
61172-atomic_t fscache_n_acquires;
61173-atomic_t fscache_n_acquires_null;
61174-atomic_t fscache_n_acquires_no_cache;
61175-atomic_t fscache_n_acquires_ok;
61176-atomic_t fscache_n_acquires_nobufs;
61177-atomic_t fscache_n_acquires_oom;
61178+atomic_unchecked_t fscache_n_acquires;
61179+atomic_unchecked_t fscache_n_acquires_null;
61180+atomic_unchecked_t fscache_n_acquires_no_cache;
61181+atomic_unchecked_t fscache_n_acquires_ok;
61182+atomic_unchecked_t fscache_n_acquires_nobufs;
61183+atomic_unchecked_t fscache_n_acquires_oom;
61184
61185-atomic_t fscache_n_invalidates;
61186-atomic_t fscache_n_invalidates_run;
61187+atomic_unchecked_t fscache_n_invalidates;
61188+atomic_unchecked_t fscache_n_invalidates_run;
61189
61190-atomic_t fscache_n_updates;
61191-atomic_t fscache_n_updates_null;
61192-atomic_t fscache_n_updates_run;
61193+atomic_unchecked_t fscache_n_updates;
61194+atomic_unchecked_t fscache_n_updates_null;
61195+atomic_unchecked_t fscache_n_updates_run;
61196
61197-atomic_t fscache_n_relinquishes;
61198-atomic_t fscache_n_relinquishes_null;
61199-atomic_t fscache_n_relinquishes_waitcrt;
61200-atomic_t fscache_n_relinquishes_retire;
61201+atomic_unchecked_t fscache_n_relinquishes;
61202+atomic_unchecked_t fscache_n_relinquishes_null;
61203+atomic_unchecked_t fscache_n_relinquishes_waitcrt;
61204+atomic_unchecked_t fscache_n_relinquishes_retire;
61205
61206-atomic_t fscache_n_cookie_index;
61207-atomic_t fscache_n_cookie_data;
61208-atomic_t fscache_n_cookie_special;
61209+atomic_unchecked_t fscache_n_cookie_index;
61210+atomic_unchecked_t fscache_n_cookie_data;
61211+atomic_unchecked_t fscache_n_cookie_special;
61212
61213-atomic_t fscache_n_object_alloc;
61214-atomic_t fscache_n_object_no_alloc;
61215-atomic_t fscache_n_object_lookups;
61216-atomic_t fscache_n_object_lookups_negative;
61217-atomic_t fscache_n_object_lookups_positive;
61218-atomic_t fscache_n_object_lookups_timed_out;
61219-atomic_t fscache_n_object_created;
61220-atomic_t fscache_n_object_avail;
61221-atomic_t fscache_n_object_dead;
61222+atomic_unchecked_t fscache_n_object_alloc;
61223+atomic_unchecked_t fscache_n_object_no_alloc;
61224+atomic_unchecked_t fscache_n_object_lookups;
61225+atomic_unchecked_t fscache_n_object_lookups_negative;
61226+atomic_unchecked_t fscache_n_object_lookups_positive;
61227+atomic_unchecked_t fscache_n_object_lookups_timed_out;
61228+atomic_unchecked_t fscache_n_object_created;
61229+atomic_unchecked_t fscache_n_object_avail;
61230+atomic_unchecked_t fscache_n_object_dead;
61231
61232-atomic_t fscache_n_checkaux_none;
61233-atomic_t fscache_n_checkaux_okay;
61234-atomic_t fscache_n_checkaux_update;
61235-atomic_t fscache_n_checkaux_obsolete;
61236+atomic_unchecked_t fscache_n_checkaux_none;
61237+atomic_unchecked_t fscache_n_checkaux_okay;
61238+atomic_unchecked_t fscache_n_checkaux_update;
61239+atomic_unchecked_t fscache_n_checkaux_obsolete;
61240
61241 atomic_t fscache_n_cop_alloc_object;
61242 atomic_t fscache_n_cop_lookup_object;
61243@@ -138,118 +138,118 @@ static int fscache_stats_show(struct seq_file *m, void *v)
61244 seq_puts(m, "FS-Cache statistics\n");
61245
61246 seq_printf(m, "Cookies: idx=%u dat=%u spc=%u\n",
61247- atomic_read(&fscache_n_cookie_index),
61248- atomic_read(&fscache_n_cookie_data),
61249- atomic_read(&fscache_n_cookie_special));
61250+ atomic_read_unchecked(&fscache_n_cookie_index),
61251+ atomic_read_unchecked(&fscache_n_cookie_data),
61252+ atomic_read_unchecked(&fscache_n_cookie_special));
61253
61254 seq_printf(m, "Objects: alc=%u nal=%u avl=%u ded=%u\n",
61255- atomic_read(&fscache_n_object_alloc),
61256- atomic_read(&fscache_n_object_no_alloc),
61257- atomic_read(&fscache_n_object_avail),
61258- atomic_read(&fscache_n_object_dead));
61259+ atomic_read_unchecked(&fscache_n_object_alloc),
61260+ atomic_read_unchecked(&fscache_n_object_no_alloc),
61261+ atomic_read_unchecked(&fscache_n_object_avail),
61262+ atomic_read_unchecked(&fscache_n_object_dead));
61263 seq_printf(m, "ChkAux : non=%u ok=%u upd=%u obs=%u\n",
61264- atomic_read(&fscache_n_checkaux_none),
61265- atomic_read(&fscache_n_checkaux_okay),
61266- atomic_read(&fscache_n_checkaux_update),
61267- atomic_read(&fscache_n_checkaux_obsolete));
61268+ atomic_read_unchecked(&fscache_n_checkaux_none),
61269+ atomic_read_unchecked(&fscache_n_checkaux_okay),
61270+ atomic_read_unchecked(&fscache_n_checkaux_update),
61271+ atomic_read_unchecked(&fscache_n_checkaux_obsolete));
61272
61273 seq_printf(m, "Pages : mrk=%u unc=%u\n",
61274- atomic_read(&fscache_n_marks),
61275- atomic_read(&fscache_n_uncaches));
61276+ atomic_read_unchecked(&fscache_n_marks),
61277+ atomic_read_unchecked(&fscache_n_uncaches));
61278
61279 seq_printf(m, "Acquire: n=%u nul=%u noc=%u ok=%u nbf=%u"
61280 " oom=%u\n",
61281- atomic_read(&fscache_n_acquires),
61282- atomic_read(&fscache_n_acquires_null),
61283- atomic_read(&fscache_n_acquires_no_cache),
61284- atomic_read(&fscache_n_acquires_ok),
61285- atomic_read(&fscache_n_acquires_nobufs),
61286- atomic_read(&fscache_n_acquires_oom));
61287+ atomic_read_unchecked(&fscache_n_acquires),
61288+ atomic_read_unchecked(&fscache_n_acquires_null),
61289+ atomic_read_unchecked(&fscache_n_acquires_no_cache),
61290+ atomic_read_unchecked(&fscache_n_acquires_ok),
61291+ atomic_read_unchecked(&fscache_n_acquires_nobufs),
61292+ atomic_read_unchecked(&fscache_n_acquires_oom));
61293
61294 seq_printf(m, "Lookups: n=%u neg=%u pos=%u crt=%u tmo=%u\n",
61295- atomic_read(&fscache_n_object_lookups),
61296- atomic_read(&fscache_n_object_lookups_negative),
61297- atomic_read(&fscache_n_object_lookups_positive),
61298- atomic_read(&fscache_n_object_created),
61299- atomic_read(&fscache_n_object_lookups_timed_out));
61300+ atomic_read_unchecked(&fscache_n_object_lookups),
61301+ atomic_read_unchecked(&fscache_n_object_lookups_negative),
61302+ atomic_read_unchecked(&fscache_n_object_lookups_positive),
61303+ atomic_read_unchecked(&fscache_n_object_created),
61304+ atomic_read_unchecked(&fscache_n_object_lookups_timed_out));
61305
61306 seq_printf(m, "Invals : n=%u run=%u\n",
61307- atomic_read(&fscache_n_invalidates),
61308- atomic_read(&fscache_n_invalidates_run));
61309+ atomic_read_unchecked(&fscache_n_invalidates),
61310+ atomic_read_unchecked(&fscache_n_invalidates_run));
61311
61312 seq_printf(m, "Updates: n=%u nul=%u run=%u\n",
61313- atomic_read(&fscache_n_updates),
61314- atomic_read(&fscache_n_updates_null),
61315- atomic_read(&fscache_n_updates_run));
61316+ atomic_read_unchecked(&fscache_n_updates),
61317+ atomic_read_unchecked(&fscache_n_updates_null),
61318+ atomic_read_unchecked(&fscache_n_updates_run));
61319
61320 seq_printf(m, "Relinqs: n=%u nul=%u wcr=%u rtr=%u\n",
61321- atomic_read(&fscache_n_relinquishes),
61322- atomic_read(&fscache_n_relinquishes_null),
61323- atomic_read(&fscache_n_relinquishes_waitcrt),
61324- atomic_read(&fscache_n_relinquishes_retire));
61325+ atomic_read_unchecked(&fscache_n_relinquishes),
61326+ atomic_read_unchecked(&fscache_n_relinquishes_null),
61327+ atomic_read_unchecked(&fscache_n_relinquishes_waitcrt),
61328+ atomic_read_unchecked(&fscache_n_relinquishes_retire));
61329
61330 seq_printf(m, "AttrChg: n=%u ok=%u nbf=%u oom=%u run=%u\n",
61331- atomic_read(&fscache_n_attr_changed),
61332- atomic_read(&fscache_n_attr_changed_ok),
61333- atomic_read(&fscache_n_attr_changed_nobufs),
61334- atomic_read(&fscache_n_attr_changed_nomem),
61335- atomic_read(&fscache_n_attr_changed_calls));
61336+ atomic_read_unchecked(&fscache_n_attr_changed),
61337+ atomic_read_unchecked(&fscache_n_attr_changed_ok),
61338+ atomic_read_unchecked(&fscache_n_attr_changed_nobufs),
61339+ atomic_read_unchecked(&fscache_n_attr_changed_nomem),
61340+ atomic_read_unchecked(&fscache_n_attr_changed_calls));
61341
61342 seq_printf(m, "Allocs : n=%u ok=%u wt=%u nbf=%u int=%u\n",
61343- atomic_read(&fscache_n_allocs),
61344- atomic_read(&fscache_n_allocs_ok),
61345- atomic_read(&fscache_n_allocs_wait),
61346- atomic_read(&fscache_n_allocs_nobufs),
61347- atomic_read(&fscache_n_allocs_intr));
61348+ atomic_read_unchecked(&fscache_n_allocs),
61349+ atomic_read_unchecked(&fscache_n_allocs_ok),
61350+ atomic_read_unchecked(&fscache_n_allocs_wait),
61351+ atomic_read_unchecked(&fscache_n_allocs_nobufs),
61352+ atomic_read_unchecked(&fscache_n_allocs_intr));
61353 seq_printf(m, "Allocs : ops=%u owt=%u abt=%u\n",
61354- atomic_read(&fscache_n_alloc_ops),
61355- atomic_read(&fscache_n_alloc_op_waits),
61356- atomic_read(&fscache_n_allocs_object_dead));
61357+ atomic_read_unchecked(&fscache_n_alloc_ops),
61358+ atomic_read_unchecked(&fscache_n_alloc_op_waits),
61359+ atomic_read_unchecked(&fscache_n_allocs_object_dead));
61360
61361 seq_printf(m, "Retrvls: n=%u ok=%u wt=%u nod=%u nbf=%u"
61362 " int=%u oom=%u\n",
61363- atomic_read(&fscache_n_retrievals),
61364- atomic_read(&fscache_n_retrievals_ok),
61365- atomic_read(&fscache_n_retrievals_wait),
61366- atomic_read(&fscache_n_retrievals_nodata),
61367- atomic_read(&fscache_n_retrievals_nobufs),
61368- atomic_read(&fscache_n_retrievals_intr),
61369- atomic_read(&fscache_n_retrievals_nomem));
61370+ atomic_read_unchecked(&fscache_n_retrievals),
61371+ atomic_read_unchecked(&fscache_n_retrievals_ok),
61372+ atomic_read_unchecked(&fscache_n_retrievals_wait),
61373+ atomic_read_unchecked(&fscache_n_retrievals_nodata),
61374+ atomic_read_unchecked(&fscache_n_retrievals_nobufs),
61375+ atomic_read_unchecked(&fscache_n_retrievals_intr),
61376+ atomic_read_unchecked(&fscache_n_retrievals_nomem));
61377 seq_printf(m, "Retrvls: ops=%u owt=%u abt=%u\n",
61378- atomic_read(&fscache_n_retrieval_ops),
61379- atomic_read(&fscache_n_retrieval_op_waits),
61380- atomic_read(&fscache_n_retrievals_object_dead));
61381+ atomic_read_unchecked(&fscache_n_retrieval_ops),
61382+ atomic_read_unchecked(&fscache_n_retrieval_op_waits),
61383+ atomic_read_unchecked(&fscache_n_retrievals_object_dead));
61384
61385 seq_printf(m, "Stores : n=%u ok=%u agn=%u nbf=%u oom=%u\n",
61386- atomic_read(&fscache_n_stores),
61387- atomic_read(&fscache_n_stores_ok),
61388- atomic_read(&fscache_n_stores_again),
61389- atomic_read(&fscache_n_stores_nobufs),
61390- atomic_read(&fscache_n_stores_oom));
61391+ atomic_read_unchecked(&fscache_n_stores),
61392+ atomic_read_unchecked(&fscache_n_stores_ok),
61393+ atomic_read_unchecked(&fscache_n_stores_again),
61394+ atomic_read_unchecked(&fscache_n_stores_nobufs),
61395+ atomic_read_unchecked(&fscache_n_stores_oom));
61396 seq_printf(m, "Stores : ops=%u run=%u pgs=%u rxd=%u olm=%u\n",
61397- atomic_read(&fscache_n_store_ops),
61398- atomic_read(&fscache_n_store_calls),
61399- atomic_read(&fscache_n_store_pages),
61400- atomic_read(&fscache_n_store_radix_deletes),
61401- atomic_read(&fscache_n_store_pages_over_limit));
61402+ atomic_read_unchecked(&fscache_n_store_ops),
61403+ atomic_read_unchecked(&fscache_n_store_calls),
61404+ atomic_read_unchecked(&fscache_n_store_pages),
61405+ atomic_read_unchecked(&fscache_n_store_radix_deletes),
61406+ atomic_read_unchecked(&fscache_n_store_pages_over_limit));
61407
61408 seq_printf(m, "VmScan : nos=%u gon=%u bsy=%u can=%u wt=%u\n",
61409- atomic_read(&fscache_n_store_vmscan_not_storing),
61410- atomic_read(&fscache_n_store_vmscan_gone),
61411- atomic_read(&fscache_n_store_vmscan_busy),
61412- atomic_read(&fscache_n_store_vmscan_cancelled),
61413- atomic_read(&fscache_n_store_vmscan_wait));
61414+ atomic_read_unchecked(&fscache_n_store_vmscan_not_storing),
61415+ atomic_read_unchecked(&fscache_n_store_vmscan_gone),
61416+ atomic_read_unchecked(&fscache_n_store_vmscan_busy),
61417+ atomic_read_unchecked(&fscache_n_store_vmscan_cancelled),
61418+ atomic_read_unchecked(&fscache_n_store_vmscan_wait));
61419
61420 seq_printf(m, "Ops : pend=%u run=%u enq=%u can=%u rej=%u\n",
61421- atomic_read(&fscache_n_op_pend),
61422- atomic_read(&fscache_n_op_run),
61423- atomic_read(&fscache_n_op_enqueue),
61424- atomic_read(&fscache_n_op_cancelled),
61425- atomic_read(&fscache_n_op_rejected));
61426+ atomic_read_unchecked(&fscache_n_op_pend),
61427+ atomic_read_unchecked(&fscache_n_op_run),
61428+ atomic_read_unchecked(&fscache_n_op_enqueue),
61429+ atomic_read_unchecked(&fscache_n_op_cancelled),
61430+ atomic_read_unchecked(&fscache_n_op_rejected));
61431 seq_printf(m, "Ops : dfr=%u rel=%u gc=%u\n",
61432- atomic_read(&fscache_n_op_deferred_release),
61433- atomic_read(&fscache_n_op_release),
61434- atomic_read(&fscache_n_op_gc));
61435+ atomic_read_unchecked(&fscache_n_op_deferred_release),
61436+ atomic_read_unchecked(&fscache_n_op_release),
61437+ atomic_read_unchecked(&fscache_n_op_gc));
61438
61439 seq_printf(m, "CacheOp: alo=%d luo=%d luc=%d gro=%d\n",
61440 atomic_read(&fscache_n_cop_alloc_object),
61441diff --git a/fs/fuse/cuse.c b/fs/fuse/cuse.c
61442index b96a49b..9bfdc47 100644
61443--- a/fs/fuse/cuse.c
61444+++ b/fs/fuse/cuse.c
61445@@ -606,10 +606,12 @@ static int __init cuse_init(void)
61446 INIT_LIST_HEAD(&cuse_conntbl[i]);
61447
61448 /* inherit and extend fuse_dev_operations */
61449- cuse_channel_fops = fuse_dev_operations;
61450- cuse_channel_fops.owner = THIS_MODULE;
61451- cuse_channel_fops.open = cuse_channel_open;
61452- cuse_channel_fops.release = cuse_channel_release;
61453+ pax_open_kernel();
61454+ memcpy((void *)&cuse_channel_fops, &fuse_dev_operations, sizeof(fuse_dev_operations));
61455+ *(void **)&cuse_channel_fops.owner = THIS_MODULE;
61456+ *(void **)&cuse_channel_fops.open = cuse_channel_open;
61457+ *(void **)&cuse_channel_fops.release = cuse_channel_release;
61458+ pax_close_kernel();
61459
61460 cuse_class = class_create(THIS_MODULE, "cuse");
61461 if (IS_ERR(cuse_class))
61462diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
61463index 0a648bb..8d463f1 100644
61464--- a/fs/fuse/dev.c
61465+++ b/fs/fuse/dev.c
61466@@ -1323,7 +1323,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
61467 ret = 0;
61468 pipe_lock(pipe);
61469
61470- if (!pipe->readers) {
61471+ if (!atomic_read(&pipe->readers)) {
61472 send_sig(SIGPIPE, current, 0);
61473 if (!ret)
61474 ret = -EPIPE;
61475@@ -1352,7 +1352,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
61476 page_nr++;
61477 ret += buf->len;
61478
61479- if (pipe->files)
61480+ if (atomic_read(&pipe->files))
61481 do_wakeup = 1;
61482 }
61483
61484diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
61485index 1d1292c..bba17ea 100644
61486--- a/fs/fuse/dir.c
61487+++ b/fs/fuse/dir.c
61488@@ -1418,7 +1418,7 @@ static char *read_link(struct dentry *dentry)
61489 return link;
61490 }
61491
61492-static void free_link(char *link)
61493+static void free_link(const char *link)
61494 {
61495 if (!IS_ERR(link))
61496 free_page((unsigned long) link);
61497diff --git a/fs/hostfs/hostfs_kern.c b/fs/hostfs/hostfs_kern.c
61498index fe649d3..c679164 100644
61499--- a/fs/hostfs/hostfs_kern.c
61500+++ b/fs/hostfs/hostfs_kern.c
61501@@ -898,7 +898,7 @@ static void *hostfs_follow_link(struct dentry *dentry, struct nameidata *nd)
61502
61503 static void hostfs_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
61504 {
61505- char *s = nd_get_link(nd);
61506+ const char *s = nd_get_link(nd);
61507 if (!IS_ERR(s))
61508 __putname(s);
61509 }
61510diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
61511index d19b30a..ef89c36 100644
61512--- a/fs/hugetlbfs/inode.c
61513+++ b/fs/hugetlbfs/inode.c
61514@@ -152,6 +152,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
61515 struct mm_struct *mm = current->mm;
61516 struct vm_area_struct *vma;
61517 struct hstate *h = hstate_file(file);
61518+ unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
61519 struct vm_unmapped_area_info info;
61520
61521 if (len & ~huge_page_mask(h))
61522@@ -165,17 +166,26 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
61523 return addr;
61524 }
61525
61526+#ifdef CONFIG_PAX_RANDMMAP
61527+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
61528+#endif
61529+
61530 if (addr) {
61531 addr = ALIGN(addr, huge_page_size(h));
61532 vma = find_vma(mm, addr);
61533- if (TASK_SIZE - len >= addr &&
61534- (!vma || addr + len <= vma->vm_start))
61535+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
61536 return addr;
61537 }
61538
61539 info.flags = 0;
61540 info.length = len;
61541 info.low_limit = TASK_UNMAPPED_BASE;
61542+
61543+#ifdef CONFIG_PAX_RANDMMAP
61544+ if (mm->pax_flags & MF_PAX_RANDMMAP)
61545+ info.low_limit += mm->delta_mmap;
61546+#endif
61547+
61548 info.high_limit = TASK_SIZE;
61549 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
61550 info.align_offset = 0;
61551@@ -908,7 +918,7 @@ static struct file_system_type hugetlbfs_fs_type = {
61552 };
61553 MODULE_ALIAS_FS("hugetlbfs");
61554
61555-static struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
61556+struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
61557
61558 static int can_do_hugetlb_shm(void)
61559 {
61560diff --git a/fs/inode.c b/fs/inode.c
61561index 4bcdad3..1883822 100644
61562--- a/fs/inode.c
61563+++ b/fs/inode.c
61564@@ -841,8 +841,8 @@ unsigned int get_next_ino(void)
61565
61566 #ifdef CONFIG_SMP
61567 if (unlikely((res & (LAST_INO_BATCH-1)) == 0)) {
61568- static atomic_t shared_last_ino;
61569- int next = atomic_add_return(LAST_INO_BATCH, &shared_last_ino);
61570+ static atomic_unchecked_t shared_last_ino;
61571+ int next = atomic_add_return_unchecked(LAST_INO_BATCH, &shared_last_ino);
61572
61573 res = next - LAST_INO_BATCH;
61574 }
61575diff --git a/fs/jffs2/erase.c b/fs/jffs2/erase.c
61576index 4a6cf28..d3a29d3 100644
61577--- a/fs/jffs2/erase.c
61578+++ b/fs/jffs2/erase.c
61579@@ -452,7 +452,8 @@ static void jffs2_mark_erased_block(struct jffs2_sb_info *c, struct jffs2_eraseb
61580 struct jffs2_unknown_node marker = {
61581 .magic = cpu_to_je16(JFFS2_MAGIC_BITMASK),
61582 .nodetype = cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
61583- .totlen = cpu_to_je32(c->cleanmarker_size)
61584+ .totlen = cpu_to_je32(c->cleanmarker_size),
61585+ .hdr_crc = cpu_to_je32(0)
61586 };
61587
61588 jffs2_prealloc_raw_node_refs(c, jeb, 1);
61589diff --git a/fs/jffs2/wbuf.c b/fs/jffs2/wbuf.c
61590index a6597d6..41b30ec 100644
61591--- a/fs/jffs2/wbuf.c
61592+++ b/fs/jffs2/wbuf.c
61593@@ -1023,7 +1023,8 @@ static const struct jffs2_unknown_node oob_cleanmarker =
61594 {
61595 .magic = constant_cpu_to_je16(JFFS2_MAGIC_BITMASK),
61596 .nodetype = constant_cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
61597- .totlen = constant_cpu_to_je32(8)
61598+ .totlen = constant_cpu_to_je32(8),
61599+ .hdr_crc = constant_cpu_to_je32(0)
61600 };
61601
61602 /*
61603diff --git a/fs/jfs/super.c b/fs/jfs/super.c
61604index e2b7483..855bca3 100644
61605--- a/fs/jfs/super.c
61606+++ b/fs/jfs/super.c
61607@@ -884,7 +884,7 @@ static int __init init_jfs_fs(void)
61608
61609 jfs_inode_cachep =
61610 kmem_cache_create("jfs_ip", sizeof(struct jfs_inode_info), 0,
61611- SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD,
61612+ SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD|SLAB_USERCOPY,
61613 init_once);
61614 if (jfs_inode_cachep == NULL)
61615 return -ENOMEM;
61616diff --git a/fs/kernfs/dir.c b/fs/kernfs/dir.c
61617index 39c0143..d54fad4 100644
61618--- a/fs/kernfs/dir.c
61619+++ b/fs/kernfs/dir.c
61620@@ -28,7 +28,7 @@ DEFINE_MUTEX(kernfs_mutex);
61621 *
61622 * Returns 31 bit hash of ns + name (so it fits in an off_t )
61623 */
61624-static unsigned int kernfs_name_hash(const char *name, const void *ns)
61625+static unsigned int kernfs_name_hash(const unsigned char *name, const void *ns)
61626 {
61627 unsigned long hash = init_name_hash();
61628 unsigned int len = strlen(name);
61629diff --git a/fs/kernfs/file.c b/fs/kernfs/file.c
61630index dbf397b..d624b48 100644
61631--- a/fs/kernfs/file.c
61632+++ b/fs/kernfs/file.c
61633@@ -33,7 +33,7 @@ static DEFINE_MUTEX(kernfs_open_file_mutex);
61634
61635 struct kernfs_open_node {
61636 atomic_t refcnt;
61637- atomic_t event;
61638+ atomic_unchecked_t event;
61639 wait_queue_head_t poll;
61640 struct list_head files; /* goes through kernfs_open_file.list */
61641 };
61642@@ -149,7 +149,7 @@ static int kernfs_seq_show(struct seq_file *sf, void *v)
61643 {
61644 struct kernfs_open_file *of = sf->private;
61645
61646- of->event = atomic_read(&of->kn->attr.open->event);
61647+ of->event = atomic_read_unchecked(&of->kn->attr.open->event);
61648
61649 return of->kn->attr.ops->seq_show(sf, v);
61650 }
61651@@ -353,12 +353,12 @@ static int kernfs_vma_page_mkwrite(struct vm_area_struct *vma,
61652 return ret;
61653 }
61654
61655-static int kernfs_vma_access(struct vm_area_struct *vma, unsigned long addr,
61656- void *buf, int len, int write)
61657+static ssize_t kernfs_vma_access(struct vm_area_struct *vma, unsigned long addr,
61658+ void *buf, size_t len, int write)
61659 {
61660 struct file *file = vma->vm_file;
61661 struct kernfs_open_file *of = kernfs_of(file);
61662- int ret;
61663+ ssize_t ret;
61664
61665 if (!of->vm_ops)
61666 return -EINVAL;
61667@@ -557,7 +557,7 @@ static int kernfs_get_open_node(struct kernfs_node *kn,
61668 return -ENOMEM;
61669
61670 atomic_set(&new_on->refcnt, 0);
61671- atomic_set(&new_on->event, 1);
61672+ atomic_set_unchecked(&new_on->event, 1);
61673 init_waitqueue_head(&new_on->poll);
61674 INIT_LIST_HEAD(&new_on->files);
61675 goto retry;
61676@@ -754,7 +754,7 @@ static unsigned int kernfs_fop_poll(struct file *filp, poll_table *wait)
61677
61678 kernfs_put_active(kn);
61679
61680- if (of->event != atomic_read(&on->event))
61681+ if (of->event != atomic_read_unchecked(&on->event))
61682 goto trigger;
61683
61684 return DEFAULT_POLLMASK;
61685@@ -779,7 +779,7 @@ void kernfs_notify(struct kernfs_node *kn)
61686 if (!WARN_ON(kernfs_type(kn) != KERNFS_FILE)) {
61687 on = kn->attr.open;
61688 if (on) {
61689- atomic_inc(&on->event);
61690+ atomic_inc_unchecked(&on->event);
61691 wake_up_interruptible(&on->poll);
61692 }
61693 }
61694diff --git a/fs/kernfs/symlink.c b/fs/kernfs/symlink.c
61695index 4d45705..b35e0bd 100644
61696--- a/fs/kernfs/symlink.c
61697+++ b/fs/kernfs/symlink.c
61698@@ -132,7 +132,7 @@ static void *kernfs_iop_follow_link(struct dentry *dentry, struct nameidata *nd)
61699 static void kernfs_iop_put_link(struct dentry *dentry, struct nameidata *nd,
61700 void *cookie)
61701 {
61702- char *page = nd_get_link(nd);
61703+ const char *page = nd_get_link(nd);
61704 if (!IS_ERR(page))
61705 free_page((unsigned long)page);
61706 }
61707diff --git a/fs/libfs.c b/fs/libfs.c
61708index a184424..944ddce 100644
61709--- a/fs/libfs.c
61710+++ b/fs/libfs.c
61711@@ -159,6 +159,9 @@ int dcache_readdir(struct file *file, struct dir_context *ctx)
61712
61713 for (p = q->next; p != &dentry->d_subdirs; p = p->next) {
61714 struct dentry *next = list_entry(p, struct dentry, d_u.d_child);
61715+ char d_name[sizeof(next->d_iname)];
61716+ const unsigned char *name;
61717+
61718 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
61719 if (!simple_positive(next)) {
61720 spin_unlock(&next->d_lock);
61721@@ -167,7 +170,12 @@ int dcache_readdir(struct file *file, struct dir_context *ctx)
61722
61723 spin_unlock(&next->d_lock);
61724 spin_unlock(&dentry->d_lock);
61725- if (!dir_emit(ctx, next->d_name.name, next->d_name.len,
61726+ name = next->d_name.name;
61727+ if (name == next->d_iname) {
61728+ memcpy(d_name, name, next->d_name.len);
61729+ name = d_name;
61730+ }
61731+ if (!dir_emit(ctx, name, next->d_name.len,
61732 next->d_inode->i_ino, dt_type(next->d_inode)))
61733 return 0;
61734 spin_lock(&dentry->d_lock);
61735@@ -999,7 +1007,7 @@ EXPORT_SYMBOL(noop_fsync);
61736 void kfree_put_link(struct dentry *dentry, struct nameidata *nd,
61737 void *cookie)
61738 {
61739- char *s = nd_get_link(nd);
61740+ const char *s = nd_get_link(nd);
61741 if (!IS_ERR(s))
61742 kfree(s);
61743 }
61744diff --git a/fs/lockd/clntproc.c b/fs/lockd/clntproc.c
61745index acd3947..1f896e2 100644
61746--- a/fs/lockd/clntproc.c
61747+++ b/fs/lockd/clntproc.c
61748@@ -36,11 +36,11 @@ static const struct rpc_call_ops nlmclnt_cancel_ops;
61749 /*
61750 * Cookie counter for NLM requests
61751 */
61752-static atomic_t nlm_cookie = ATOMIC_INIT(0x1234);
61753+static atomic_unchecked_t nlm_cookie = ATOMIC_INIT(0x1234);
61754
61755 void nlmclnt_next_cookie(struct nlm_cookie *c)
61756 {
61757- u32 cookie = atomic_inc_return(&nlm_cookie);
61758+ u32 cookie = atomic_inc_return_unchecked(&nlm_cookie);
61759
61760 memcpy(c->data, &cookie, 4);
61761 c->len=4;
61762diff --git a/fs/locks.c b/fs/locks.c
61763index 4dd39b9..12d6aaf 100644
61764--- a/fs/locks.c
61765+++ b/fs/locks.c
61766@@ -2218,16 +2218,16 @@ void locks_remove_flock(struct file *filp)
61767 return;
61768
61769 if (filp->f_op->flock) {
61770- struct file_lock fl = {
61771+ struct file_lock flock = {
61772 .fl_pid = current->tgid,
61773 .fl_file = filp,
61774 .fl_flags = FL_FLOCK,
61775 .fl_type = F_UNLCK,
61776 .fl_end = OFFSET_MAX,
61777 };
61778- filp->f_op->flock(filp, F_SETLKW, &fl);
61779- if (fl.fl_ops && fl.fl_ops->fl_release_private)
61780- fl.fl_ops->fl_release_private(&fl);
61781+ filp->f_op->flock(filp, F_SETLKW, &flock);
61782+ if (flock.fl_ops && flock.fl_ops->fl_release_private)
61783+ flock.fl_ops->fl_release_private(&flock);
61784 }
61785
61786 spin_lock(&inode->i_lock);
61787diff --git a/fs/mount.h b/fs/mount.h
61788index b29e42f..5ea7fdf 100644
61789--- a/fs/mount.h
61790+++ b/fs/mount.h
61791@@ -11,7 +11,7 @@ struct mnt_namespace {
61792 u64 seq; /* Sequence number to prevent loops */
61793 wait_queue_head_t poll;
61794 int event;
61795-};
61796+} __randomize_layout;
61797
61798 struct mnt_pcp {
61799 int mnt_count;
61800@@ -57,7 +57,7 @@ struct mount {
61801 int mnt_expiry_mark; /* true if marked for expiry */
61802 int mnt_pinned;
61803 struct path mnt_ex_mountpoint;
61804-};
61805+} __randomize_layout;
61806
61807 #define MNT_NS_INTERNAL ERR_PTR(-EINVAL) /* distinct from any mnt_namespace */
61808
61809diff --git a/fs/namei.c b/fs/namei.c
61810index 4b491b4..a0166f9 100644
61811--- a/fs/namei.c
61812+++ b/fs/namei.c
61813@@ -330,16 +330,32 @@ int generic_permission(struct inode *inode, int mask)
61814 if (ret != -EACCES)
61815 return ret;
61816
61817+#ifdef CONFIG_GRKERNSEC
61818+ /* we'll block if we have to log due to a denied capability use */
61819+ if (mask & MAY_NOT_BLOCK)
61820+ return -ECHILD;
61821+#endif
61822+
61823 if (S_ISDIR(inode->i_mode)) {
61824 /* DACs are overridable for directories */
61825- if (inode_capable(inode, CAP_DAC_OVERRIDE))
61826- return 0;
61827 if (!(mask & MAY_WRITE))
61828- if (inode_capable(inode, CAP_DAC_READ_SEARCH))
61829+ if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
61830+ inode_capable(inode, CAP_DAC_READ_SEARCH))
61831 return 0;
61832+ if (inode_capable(inode, CAP_DAC_OVERRIDE))
61833+ return 0;
61834 return -EACCES;
61835 }
61836 /*
61837+ * Searching includes executable on directories, else just read.
61838+ */
61839+ mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
61840+ if (mask == MAY_READ)
61841+ if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
61842+ inode_capable(inode, CAP_DAC_READ_SEARCH))
61843+ return 0;
61844+
61845+ /*
61846 * Read/write DACs are always overridable.
61847 * Executable DACs are overridable when there is
61848 * at least one exec bit set.
61849@@ -348,14 +364,6 @@ int generic_permission(struct inode *inode, int mask)
61850 if (inode_capable(inode, CAP_DAC_OVERRIDE))
61851 return 0;
61852
61853- /*
61854- * Searching includes executable on directories, else just read.
61855- */
61856- mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
61857- if (mask == MAY_READ)
61858- if (inode_capable(inode, CAP_DAC_READ_SEARCH))
61859- return 0;
61860-
61861 return -EACCES;
61862 }
61863
61864@@ -821,7 +829,7 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
61865 {
61866 struct dentry *dentry = link->dentry;
61867 int error;
61868- char *s;
61869+ const char *s;
61870
61871 BUG_ON(nd->flags & LOOKUP_RCU);
61872
61873@@ -842,6 +850,12 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
61874 if (error)
61875 goto out_put_nd_path;
61876
61877+ if (gr_handle_follow_link(dentry->d_parent->d_inode,
61878+ dentry->d_inode, dentry, nd->path.mnt)) {
61879+ error = -EACCES;
61880+ goto out_put_nd_path;
61881+ }
61882+
61883 nd->last_type = LAST_BIND;
61884 *p = dentry->d_inode->i_op->follow_link(dentry, nd);
61885 error = PTR_ERR(*p);
61886@@ -1590,6 +1604,8 @@ static inline int nested_symlink(struct path *path, struct nameidata *nd)
61887 if (res)
61888 break;
61889 res = walk_component(nd, path, LOOKUP_FOLLOW);
61890+ if (res >= 0 && gr_handle_symlink_owner(&link, nd->inode))
61891+ res = -EACCES;
61892 put_link(nd, &link, cookie);
61893 } while (res > 0);
61894
61895@@ -1663,7 +1679,7 @@ EXPORT_SYMBOL(full_name_hash);
61896 static inline unsigned long hash_name(const char *name, unsigned int *hashp)
61897 {
61898 unsigned long a, b, adata, bdata, mask, hash, len;
61899- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
61900+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
61901
61902 hash = a = 0;
61903 len = -sizeof(unsigned long);
61904@@ -1947,6 +1963,8 @@ static int path_lookupat(int dfd, const char *name,
61905 if (err)
61906 break;
61907 err = lookup_last(nd, &path);
61908+ if (!err && gr_handle_symlink_owner(&link, nd->inode))
61909+ err = -EACCES;
61910 put_link(nd, &link, cookie);
61911 }
61912 }
61913@@ -1954,6 +1972,13 @@ static int path_lookupat(int dfd, const char *name,
61914 if (!err)
61915 err = complete_walk(nd);
61916
61917+ if (!err && !(nd->flags & LOOKUP_PARENT)) {
61918+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
61919+ path_put(&nd->path);
61920+ err = -ENOENT;
61921+ }
61922+ }
61923+
61924 if (!err && nd->flags & LOOKUP_DIRECTORY) {
61925 if (!d_is_directory(nd->path.dentry)) {
61926 path_put(&nd->path);
61927@@ -1981,8 +2006,15 @@ static int filename_lookup(int dfd, struct filename *name,
61928 retval = path_lookupat(dfd, name->name,
61929 flags | LOOKUP_REVAL, nd);
61930
61931- if (likely(!retval))
61932+ if (likely(!retval)) {
61933 audit_inode(name, nd->path.dentry, flags & LOOKUP_PARENT);
61934+ if (name->name[0] != '/' && nd->path.dentry && nd->inode) {
61935+ if (!gr_chroot_fchdir(nd->path.dentry, nd->path.mnt)) {
61936+ path_put(&nd->path);
61937+ return -ENOENT;
61938+ }
61939+ }
61940+ }
61941 return retval;
61942 }
61943
61944@@ -2556,6 +2588,13 @@ static int may_open(struct path *path, int acc_mode, int flag)
61945 if (flag & O_NOATIME && !inode_owner_or_capable(inode))
61946 return -EPERM;
61947
61948+ if (gr_handle_rofs_blockwrite(dentry, path->mnt, acc_mode))
61949+ return -EPERM;
61950+ if (gr_handle_rawio(inode))
61951+ return -EPERM;
61952+ if (!gr_acl_handle_open(dentry, path->mnt, acc_mode))
61953+ return -EACCES;
61954+
61955 return 0;
61956 }
61957
61958@@ -2787,7 +2826,7 @@ looked_up:
61959 * cleared otherwise prior to returning.
61960 */
61961 static int lookup_open(struct nameidata *nd, struct path *path,
61962- struct file *file,
61963+ struct path *link, struct file *file,
61964 const struct open_flags *op,
61965 bool got_write, int *opened)
61966 {
61967@@ -2822,6 +2861,17 @@ static int lookup_open(struct nameidata *nd, struct path *path,
61968 /* Negative dentry, just create the file */
61969 if (!dentry->d_inode && (op->open_flag & O_CREAT)) {
61970 umode_t mode = op->mode;
61971+
61972+ if (link && gr_handle_symlink_owner(link, dir->d_inode)) {
61973+ error = -EACCES;
61974+ goto out_dput;
61975+ }
61976+
61977+ if (!gr_acl_handle_creat(dentry, dir, nd->path.mnt, op->open_flag, op->acc_mode, mode)) {
61978+ error = -EACCES;
61979+ goto out_dput;
61980+ }
61981+
61982 if (!IS_POSIXACL(dir->d_inode))
61983 mode &= ~current_umask();
61984 /*
61985@@ -2843,6 +2893,8 @@ static int lookup_open(struct nameidata *nd, struct path *path,
61986 nd->flags & LOOKUP_EXCL);
61987 if (error)
61988 goto out_dput;
61989+ else
61990+ gr_handle_create(dentry, nd->path.mnt);
61991 }
61992 out_no_open:
61993 path->dentry = dentry;
61994@@ -2857,7 +2909,7 @@ out_dput:
61995 /*
61996 * Handle the last step of open()
61997 */
61998-static int do_last(struct nameidata *nd, struct path *path,
61999+static int do_last(struct nameidata *nd, struct path *path, struct path *link,
62000 struct file *file, const struct open_flags *op,
62001 int *opened, struct filename *name)
62002 {
62003@@ -2907,6 +2959,15 @@ static int do_last(struct nameidata *nd, struct path *path,
62004 if (error)
62005 return error;
62006
62007+ if (!gr_acl_handle_hidden_file(dir, nd->path.mnt)) {
62008+ error = -ENOENT;
62009+ goto out;
62010+ }
62011+ if (link && gr_handle_symlink_owner(link, nd->inode)) {
62012+ error = -EACCES;
62013+ goto out;
62014+ }
62015+
62016 audit_inode(name, dir, LOOKUP_PARENT);
62017 error = -EISDIR;
62018 /* trailing slashes? */
62019@@ -2926,7 +2987,7 @@ retry_lookup:
62020 */
62021 }
62022 mutex_lock(&dir->d_inode->i_mutex);
62023- error = lookup_open(nd, path, file, op, got_write, opened);
62024+ error = lookup_open(nd, path, link, file, op, got_write, opened);
62025 mutex_unlock(&dir->d_inode->i_mutex);
62026
62027 if (error <= 0) {
62028@@ -2950,11 +3011,28 @@ retry_lookup:
62029 goto finish_open_created;
62030 }
62031
62032+ if (!gr_acl_handle_hidden_file(path->dentry, nd->path.mnt)) {
62033+ error = -ENOENT;
62034+ goto exit_dput;
62035+ }
62036+ if (link && gr_handle_symlink_owner(link, path->dentry->d_inode)) {
62037+ error = -EACCES;
62038+ goto exit_dput;
62039+ }
62040+
62041 /*
62042 * create/update audit record if it already exists.
62043 */
62044- if (d_is_positive(path->dentry))
62045+ if (d_is_positive(path->dentry)) {
62046+ /* only check if O_CREAT is specified, all other checks need to go
62047+ into may_open */
62048+ if (gr_handle_fifo(path->dentry, path->mnt, dir, open_flag, acc_mode)) {
62049+ error = -EACCES;
62050+ goto exit_dput;
62051+ }
62052+
62053 audit_inode(name, path->dentry, 0);
62054+ }
62055
62056 /*
62057 * If atomic_open() acquired write access it is dropped now due to
62058@@ -2995,6 +3073,11 @@ finish_lookup:
62059 }
62060 }
62061 BUG_ON(inode != path->dentry->d_inode);
62062+ /* if we're resolving a symlink to another symlink */
62063+ if (link && gr_handle_symlink_owner(link, inode)) {
62064+ error = -EACCES;
62065+ goto out;
62066+ }
62067 return 1;
62068 }
62069
62070@@ -3004,7 +3087,6 @@ finish_lookup:
62071 save_parent.dentry = nd->path.dentry;
62072 save_parent.mnt = mntget(path->mnt);
62073 nd->path.dentry = path->dentry;
62074-
62075 }
62076 nd->inode = inode;
62077 /* Why this, you ask? _Now_ we might have grown LOOKUP_JUMPED... */
62078@@ -3014,7 +3096,18 @@ finish_open:
62079 path_put(&save_parent);
62080 return error;
62081 }
62082+
62083+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
62084+ error = -ENOENT;
62085+ goto out;
62086+ }
62087+ if (link && gr_handle_symlink_owner(link, nd->inode)) {
62088+ error = -EACCES;
62089+ goto out;
62090+ }
62091+
62092 audit_inode(name, nd->path.dentry, 0);
62093+
62094 error = -EISDIR;
62095 if ((open_flag & O_CREAT) &&
62096 (d_is_directory(nd->path.dentry) || d_is_autodir(nd->path.dentry)))
62097@@ -3178,7 +3271,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
62098 if (unlikely(error))
62099 goto out;
62100
62101- error = do_last(nd, &path, file, op, &opened, pathname);
62102+ error = do_last(nd, &path, NULL, file, op, &opened, pathname);
62103 while (unlikely(error > 0)) { /* trailing symlink */
62104 struct path link = path;
62105 void *cookie;
62106@@ -3196,7 +3289,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
62107 error = follow_link(&link, nd, &cookie);
62108 if (unlikely(error))
62109 break;
62110- error = do_last(nd, &path, file, op, &opened, pathname);
62111+ error = do_last(nd, &path, &link, file, op, &opened, pathname);
62112 put_link(nd, &link, cookie);
62113 }
62114 out:
62115@@ -3296,9 +3389,11 @@ struct dentry *kern_path_create(int dfd, const char *pathname,
62116 goto unlock;
62117
62118 error = -EEXIST;
62119- if (d_is_positive(dentry))
62120+ if (d_is_positive(dentry)) {
62121+ if (!gr_acl_handle_hidden_file(dentry, nd.path.mnt))
62122+ error = -ENOENT;
62123 goto fail;
62124-
62125+ }
62126 /*
62127 * Special case - lookup gave negative, but... we had foo/bar/
62128 * From the vfs_mknod() POV we just have a negative dentry -
62129@@ -3350,6 +3445,20 @@ struct dentry *user_path_create(int dfd, const char __user *pathname,
62130 }
62131 EXPORT_SYMBOL(user_path_create);
62132
62133+static struct dentry *user_path_create_with_name(int dfd, const char __user *pathname, struct path *path, struct filename **to, unsigned int lookup_flags)
62134+{
62135+ struct filename *tmp = getname(pathname);
62136+ struct dentry *res;
62137+ if (IS_ERR(tmp))
62138+ return ERR_CAST(tmp);
62139+ res = kern_path_create(dfd, tmp->name, path, lookup_flags);
62140+ if (IS_ERR(res))
62141+ putname(tmp);
62142+ else
62143+ *to = tmp;
62144+ return res;
62145+}
62146+
62147 int vfs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dev_t dev)
62148 {
62149 int error = may_create(dir, dentry);
62150@@ -3412,6 +3521,17 @@ retry:
62151
62152 if (!IS_POSIXACL(path.dentry->d_inode))
62153 mode &= ~current_umask();
62154+
62155+ if (gr_handle_chroot_mknod(dentry, path.mnt, mode)) {
62156+ error = -EPERM;
62157+ goto out;
62158+ }
62159+
62160+ if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
62161+ error = -EACCES;
62162+ goto out;
62163+ }
62164+
62165 error = security_path_mknod(&path, dentry, mode, dev);
62166 if (error)
62167 goto out;
62168@@ -3428,6 +3548,8 @@ retry:
62169 break;
62170 }
62171 out:
62172+ if (!error)
62173+ gr_handle_create(dentry, path.mnt);
62174 done_path_create(&path, dentry);
62175 if (retry_estale(error, lookup_flags)) {
62176 lookup_flags |= LOOKUP_REVAL;
62177@@ -3480,9 +3602,16 @@ retry:
62178
62179 if (!IS_POSIXACL(path.dentry->d_inode))
62180 mode &= ~current_umask();
62181+ if (!gr_acl_handle_mkdir(dentry, path.dentry, path.mnt)) {
62182+ error = -EACCES;
62183+ goto out;
62184+ }
62185 error = security_path_mkdir(&path, dentry, mode);
62186 if (!error)
62187 error = vfs_mkdir(path.dentry->d_inode, dentry, mode);
62188+ if (!error)
62189+ gr_handle_create(dentry, path.mnt);
62190+out:
62191 done_path_create(&path, dentry);
62192 if (retry_estale(error, lookup_flags)) {
62193 lookup_flags |= LOOKUP_REVAL;
62194@@ -3563,6 +3692,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
62195 struct filename *name;
62196 struct dentry *dentry;
62197 struct nameidata nd;
62198+ ino_t saved_ino = 0;
62199+ dev_t saved_dev = 0;
62200 unsigned int lookup_flags = 0;
62201 retry:
62202 name = user_path_parent(dfd, pathname, &nd, lookup_flags);
62203@@ -3595,10 +3726,21 @@ retry:
62204 error = -ENOENT;
62205 goto exit3;
62206 }
62207+
62208+ saved_ino = dentry->d_inode->i_ino;
62209+ saved_dev = gr_get_dev_from_dentry(dentry);
62210+
62211+ if (!gr_acl_handle_rmdir(dentry, nd.path.mnt)) {
62212+ error = -EACCES;
62213+ goto exit3;
62214+ }
62215+
62216 error = security_path_rmdir(&nd.path, dentry);
62217 if (error)
62218 goto exit3;
62219 error = vfs_rmdir(nd.path.dentry->d_inode, dentry);
62220+ if (!error && (saved_dev || saved_ino))
62221+ gr_handle_delete(saved_ino, saved_dev);
62222 exit3:
62223 dput(dentry);
62224 exit2:
62225@@ -3688,6 +3830,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
62226 struct nameidata nd;
62227 struct inode *inode = NULL;
62228 struct inode *delegated_inode = NULL;
62229+ ino_t saved_ino = 0;
62230+ dev_t saved_dev = 0;
62231 unsigned int lookup_flags = 0;
62232 retry:
62233 name = user_path_parent(dfd, pathname, &nd, lookup_flags);
62234@@ -3714,10 +3858,22 @@ retry_deleg:
62235 if (d_is_negative(dentry))
62236 goto slashes;
62237 ihold(inode);
62238+
62239+ if (inode->i_nlink <= 1) {
62240+ saved_ino = inode->i_ino;
62241+ saved_dev = gr_get_dev_from_dentry(dentry);
62242+ }
62243+ if (!gr_acl_handle_unlink(dentry, nd.path.mnt)) {
62244+ error = -EACCES;
62245+ goto exit2;
62246+ }
62247+
62248 error = security_path_unlink(&nd.path, dentry);
62249 if (error)
62250 goto exit2;
62251 error = vfs_unlink(nd.path.dentry->d_inode, dentry, &delegated_inode);
62252+ if (!error && (saved_ino || saved_dev))
62253+ gr_handle_delete(saved_ino, saved_dev);
62254 exit2:
62255 dput(dentry);
62256 }
62257@@ -3805,9 +3961,17 @@ retry:
62258 if (IS_ERR(dentry))
62259 goto out_putname;
62260
62261+ if (!gr_acl_handle_symlink(dentry, path.dentry, path.mnt, from)) {
62262+ error = -EACCES;
62263+ goto out;
62264+ }
62265+
62266 error = security_path_symlink(&path, dentry, from->name);
62267 if (!error)
62268 error = vfs_symlink(path.dentry->d_inode, dentry, from->name);
62269+ if (!error)
62270+ gr_handle_create(dentry, path.mnt);
62271+out:
62272 done_path_create(&path, dentry);
62273 if (retry_estale(error, lookup_flags)) {
62274 lookup_flags |= LOOKUP_REVAL;
62275@@ -3910,6 +4074,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
62276 struct dentry *new_dentry;
62277 struct path old_path, new_path;
62278 struct inode *delegated_inode = NULL;
62279+ struct filename *to = NULL;
62280 int how = 0;
62281 int error;
62282
62283@@ -3933,7 +4098,7 @@ retry:
62284 if (error)
62285 return error;
62286
62287- new_dentry = user_path_create(newdfd, newname, &new_path,
62288+ new_dentry = user_path_create_with_name(newdfd, newname, &new_path, &to,
62289 (how & LOOKUP_REVAL));
62290 error = PTR_ERR(new_dentry);
62291 if (IS_ERR(new_dentry))
62292@@ -3945,11 +4110,28 @@ retry:
62293 error = may_linkat(&old_path);
62294 if (unlikely(error))
62295 goto out_dput;
62296+
62297+ if (gr_handle_hardlink(old_path.dentry, old_path.mnt,
62298+ old_path.dentry->d_inode,
62299+ old_path.dentry->d_inode->i_mode, to)) {
62300+ error = -EACCES;
62301+ goto out_dput;
62302+ }
62303+
62304+ if (!gr_acl_handle_link(new_dentry, new_path.dentry, new_path.mnt,
62305+ old_path.dentry, old_path.mnt, to)) {
62306+ error = -EACCES;
62307+ goto out_dput;
62308+ }
62309+
62310 error = security_path_link(old_path.dentry, &new_path, new_dentry);
62311 if (error)
62312 goto out_dput;
62313 error = vfs_link(old_path.dentry, new_path.dentry->d_inode, new_dentry, &delegated_inode);
62314+ if (!error)
62315+ gr_handle_create(new_dentry, new_path.mnt);
62316 out_dput:
62317+ putname(to);
62318 done_path_create(&new_path, new_dentry);
62319 if (delegated_inode) {
62320 error = break_deleg_wait(&delegated_inode);
62321@@ -4236,6 +4418,12 @@ retry_deleg:
62322 if (new_dentry == trap)
62323 goto exit5;
62324
62325+ error = gr_acl_handle_rename(new_dentry, new_dir, newnd.path.mnt,
62326+ old_dentry, old_dir->d_inode, oldnd.path.mnt,
62327+ to);
62328+ if (error)
62329+ goto exit5;
62330+
62331 error = security_path_rename(&oldnd.path, old_dentry,
62332 &newnd.path, new_dentry);
62333 if (error)
62334@@ -4243,6 +4431,9 @@ retry_deleg:
62335 error = vfs_rename(old_dir->d_inode, old_dentry,
62336 new_dir->d_inode, new_dentry,
62337 &delegated_inode);
62338+ if (!error)
62339+ gr_handle_rename(old_dir->d_inode, new_dir->d_inode, old_dentry,
62340+ new_dentry, oldnd.path.mnt, new_dentry->d_inode ? 1 : 0);
62341 exit5:
62342 dput(new_dentry);
62343 exit4:
62344@@ -4279,6 +4470,8 @@ SYSCALL_DEFINE2(rename, const char __user *, oldname, const char __user *, newna
62345
62346 int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const char *link)
62347 {
62348+ char tmpbuf[64];
62349+ const char *newlink;
62350 int len;
62351
62352 len = PTR_ERR(link);
62353@@ -4288,7 +4481,14 @@ int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const c
62354 len = strlen(link);
62355 if (len > (unsigned) buflen)
62356 len = buflen;
62357- if (copy_to_user(buffer, link, len))
62358+
62359+ if (len < sizeof(tmpbuf)) {
62360+ memcpy(tmpbuf, link, len);
62361+ newlink = tmpbuf;
62362+ } else
62363+ newlink = link;
62364+
62365+ if (copy_to_user(buffer, newlink, len))
62366 len = -EFAULT;
62367 out:
62368 return len;
62369diff --git a/fs/namespace.c b/fs/namespace.c
62370index 65233a5..82ac953 100644
62371--- a/fs/namespace.c
62372+++ b/fs/namespace.c
62373@@ -1339,6 +1339,9 @@ static int do_umount(struct mount *mnt, int flags)
62374 if (!(sb->s_flags & MS_RDONLY))
62375 retval = do_remount_sb(sb, MS_RDONLY, NULL, 0);
62376 up_write(&sb->s_umount);
62377+
62378+ gr_log_remount(mnt->mnt_devname, retval);
62379+
62380 return retval;
62381 }
62382
62383@@ -1361,6 +1364,9 @@ static int do_umount(struct mount *mnt, int flags)
62384 }
62385 unlock_mount_hash();
62386 namespace_unlock();
62387+
62388+ gr_log_unmount(mnt->mnt_devname, retval);
62389+
62390 return retval;
62391 }
62392
62393@@ -1380,7 +1386,7 @@ static inline bool may_mount(void)
62394 * unixes. Our API is identical to OSF/1 to avoid making a mess of AMD
62395 */
62396
62397-SYSCALL_DEFINE2(umount, char __user *, name, int, flags)
62398+SYSCALL_DEFINE2(umount, const char __user *, name, int, flags)
62399 {
62400 struct path path;
62401 struct mount *mnt;
62402@@ -1422,7 +1428,7 @@ out:
62403 /*
62404 * The 2.0 compatible umount. No flags.
62405 */
62406-SYSCALL_DEFINE1(oldumount, char __user *, name)
62407+SYSCALL_DEFINE1(oldumount, const char __user *, name)
62408 {
62409 return sys_umount(name, 0);
62410 }
62411@@ -2431,6 +2437,16 @@ long do_mount(const char *dev_name, const char *dir_name,
62412 MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
62413 MS_STRICTATIME);
62414
62415+ if (gr_handle_rofs_mount(path.dentry, path.mnt, mnt_flags)) {
62416+ retval = -EPERM;
62417+ goto dput_out;
62418+ }
62419+
62420+ if (gr_handle_chroot_mount(path.dentry, path.mnt, dev_name)) {
62421+ retval = -EPERM;
62422+ goto dput_out;
62423+ }
62424+
62425 if (flags & MS_REMOUNT)
62426 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
62427 data_page);
62428@@ -2445,6 +2461,9 @@ long do_mount(const char *dev_name, const char *dir_name,
62429 dev_name, data_page);
62430 dput_out:
62431 path_put(&path);
62432+
62433+ gr_log_mount(dev_name, dir_name, retval);
62434+
62435 return retval;
62436 }
62437
62438@@ -2462,7 +2481,7 @@ static void free_mnt_ns(struct mnt_namespace *ns)
62439 * number incrementing at 10Ghz will take 12,427 years to wrap which
62440 * is effectively never, so we can ignore the possibility.
62441 */
62442-static atomic64_t mnt_ns_seq = ATOMIC64_INIT(1);
62443+static atomic64_unchecked_t mnt_ns_seq = ATOMIC64_INIT(1);
62444
62445 static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
62446 {
62447@@ -2477,7 +2496,7 @@ static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
62448 kfree(new_ns);
62449 return ERR_PTR(ret);
62450 }
62451- new_ns->seq = atomic64_add_return(1, &mnt_ns_seq);
62452+ new_ns->seq = atomic64_inc_return_unchecked(&mnt_ns_seq);
62453 atomic_set(&new_ns->count, 1);
62454 new_ns->root = NULL;
62455 INIT_LIST_HEAD(&new_ns->list);
62456@@ -2487,7 +2506,7 @@ static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
62457 return new_ns;
62458 }
62459
62460-struct mnt_namespace *copy_mnt_ns(unsigned long flags, struct mnt_namespace *ns,
62461+__latent_entropy struct mnt_namespace *copy_mnt_ns(unsigned long flags, struct mnt_namespace *ns,
62462 struct user_namespace *user_ns, struct fs_struct *new_fs)
62463 {
62464 struct mnt_namespace *new_ns;
62465@@ -2608,8 +2627,8 @@ struct dentry *mount_subtree(struct vfsmount *mnt, const char *name)
62466 }
62467 EXPORT_SYMBOL(mount_subtree);
62468
62469-SYSCALL_DEFINE5(mount, char __user *, dev_name, char __user *, dir_name,
62470- char __user *, type, unsigned long, flags, void __user *, data)
62471+SYSCALL_DEFINE5(mount, const char __user *, dev_name, const char __user *, dir_name,
62472+ const char __user *, type, unsigned long, flags, void __user *, data)
62473 {
62474 int ret;
62475 char *kernel_type;
62476@@ -2722,6 +2741,11 @@ SYSCALL_DEFINE2(pivot_root, const char __user *, new_root,
62477 if (error)
62478 goto out2;
62479
62480+ if (gr_handle_chroot_pivot()) {
62481+ error = -EPERM;
62482+ goto out2;
62483+ }
62484+
62485 get_fs_root(current->fs, &root);
62486 old_mp = lock_mount(&old);
62487 error = PTR_ERR(old_mp);
62488@@ -2990,7 +3014,7 @@ static int mntns_install(struct nsproxy *nsproxy, void *ns)
62489 !ns_capable(current_user_ns(), CAP_SYS_ADMIN))
62490 return -EPERM;
62491
62492- if (fs->users != 1)
62493+ if (atomic_read(&fs->users) != 1)
62494 return -EINVAL;
62495
62496 get_mnt_ns(mnt_ns);
62497diff --git a/fs/nfs/callback_xdr.c b/fs/nfs/callback_xdr.c
62498index f4ccfe6..a5cf064 100644
62499--- a/fs/nfs/callback_xdr.c
62500+++ b/fs/nfs/callback_xdr.c
62501@@ -51,7 +51,7 @@ struct callback_op {
62502 callback_decode_arg_t decode_args;
62503 callback_encode_res_t encode_res;
62504 long res_maxsize;
62505-};
62506+} __do_const;
62507
62508 static struct callback_op callback_ops[];
62509
62510diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
62511index 360114a..ac6e265 100644
62512--- a/fs/nfs/inode.c
62513+++ b/fs/nfs/inode.c
62514@@ -1189,16 +1189,16 @@ static int nfs_size_need_update(const struct inode *inode, const struct nfs_fatt
62515 return nfs_size_to_loff_t(fattr->size) > i_size_read(inode);
62516 }
62517
62518-static atomic_long_t nfs_attr_generation_counter;
62519+static atomic_long_unchecked_t nfs_attr_generation_counter;
62520
62521 static unsigned long nfs_read_attr_generation_counter(void)
62522 {
62523- return atomic_long_read(&nfs_attr_generation_counter);
62524+ return atomic_long_read_unchecked(&nfs_attr_generation_counter);
62525 }
62526
62527 unsigned long nfs_inc_attr_generation_counter(void)
62528 {
62529- return atomic_long_inc_return(&nfs_attr_generation_counter);
62530+ return atomic_long_inc_return_unchecked(&nfs_attr_generation_counter);
62531 }
62532
62533 void nfs_fattr_init(struct nfs_fattr *fattr)
62534diff --git a/fs/nfsd/nfs4proc.c b/fs/nfsd/nfs4proc.c
62535index 9a914e8..e89c0ea 100644
62536--- a/fs/nfsd/nfs4proc.c
62537+++ b/fs/nfsd/nfs4proc.c
62538@@ -1178,7 +1178,7 @@ struct nfsd4_operation {
62539 nfsd4op_rsize op_rsize_bop;
62540 stateid_getter op_get_currentstateid;
62541 stateid_setter op_set_currentstateid;
62542-};
62543+} __do_const;
62544
62545 static struct nfsd4_operation nfsd4_ops[];
62546
62547diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c
62548index 16e8fa7..b0803f6 100644
62549--- a/fs/nfsd/nfs4xdr.c
62550+++ b/fs/nfsd/nfs4xdr.c
62551@@ -1531,7 +1531,7 @@ nfsd4_decode_notsupp(struct nfsd4_compoundargs *argp, void *p)
62552
62553 typedef __be32(*nfsd4_dec)(struct nfsd4_compoundargs *argp, void *);
62554
62555-static nfsd4_dec nfsd4_dec_ops[] = {
62556+static const nfsd4_dec nfsd4_dec_ops[] = {
62557 [OP_ACCESS] = (nfsd4_dec)nfsd4_decode_access,
62558 [OP_CLOSE] = (nfsd4_dec)nfsd4_decode_close,
62559 [OP_COMMIT] = (nfsd4_dec)nfsd4_decode_commit,
62560diff --git a/fs/nfsd/nfscache.c b/fs/nfsd/nfscache.c
62561index f8f060f..c4ba09a 100644
62562--- a/fs/nfsd/nfscache.c
62563+++ b/fs/nfsd/nfscache.c
62564@@ -519,14 +519,17 @@ nfsd_cache_update(struct svc_rqst *rqstp, int cachetype, __be32 *statp)
62565 {
62566 struct svc_cacherep *rp = rqstp->rq_cacherep;
62567 struct kvec *resv = &rqstp->rq_res.head[0], *cachv;
62568- int len;
62569+ long len;
62570 size_t bufsize = 0;
62571
62572 if (!rp)
62573 return;
62574
62575- len = resv->iov_len - ((char*)statp - (char*)resv->iov_base);
62576- len >>= 2;
62577+ if (statp) {
62578+ len = (char*)statp - (char*)resv->iov_base;
62579+ len = resv->iov_len - len;
62580+ len >>= 2;
62581+ }
62582
62583 /* Don't cache excessive amounts of data and XDR failures */
62584 if (!statp || len > (256 >> 2)) {
62585diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
62586index eea5ad1..5a84ac7 100644
62587--- a/fs/nfsd/vfs.c
62588+++ b/fs/nfsd/vfs.c
62589@@ -843,7 +843,7 @@ nfsd_vfs_read(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
62590 } else {
62591 oldfs = get_fs();
62592 set_fs(KERNEL_DS);
62593- host_err = vfs_readv(file, (struct iovec __user *)vec, vlen, &offset);
62594+ host_err = vfs_readv(file, (struct iovec __force_user *)vec, vlen, &offset);
62595 set_fs(oldfs);
62596 }
62597
62598@@ -934,7 +934,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
62599
62600 /* Write the data. */
62601 oldfs = get_fs(); set_fs(KERNEL_DS);
62602- host_err = vfs_writev(file, (struct iovec __user *)vec, vlen, &pos);
62603+ host_err = vfs_writev(file, (struct iovec __force_user *)vec, vlen, &pos);
62604 set_fs(oldfs);
62605 if (host_err < 0)
62606 goto out_nfserr;
62607@@ -1479,7 +1479,7 @@ nfsd_readlink(struct svc_rqst *rqstp, struct svc_fh *fhp, char *buf, int *lenp)
62608 */
62609
62610 oldfs = get_fs(); set_fs(KERNEL_DS);
62611- host_err = inode->i_op->readlink(path.dentry, (char __user *)buf, *lenp);
62612+ host_err = inode->i_op->readlink(path.dentry, (char __force_user *)buf, *lenp);
62613 set_fs(oldfs);
62614
62615 if (host_err < 0)
62616diff --git a/fs/nls/nls_base.c b/fs/nls/nls_base.c
62617index 52ccd34..43a53b1 100644
62618--- a/fs/nls/nls_base.c
62619+++ b/fs/nls/nls_base.c
62620@@ -234,21 +234,25 @@ EXPORT_SYMBOL(utf16s_to_utf8s);
62621
62622 int __register_nls(struct nls_table *nls, struct module *owner)
62623 {
62624- struct nls_table ** tmp = &tables;
62625+ struct nls_table *tmp = tables;
62626
62627 if (nls->next)
62628 return -EBUSY;
62629
62630- nls->owner = owner;
62631+ pax_open_kernel();
62632+ *(void **)&nls->owner = owner;
62633+ pax_close_kernel();
62634 spin_lock(&nls_lock);
62635- while (*tmp) {
62636- if (nls == *tmp) {
62637+ while (tmp) {
62638+ if (nls == tmp) {
62639 spin_unlock(&nls_lock);
62640 return -EBUSY;
62641 }
62642- tmp = &(*tmp)->next;
62643+ tmp = tmp->next;
62644 }
62645- nls->next = tables;
62646+ pax_open_kernel();
62647+ *(struct nls_table **)&nls->next = tables;
62648+ pax_close_kernel();
62649 tables = nls;
62650 spin_unlock(&nls_lock);
62651 return 0;
62652@@ -257,12 +261,14 @@ EXPORT_SYMBOL(__register_nls);
62653
62654 int unregister_nls(struct nls_table * nls)
62655 {
62656- struct nls_table ** tmp = &tables;
62657+ struct nls_table * const * tmp = &tables;
62658
62659 spin_lock(&nls_lock);
62660 while (*tmp) {
62661 if (nls == *tmp) {
62662- *tmp = nls->next;
62663+ pax_open_kernel();
62664+ *(struct nls_table **)tmp = nls->next;
62665+ pax_close_kernel();
62666 spin_unlock(&nls_lock);
62667 return 0;
62668 }
62669diff --git a/fs/nls/nls_euc-jp.c b/fs/nls/nls_euc-jp.c
62670index 162b3f1..6076a7c 100644
62671--- a/fs/nls/nls_euc-jp.c
62672+++ b/fs/nls/nls_euc-jp.c
62673@@ -560,8 +560,10 @@ static int __init init_nls_euc_jp(void)
62674 p_nls = load_nls("cp932");
62675
62676 if (p_nls) {
62677- table.charset2upper = p_nls->charset2upper;
62678- table.charset2lower = p_nls->charset2lower;
62679+ pax_open_kernel();
62680+ *(const unsigned char **)&table.charset2upper = p_nls->charset2upper;
62681+ *(const unsigned char **)&table.charset2lower = p_nls->charset2lower;
62682+ pax_close_kernel();
62683 return register_nls(&table);
62684 }
62685
62686diff --git a/fs/nls/nls_koi8-ru.c b/fs/nls/nls_koi8-ru.c
62687index a80a741..7b96e1b 100644
62688--- a/fs/nls/nls_koi8-ru.c
62689+++ b/fs/nls/nls_koi8-ru.c
62690@@ -62,8 +62,10 @@ static int __init init_nls_koi8_ru(void)
62691 p_nls = load_nls("koi8-u");
62692
62693 if (p_nls) {
62694- table.charset2upper = p_nls->charset2upper;
62695- table.charset2lower = p_nls->charset2lower;
62696+ pax_open_kernel();
62697+ *(const unsigned char **)&table.charset2upper = p_nls->charset2upper;
62698+ *(const unsigned char **)&table.charset2lower = p_nls->charset2lower;
62699+ pax_close_kernel();
62700 return register_nls(&table);
62701 }
62702
62703diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
62704index 287a22c..4e56e4e 100644
62705--- a/fs/notify/fanotify/fanotify_user.c
62706+++ b/fs/notify/fanotify/fanotify_user.c
62707@@ -251,8 +251,8 @@ static ssize_t copy_event_to_user(struct fsnotify_group *group,
62708
62709 fd = fanotify_event_metadata.fd;
62710 ret = -EFAULT;
62711- if (copy_to_user(buf, &fanotify_event_metadata,
62712- fanotify_event_metadata.event_len))
62713+ if (fanotify_event_metadata.event_len > sizeof fanotify_event_metadata ||
62714+ copy_to_user(buf, &fanotify_event_metadata, fanotify_event_metadata.event_len))
62715 goto out_close_fd;
62716
62717 ret = prepare_for_access_response(group, event, fd);
62718@@ -742,6 +742,8 @@ SYSCALL_DEFINE2(fanotify_init, unsigned int, flags, unsigned int, event_f_flags)
62719 oevent->path.mnt = NULL;
62720 oevent->path.dentry = NULL;
62721
62722+ if (force_o_largefile())
62723+ event_f_flags |= O_LARGEFILE;
62724 group->fanotify_data.f_flags = event_f_flags;
62725 #ifdef CONFIG_FANOTIFY_ACCESS_PERMISSIONS
62726 oevent->response = 0;
62727diff --git a/fs/notify/notification.c b/fs/notify/notification.c
62728index 1e58402..bb2d6f4 100644
62729--- a/fs/notify/notification.c
62730+++ b/fs/notify/notification.c
62731@@ -48,7 +48,7 @@
62732 #include <linux/fsnotify_backend.h>
62733 #include "fsnotify.h"
62734
62735-static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
62736+static atomic_unchecked_t fsnotify_sync_cookie = ATOMIC_INIT(0);
62737
62738 /**
62739 * fsnotify_get_cookie - return a unique cookie for use in synchronizing events.
62740@@ -56,7 +56,7 @@ static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
62741 */
62742 u32 fsnotify_get_cookie(void)
62743 {
62744- return atomic_inc_return(&fsnotify_sync_cookie);
62745+ return atomic_inc_return_unchecked(&fsnotify_sync_cookie);
62746 }
62747 EXPORT_SYMBOL_GPL(fsnotify_get_cookie);
62748
62749diff --git a/fs/ntfs/dir.c b/fs/ntfs/dir.c
62750index 9e38daf..5727cae 100644
62751--- a/fs/ntfs/dir.c
62752+++ b/fs/ntfs/dir.c
62753@@ -1310,7 +1310,7 @@ find_next_index_buffer:
62754 ia = (INDEX_ALLOCATION*)(kaddr + (ia_pos & ~PAGE_CACHE_MASK &
62755 ~(s64)(ndir->itype.index.block_size - 1)));
62756 /* Bounds checks. */
62757- if (unlikely((u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
62758+ if (unlikely(!kaddr || (u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
62759 ntfs_error(sb, "Out of bounds check failed. Corrupt directory "
62760 "inode 0x%lx or driver bug.", vdir->i_ino);
62761 goto err_out;
62762diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c
62763index db9bd8a..8338fb6 100644
62764--- a/fs/ntfs/file.c
62765+++ b/fs/ntfs/file.c
62766@@ -1282,7 +1282,7 @@ static inline size_t ntfs_copy_from_user(struct page **pages,
62767 char *addr;
62768 size_t total = 0;
62769 unsigned len;
62770- int left;
62771+ unsigned left;
62772
62773 do {
62774 len = PAGE_CACHE_SIZE - ofs;
62775diff --git a/fs/ntfs/super.c b/fs/ntfs/super.c
62776index 82650d5..db37dcf 100644
62777--- a/fs/ntfs/super.c
62778+++ b/fs/ntfs/super.c
62779@@ -685,7 +685,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
62780 if (!silent)
62781 ntfs_error(sb, "Primary boot sector is invalid.");
62782 } else if (!silent)
62783- ntfs_error(sb, read_err_str, "primary");
62784+ ntfs_error(sb, read_err_str, "%s", "primary");
62785 if (!(NTFS_SB(sb)->on_errors & ON_ERRORS_RECOVER)) {
62786 if (bh_primary)
62787 brelse(bh_primary);
62788@@ -701,7 +701,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
62789 goto hotfix_primary_boot_sector;
62790 brelse(bh_backup);
62791 } else if (!silent)
62792- ntfs_error(sb, read_err_str, "backup");
62793+ ntfs_error(sb, read_err_str, "%s", "backup");
62794 /* Try to read NT3.51- backup boot sector. */
62795 if ((bh_backup = sb_bread(sb, nr_blocks >> 1))) {
62796 if (is_boot_sector_ntfs(sb, (NTFS_BOOT_SECTOR*)
62797@@ -712,7 +712,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
62798 "sector.");
62799 brelse(bh_backup);
62800 } else if (!silent)
62801- ntfs_error(sb, read_err_str, "backup");
62802+ ntfs_error(sb, read_err_str, "%s", "backup");
62803 /* We failed. Cleanup and return. */
62804 if (bh_primary)
62805 brelse(bh_primary);
62806diff --git a/fs/ocfs2/localalloc.c b/fs/ocfs2/localalloc.c
62807index 0440134..d52c93a 100644
62808--- a/fs/ocfs2/localalloc.c
62809+++ b/fs/ocfs2/localalloc.c
62810@@ -1320,7 +1320,7 @@ static int ocfs2_local_alloc_slide_window(struct ocfs2_super *osb,
62811 goto bail;
62812 }
62813
62814- atomic_inc(&osb->alloc_stats.moves);
62815+ atomic_inc_unchecked(&osb->alloc_stats.moves);
62816
62817 bail:
62818 if (handle)
62819diff --git a/fs/ocfs2/ocfs2.h b/fs/ocfs2/ocfs2.h
62820index 553f53c..aaf5133 100644
62821--- a/fs/ocfs2/ocfs2.h
62822+++ b/fs/ocfs2/ocfs2.h
62823@@ -235,11 +235,11 @@ enum ocfs2_vol_state
62824
62825 struct ocfs2_alloc_stats
62826 {
62827- atomic_t moves;
62828- atomic_t local_data;
62829- atomic_t bitmap_data;
62830- atomic_t bg_allocs;
62831- atomic_t bg_extends;
62832+ atomic_unchecked_t moves;
62833+ atomic_unchecked_t local_data;
62834+ atomic_unchecked_t bitmap_data;
62835+ atomic_unchecked_t bg_allocs;
62836+ atomic_unchecked_t bg_extends;
62837 };
62838
62839 enum ocfs2_local_alloc_state
62840diff --git a/fs/ocfs2/suballoc.c b/fs/ocfs2/suballoc.c
62841index 47ae266..6e8b793 100644
62842--- a/fs/ocfs2/suballoc.c
62843+++ b/fs/ocfs2/suballoc.c
62844@@ -866,7 +866,7 @@ static int ocfs2_reserve_suballoc_bits(struct ocfs2_super *osb,
62845 mlog_errno(status);
62846 goto bail;
62847 }
62848- atomic_inc(&osb->alloc_stats.bg_extends);
62849+ atomic_inc_unchecked(&osb->alloc_stats.bg_extends);
62850
62851 /* You should never ask for this much metadata */
62852 BUG_ON(bits_wanted >
62853@@ -1992,7 +1992,7 @@ int ocfs2_claim_metadata(handle_t *handle,
62854 mlog_errno(status);
62855 goto bail;
62856 }
62857- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
62858+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
62859
62860 *suballoc_loc = res.sr_bg_blkno;
62861 *suballoc_bit_start = res.sr_bit_offset;
62862@@ -2156,7 +2156,7 @@ int ocfs2_claim_new_inode_at_loc(handle_t *handle,
62863 trace_ocfs2_claim_new_inode_at_loc((unsigned long long)di_blkno,
62864 res->sr_bits);
62865
62866- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
62867+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
62868
62869 BUG_ON(res->sr_bits != 1);
62870
62871@@ -2198,7 +2198,7 @@ int ocfs2_claim_new_inode(handle_t *handle,
62872 mlog_errno(status);
62873 goto bail;
62874 }
62875- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
62876+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
62877
62878 BUG_ON(res.sr_bits != 1);
62879
62880@@ -2302,7 +2302,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
62881 cluster_start,
62882 num_clusters);
62883 if (!status)
62884- atomic_inc(&osb->alloc_stats.local_data);
62885+ atomic_inc_unchecked(&osb->alloc_stats.local_data);
62886 } else {
62887 if (min_clusters > (osb->bitmap_cpg - 1)) {
62888 /* The only paths asking for contiguousness
62889@@ -2328,7 +2328,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
62890 ocfs2_desc_bitmap_to_cluster_off(ac->ac_inode,
62891 res.sr_bg_blkno,
62892 res.sr_bit_offset);
62893- atomic_inc(&osb->alloc_stats.bitmap_data);
62894+ atomic_inc_unchecked(&osb->alloc_stats.bitmap_data);
62895 *num_clusters = res.sr_bits;
62896 }
62897 }
62898diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c
62899index 49d84f8..4807e0b 100644
62900--- a/fs/ocfs2/super.c
62901+++ b/fs/ocfs2/super.c
62902@@ -300,11 +300,11 @@ static int ocfs2_osb_dump(struct ocfs2_super *osb, char *buf, int len)
62903 "%10s => GlobalAllocs: %d LocalAllocs: %d "
62904 "SubAllocs: %d LAWinMoves: %d SAExtends: %d\n",
62905 "Stats",
62906- atomic_read(&osb->alloc_stats.bitmap_data),
62907- atomic_read(&osb->alloc_stats.local_data),
62908- atomic_read(&osb->alloc_stats.bg_allocs),
62909- atomic_read(&osb->alloc_stats.moves),
62910- atomic_read(&osb->alloc_stats.bg_extends));
62911+ atomic_read_unchecked(&osb->alloc_stats.bitmap_data),
62912+ atomic_read_unchecked(&osb->alloc_stats.local_data),
62913+ atomic_read_unchecked(&osb->alloc_stats.bg_allocs),
62914+ atomic_read_unchecked(&osb->alloc_stats.moves),
62915+ atomic_read_unchecked(&osb->alloc_stats.bg_extends));
62916
62917 out += snprintf(buf + out, len - out,
62918 "%10s => State: %u Descriptor: %llu Size: %u bits "
62919@@ -2123,11 +2123,11 @@ static int ocfs2_initialize_super(struct super_block *sb,
62920 spin_lock_init(&osb->osb_xattr_lock);
62921 ocfs2_init_steal_slots(osb);
62922
62923- atomic_set(&osb->alloc_stats.moves, 0);
62924- atomic_set(&osb->alloc_stats.local_data, 0);
62925- atomic_set(&osb->alloc_stats.bitmap_data, 0);
62926- atomic_set(&osb->alloc_stats.bg_allocs, 0);
62927- atomic_set(&osb->alloc_stats.bg_extends, 0);
62928+ atomic_set_unchecked(&osb->alloc_stats.moves, 0);
62929+ atomic_set_unchecked(&osb->alloc_stats.local_data, 0);
62930+ atomic_set_unchecked(&osb->alloc_stats.bitmap_data, 0);
62931+ atomic_set_unchecked(&osb->alloc_stats.bg_allocs, 0);
62932+ atomic_set_unchecked(&osb->alloc_stats.bg_extends, 0);
62933
62934 /* Copy the blockcheck stats from the superblock probe */
62935 osb->osb_ecc_stats = *stats;
62936diff --git a/fs/open.c b/fs/open.c
62937index b9ed8b2..0d5c7a0 100644
62938--- a/fs/open.c
62939+++ b/fs/open.c
62940@@ -32,6 +32,8 @@
62941 #include <linux/dnotify.h>
62942 #include <linux/compat.h>
62943
62944+#define CREATE_TRACE_POINTS
62945+#include <trace/events/fs.h>
62946 #include "internal.h"
62947
62948 int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
62949@@ -103,6 +105,8 @@ long vfs_truncate(struct path *path, loff_t length)
62950 error = locks_verify_truncate(inode, NULL, length);
62951 if (!error)
62952 error = security_path_truncate(path);
62953+ if (!error && !gr_acl_handle_truncate(path->dentry, path->mnt))
62954+ error = -EACCES;
62955 if (!error)
62956 error = do_truncate(path->dentry, length, 0, NULL);
62957
62958@@ -187,6 +191,8 @@ static long do_sys_ftruncate(unsigned int fd, loff_t length, int small)
62959 error = locks_verify_truncate(inode, f.file, length);
62960 if (!error)
62961 error = security_path_truncate(&f.file->f_path);
62962+ if (!error && !gr_acl_handle_truncate(f.file->f_path.dentry, f.file->f_path.mnt))
62963+ error = -EACCES;
62964 if (!error)
62965 error = do_truncate(dentry, length, ATTR_MTIME|ATTR_CTIME, f.file);
62966 sb_end_write(inode->i_sb);
62967@@ -361,6 +367,9 @@ retry:
62968 if (__mnt_is_readonly(path.mnt))
62969 res = -EROFS;
62970
62971+ if (!res && !gr_acl_handle_access(path.dentry, path.mnt, mode))
62972+ res = -EACCES;
62973+
62974 out_path_release:
62975 path_put(&path);
62976 if (retry_estale(res, lookup_flags)) {
62977@@ -392,6 +401,8 @@ retry:
62978 if (error)
62979 goto dput_and_out;
62980
62981+ gr_log_chdir(path.dentry, path.mnt);
62982+
62983 set_fs_pwd(current->fs, &path);
62984
62985 dput_and_out:
62986@@ -421,6 +432,13 @@ SYSCALL_DEFINE1(fchdir, unsigned int, fd)
62987 goto out_putf;
62988
62989 error = inode_permission(inode, MAY_EXEC | MAY_CHDIR);
62990+
62991+ if (!error && !gr_chroot_fchdir(f.file->f_path.dentry, f.file->f_path.mnt))
62992+ error = -EPERM;
62993+
62994+ if (!error)
62995+ gr_log_chdir(f.file->f_path.dentry, f.file->f_path.mnt);
62996+
62997 if (!error)
62998 set_fs_pwd(current->fs, &f.file->f_path);
62999 out_putf:
63000@@ -450,7 +468,13 @@ retry:
63001 if (error)
63002 goto dput_and_out;
63003
63004+ if (gr_handle_chroot_chroot(path.dentry, path.mnt))
63005+ goto dput_and_out;
63006+
63007 set_fs_root(current->fs, &path);
63008+
63009+ gr_handle_chroot_chdir(&path);
63010+
63011 error = 0;
63012 dput_and_out:
63013 path_put(&path);
63014@@ -474,6 +498,16 @@ static int chmod_common(struct path *path, umode_t mode)
63015 return error;
63016 retry_deleg:
63017 mutex_lock(&inode->i_mutex);
63018+
63019+ if (!gr_acl_handle_chmod(path->dentry, path->mnt, &mode)) {
63020+ error = -EACCES;
63021+ goto out_unlock;
63022+ }
63023+ if (gr_handle_chroot_chmod(path->dentry, path->mnt, mode)) {
63024+ error = -EACCES;
63025+ goto out_unlock;
63026+ }
63027+
63028 error = security_path_chmod(path, mode);
63029 if (error)
63030 goto out_unlock;
63031@@ -539,6 +573,9 @@ static int chown_common(struct path *path, uid_t user, gid_t group)
63032 uid = make_kuid(current_user_ns(), user);
63033 gid = make_kgid(current_user_ns(), group);
63034
63035+ if (!gr_acl_handle_chown(path->dentry, path->mnt))
63036+ return -EACCES;
63037+
63038 newattrs.ia_valid = ATTR_CTIME;
63039 if (user != (uid_t) -1) {
63040 if (!uid_valid(uid))
63041@@ -994,6 +1031,7 @@ long do_sys_open(int dfd, const char __user *filename, int flags, umode_t mode)
63042 } else {
63043 fsnotify_open(f);
63044 fd_install(fd, f);
63045+ trace_do_sys_open(tmp->name, flags, mode);
63046 }
63047 }
63048 putname(tmp);
63049diff --git a/fs/pipe.c b/fs/pipe.c
63050index 78fd0d0..f71fc09 100644
63051--- a/fs/pipe.c
63052+++ b/fs/pipe.c
63053@@ -56,7 +56,7 @@ unsigned int pipe_min_size = PAGE_SIZE;
63054
63055 static void pipe_lock_nested(struct pipe_inode_info *pipe, int subclass)
63056 {
63057- if (pipe->files)
63058+ if (atomic_read(&pipe->files))
63059 mutex_lock_nested(&pipe->mutex, subclass);
63060 }
63061
63062@@ -71,7 +71,7 @@ EXPORT_SYMBOL(pipe_lock);
63063
63064 void pipe_unlock(struct pipe_inode_info *pipe)
63065 {
63066- if (pipe->files)
63067+ if (atomic_read(&pipe->files))
63068 mutex_unlock(&pipe->mutex);
63069 }
63070 EXPORT_SYMBOL(pipe_unlock);
63071@@ -449,9 +449,9 @@ redo:
63072 }
63073 if (bufs) /* More to do? */
63074 continue;
63075- if (!pipe->writers)
63076+ if (!atomic_read(&pipe->writers))
63077 break;
63078- if (!pipe->waiting_writers) {
63079+ if (!atomic_read(&pipe->waiting_writers)) {
63080 /* syscall merging: Usually we must not sleep
63081 * if O_NONBLOCK is set, or if we got some data.
63082 * But if a writer sleeps in kernel space, then
63083@@ -513,7 +513,7 @@ pipe_write(struct kiocb *iocb, const struct iovec *_iov,
63084 ret = 0;
63085 __pipe_lock(pipe);
63086
63087- if (!pipe->readers) {
63088+ if (!atomic_read(&pipe->readers)) {
63089 send_sig(SIGPIPE, current, 0);
63090 ret = -EPIPE;
63091 goto out;
63092@@ -562,7 +562,7 @@ redo1:
63093 for (;;) {
63094 int bufs;
63095
63096- if (!pipe->readers) {
63097+ if (!atomic_read(&pipe->readers)) {
63098 send_sig(SIGPIPE, current, 0);
63099 if (!ret)
63100 ret = -EPIPE;
63101@@ -653,9 +653,9 @@ redo2:
63102 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
63103 do_wakeup = 0;
63104 }
63105- pipe->waiting_writers++;
63106+ atomic_inc(&pipe->waiting_writers);
63107 pipe_wait(pipe);
63108- pipe->waiting_writers--;
63109+ atomic_dec(&pipe->waiting_writers);
63110 }
63111 out:
63112 __pipe_unlock(pipe);
63113@@ -710,7 +710,7 @@ pipe_poll(struct file *filp, poll_table *wait)
63114 mask = 0;
63115 if (filp->f_mode & FMODE_READ) {
63116 mask = (nrbufs > 0) ? POLLIN | POLLRDNORM : 0;
63117- if (!pipe->writers && filp->f_version != pipe->w_counter)
63118+ if (!atomic_read(&pipe->writers) && filp->f_version != pipe->w_counter)
63119 mask |= POLLHUP;
63120 }
63121
63122@@ -720,7 +720,7 @@ pipe_poll(struct file *filp, poll_table *wait)
63123 * Most Unices do not set POLLERR for FIFOs but on Linux they
63124 * behave exactly like pipes for poll().
63125 */
63126- if (!pipe->readers)
63127+ if (!atomic_read(&pipe->readers))
63128 mask |= POLLERR;
63129 }
63130
63131@@ -732,7 +732,7 @@ static void put_pipe_info(struct inode *inode, struct pipe_inode_info *pipe)
63132 int kill = 0;
63133
63134 spin_lock(&inode->i_lock);
63135- if (!--pipe->files) {
63136+ if (atomic_dec_and_test(&pipe->files)) {
63137 inode->i_pipe = NULL;
63138 kill = 1;
63139 }
63140@@ -749,11 +749,11 @@ pipe_release(struct inode *inode, struct file *file)
63141
63142 __pipe_lock(pipe);
63143 if (file->f_mode & FMODE_READ)
63144- pipe->readers--;
63145+ atomic_dec(&pipe->readers);
63146 if (file->f_mode & FMODE_WRITE)
63147- pipe->writers--;
63148+ atomic_dec(&pipe->writers);
63149
63150- if (pipe->readers || pipe->writers) {
63151+ if (atomic_read(&pipe->readers) || atomic_read(&pipe->writers)) {
63152 wake_up_interruptible_sync_poll(&pipe->wait, POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM | POLLERR | POLLHUP);
63153 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
63154 kill_fasync(&pipe->fasync_writers, SIGIO, POLL_OUT);
63155@@ -818,7 +818,7 @@ void free_pipe_info(struct pipe_inode_info *pipe)
63156 kfree(pipe);
63157 }
63158
63159-static struct vfsmount *pipe_mnt __read_mostly;
63160+struct vfsmount *pipe_mnt __read_mostly;
63161
63162 /*
63163 * pipefs_dname() is called from d_path().
63164@@ -848,8 +848,9 @@ static struct inode * get_pipe_inode(void)
63165 goto fail_iput;
63166
63167 inode->i_pipe = pipe;
63168- pipe->files = 2;
63169- pipe->readers = pipe->writers = 1;
63170+ atomic_set(&pipe->files, 2);
63171+ atomic_set(&pipe->readers, 1);
63172+ atomic_set(&pipe->writers, 1);
63173 inode->i_fop = &pipefifo_fops;
63174
63175 /*
63176@@ -1028,17 +1029,17 @@ static int fifo_open(struct inode *inode, struct file *filp)
63177 spin_lock(&inode->i_lock);
63178 if (inode->i_pipe) {
63179 pipe = inode->i_pipe;
63180- pipe->files++;
63181+ atomic_inc(&pipe->files);
63182 spin_unlock(&inode->i_lock);
63183 } else {
63184 spin_unlock(&inode->i_lock);
63185 pipe = alloc_pipe_info();
63186 if (!pipe)
63187 return -ENOMEM;
63188- pipe->files = 1;
63189+ atomic_set(&pipe->files, 1);
63190 spin_lock(&inode->i_lock);
63191 if (unlikely(inode->i_pipe)) {
63192- inode->i_pipe->files++;
63193+ atomic_inc(&inode->i_pipe->files);
63194 spin_unlock(&inode->i_lock);
63195 free_pipe_info(pipe);
63196 pipe = inode->i_pipe;
63197@@ -1063,10 +1064,10 @@ static int fifo_open(struct inode *inode, struct file *filp)
63198 * opened, even when there is no process writing the FIFO.
63199 */
63200 pipe->r_counter++;
63201- if (pipe->readers++ == 0)
63202+ if (atomic_inc_return(&pipe->readers) == 1)
63203 wake_up_partner(pipe);
63204
63205- if (!is_pipe && !pipe->writers) {
63206+ if (!is_pipe && !atomic_read(&pipe->writers)) {
63207 if ((filp->f_flags & O_NONBLOCK)) {
63208 /* suppress POLLHUP until we have
63209 * seen a writer */
63210@@ -1085,14 +1086,14 @@ static int fifo_open(struct inode *inode, struct file *filp)
63211 * errno=ENXIO when there is no process reading the FIFO.
63212 */
63213 ret = -ENXIO;
63214- if (!is_pipe && (filp->f_flags & O_NONBLOCK) && !pipe->readers)
63215+ if (!is_pipe && (filp->f_flags & O_NONBLOCK) && !atomic_read(&pipe->readers))
63216 goto err;
63217
63218 pipe->w_counter++;
63219- if (!pipe->writers++)
63220+ if (atomic_inc_return(&pipe->writers) == 1)
63221 wake_up_partner(pipe);
63222
63223- if (!is_pipe && !pipe->readers) {
63224+ if (!is_pipe && !atomic_read(&pipe->readers)) {
63225 if (wait_for_partner(pipe, &pipe->r_counter))
63226 goto err_wr;
63227 }
63228@@ -1106,11 +1107,11 @@ static int fifo_open(struct inode *inode, struct file *filp)
63229 * the process can at least talk to itself.
63230 */
63231
63232- pipe->readers++;
63233- pipe->writers++;
63234+ atomic_inc(&pipe->readers);
63235+ atomic_inc(&pipe->writers);
63236 pipe->r_counter++;
63237 pipe->w_counter++;
63238- if (pipe->readers == 1 || pipe->writers == 1)
63239+ if (atomic_read(&pipe->readers) == 1 || atomic_read(&pipe->writers) == 1)
63240 wake_up_partner(pipe);
63241 break;
63242
63243@@ -1124,13 +1125,13 @@ static int fifo_open(struct inode *inode, struct file *filp)
63244 return 0;
63245
63246 err_rd:
63247- if (!--pipe->readers)
63248+ if (atomic_dec_and_test(&pipe->readers))
63249 wake_up_interruptible(&pipe->wait);
63250 ret = -ERESTARTSYS;
63251 goto err;
63252
63253 err_wr:
63254- if (!--pipe->writers)
63255+ if (atomic_dec_and_test(&pipe->writers))
63256 wake_up_interruptible(&pipe->wait);
63257 ret = -ERESTARTSYS;
63258 goto err;
63259diff --git a/fs/posix_acl.c b/fs/posix_acl.c
63260index 9e363e4..d936d15 100644
63261--- a/fs/posix_acl.c
63262+++ b/fs/posix_acl.c
63263@@ -20,6 +20,7 @@
63264 #include <linux/xattr.h>
63265 #include <linux/export.h>
63266 #include <linux/user_namespace.h>
63267+#include <linux/grsecurity.h>
63268
63269 struct posix_acl **acl_by_type(struct inode *inode, int type)
63270 {
63271@@ -271,7 +272,7 @@ posix_acl_equiv_mode(const struct posix_acl *acl, umode_t *mode_p)
63272 }
63273 }
63274 if (mode_p)
63275- *mode_p = (*mode_p & ~S_IRWXUGO) | mode;
63276+ *mode_p = ((*mode_p & ~S_IRWXUGO) | mode) & ~gr_acl_umask();
63277 return not_equiv;
63278 }
63279 EXPORT_SYMBOL(posix_acl_equiv_mode);
63280@@ -421,7 +422,7 @@ static int posix_acl_create_masq(struct posix_acl *acl, umode_t *mode_p)
63281 mode &= (group_obj->e_perm << 3) | ~S_IRWXG;
63282 }
63283
63284- *mode_p = (*mode_p & ~S_IRWXUGO) | mode;
63285+ *mode_p = ((*mode_p & ~S_IRWXUGO) | mode) & ~gr_acl_umask();
63286 return not_equiv;
63287 }
63288
63289@@ -479,6 +480,8 @@ __posix_acl_create(struct posix_acl **acl, gfp_t gfp, umode_t *mode_p)
63290 struct posix_acl *clone = posix_acl_clone(*acl, gfp);
63291 int err = -ENOMEM;
63292 if (clone) {
63293+ *mode_p &= ~gr_acl_umask();
63294+
63295 err = posix_acl_create_masq(clone, mode_p);
63296 if (err < 0) {
63297 posix_acl_release(clone);
63298@@ -653,11 +656,12 @@ struct posix_acl *
63299 posix_acl_from_xattr(struct user_namespace *user_ns,
63300 const void *value, size_t size)
63301 {
63302- posix_acl_xattr_header *header = (posix_acl_xattr_header *)value;
63303- posix_acl_xattr_entry *entry = (posix_acl_xattr_entry *)(header+1), *end;
63304+ const posix_acl_xattr_header *header = (const posix_acl_xattr_header *)value;
63305+ const posix_acl_xattr_entry *entry = (const posix_acl_xattr_entry *)(header+1), *end;
63306 int count;
63307 struct posix_acl *acl;
63308 struct posix_acl_entry *acl_e;
63309+ umode_t umask = gr_acl_umask();
63310
63311 if (!value)
63312 return NULL;
63313@@ -683,12 +687,18 @@ posix_acl_from_xattr(struct user_namespace *user_ns,
63314
63315 switch(acl_e->e_tag) {
63316 case ACL_USER_OBJ:
63317+ acl_e->e_perm &= ~((umask & S_IRWXU) >> 6);
63318+ break;
63319 case ACL_GROUP_OBJ:
63320 case ACL_MASK:
63321+ acl_e->e_perm &= ~((umask & S_IRWXG) >> 3);
63322+ break;
63323 case ACL_OTHER:
63324+ acl_e->e_perm &= ~(umask & S_IRWXO);
63325 break;
63326
63327 case ACL_USER:
63328+ acl_e->e_perm &= ~((umask & S_IRWXU) >> 6);
63329 acl_e->e_uid =
63330 make_kuid(user_ns,
63331 le32_to_cpu(entry->e_id));
63332@@ -696,6 +706,7 @@ posix_acl_from_xattr(struct user_namespace *user_ns,
63333 goto fail;
63334 break;
63335 case ACL_GROUP:
63336+ acl_e->e_perm &= ~((umask & S_IRWXG) >> 3);
63337 acl_e->e_gid =
63338 make_kgid(user_ns,
63339 le32_to_cpu(entry->e_id));
63340diff --git a/fs/proc/Kconfig b/fs/proc/Kconfig
63341index 2183fcf..3c32a98 100644
63342--- a/fs/proc/Kconfig
63343+++ b/fs/proc/Kconfig
63344@@ -30,7 +30,7 @@ config PROC_FS
63345
63346 config PROC_KCORE
63347 bool "/proc/kcore support" if !ARM
63348- depends on PROC_FS && MMU
63349+ depends on PROC_FS && MMU && !GRKERNSEC_PROC_ADD
63350 help
63351 Provides a virtual ELF core file of the live kernel. This can
63352 be read with gdb and other ELF tools. No modifications can be
63353@@ -38,8 +38,8 @@ config PROC_KCORE
63354
63355 config PROC_VMCORE
63356 bool "/proc/vmcore support"
63357- depends on PROC_FS && CRASH_DUMP
63358- default y
63359+ depends on PROC_FS && CRASH_DUMP && !GRKERNSEC
63360+ default n
63361 help
63362 Exports the dump image of crashed kernel in ELF format.
63363
63364@@ -63,8 +63,8 @@ config PROC_SYSCTL
63365 limited in memory.
63366
63367 config PROC_PAGE_MONITOR
63368- default y
63369- depends on PROC_FS && MMU
63370+ default n
63371+ depends on PROC_FS && MMU && !GRKERNSEC
63372 bool "Enable /proc page monitoring" if EXPERT
63373 help
63374 Various /proc files exist to monitor process memory utilization:
63375diff --git a/fs/proc/array.c b/fs/proc/array.c
63376index 656e401..b5b86b9 100644
63377--- a/fs/proc/array.c
63378+++ b/fs/proc/array.c
63379@@ -60,6 +60,7 @@
63380 #include <linux/tty.h>
63381 #include <linux/string.h>
63382 #include <linux/mman.h>
63383+#include <linux/grsecurity.h>
63384 #include <linux/proc_fs.h>
63385 #include <linux/ioport.h>
63386 #include <linux/uaccess.h>
63387@@ -356,6 +357,21 @@ static void task_cpus_allowed(struct seq_file *m, struct task_struct *task)
63388 seq_putc(m, '\n');
63389 }
63390
63391+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
63392+static inline void task_pax(struct seq_file *m, struct task_struct *p)
63393+{
63394+ if (p->mm)
63395+ seq_printf(m, "PaX:\t%c%c%c%c%c\n",
63396+ p->mm->pax_flags & MF_PAX_PAGEEXEC ? 'P' : 'p',
63397+ p->mm->pax_flags & MF_PAX_EMUTRAMP ? 'E' : 'e',
63398+ p->mm->pax_flags & MF_PAX_MPROTECT ? 'M' : 'm',
63399+ p->mm->pax_flags & MF_PAX_RANDMMAP ? 'R' : 'r',
63400+ p->mm->pax_flags & MF_PAX_SEGMEXEC ? 'S' : 's');
63401+ else
63402+ seq_printf(m, "PaX:\t-----\n");
63403+}
63404+#endif
63405+
63406 int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
63407 struct pid *pid, struct task_struct *task)
63408 {
63409@@ -374,9 +390,24 @@ int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
63410 task_cpus_allowed(m, task);
63411 cpuset_task_status_allowed(m, task);
63412 task_context_switch_counts(m, task);
63413+
63414+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
63415+ task_pax(m, task);
63416+#endif
63417+
63418+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
63419+ task_grsec_rbac(m, task);
63420+#endif
63421+
63422 return 0;
63423 }
63424
63425+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63426+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
63427+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
63428+ _mm->pax_flags & MF_PAX_SEGMEXEC))
63429+#endif
63430+
63431 static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
63432 struct pid *pid, struct task_struct *task, int whole)
63433 {
63434@@ -398,6 +429,13 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
63435 char tcomm[sizeof(task->comm)];
63436 unsigned long flags;
63437
63438+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63439+ if (current->exec_id != m->exec_id) {
63440+ gr_log_badprocpid("stat");
63441+ return 0;
63442+ }
63443+#endif
63444+
63445 state = *get_task_state(task);
63446 vsize = eip = esp = 0;
63447 permitted = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
63448@@ -468,6 +506,19 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
63449 gtime = task_gtime(task);
63450 }
63451
63452+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63453+ if (PAX_RAND_FLAGS(mm)) {
63454+ eip = 0;
63455+ esp = 0;
63456+ wchan = 0;
63457+ }
63458+#endif
63459+#ifdef CONFIG_GRKERNSEC_HIDESYM
63460+ wchan = 0;
63461+ eip =0;
63462+ esp =0;
63463+#endif
63464+
63465 /* scale priority and nice values from timeslices to -20..20 */
63466 /* to make it look like a "normal" Unix priority/nice value */
63467 priority = task_prio(task);
63468@@ -504,9 +555,15 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
63469 seq_put_decimal_ull(m, ' ', vsize);
63470 seq_put_decimal_ull(m, ' ', mm ? get_mm_rss(mm) : 0);
63471 seq_put_decimal_ull(m, ' ', rsslim);
63472+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63473+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->start_code : 1) : 0));
63474+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->end_code : 1) : 0));
63475+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 0 : ((permitted && mm) ? mm->start_stack : 0));
63476+#else
63477 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->start_code : 1) : 0);
63478 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->end_code : 1) : 0);
63479 seq_put_decimal_ull(m, ' ', (permitted && mm) ? mm->start_stack : 0);
63480+#endif
63481 seq_put_decimal_ull(m, ' ', esp);
63482 seq_put_decimal_ull(m, ' ', eip);
63483 /* The signal information here is obsolete.
63484@@ -528,7 +585,11 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
63485 seq_put_decimal_ull(m, ' ', cputime_to_clock_t(gtime));
63486 seq_put_decimal_ll(m, ' ', cputime_to_clock_t(cgtime));
63487
63488- if (mm && permitted) {
63489+ if (mm && permitted
63490+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63491+ && !PAX_RAND_FLAGS(mm)
63492+#endif
63493+ ) {
63494 seq_put_decimal_ull(m, ' ', mm->start_data);
63495 seq_put_decimal_ull(m, ' ', mm->end_data);
63496 seq_put_decimal_ull(m, ' ', mm->start_brk);
63497@@ -566,8 +627,15 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
63498 struct pid *pid, struct task_struct *task)
63499 {
63500 unsigned long size = 0, resident = 0, shared = 0, text = 0, data = 0;
63501- struct mm_struct *mm = get_task_mm(task);
63502+ struct mm_struct *mm;
63503
63504+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63505+ if (current->exec_id != m->exec_id) {
63506+ gr_log_badprocpid("statm");
63507+ return 0;
63508+ }
63509+#endif
63510+ mm = get_task_mm(task);
63511 if (mm) {
63512 size = task_statm(mm, &shared, &text, &data, &resident);
63513 mmput(mm);
63514@@ -590,6 +658,13 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
63515 return 0;
63516 }
63517
63518+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
63519+int proc_pid_ipaddr(struct task_struct *task, char *buffer)
63520+{
63521+ return sprintf(buffer, "%pI4\n", &task->signal->curr_ip);
63522+}
63523+#endif
63524+
63525 #ifdef CONFIG_CHECKPOINT_RESTORE
63526 static struct pid *
63527 get_children_pid(struct inode *inode, struct pid *pid_prev, loff_t pos)
63528diff --git a/fs/proc/base.c b/fs/proc/base.c
63529index b976062..584d0bc 100644
63530--- a/fs/proc/base.c
63531+++ b/fs/proc/base.c
63532@@ -113,6 +113,14 @@ struct pid_entry {
63533 union proc_op op;
63534 };
63535
63536+struct getdents_callback {
63537+ struct linux_dirent __user * current_dir;
63538+ struct linux_dirent __user * previous;
63539+ struct file * file;
63540+ int count;
63541+ int error;
63542+};
63543+
63544 #define NOD(NAME, MODE, IOP, FOP, OP) { \
63545 .name = (NAME), \
63546 .len = sizeof(NAME) - 1, \
63547@@ -210,6 +218,9 @@ static int proc_pid_cmdline(struct task_struct *task, char * buffer)
63548 if (!mm->arg_end)
63549 goto out_mm; /* Shh! No looking before we're done */
63550
63551+ if (gr_acl_handle_procpidmem(task))
63552+ goto out_mm;
63553+
63554 len = mm->arg_end - mm->arg_start;
63555
63556 if (len > PAGE_SIZE)
63557@@ -237,12 +248,28 @@ out:
63558 return res;
63559 }
63560
63561+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63562+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
63563+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
63564+ _mm->pax_flags & MF_PAX_SEGMEXEC))
63565+#endif
63566+
63567 static int proc_pid_auxv(struct task_struct *task, char *buffer)
63568 {
63569 struct mm_struct *mm = mm_access(task, PTRACE_MODE_READ);
63570 int res = PTR_ERR(mm);
63571 if (mm && !IS_ERR(mm)) {
63572 unsigned int nwords = 0;
63573+
63574+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63575+ /* allow if we're currently ptracing this task */
63576+ if (PAX_RAND_FLAGS(mm) &&
63577+ (!(task->ptrace & PT_PTRACED) || (task->parent != current))) {
63578+ mmput(mm);
63579+ return 0;
63580+ }
63581+#endif
63582+
63583 do {
63584 nwords += 2;
63585 } while (mm->saved_auxv[nwords - 2] != 0); /* AT_NULL */
63586@@ -256,7 +283,7 @@ static int proc_pid_auxv(struct task_struct *task, char *buffer)
63587 }
63588
63589
63590-#ifdef CONFIG_KALLSYMS
63591+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
63592 /*
63593 * Provides a wchan file via kallsyms in a proper one-value-per-file format.
63594 * Returns the resolved symbol. If that fails, simply return the address.
63595@@ -295,7 +322,7 @@ static void unlock_trace(struct task_struct *task)
63596 mutex_unlock(&task->signal->cred_guard_mutex);
63597 }
63598
63599-#ifdef CONFIG_STACKTRACE
63600+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
63601
63602 #define MAX_STACK_TRACE_DEPTH 64
63603
63604@@ -518,7 +545,7 @@ static int proc_pid_limits(struct task_struct *task, char *buffer)
63605 return count;
63606 }
63607
63608-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
63609+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
63610 static int proc_pid_syscall(struct task_struct *task, char *buffer)
63611 {
63612 long nr;
63613@@ -547,7 +574,7 @@ static int proc_pid_syscall(struct task_struct *task, char *buffer)
63614 /************************************************************************/
63615
63616 /* permission checks */
63617-static int proc_fd_access_allowed(struct inode *inode)
63618+static int proc_fd_access_allowed(struct inode *inode, unsigned int log)
63619 {
63620 struct task_struct *task;
63621 int allowed = 0;
63622@@ -557,7 +584,10 @@ static int proc_fd_access_allowed(struct inode *inode)
63623 */
63624 task = get_proc_task(inode);
63625 if (task) {
63626- allowed = ptrace_may_access(task, PTRACE_MODE_READ);
63627+ if (log)
63628+ allowed = ptrace_may_access(task, PTRACE_MODE_READ);
63629+ else
63630+ allowed = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
63631 put_task_struct(task);
63632 }
63633 return allowed;
63634@@ -588,10 +618,35 @@ static bool has_pid_permissions(struct pid_namespace *pid,
63635 struct task_struct *task,
63636 int hide_pid_min)
63637 {
63638+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
63639+ return false;
63640+
63641+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
63642+ rcu_read_lock();
63643+ {
63644+ const struct cred *tmpcred = current_cred();
63645+ const struct cred *cred = __task_cred(task);
63646+
63647+ if (uid_eq(tmpcred->uid, GLOBAL_ROOT_UID) || uid_eq(tmpcred->uid, cred->uid)
63648+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
63649+ || in_group_p(grsec_proc_gid)
63650+#endif
63651+ ) {
63652+ rcu_read_unlock();
63653+ return true;
63654+ }
63655+ }
63656+ rcu_read_unlock();
63657+
63658+ if (!pid->hide_pid)
63659+ return false;
63660+#endif
63661+
63662 if (pid->hide_pid < hide_pid_min)
63663 return true;
63664 if (in_group_p(pid->pid_gid))
63665 return true;
63666+
63667 return ptrace_may_access(task, PTRACE_MODE_READ);
63668 }
63669
63670@@ -609,7 +664,11 @@ static int proc_pid_permission(struct inode *inode, int mask)
63671 put_task_struct(task);
63672
63673 if (!has_perms) {
63674+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
63675+ {
63676+#else
63677 if (pid->hide_pid == 2) {
63678+#endif
63679 /*
63680 * Let's make getdents(), stat(), and open()
63681 * consistent with each other. If a process
63682@@ -707,6 +766,11 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
63683 if (!task)
63684 return -ESRCH;
63685
63686+ if (gr_acl_handle_procpidmem(task)) {
63687+ put_task_struct(task);
63688+ return -EPERM;
63689+ }
63690+
63691 mm = mm_access(task, mode);
63692 put_task_struct(task);
63693
63694@@ -722,6 +786,10 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
63695
63696 file->private_data = mm;
63697
63698+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63699+ file->f_version = current->exec_id;
63700+#endif
63701+
63702 return 0;
63703 }
63704
63705@@ -743,6 +811,17 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
63706 ssize_t copied;
63707 char *page;
63708
63709+#ifdef CONFIG_GRKERNSEC
63710+ if (write)
63711+ return -EPERM;
63712+#endif
63713+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63714+ if (file->f_version != current->exec_id) {
63715+ gr_log_badprocpid("mem");
63716+ return 0;
63717+ }
63718+#endif
63719+
63720 if (!mm)
63721 return 0;
63722
63723@@ -755,7 +834,7 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
63724 goto free;
63725
63726 while (count > 0) {
63727- int this_len = min_t(int, count, PAGE_SIZE);
63728+ ssize_t this_len = min_t(ssize_t, count, PAGE_SIZE);
63729
63730 if (write && copy_from_user(page, buf, this_len)) {
63731 copied = -EFAULT;
63732@@ -847,6 +926,13 @@ static ssize_t environ_read(struct file *file, char __user *buf,
63733 if (!mm)
63734 return 0;
63735
63736+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63737+ if (file->f_version != current->exec_id) {
63738+ gr_log_badprocpid("environ");
63739+ return 0;
63740+ }
63741+#endif
63742+
63743 page = (char *)__get_free_page(GFP_TEMPORARY);
63744 if (!page)
63745 return -ENOMEM;
63746@@ -856,7 +942,7 @@ static ssize_t environ_read(struct file *file, char __user *buf,
63747 goto free;
63748 while (count > 0) {
63749 size_t this_len, max_len;
63750- int retval;
63751+ ssize_t retval;
63752
63753 if (src >= (mm->env_end - mm->env_start))
63754 break;
63755@@ -1467,7 +1553,7 @@ static void *proc_pid_follow_link(struct dentry *dentry, struct nameidata *nd)
63756 int error = -EACCES;
63757
63758 /* Are we allowed to snoop on the tasks file descriptors? */
63759- if (!proc_fd_access_allowed(inode))
63760+ if (!proc_fd_access_allowed(inode, 0))
63761 goto out;
63762
63763 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
63764@@ -1511,8 +1597,18 @@ static int proc_pid_readlink(struct dentry * dentry, char __user * buffer, int b
63765 struct path path;
63766
63767 /* Are we allowed to snoop on the tasks file descriptors? */
63768- if (!proc_fd_access_allowed(inode))
63769- goto out;
63770+ /* logging this is needed for learning on chromium to work properly,
63771+ but we don't want to flood the logs from 'ps' which does a readlink
63772+ on /proc/fd/2 of tasks in the listing, nor do we want 'ps' to learn
63773+ CAP_SYS_PTRACE as it's not necessary for its basic functionality
63774+ */
63775+ if (dentry->d_name.name[0] == '2' && dentry->d_name.name[1] == '\0') {
63776+ if (!proc_fd_access_allowed(inode,0))
63777+ goto out;
63778+ } else {
63779+ if (!proc_fd_access_allowed(inode,1))
63780+ goto out;
63781+ }
63782
63783 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
63784 if (error)
63785@@ -1562,7 +1658,11 @@ struct inode *proc_pid_make_inode(struct super_block * sb, struct task_struct *t
63786 rcu_read_lock();
63787 cred = __task_cred(task);
63788 inode->i_uid = cred->euid;
63789+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
63790+ inode->i_gid = grsec_proc_gid;
63791+#else
63792 inode->i_gid = cred->egid;
63793+#endif
63794 rcu_read_unlock();
63795 }
63796 security_task_to_inode(task, inode);
63797@@ -1598,10 +1698,19 @@ int pid_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
63798 return -ENOENT;
63799 }
63800 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
63801+#ifdef CONFIG_GRKERNSEC_PROC_USER
63802+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
63803+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
63804+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
63805+#endif
63806 task_dumpable(task)) {
63807 cred = __task_cred(task);
63808 stat->uid = cred->euid;
63809+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
63810+ stat->gid = grsec_proc_gid;
63811+#else
63812 stat->gid = cred->egid;
63813+#endif
63814 }
63815 }
63816 rcu_read_unlock();
63817@@ -1639,11 +1748,20 @@ int pid_revalidate(struct dentry *dentry, unsigned int flags)
63818
63819 if (task) {
63820 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
63821+#ifdef CONFIG_GRKERNSEC_PROC_USER
63822+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
63823+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
63824+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
63825+#endif
63826 task_dumpable(task)) {
63827 rcu_read_lock();
63828 cred = __task_cred(task);
63829 inode->i_uid = cred->euid;
63830+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
63831+ inode->i_gid = grsec_proc_gid;
63832+#else
63833 inode->i_gid = cred->egid;
63834+#endif
63835 rcu_read_unlock();
63836 } else {
63837 inode->i_uid = GLOBAL_ROOT_UID;
63838@@ -2178,6 +2296,9 @@ static struct dentry *proc_pident_lookup(struct inode *dir,
63839 if (!task)
63840 goto out_no_task;
63841
63842+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
63843+ goto out;
63844+
63845 /*
63846 * Yes, it does not scale. And it should not. Don't add
63847 * new entries into /proc/<tgid>/ without very good reasons.
63848@@ -2208,6 +2329,9 @@ static int proc_pident_readdir(struct file *file, struct dir_context *ctx,
63849 if (!task)
63850 return -ENOENT;
63851
63852+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
63853+ goto out;
63854+
63855 if (!dir_emit_dots(file, ctx))
63856 goto out;
63857
63858@@ -2597,7 +2721,7 @@ static const struct pid_entry tgid_base_stuff[] = {
63859 REG("autogroup", S_IRUGO|S_IWUSR, proc_pid_sched_autogroup_operations),
63860 #endif
63861 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
63862-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
63863+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
63864 INF("syscall", S_IRUGO, proc_pid_syscall),
63865 #endif
63866 INF("cmdline", S_IRUGO, proc_pid_cmdline),
63867@@ -2622,10 +2746,10 @@ static const struct pid_entry tgid_base_stuff[] = {
63868 #ifdef CONFIG_SECURITY
63869 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
63870 #endif
63871-#ifdef CONFIG_KALLSYMS
63872+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
63873 INF("wchan", S_IRUGO, proc_pid_wchan),
63874 #endif
63875-#ifdef CONFIG_STACKTRACE
63876+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
63877 ONE("stack", S_IRUGO, proc_pid_stack),
63878 #endif
63879 #ifdef CONFIG_SCHEDSTATS
63880@@ -2659,6 +2783,9 @@ static const struct pid_entry tgid_base_stuff[] = {
63881 #ifdef CONFIG_HARDWALL
63882 INF("hardwall", S_IRUGO, proc_pid_hardwall),
63883 #endif
63884+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
63885+ INF("ipaddr", S_IRUSR, proc_pid_ipaddr),
63886+#endif
63887 #ifdef CONFIG_USER_NS
63888 REG("uid_map", S_IRUGO|S_IWUSR, proc_uid_map_operations),
63889 REG("gid_map", S_IRUGO|S_IWUSR, proc_gid_map_operations),
63890@@ -2789,7 +2916,14 @@ static int proc_pid_instantiate(struct inode *dir,
63891 if (!inode)
63892 goto out;
63893
63894+#ifdef CONFIG_GRKERNSEC_PROC_USER
63895+ inode->i_mode = S_IFDIR|S_IRUSR|S_IXUSR;
63896+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
63897+ inode->i_gid = grsec_proc_gid;
63898+ inode->i_mode = S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP;
63899+#else
63900 inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO;
63901+#endif
63902 inode->i_op = &proc_tgid_base_inode_operations;
63903 inode->i_fop = &proc_tgid_base_operations;
63904 inode->i_flags|=S_IMMUTABLE;
63905@@ -2827,7 +2961,11 @@ struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, unsign
63906 if (!task)
63907 goto out;
63908
63909+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
63910+ goto out_put_task;
63911+
63912 result = proc_pid_instantiate(dir, dentry, task, NULL);
63913+out_put_task:
63914 put_task_struct(task);
63915 out:
63916 return ERR_PTR(result);
63917@@ -2933,7 +3071,7 @@ static const struct pid_entry tid_base_stuff[] = {
63918 REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations),
63919 #endif
63920 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
63921-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
63922+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
63923 INF("syscall", S_IRUGO, proc_pid_syscall),
63924 #endif
63925 INF("cmdline", S_IRUGO, proc_pid_cmdline),
63926@@ -2960,10 +3098,10 @@ static const struct pid_entry tid_base_stuff[] = {
63927 #ifdef CONFIG_SECURITY
63928 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
63929 #endif
63930-#ifdef CONFIG_KALLSYMS
63931+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
63932 INF("wchan", S_IRUGO, proc_pid_wchan),
63933 #endif
63934-#ifdef CONFIG_STACKTRACE
63935+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
63936 ONE("stack", S_IRUGO, proc_pid_stack),
63937 #endif
63938 #ifdef CONFIG_SCHEDSTATS
63939diff --git a/fs/proc/cmdline.c b/fs/proc/cmdline.c
63940index cbd82df..c0407d2 100644
63941--- a/fs/proc/cmdline.c
63942+++ b/fs/proc/cmdline.c
63943@@ -23,7 +23,11 @@ static const struct file_operations cmdline_proc_fops = {
63944
63945 static int __init proc_cmdline_init(void)
63946 {
63947+#ifdef CONFIG_GRKERNSEC_PROC_ADD
63948+ proc_create_grsec("cmdline", 0, NULL, &cmdline_proc_fops);
63949+#else
63950 proc_create("cmdline", 0, NULL, &cmdline_proc_fops);
63951+#endif
63952 return 0;
63953 }
63954 fs_initcall(proc_cmdline_init);
63955diff --git a/fs/proc/devices.c b/fs/proc/devices.c
63956index 50493ed..248166b 100644
63957--- a/fs/proc/devices.c
63958+++ b/fs/proc/devices.c
63959@@ -64,7 +64,11 @@ static const struct file_operations proc_devinfo_operations = {
63960
63961 static int __init proc_devices_init(void)
63962 {
63963+#ifdef CONFIG_GRKERNSEC_PROC_ADD
63964+ proc_create_grsec("devices", 0, NULL, &proc_devinfo_operations);
63965+#else
63966 proc_create("devices", 0, NULL, &proc_devinfo_operations);
63967+#endif
63968 return 0;
63969 }
63970 fs_initcall(proc_devices_init);
63971diff --git a/fs/proc/fd.c b/fs/proc/fd.c
63972index 985ea88..d118a0a 100644
63973--- a/fs/proc/fd.c
63974+++ b/fs/proc/fd.c
63975@@ -25,7 +25,8 @@ static int seq_show(struct seq_file *m, void *v)
63976 if (!task)
63977 return -ENOENT;
63978
63979- files = get_files_struct(task);
63980+ if (!gr_acl_handle_procpidmem(task))
63981+ files = get_files_struct(task);
63982 put_task_struct(task);
63983
63984 if (files) {
63985@@ -283,11 +284,21 @@ static struct dentry *proc_lookupfd(struct inode *dir, struct dentry *dentry,
63986 */
63987 int proc_fd_permission(struct inode *inode, int mask)
63988 {
63989+ struct task_struct *task;
63990 int rv = generic_permission(inode, mask);
63991- if (rv == 0)
63992- return 0;
63993+
63994 if (task_tgid(current) == proc_pid(inode))
63995 rv = 0;
63996+
63997+ task = get_proc_task(inode);
63998+ if (task == NULL)
63999+ return rv;
64000+
64001+ if (gr_acl_handle_procpidmem(task))
64002+ rv = -EACCES;
64003+
64004+ put_task_struct(task);
64005+
64006 return rv;
64007 }
64008
64009diff --git a/fs/proc/generic.c b/fs/proc/generic.c
64010index b7f268e..3bea6b7 100644
64011--- a/fs/proc/generic.c
64012+++ b/fs/proc/generic.c
64013@@ -23,6 +23,7 @@
64014 #include <linux/bitops.h>
64015 #include <linux/spinlock.h>
64016 #include <linux/completion.h>
64017+#include <linux/grsecurity.h>
64018 #include <asm/uaccess.h>
64019
64020 #include "internal.h"
64021@@ -207,6 +208,15 @@ struct dentry *proc_lookup(struct inode *dir, struct dentry *dentry,
64022 return proc_lookup_de(PDE(dir), dir, dentry);
64023 }
64024
64025+struct dentry *proc_lookup_restrict(struct inode *dir, struct dentry *dentry,
64026+ unsigned int flags)
64027+{
64028+ if (gr_proc_is_restricted())
64029+ return ERR_PTR(-EACCES);
64030+
64031+ return proc_lookup_de(PDE(dir), dir, dentry);
64032+}
64033+
64034 /*
64035 * This returns non-zero if at EOF, so that the /proc
64036 * root directory can use this and check if it should
64037@@ -264,6 +274,16 @@ int proc_readdir(struct file *file, struct dir_context *ctx)
64038 return proc_readdir_de(PDE(inode), file, ctx);
64039 }
64040
64041+int proc_readdir_restrict(struct file *file, struct dir_context *ctx)
64042+{
64043+ struct inode *inode = file_inode(file);
64044+
64045+ if (gr_proc_is_restricted())
64046+ return -EACCES;
64047+
64048+ return proc_readdir_de(PDE(inode), file, ctx);
64049+}
64050+
64051 /*
64052 * These are the generic /proc directory operations. They
64053 * use the in-memory "struct proc_dir_entry" tree to parse
64054@@ -275,6 +295,12 @@ static const struct file_operations proc_dir_operations = {
64055 .iterate = proc_readdir,
64056 };
64057
64058+static const struct file_operations proc_dir_restricted_operations = {
64059+ .llseek = generic_file_llseek,
64060+ .read = generic_read_dir,
64061+ .iterate = proc_readdir_restrict,
64062+};
64063+
64064 /*
64065 * proc directories can do almost nothing..
64066 */
64067@@ -284,6 +310,12 @@ static const struct inode_operations proc_dir_inode_operations = {
64068 .setattr = proc_notify_change,
64069 };
64070
64071+static const struct inode_operations proc_dir_restricted_inode_operations = {
64072+ .lookup = proc_lookup_restrict,
64073+ .getattr = proc_getattr,
64074+ .setattr = proc_notify_change,
64075+};
64076+
64077 static int proc_register(struct proc_dir_entry * dir, struct proc_dir_entry * dp)
64078 {
64079 struct proc_dir_entry *tmp;
64080@@ -294,8 +326,13 @@ static int proc_register(struct proc_dir_entry * dir, struct proc_dir_entry * dp
64081 return ret;
64082
64083 if (S_ISDIR(dp->mode)) {
64084- dp->proc_fops = &proc_dir_operations;
64085- dp->proc_iops = &proc_dir_inode_operations;
64086+ if (dp->restricted) {
64087+ dp->proc_fops = &proc_dir_restricted_operations;
64088+ dp->proc_iops = &proc_dir_restricted_inode_operations;
64089+ } else {
64090+ dp->proc_fops = &proc_dir_operations;
64091+ dp->proc_iops = &proc_dir_inode_operations;
64092+ }
64093 dir->nlink++;
64094 } else if (S_ISLNK(dp->mode)) {
64095 dp->proc_iops = &proc_link_inode_operations;
64096@@ -407,6 +444,27 @@ struct proc_dir_entry *proc_mkdir_data(const char *name, umode_t mode,
64097 }
64098 EXPORT_SYMBOL_GPL(proc_mkdir_data);
64099
64100+struct proc_dir_entry *proc_mkdir_data_restrict(const char *name, umode_t mode,
64101+ struct proc_dir_entry *parent, void *data)
64102+{
64103+ struct proc_dir_entry *ent;
64104+
64105+ if (mode == 0)
64106+ mode = S_IRUGO | S_IXUGO;
64107+
64108+ ent = __proc_create(&parent, name, S_IFDIR | mode, 2);
64109+ if (ent) {
64110+ ent->data = data;
64111+ ent->restricted = 1;
64112+ if (proc_register(parent, ent) < 0) {
64113+ kfree(ent);
64114+ ent = NULL;
64115+ }
64116+ }
64117+ return ent;
64118+}
64119+EXPORT_SYMBOL_GPL(proc_mkdir_data_restrict);
64120+
64121 struct proc_dir_entry *proc_mkdir_mode(const char *name, umode_t mode,
64122 struct proc_dir_entry *parent)
64123 {
64124@@ -421,6 +479,13 @@ struct proc_dir_entry *proc_mkdir(const char *name,
64125 }
64126 EXPORT_SYMBOL(proc_mkdir);
64127
64128+struct proc_dir_entry *proc_mkdir_restrict(const char *name,
64129+ struct proc_dir_entry *parent)
64130+{
64131+ return proc_mkdir_data_restrict(name, 0, parent, NULL);
64132+}
64133+EXPORT_SYMBOL(proc_mkdir_restrict);
64134+
64135 struct proc_dir_entry *proc_create_data(const char *name, umode_t mode,
64136 struct proc_dir_entry *parent,
64137 const struct file_operations *proc_fops,
64138diff --git a/fs/proc/inode.c b/fs/proc/inode.c
64139index 124fc43..8afbb02 100644
64140--- a/fs/proc/inode.c
64141+++ b/fs/proc/inode.c
64142@@ -23,11 +23,17 @@
64143 #include <linux/slab.h>
64144 #include <linux/mount.h>
64145 #include <linux/magic.h>
64146+#include <linux/grsecurity.h>
64147
64148 #include <asm/uaccess.h>
64149
64150 #include "internal.h"
64151
64152+#ifdef CONFIG_PROC_SYSCTL
64153+extern const struct inode_operations proc_sys_inode_operations;
64154+extern const struct inode_operations proc_sys_dir_operations;
64155+#endif
64156+
64157 static void proc_evict_inode(struct inode *inode)
64158 {
64159 struct proc_dir_entry *de;
64160@@ -55,6 +61,13 @@ static void proc_evict_inode(struct inode *inode)
64161 ns = PROC_I(inode)->ns.ns;
64162 if (ns_ops && ns)
64163 ns_ops->put(ns);
64164+
64165+#ifdef CONFIG_PROC_SYSCTL
64166+ if (inode->i_op == &proc_sys_inode_operations ||
64167+ inode->i_op == &proc_sys_dir_operations)
64168+ gr_handle_delete(inode->i_ino, inode->i_sb->s_dev);
64169+#endif
64170+
64171 }
64172
64173 static struct kmem_cache * proc_inode_cachep;
64174@@ -413,7 +426,11 @@ struct inode *proc_get_inode(struct super_block *sb, struct proc_dir_entry *de)
64175 if (de->mode) {
64176 inode->i_mode = de->mode;
64177 inode->i_uid = de->uid;
64178+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
64179+ inode->i_gid = grsec_proc_gid;
64180+#else
64181 inode->i_gid = de->gid;
64182+#endif
64183 }
64184 if (de->size)
64185 inode->i_size = de->size;
64186diff --git a/fs/proc/internal.h b/fs/proc/internal.h
64187index 651d09a..6a4b495 100644
64188--- a/fs/proc/internal.h
64189+++ b/fs/proc/internal.h
64190@@ -46,9 +46,10 @@ struct proc_dir_entry {
64191 struct completion *pde_unload_completion;
64192 struct list_head pde_openers; /* who did ->open, but not ->release */
64193 spinlock_t pde_unload_lock; /* proc_fops checks and pde_users bumps */
64194+ u8 restricted; /* a directory in /proc/net that should be restricted via GRKERNSEC_PROC */
64195 u8 namelen;
64196 char name[];
64197-};
64198+} __randomize_layout;
64199
64200 union proc_op {
64201 int (*proc_get_link)(struct dentry *, struct path *);
64202@@ -67,7 +68,7 @@ struct proc_inode {
64203 struct ctl_table *sysctl_entry;
64204 struct proc_ns ns;
64205 struct inode vfs_inode;
64206-};
64207+} __randomize_layout;
64208
64209 /*
64210 * General functions
64211@@ -155,6 +156,9 @@ extern int proc_pid_status(struct seq_file *, struct pid_namespace *,
64212 struct pid *, struct task_struct *);
64213 extern int proc_pid_statm(struct seq_file *, struct pid_namespace *,
64214 struct pid *, struct task_struct *);
64215+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
64216+extern int proc_pid_ipaddr(struct task_struct *task, char *buffer);
64217+#endif
64218
64219 /*
64220 * base.c
64221@@ -181,9 +185,11 @@ extern bool proc_fill_cache(struct file *, struct dir_context *, const char *, i
64222 extern spinlock_t proc_subdir_lock;
64223
64224 extern struct dentry *proc_lookup(struct inode *, struct dentry *, unsigned int);
64225+extern struct dentry *proc_lookup_restrict(struct inode *, struct dentry *, unsigned int);
64226 extern struct dentry *proc_lookup_de(struct proc_dir_entry *, struct inode *,
64227 struct dentry *);
64228 extern int proc_readdir(struct file *, struct dir_context *);
64229+extern int proc_readdir_restrict(struct file *, struct dir_context *);
64230 extern int proc_readdir_de(struct proc_dir_entry *, struct file *, struct dir_context *);
64231
64232 static inline struct proc_dir_entry *pde_get(struct proc_dir_entry *pde)
64233diff --git a/fs/proc/interrupts.c b/fs/proc/interrupts.c
64234index a352d57..cb94a5c 100644
64235--- a/fs/proc/interrupts.c
64236+++ b/fs/proc/interrupts.c
64237@@ -47,7 +47,11 @@ static const struct file_operations proc_interrupts_operations = {
64238
64239 static int __init proc_interrupts_init(void)
64240 {
64241+#ifdef CONFIG_GRKERNSEC_PROC_ADD
64242+ proc_create_grsec("interrupts", 0, NULL, &proc_interrupts_operations);
64243+#else
64244 proc_create("interrupts", 0, NULL, &proc_interrupts_operations);
64245+#endif
64246 return 0;
64247 }
64248 fs_initcall(proc_interrupts_init);
64249diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
64250index 39e6ef3..2f9cb5e 100644
64251--- a/fs/proc/kcore.c
64252+++ b/fs/proc/kcore.c
64253@@ -483,9 +483,10 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
64254 * the addresses in the elf_phdr on our list.
64255 */
64256 start = kc_offset_to_vaddr(*fpos - elf_buflen);
64257- if ((tsz = (PAGE_SIZE - (start & ~PAGE_MASK))) > buflen)
64258+ tsz = PAGE_SIZE - (start & ~PAGE_MASK);
64259+ if (tsz > buflen)
64260 tsz = buflen;
64261-
64262+
64263 while (buflen) {
64264 struct kcore_list *m;
64265
64266@@ -514,20 +515,23 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
64267 kfree(elf_buf);
64268 } else {
64269 if (kern_addr_valid(start)) {
64270- unsigned long n;
64271+ char *elf_buf;
64272+ mm_segment_t oldfs;
64273
64274- n = copy_to_user(buffer, (char *)start, tsz);
64275- /*
64276- * We cannot distinguish between fault on source
64277- * and fault on destination. When this happens
64278- * we clear too and hope it will trigger the
64279- * EFAULT again.
64280- */
64281- if (n) {
64282- if (clear_user(buffer + tsz - n,
64283- n))
64284+ elf_buf = kmalloc(tsz, GFP_KERNEL);
64285+ if (!elf_buf)
64286+ return -ENOMEM;
64287+ oldfs = get_fs();
64288+ set_fs(KERNEL_DS);
64289+ if (!__copy_from_user(elf_buf, (const void __user *)start, tsz)) {
64290+ set_fs(oldfs);
64291+ if (copy_to_user(buffer, elf_buf, tsz)) {
64292+ kfree(elf_buf);
64293 return -EFAULT;
64294+ }
64295 }
64296+ set_fs(oldfs);
64297+ kfree(elf_buf);
64298 } else {
64299 if (clear_user(buffer, tsz))
64300 return -EFAULT;
64301@@ -547,6 +551,9 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
64302
64303 static int open_kcore(struct inode *inode, struct file *filp)
64304 {
64305+#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
64306+ return -EPERM;
64307+#endif
64308 if (!capable(CAP_SYS_RAWIO))
64309 return -EPERM;
64310 if (kcore_need_update)
64311diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c
64312index 136e548..1f88922 100644
64313--- a/fs/proc/meminfo.c
64314+++ b/fs/proc/meminfo.c
64315@@ -187,7 +187,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
64316 vmi.used >> 10,
64317 vmi.largest_chunk >> 10
64318 #ifdef CONFIG_MEMORY_FAILURE
64319- ,atomic_long_read(&num_poisoned_pages) << (PAGE_SHIFT - 10)
64320+ ,atomic_long_read_unchecked(&num_poisoned_pages) << (PAGE_SHIFT - 10)
64321 #endif
64322 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
64323 ,K(global_page_state(NR_ANON_TRANSPARENT_HUGEPAGES) *
64324diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
64325index d4a3574..b421ce9 100644
64326--- a/fs/proc/nommu.c
64327+++ b/fs/proc/nommu.c
64328@@ -64,7 +64,7 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
64329
64330 if (file) {
64331 seq_pad(m, ' ');
64332- seq_path(m, &file->f_path, "");
64333+ seq_path(m, &file->f_path, "\n\\");
64334 }
64335
64336 seq_putc(m, '\n');
64337diff --git a/fs/proc/proc_net.c b/fs/proc/proc_net.c
64338index 4677bb7..94067cd 100644
64339--- a/fs/proc/proc_net.c
64340+++ b/fs/proc/proc_net.c
64341@@ -23,6 +23,7 @@
64342 #include <linux/nsproxy.h>
64343 #include <net/net_namespace.h>
64344 #include <linux/seq_file.h>
64345+#include <linux/grsecurity.h>
64346
64347 #include "internal.h"
64348
64349@@ -36,6 +37,8 @@ static struct net *get_proc_net(const struct inode *inode)
64350 return maybe_get_net(PDE_NET(PDE(inode)));
64351 }
64352
64353+extern const struct seq_operations dev_seq_ops;
64354+
64355 int seq_open_net(struct inode *ino, struct file *f,
64356 const struct seq_operations *ops, int size)
64357 {
64358@@ -44,6 +47,10 @@ int seq_open_net(struct inode *ino, struct file *f,
64359
64360 BUG_ON(size < sizeof(*p));
64361
64362+ /* only permit access to /proc/net/dev */
64363+ if (ops != &dev_seq_ops && gr_proc_is_restricted())
64364+ return -EACCES;
64365+
64366 net = get_proc_net(ino);
64367 if (net == NULL)
64368 return -ENXIO;
64369@@ -66,6 +73,9 @@ int single_open_net(struct inode *inode, struct file *file,
64370 int err;
64371 struct net *net;
64372
64373+ if (gr_proc_is_restricted())
64374+ return -EACCES;
64375+
64376 err = -ENXIO;
64377 net = get_proc_net(inode);
64378 if (net == NULL)
64379diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
64380index 7129046..6914844 100644
64381--- a/fs/proc/proc_sysctl.c
64382+++ b/fs/proc/proc_sysctl.c
64383@@ -11,13 +11,21 @@
64384 #include <linux/namei.h>
64385 #include <linux/mm.h>
64386 #include <linux/module.h>
64387+#include <linux/nsproxy.h>
64388+#ifdef CONFIG_GRKERNSEC
64389+#include <net/net_namespace.h>
64390+#endif
64391 #include "internal.h"
64392
64393+extern int gr_handle_chroot_sysctl(const int op);
64394+extern int gr_handle_sysctl_mod(const char *dirname, const char *name,
64395+ const int op);
64396+
64397 static const struct dentry_operations proc_sys_dentry_operations;
64398 static const struct file_operations proc_sys_file_operations;
64399-static const struct inode_operations proc_sys_inode_operations;
64400+const struct inode_operations proc_sys_inode_operations;
64401 static const struct file_operations proc_sys_dir_file_operations;
64402-static const struct inode_operations proc_sys_dir_operations;
64403+const struct inode_operations proc_sys_dir_operations;
64404
64405 void proc_sys_poll_notify(struct ctl_table_poll *poll)
64406 {
64407@@ -467,6 +475,9 @@ static struct dentry *proc_sys_lookup(struct inode *dir, struct dentry *dentry,
64408
64409 err = NULL;
64410 d_set_d_op(dentry, &proc_sys_dentry_operations);
64411+
64412+ gr_handle_proc_create(dentry, inode);
64413+
64414 d_add(dentry, inode);
64415
64416 out:
64417@@ -482,6 +493,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
64418 struct inode *inode = file_inode(filp);
64419 struct ctl_table_header *head = grab_header(inode);
64420 struct ctl_table *table = PROC_I(inode)->sysctl_entry;
64421+ int op = write ? MAY_WRITE : MAY_READ;
64422 ssize_t error;
64423 size_t res;
64424
64425@@ -493,7 +505,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
64426 * and won't be until we finish.
64427 */
64428 error = -EPERM;
64429- if (sysctl_perm(head, table, write ? MAY_WRITE : MAY_READ))
64430+ if (sysctl_perm(head, table, op))
64431 goto out;
64432
64433 /* if that can happen at all, it should be -EINVAL, not -EISDIR */
64434@@ -501,6 +513,27 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
64435 if (!table->proc_handler)
64436 goto out;
64437
64438+#ifdef CONFIG_GRKERNSEC
64439+ error = -EPERM;
64440+ if (gr_handle_chroot_sysctl(op))
64441+ goto out;
64442+ dget(filp->f_path.dentry);
64443+ if (gr_handle_sysctl_mod(filp->f_path.dentry->d_parent->d_name.name, table->procname, op)) {
64444+ dput(filp->f_path.dentry);
64445+ goto out;
64446+ }
64447+ dput(filp->f_path.dentry);
64448+ if (!gr_acl_handle_open(filp->f_path.dentry, filp->f_path.mnt, op))
64449+ goto out;
64450+ if (write) {
64451+ if (current->nsproxy->net_ns != table->extra2) {
64452+ if (!capable(CAP_SYS_ADMIN))
64453+ goto out;
64454+ } else if (!ns_capable(current->nsproxy->net_ns->user_ns, CAP_NET_ADMIN))
64455+ goto out;
64456+ }
64457+#endif
64458+
64459 /* careful: calling conventions are nasty here */
64460 res = count;
64461 error = table->proc_handler(table, write, buf, &res, ppos);
64462@@ -598,6 +631,9 @@ static bool proc_sys_fill_cache(struct file *file,
64463 return false;
64464 } else {
64465 d_set_d_op(child, &proc_sys_dentry_operations);
64466+
64467+ gr_handle_proc_create(child, inode);
64468+
64469 d_add(child, inode);
64470 }
64471 } else {
64472@@ -641,6 +677,9 @@ static int scan(struct ctl_table_header *head, ctl_table *table,
64473 if ((*pos)++ < ctx->pos)
64474 return true;
64475
64476+ if (!gr_acl_handle_hidden_file(file->f_path.dentry, file->f_path.mnt))
64477+ return 0;
64478+
64479 if (unlikely(S_ISLNK(table->mode)))
64480 res = proc_sys_link_fill_cache(file, ctx, head, table);
64481 else
64482@@ -734,6 +773,9 @@ static int proc_sys_getattr(struct vfsmount *mnt, struct dentry *dentry, struct
64483 if (IS_ERR(head))
64484 return PTR_ERR(head);
64485
64486+ if (table && !gr_acl_handle_hidden_file(dentry, mnt))
64487+ return -ENOENT;
64488+
64489 generic_fillattr(inode, stat);
64490 if (table)
64491 stat->mode = (stat->mode & S_IFMT) | table->mode;
64492@@ -756,13 +798,13 @@ static const struct file_operations proc_sys_dir_file_operations = {
64493 .llseek = generic_file_llseek,
64494 };
64495
64496-static const struct inode_operations proc_sys_inode_operations = {
64497+const struct inode_operations proc_sys_inode_operations = {
64498 .permission = proc_sys_permission,
64499 .setattr = proc_sys_setattr,
64500 .getattr = proc_sys_getattr,
64501 };
64502
64503-static const struct inode_operations proc_sys_dir_operations = {
64504+const struct inode_operations proc_sys_dir_operations = {
64505 .lookup = proc_sys_lookup,
64506 .permission = proc_sys_permission,
64507 .setattr = proc_sys_setattr,
64508@@ -839,7 +881,7 @@ static struct ctl_dir *find_subdir(struct ctl_dir *dir,
64509 static struct ctl_dir *new_dir(struct ctl_table_set *set,
64510 const char *name, int namelen)
64511 {
64512- struct ctl_table *table;
64513+ ctl_table_no_const *table;
64514 struct ctl_dir *new;
64515 struct ctl_node *node;
64516 char *new_name;
64517@@ -851,7 +893,7 @@ static struct ctl_dir *new_dir(struct ctl_table_set *set,
64518 return NULL;
64519
64520 node = (struct ctl_node *)(new + 1);
64521- table = (struct ctl_table *)(node + 1);
64522+ table = (ctl_table_no_const *)(node + 1);
64523 new_name = (char *)(table + 2);
64524 memcpy(new_name, name, namelen);
64525 new_name[namelen] = '\0';
64526@@ -1020,7 +1062,8 @@ static int sysctl_check_table(const char *path, struct ctl_table *table)
64527 static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table *table,
64528 struct ctl_table_root *link_root)
64529 {
64530- struct ctl_table *link_table, *entry, *link;
64531+ ctl_table_no_const *link_table, *link;
64532+ struct ctl_table *entry;
64533 struct ctl_table_header *links;
64534 struct ctl_node *node;
64535 char *link_name;
64536@@ -1043,7 +1086,7 @@ static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table
64537 return NULL;
64538
64539 node = (struct ctl_node *)(links + 1);
64540- link_table = (struct ctl_table *)(node + nr_entries);
64541+ link_table = (ctl_table_no_const *)(node + nr_entries);
64542 link_name = (char *)&link_table[nr_entries + 1];
64543
64544 for (link = link_table, entry = table; entry->procname; link++, entry++) {
64545@@ -1291,8 +1334,8 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
64546 struct ctl_table_header ***subheader, struct ctl_table_set *set,
64547 struct ctl_table *table)
64548 {
64549- struct ctl_table *ctl_table_arg = NULL;
64550- struct ctl_table *entry, *files;
64551+ ctl_table_no_const *ctl_table_arg = NULL, *files = NULL;
64552+ struct ctl_table *entry;
64553 int nr_files = 0;
64554 int nr_dirs = 0;
64555 int err = -ENOMEM;
64556@@ -1304,10 +1347,9 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
64557 nr_files++;
64558 }
64559
64560- files = table;
64561 /* If there are mixed files and directories we need a new table */
64562 if (nr_dirs && nr_files) {
64563- struct ctl_table *new;
64564+ ctl_table_no_const *new;
64565 files = kzalloc(sizeof(struct ctl_table) * (nr_files + 1),
64566 GFP_KERNEL);
64567 if (!files)
64568@@ -1325,7 +1367,7 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
64569 /* Register everything except a directory full of subdirectories */
64570 if (nr_files || !nr_dirs) {
64571 struct ctl_table_header *header;
64572- header = __register_sysctl_table(set, path, files);
64573+ header = __register_sysctl_table(set, path, files ? files : table);
64574 if (!header) {
64575 kfree(ctl_table_arg);
64576 goto out;
64577diff --git a/fs/proc/root.c b/fs/proc/root.c
64578index 87dbcbe..55e1b4d 100644
64579--- a/fs/proc/root.c
64580+++ b/fs/proc/root.c
64581@@ -186,7 +186,15 @@ void __init proc_root_init(void)
64582 #ifdef CONFIG_PROC_DEVICETREE
64583 proc_device_tree_init();
64584 #endif
64585+#ifdef CONFIG_GRKERNSEC_PROC_ADD
64586+#ifdef CONFIG_GRKERNSEC_PROC_USER
64587+ proc_mkdir_mode("bus", S_IRUSR | S_IXUSR, NULL);
64588+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
64589+ proc_mkdir_mode("bus", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
64590+#endif
64591+#else
64592 proc_mkdir("bus", NULL);
64593+#endif
64594 proc_sys_init();
64595 }
64596
64597diff --git a/fs/proc/stat.c b/fs/proc/stat.c
64598index 6f599c6..bd00271 100644
64599--- a/fs/proc/stat.c
64600+++ b/fs/proc/stat.c
64601@@ -11,6 +11,7 @@
64602 #include <linux/irqnr.h>
64603 #include <asm/cputime.h>
64604 #include <linux/tick.h>
64605+#include <linux/grsecurity.h>
64606
64607 #ifndef arch_irq_stat_cpu
64608 #define arch_irq_stat_cpu(cpu) 0
64609@@ -87,6 +88,18 @@ static int show_stat(struct seq_file *p, void *v)
64610 u64 sum_softirq = 0;
64611 unsigned int per_softirq_sums[NR_SOFTIRQS] = {0};
64612 struct timespec boottime;
64613+ int unrestricted = 1;
64614+
64615+#ifdef CONFIG_GRKERNSEC_PROC_ADD
64616+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
64617+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)
64618+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
64619+ && !in_group_p(grsec_proc_gid)
64620+#endif
64621+ )
64622+ unrestricted = 0;
64623+#endif
64624+#endif
64625
64626 user = nice = system = idle = iowait =
64627 irq = softirq = steal = 0;
64628@@ -99,23 +112,25 @@ static int show_stat(struct seq_file *p, void *v)
64629 nice += kcpustat_cpu(i).cpustat[CPUTIME_NICE];
64630 system += kcpustat_cpu(i).cpustat[CPUTIME_SYSTEM];
64631 idle += get_idle_time(i);
64632- iowait += get_iowait_time(i);
64633- irq += kcpustat_cpu(i).cpustat[CPUTIME_IRQ];
64634- softirq += kcpustat_cpu(i).cpustat[CPUTIME_SOFTIRQ];
64635- steal += kcpustat_cpu(i).cpustat[CPUTIME_STEAL];
64636- guest += kcpustat_cpu(i).cpustat[CPUTIME_GUEST];
64637- guest_nice += kcpustat_cpu(i).cpustat[CPUTIME_GUEST_NICE];
64638- sum += kstat_cpu_irqs_sum(i);
64639- sum += arch_irq_stat_cpu(i);
64640+ if (unrestricted) {
64641+ iowait += get_iowait_time(i);
64642+ irq += kcpustat_cpu(i).cpustat[CPUTIME_IRQ];
64643+ softirq += kcpustat_cpu(i).cpustat[CPUTIME_SOFTIRQ];
64644+ steal += kcpustat_cpu(i).cpustat[CPUTIME_STEAL];
64645+ guest += kcpustat_cpu(i).cpustat[CPUTIME_GUEST];
64646+ guest_nice += kcpustat_cpu(i).cpustat[CPUTIME_GUEST_NICE];
64647+ sum += kstat_cpu_irqs_sum(i);
64648+ sum += arch_irq_stat_cpu(i);
64649+ for (j = 0; j < NR_SOFTIRQS; j++) {
64650+ unsigned int softirq_stat = kstat_softirqs_cpu(j, i);
64651
64652- for (j = 0; j < NR_SOFTIRQS; j++) {
64653- unsigned int softirq_stat = kstat_softirqs_cpu(j, i);
64654-
64655- per_softirq_sums[j] += softirq_stat;
64656- sum_softirq += softirq_stat;
64657+ per_softirq_sums[j] += softirq_stat;
64658+ sum_softirq += softirq_stat;
64659+ }
64660 }
64661 }
64662- sum += arch_irq_stat();
64663+ if (unrestricted)
64664+ sum += arch_irq_stat();
64665
64666 seq_puts(p, "cpu ");
64667 seq_put_decimal_ull(p, ' ', cputime64_to_clock_t(user));
64668@@ -136,12 +151,14 @@ static int show_stat(struct seq_file *p, void *v)
64669 nice = kcpustat_cpu(i).cpustat[CPUTIME_NICE];
64670 system = kcpustat_cpu(i).cpustat[CPUTIME_SYSTEM];
64671 idle = get_idle_time(i);
64672- iowait = get_iowait_time(i);
64673- irq = kcpustat_cpu(i).cpustat[CPUTIME_IRQ];
64674- softirq = kcpustat_cpu(i).cpustat[CPUTIME_SOFTIRQ];
64675- steal = kcpustat_cpu(i).cpustat[CPUTIME_STEAL];
64676- guest = kcpustat_cpu(i).cpustat[CPUTIME_GUEST];
64677- guest_nice = kcpustat_cpu(i).cpustat[CPUTIME_GUEST_NICE];
64678+ if (unrestricted) {
64679+ iowait = get_iowait_time(i);
64680+ irq = kcpustat_cpu(i).cpustat[CPUTIME_IRQ];
64681+ softirq = kcpustat_cpu(i).cpustat[CPUTIME_SOFTIRQ];
64682+ steal = kcpustat_cpu(i).cpustat[CPUTIME_STEAL];
64683+ guest = kcpustat_cpu(i).cpustat[CPUTIME_GUEST];
64684+ guest_nice = kcpustat_cpu(i).cpustat[CPUTIME_GUEST_NICE];
64685+ }
64686 seq_printf(p, "cpu%d", i);
64687 seq_put_decimal_ull(p, ' ', cputime64_to_clock_t(user));
64688 seq_put_decimal_ull(p, ' ', cputime64_to_clock_t(nice));
64689@@ -159,7 +176,7 @@ static int show_stat(struct seq_file *p, void *v)
64690
64691 /* sum again ? it could be updated? */
64692 for_each_irq_nr(j)
64693- seq_put_decimal_ull(p, ' ', kstat_irqs(j));
64694+ seq_put_decimal_ull(p, ' ', unrestricted ? kstat_irqs(j) : 0ULL);
64695
64696 seq_printf(p,
64697 "\nctxt %llu\n"
64698@@ -167,11 +184,11 @@ static int show_stat(struct seq_file *p, void *v)
64699 "processes %lu\n"
64700 "procs_running %lu\n"
64701 "procs_blocked %lu\n",
64702- nr_context_switches(),
64703+ unrestricted ? nr_context_switches() : 0ULL,
64704 (unsigned long)jif,
64705- total_forks,
64706- nr_running(),
64707- nr_iowait());
64708+ unrestricted ? total_forks : 0UL,
64709+ unrestricted ? nr_running() : 0UL,
64710+ unrestricted ? nr_iowait() : 0UL);
64711
64712 seq_printf(p, "softirq %llu", (unsigned long long)sum_softirq);
64713
64714diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
64715index fb52b54..5fc7c14 100644
64716--- a/fs/proc/task_mmu.c
64717+++ b/fs/proc/task_mmu.c
64718@@ -12,12 +12,19 @@
64719 #include <linux/swap.h>
64720 #include <linux/swapops.h>
64721 #include <linux/mmu_notifier.h>
64722+#include <linux/grsecurity.h>
64723
64724 #include <asm/elf.h>
64725 #include <asm/uaccess.h>
64726 #include <asm/tlbflush.h>
64727 #include "internal.h"
64728
64729+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64730+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
64731+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
64732+ _mm->pax_flags & MF_PAX_SEGMEXEC))
64733+#endif
64734+
64735 void task_mem(struct seq_file *m, struct mm_struct *mm)
64736 {
64737 unsigned long data, text, lib, swap;
64738@@ -53,8 +60,13 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
64739 "VmExe:\t%8lu kB\n"
64740 "VmLib:\t%8lu kB\n"
64741 "VmPTE:\t%8lu kB\n"
64742- "VmSwap:\t%8lu kB\n",
64743- hiwater_vm << (PAGE_SHIFT-10),
64744+ "VmSwap:\t%8lu kB\n"
64745+
64746+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
64747+ "CsBase:\t%8lx\nCsLim:\t%8lx\n"
64748+#endif
64749+
64750+ ,hiwater_vm << (PAGE_SHIFT-10),
64751 total_vm << (PAGE_SHIFT-10),
64752 mm->locked_vm << (PAGE_SHIFT-10),
64753 mm->pinned_vm << (PAGE_SHIFT-10),
64754@@ -64,7 +76,19 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
64755 mm->stack_vm << (PAGE_SHIFT-10), text, lib,
64756 (PTRS_PER_PTE * sizeof(pte_t) *
64757 atomic_long_read(&mm->nr_ptes)) >> 10,
64758- swap << (PAGE_SHIFT-10));
64759+ swap << (PAGE_SHIFT-10)
64760+
64761+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
64762+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64763+ , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_base
64764+ , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_limit
64765+#else
64766+ , mm->context.user_cs_base
64767+ , mm->context.user_cs_limit
64768+#endif
64769+#endif
64770+
64771+ );
64772 }
64773
64774 unsigned long task_vsize(struct mm_struct *mm)
64775@@ -270,13 +294,13 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
64776 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
64777 }
64778
64779- /* We don't show the stack guard page in /proc/maps */
64780+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64781+ start = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_start;
64782+ end = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_end;
64783+#else
64784 start = vma->vm_start;
64785- if (stack_guard_page_start(vma, start))
64786- start += PAGE_SIZE;
64787 end = vma->vm_end;
64788- if (stack_guard_page_end(vma, end))
64789- end -= PAGE_SIZE;
64790+#endif
64791
64792 seq_setwidth(m, 25 + sizeof(void *) * 6 - 1);
64793 seq_printf(m, "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %lu ",
64794@@ -286,7 +310,11 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
64795 flags & VM_WRITE ? 'w' : '-',
64796 flags & VM_EXEC ? 'x' : '-',
64797 flags & VM_MAYSHARE ? 's' : 'p',
64798+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64799+ PAX_RAND_FLAGS(mm) ? 0UL : pgoff,
64800+#else
64801 pgoff,
64802+#endif
64803 MAJOR(dev), MINOR(dev), ino);
64804
64805 /*
64806@@ -295,7 +323,7 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
64807 */
64808 if (file) {
64809 seq_pad(m, ' ');
64810- seq_path(m, &file->f_path, "\n");
64811+ seq_path(m, &file->f_path, "\n\\");
64812 goto done;
64813 }
64814
64815@@ -321,8 +349,9 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
64816 * Thread stack in /proc/PID/task/TID/maps or
64817 * the main process stack.
64818 */
64819- if (!is_pid || (vma->vm_start <= mm->start_stack &&
64820- vma->vm_end >= mm->start_stack)) {
64821+ if (!is_pid || (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP)) ||
64822+ (vma->vm_start <= mm->start_stack &&
64823+ vma->vm_end >= mm->start_stack)) {
64824 name = "[stack]";
64825 } else {
64826 /* Thread stack in /proc/PID/maps */
64827@@ -346,6 +375,13 @@ static int show_map(struct seq_file *m, void *v, int is_pid)
64828 struct proc_maps_private *priv = m->private;
64829 struct task_struct *task = priv->task;
64830
64831+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64832+ if (current->exec_id != m->exec_id) {
64833+ gr_log_badprocpid("maps");
64834+ return 0;
64835+ }
64836+#endif
64837+
64838 show_map_vma(m, vma, is_pid);
64839
64840 if (m->count < m->size) /* vma is copied successfully */
64841@@ -586,12 +622,23 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
64842 .private = &mss,
64843 };
64844
64845+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64846+ if (current->exec_id != m->exec_id) {
64847+ gr_log_badprocpid("smaps");
64848+ return 0;
64849+ }
64850+#endif
64851 memset(&mss, 0, sizeof mss);
64852- mss.vma = vma;
64853- /* mmap_sem is held in m_start */
64854- if (vma->vm_mm && !is_vm_hugetlb_page(vma))
64855- walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
64856-
64857+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64858+ if (!PAX_RAND_FLAGS(vma->vm_mm)) {
64859+#endif
64860+ mss.vma = vma;
64861+ /* mmap_sem is held in m_start */
64862+ if (vma->vm_mm && !is_vm_hugetlb_page(vma))
64863+ walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
64864+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64865+ }
64866+#endif
64867 show_map_vma(m, vma, is_pid);
64868
64869 seq_printf(m,
64870@@ -609,7 +656,11 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
64871 "KernelPageSize: %8lu kB\n"
64872 "MMUPageSize: %8lu kB\n"
64873 "Locked: %8lu kB\n",
64874+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64875+ PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : (vma->vm_end - vma->vm_start) >> 10,
64876+#else
64877 (vma->vm_end - vma->vm_start) >> 10,
64878+#endif
64879 mss.resident >> 10,
64880 (unsigned long)(mss.pss >> (10 + PSS_SHIFT)),
64881 mss.shared_clean >> 10,
64882@@ -1387,6 +1438,13 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
64883 char buffer[64];
64884 int nid;
64885
64886+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64887+ if (current->exec_id != m->exec_id) {
64888+ gr_log_badprocpid("numa_maps");
64889+ return 0;
64890+ }
64891+#endif
64892+
64893 if (!mm)
64894 return 0;
64895
64896@@ -1404,11 +1462,15 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
64897 mpol_to_str(buffer, sizeof(buffer), pol);
64898 mpol_cond_put(pol);
64899
64900+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64901+ seq_printf(m, "%08lx %s", PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : vma->vm_start, buffer);
64902+#else
64903 seq_printf(m, "%08lx %s", vma->vm_start, buffer);
64904+#endif
64905
64906 if (file) {
64907 seq_printf(m, " file=");
64908- seq_path(m, &file->f_path, "\n\t= ");
64909+ seq_path(m, &file->f_path, "\n\t\\= ");
64910 } else if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) {
64911 seq_printf(m, " heap");
64912 } else {
64913diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
64914index 678455d..ebd3245 100644
64915--- a/fs/proc/task_nommu.c
64916+++ b/fs/proc/task_nommu.c
64917@@ -51,7 +51,7 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
64918 else
64919 bytes += kobjsize(mm);
64920
64921- if (current->fs && current->fs->users > 1)
64922+ if (current->fs && atomic_read(&current->fs->users) > 1)
64923 sbytes += kobjsize(current->fs);
64924 else
64925 bytes += kobjsize(current->fs);
64926@@ -161,7 +161,7 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma,
64927
64928 if (file) {
64929 seq_pad(m, ' ');
64930- seq_path(m, &file->f_path, "");
64931+ seq_path(m, &file->f_path, "\n\\");
64932 } else if (mm) {
64933 pid_t tid = vm_is_stack(priv->task, vma, is_pid);
64934
64935diff --git a/fs/proc/vmcore.c b/fs/proc/vmcore.c
64936index 88d4585..c10bfeb 100644
64937--- a/fs/proc/vmcore.c
64938+++ b/fs/proc/vmcore.c
64939@@ -105,9 +105,13 @@ static ssize_t read_from_oldmem(char *buf, size_t count,
64940 nr_bytes = count;
64941
64942 /* If pfn is not ram, return zeros for sparse dump files */
64943- if (pfn_is_ram(pfn) == 0)
64944- memset(buf, 0, nr_bytes);
64945- else {
64946+ if (pfn_is_ram(pfn) == 0) {
64947+ if (userbuf) {
64948+ if (clear_user((char __force_user *)buf, nr_bytes))
64949+ return -EFAULT;
64950+ } else
64951+ memset(buf, 0, nr_bytes);
64952+ } else {
64953 tmp = copy_oldmem_page(pfn, buf, nr_bytes,
64954 offset, userbuf);
64955 if (tmp < 0)
64956@@ -170,7 +174,7 @@ int __weak remap_oldmem_pfn_range(struct vm_area_struct *vma,
64957 static int copy_to(void *target, void *src, size_t size, int userbuf)
64958 {
64959 if (userbuf) {
64960- if (copy_to_user((char __user *) target, src, size))
64961+ if (copy_to_user((char __force_user *) target, src, size))
64962 return -EFAULT;
64963 } else {
64964 memcpy(target, src, size);
64965@@ -233,7 +237,7 @@ static ssize_t __read_vmcore(char *buffer, size_t buflen, loff_t *fpos,
64966 if (*fpos < m->offset + m->size) {
64967 tsz = min_t(size_t, m->offset + m->size - *fpos, buflen);
64968 start = m->paddr + *fpos - m->offset;
64969- tmp = read_from_oldmem(buffer, tsz, &start, userbuf);
64970+ tmp = read_from_oldmem((char __force_kernel *)buffer, tsz, &start, userbuf);
64971 if (tmp < 0)
64972 return tmp;
64973 buflen -= tsz;
64974@@ -253,7 +257,7 @@ static ssize_t __read_vmcore(char *buffer, size_t buflen, loff_t *fpos,
64975 static ssize_t read_vmcore(struct file *file, char __user *buffer,
64976 size_t buflen, loff_t *fpos)
64977 {
64978- return __read_vmcore((__force char *) buffer, buflen, fpos, 1);
64979+ return __read_vmcore((__force_kernel char *) buffer, buflen, fpos, 1);
64980 }
64981
64982 /*
64983diff --git a/fs/qnx6/qnx6.h b/fs/qnx6/qnx6.h
64984index b00fcc9..e0c6381 100644
64985--- a/fs/qnx6/qnx6.h
64986+++ b/fs/qnx6/qnx6.h
64987@@ -74,7 +74,7 @@ enum {
64988 BYTESEX_BE,
64989 };
64990
64991-static inline __u64 fs64_to_cpu(struct qnx6_sb_info *sbi, __fs64 n)
64992+static inline __u64 __intentional_overflow(-1) fs64_to_cpu(struct qnx6_sb_info *sbi, __fs64 n)
64993 {
64994 if (sbi->s_bytesex == BYTESEX_LE)
64995 return le64_to_cpu((__force __le64)n);
64996@@ -90,7 +90,7 @@ static inline __fs64 cpu_to_fs64(struct qnx6_sb_info *sbi, __u64 n)
64997 return (__force __fs64)cpu_to_be64(n);
64998 }
64999
65000-static inline __u32 fs32_to_cpu(struct qnx6_sb_info *sbi, __fs32 n)
65001+static inline __u32 __intentional_overflow(-1) fs32_to_cpu(struct qnx6_sb_info *sbi, __fs32 n)
65002 {
65003 if (sbi->s_bytesex == BYTESEX_LE)
65004 return le32_to_cpu((__force __le32)n);
65005diff --git a/fs/quota/netlink.c b/fs/quota/netlink.c
65006index 72d2917..c917c12 100644
65007--- a/fs/quota/netlink.c
65008+++ b/fs/quota/netlink.c
65009@@ -45,7 +45,7 @@ static struct genl_family quota_genl_family = {
65010 void quota_send_warning(struct kqid qid, dev_t dev,
65011 const char warntype)
65012 {
65013- static atomic_t seq;
65014+ static atomic_unchecked_t seq;
65015 struct sk_buff *skb;
65016 void *msg_head;
65017 int ret;
65018@@ -61,7 +61,7 @@ void quota_send_warning(struct kqid qid, dev_t dev,
65019 "VFS: Not enough memory to send quota warning.\n");
65020 return;
65021 }
65022- msg_head = genlmsg_put(skb, 0, atomic_add_return(1, &seq),
65023+ msg_head = genlmsg_put(skb, 0, atomic_add_return_unchecked(1, &seq),
65024 &quota_genl_family, 0, QUOTA_NL_C_WARNING);
65025 if (!msg_head) {
65026 printk(KERN_ERR
65027diff --git a/fs/read_write.c b/fs/read_write.c
65028index 28cc9c8..208e4fb 100644
65029--- a/fs/read_write.c
65030+++ b/fs/read_write.c
65031@@ -450,7 +450,7 @@ ssize_t __kernel_write(struct file *file, const char *buf, size_t count, loff_t
65032
65033 old_fs = get_fs();
65034 set_fs(get_ds());
65035- p = (__force const char __user *)buf;
65036+ p = (const char __force_user *)buf;
65037 if (count > MAX_RW_COUNT)
65038 count = MAX_RW_COUNT;
65039 if (file->f_op->write)
65040diff --git a/fs/readdir.c b/fs/readdir.c
65041index 5b53d99..a6c3049 100644
65042--- a/fs/readdir.c
65043+++ b/fs/readdir.c
65044@@ -17,6 +17,7 @@
65045 #include <linux/security.h>
65046 #include <linux/syscalls.h>
65047 #include <linux/unistd.h>
65048+#include <linux/namei.h>
65049
65050 #include <asm/uaccess.h>
65051
65052@@ -69,6 +70,7 @@ struct old_linux_dirent {
65053 struct readdir_callback {
65054 struct dir_context ctx;
65055 struct old_linux_dirent __user * dirent;
65056+ struct file * file;
65057 int result;
65058 };
65059
65060@@ -86,6 +88,10 @@ static int fillonedir(void * __buf, const char * name, int namlen, loff_t offset
65061 buf->result = -EOVERFLOW;
65062 return -EOVERFLOW;
65063 }
65064+
65065+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
65066+ return 0;
65067+
65068 buf->result++;
65069 dirent = buf->dirent;
65070 if (!access_ok(VERIFY_WRITE, dirent,
65071@@ -117,6 +123,7 @@ SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
65072 if (!f.file)
65073 return -EBADF;
65074
65075+ buf.file = f.file;
65076 error = iterate_dir(f.file, &buf.ctx);
65077 if (buf.result)
65078 error = buf.result;
65079@@ -142,6 +149,7 @@ struct getdents_callback {
65080 struct dir_context ctx;
65081 struct linux_dirent __user * current_dir;
65082 struct linux_dirent __user * previous;
65083+ struct file * file;
65084 int count;
65085 int error;
65086 };
65087@@ -163,6 +171,10 @@ static int filldir(void * __buf, const char * name, int namlen, loff_t offset,
65088 buf->error = -EOVERFLOW;
65089 return -EOVERFLOW;
65090 }
65091+
65092+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
65093+ return 0;
65094+
65095 dirent = buf->previous;
65096 if (dirent) {
65097 if (__put_user(offset, &dirent->d_off))
65098@@ -208,6 +220,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
65099 if (!f.file)
65100 return -EBADF;
65101
65102+ buf.file = f.file;
65103 error = iterate_dir(f.file, &buf.ctx);
65104 if (error >= 0)
65105 error = buf.error;
65106@@ -226,6 +239,7 @@ struct getdents_callback64 {
65107 struct dir_context ctx;
65108 struct linux_dirent64 __user * current_dir;
65109 struct linux_dirent64 __user * previous;
65110+ struct file *file;
65111 int count;
65112 int error;
65113 };
65114@@ -241,6 +255,10 @@ static int filldir64(void * __buf, const char * name, int namlen, loff_t offset,
65115 buf->error = -EINVAL; /* only used if we fail.. */
65116 if (reclen > buf->count)
65117 return -EINVAL;
65118+
65119+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
65120+ return 0;
65121+
65122 dirent = buf->previous;
65123 if (dirent) {
65124 if (__put_user(offset, &dirent->d_off))
65125@@ -288,6 +306,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
65126 if (!f.file)
65127 return -EBADF;
65128
65129+ buf.file = f.file;
65130 error = iterate_dir(f.file, &buf.ctx);
65131 if (error >= 0)
65132 error = buf.error;
65133diff --git a/fs/reiserfs/do_balan.c b/fs/reiserfs/do_balan.c
65134index 9a3c68c..767933e 100644
65135--- a/fs/reiserfs/do_balan.c
65136+++ b/fs/reiserfs/do_balan.c
65137@@ -1546,7 +1546,7 @@ void do_balance(struct tree_balance *tb, /* tree_balance structure */
65138 return;
65139 }
65140
65141- atomic_inc(&(fs_generation(tb->tb_sb)));
65142+ atomic_inc_unchecked(&(fs_generation(tb->tb_sb)));
65143 do_balance_starts(tb);
65144
65145 /* balance leaf returns 0 except if combining L R and S into
65146diff --git a/fs/reiserfs/item_ops.c b/fs/reiserfs/item_ops.c
65147index ee382ef..f4eb6eb5 100644
65148--- a/fs/reiserfs/item_ops.c
65149+++ b/fs/reiserfs/item_ops.c
65150@@ -725,18 +725,18 @@ static void errcatch_print_vi(struct virtual_item *vi)
65151 }
65152
65153 static struct item_operations errcatch_ops = {
65154- errcatch_bytes_number,
65155- errcatch_decrement_key,
65156- errcatch_is_left_mergeable,
65157- errcatch_print_item,
65158- errcatch_check_item,
65159+ .bytes_number = errcatch_bytes_number,
65160+ .decrement_key = errcatch_decrement_key,
65161+ .is_left_mergeable = errcatch_is_left_mergeable,
65162+ .print_item = errcatch_print_item,
65163+ .check_item = errcatch_check_item,
65164
65165- errcatch_create_vi,
65166- errcatch_check_left,
65167- errcatch_check_right,
65168- errcatch_part_size,
65169- errcatch_unit_num,
65170- errcatch_print_vi
65171+ .create_vi = errcatch_create_vi,
65172+ .check_left = errcatch_check_left,
65173+ .check_right = errcatch_check_right,
65174+ .part_size = errcatch_part_size,
65175+ .unit_num = errcatch_unit_num,
65176+ .print_vi = errcatch_print_vi
65177 };
65178
65179 //////////////////////////////////////////////////////////////////////////////
65180diff --git a/fs/reiserfs/procfs.c b/fs/reiserfs/procfs.c
65181index 02b0b7d..c85018b 100644
65182--- a/fs/reiserfs/procfs.c
65183+++ b/fs/reiserfs/procfs.c
65184@@ -114,7 +114,7 @@ static int show_super(struct seq_file *m, void *unused)
65185 "SMALL_TAILS " : "NO_TAILS ",
65186 replay_only(sb) ? "REPLAY_ONLY " : "",
65187 convert_reiserfs(sb) ? "CONV " : "",
65188- atomic_read(&r->s_generation_counter),
65189+ atomic_read_unchecked(&r->s_generation_counter),
65190 SF(s_disk_reads), SF(s_disk_writes), SF(s_fix_nodes),
65191 SF(s_do_balance), SF(s_unneeded_left_neighbor),
65192 SF(s_good_search_by_key_reada), SF(s_bmaps),
65193diff --git a/fs/reiserfs/reiserfs.h b/fs/reiserfs/reiserfs.h
65194index 8d06adf..7e1c9f8 100644
65195--- a/fs/reiserfs/reiserfs.h
65196+++ b/fs/reiserfs/reiserfs.h
65197@@ -453,7 +453,7 @@ struct reiserfs_sb_info {
65198 /* Comment? -Hans */
65199 wait_queue_head_t s_wait;
65200 /* To be obsoleted soon by per buffer seals.. -Hans */
65201- atomic_t s_generation_counter; // increased by one every time the
65202+ atomic_unchecked_t s_generation_counter; // increased by one every time the
65203 // tree gets re-balanced
65204 unsigned long s_properties; /* File system properties. Currently holds
65205 on-disk FS format */
65206@@ -1972,7 +1972,7 @@ static inline loff_t max_reiserfs_offset(struct inode *inode)
65207 #define REISERFS_USER_MEM 1 /* reiserfs user memory mode */
65208
65209 #define fs_generation(s) (REISERFS_SB(s)->s_generation_counter)
65210-#define get_generation(s) atomic_read (&fs_generation(s))
65211+#define get_generation(s) atomic_read_unchecked (&fs_generation(s))
65212 #define FILESYSTEM_CHANGED_TB(tb) (get_generation((tb)->tb_sb) != (tb)->fs_gen)
65213 #define __fs_changed(gen,s) (gen != get_generation (s))
65214 #define fs_changed(gen,s) \
65215diff --git a/fs/select.c b/fs/select.c
65216index 467bb1c..cf9d65a 100644
65217--- a/fs/select.c
65218+++ b/fs/select.c
65219@@ -20,6 +20,7 @@
65220 #include <linux/export.h>
65221 #include <linux/slab.h>
65222 #include <linux/poll.h>
65223+#include <linux/security.h>
65224 #include <linux/personality.h> /* for STICKY_TIMEOUTS */
65225 #include <linux/file.h>
65226 #include <linux/fdtable.h>
65227@@ -880,6 +881,7 @@ int do_sys_poll(struct pollfd __user *ufds, unsigned int nfds,
65228 struct poll_list *walk = head;
65229 unsigned long todo = nfds;
65230
65231+ gr_learn_resource(current, RLIMIT_NOFILE, nfds, 1);
65232 if (nfds > rlimit(RLIMIT_NOFILE))
65233 return -EINVAL;
65234
65235diff --git a/fs/seq_file.c b/fs/seq_file.c
65236index 1d641bb..c2f4743 100644
65237--- a/fs/seq_file.c
65238+++ b/fs/seq_file.c
65239@@ -10,6 +10,8 @@
65240 #include <linux/seq_file.h>
65241 #include <linux/slab.h>
65242 #include <linux/cred.h>
65243+#include <linux/sched.h>
65244+#include <linux/grsecurity.h>
65245
65246 #include <asm/uaccess.h>
65247 #include <asm/page.h>
65248@@ -60,6 +62,9 @@ int seq_open(struct file *file, const struct seq_operations *op)
65249 #ifdef CONFIG_USER_NS
65250 p->user_ns = file->f_cred->user_ns;
65251 #endif
65252+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
65253+ p->exec_id = current->exec_id;
65254+#endif
65255
65256 /*
65257 * Wrappers around seq_open(e.g. swaps_open) need to be
65258@@ -82,6 +87,16 @@ int seq_open(struct file *file, const struct seq_operations *op)
65259 }
65260 EXPORT_SYMBOL(seq_open);
65261
65262+
65263+int seq_open_restrict(struct file *file, const struct seq_operations *op)
65264+{
65265+ if (gr_proc_is_restricted())
65266+ return -EACCES;
65267+
65268+ return seq_open(file, op);
65269+}
65270+EXPORT_SYMBOL(seq_open_restrict);
65271+
65272 static int traverse(struct seq_file *m, loff_t offset)
65273 {
65274 loff_t pos = 0, index;
65275@@ -96,7 +111,7 @@ static int traverse(struct seq_file *m, loff_t offset)
65276 return 0;
65277 }
65278 if (!m->buf) {
65279- m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
65280+ m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
65281 if (!m->buf)
65282 return -ENOMEM;
65283 }
65284@@ -137,7 +152,7 @@ Eoverflow:
65285 m->op->stop(m, p);
65286 kfree(m->buf);
65287 m->count = 0;
65288- m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
65289+ m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
65290 return !m->buf ? -ENOMEM : -EAGAIN;
65291 }
65292
65293@@ -153,7 +168,7 @@ Eoverflow:
65294 ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
65295 {
65296 struct seq_file *m = file->private_data;
65297- size_t copied = 0;
65298+ ssize_t copied = 0;
65299 loff_t pos;
65300 size_t n;
65301 void *p;
65302@@ -192,7 +207,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
65303
65304 /* grab buffer if we didn't have one */
65305 if (!m->buf) {
65306- m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
65307+ m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
65308 if (!m->buf)
65309 goto Enomem;
65310 }
65311@@ -234,7 +249,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
65312 m->op->stop(m, p);
65313 kfree(m->buf);
65314 m->count = 0;
65315- m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
65316+ m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
65317 if (!m->buf)
65318 goto Enomem;
65319 m->version = 0;
65320@@ -584,7 +599,7 @@ static void single_stop(struct seq_file *p, void *v)
65321 int single_open(struct file *file, int (*show)(struct seq_file *, void *),
65322 void *data)
65323 {
65324- struct seq_operations *op = kmalloc(sizeof(*op), GFP_KERNEL);
65325+ seq_operations_no_const *op = kzalloc(sizeof(*op), GFP_KERNEL);
65326 int res = -ENOMEM;
65327
65328 if (op) {
65329@@ -620,6 +635,17 @@ int single_open_size(struct file *file, int (*show)(struct seq_file *, void *),
65330 }
65331 EXPORT_SYMBOL(single_open_size);
65332
65333+int single_open_restrict(struct file *file, int (*show)(struct seq_file *, void *),
65334+ void *data)
65335+{
65336+ if (gr_proc_is_restricted())
65337+ return -EACCES;
65338+
65339+ return single_open(file, show, data);
65340+}
65341+EXPORT_SYMBOL(single_open_restrict);
65342+
65343+
65344 int single_release(struct inode *inode, struct file *file)
65345 {
65346 const struct seq_operations *op = ((struct seq_file *)file->private_data)->op;
65347diff --git a/fs/splice.c b/fs/splice.c
65348index 12028fa..a6f2619 100644
65349--- a/fs/splice.c
65350+++ b/fs/splice.c
65351@@ -196,7 +196,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
65352 pipe_lock(pipe);
65353
65354 for (;;) {
65355- if (!pipe->readers) {
65356+ if (!atomic_read(&pipe->readers)) {
65357 send_sig(SIGPIPE, current, 0);
65358 if (!ret)
65359 ret = -EPIPE;
65360@@ -219,7 +219,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
65361 page_nr++;
65362 ret += buf->len;
65363
65364- if (pipe->files)
65365+ if (atomic_read(&pipe->files))
65366 do_wakeup = 1;
65367
65368 if (!--spd->nr_pages)
65369@@ -250,9 +250,9 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
65370 do_wakeup = 0;
65371 }
65372
65373- pipe->waiting_writers++;
65374+ atomic_inc(&pipe->waiting_writers);
65375 pipe_wait(pipe);
65376- pipe->waiting_writers--;
65377+ atomic_dec(&pipe->waiting_writers);
65378 }
65379
65380 pipe_unlock(pipe);
65381@@ -583,7 +583,7 @@ static ssize_t kernel_readv(struct file *file, const struct iovec *vec,
65382 old_fs = get_fs();
65383 set_fs(get_ds());
65384 /* The cast to a user pointer is valid due to the set_fs() */
65385- res = vfs_readv(file, (const struct iovec __user *)vec, vlen, &pos);
65386+ res = vfs_readv(file, (const struct iovec __force_user *)vec, vlen, &pos);
65387 set_fs(old_fs);
65388
65389 return res;
65390@@ -598,7 +598,7 @@ ssize_t kernel_write(struct file *file, const char *buf, size_t count,
65391 old_fs = get_fs();
65392 set_fs(get_ds());
65393 /* The cast to a user pointer is valid due to the set_fs() */
65394- res = vfs_write(file, (__force const char __user *)buf, count, &pos);
65395+ res = vfs_write(file, (const char __force_user *)buf, count, &pos);
65396 set_fs(old_fs);
65397
65398 return res;
65399@@ -651,7 +651,7 @@ ssize_t default_file_splice_read(struct file *in, loff_t *ppos,
65400 goto err;
65401
65402 this_len = min_t(size_t, len, PAGE_CACHE_SIZE - offset);
65403- vec[i].iov_base = (void __user *) page_address(page);
65404+ vec[i].iov_base = (void __force_user *) page_address(page);
65405 vec[i].iov_len = this_len;
65406 spd.pages[i] = page;
65407 spd.nr_pages++;
65408@@ -847,7 +847,7 @@ int splice_from_pipe_feed(struct pipe_inode_info *pipe, struct splice_desc *sd,
65409 ops->release(pipe, buf);
65410 pipe->curbuf = (pipe->curbuf + 1) & (pipe->buffers - 1);
65411 pipe->nrbufs--;
65412- if (pipe->files)
65413+ if (atomic_read(&pipe->files))
65414 sd->need_wakeup = true;
65415 }
65416
65417@@ -872,10 +872,10 @@ EXPORT_SYMBOL(splice_from_pipe_feed);
65418 int splice_from_pipe_next(struct pipe_inode_info *pipe, struct splice_desc *sd)
65419 {
65420 while (!pipe->nrbufs) {
65421- if (!pipe->writers)
65422+ if (!atomic_read(&pipe->writers))
65423 return 0;
65424
65425- if (!pipe->waiting_writers && sd->num_spliced)
65426+ if (!atomic_read(&pipe->waiting_writers) && sd->num_spliced)
65427 return 0;
65428
65429 if (sd->flags & SPLICE_F_NONBLOCK)
65430@@ -1197,7 +1197,7 @@ ssize_t splice_direct_to_actor(struct file *in, struct splice_desc *sd,
65431 * out of the pipe right after the splice_to_pipe(). So set
65432 * PIPE_READERS appropriately.
65433 */
65434- pipe->readers = 1;
65435+ atomic_set(&pipe->readers, 1);
65436
65437 current->splice_pipe = pipe;
65438 }
65439@@ -1493,6 +1493,7 @@ static int get_iovec_page_array(const struct iovec __user *iov,
65440
65441 partial[buffers].offset = off;
65442 partial[buffers].len = plen;
65443+ partial[buffers].private = 0;
65444
65445 off = 0;
65446 len -= plen;
65447@@ -1795,9 +1796,9 @@ static int ipipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
65448 ret = -ERESTARTSYS;
65449 break;
65450 }
65451- if (!pipe->writers)
65452+ if (!atomic_read(&pipe->writers))
65453 break;
65454- if (!pipe->waiting_writers) {
65455+ if (!atomic_read(&pipe->waiting_writers)) {
65456 if (flags & SPLICE_F_NONBLOCK) {
65457 ret = -EAGAIN;
65458 break;
65459@@ -1829,7 +1830,7 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
65460 pipe_lock(pipe);
65461
65462 while (pipe->nrbufs >= pipe->buffers) {
65463- if (!pipe->readers) {
65464+ if (!atomic_read(&pipe->readers)) {
65465 send_sig(SIGPIPE, current, 0);
65466 ret = -EPIPE;
65467 break;
65468@@ -1842,9 +1843,9 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
65469 ret = -ERESTARTSYS;
65470 break;
65471 }
65472- pipe->waiting_writers++;
65473+ atomic_inc(&pipe->waiting_writers);
65474 pipe_wait(pipe);
65475- pipe->waiting_writers--;
65476+ atomic_dec(&pipe->waiting_writers);
65477 }
65478
65479 pipe_unlock(pipe);
65480@@ -1880,14 +1881,14 @@ retry:
65481 pipe_double_lock(ipipe, opipe);
65482
65483 do {
65484- if (!opipe->readers) {
65485+ if (!atomic_read(&opipe->readers)) {
65486 send_sig(SIGPIPE, current, 0);
65487 if (!ret)
65488 ret = -EPIPE;
65489 break;
65490 }
65491
65492- if (!ipipe->nrbufs && !ipipe->writers)
65493+ if (!ipipe->nrbufs && !atomic_read(&ipipe->writers))
65494 break;
65495
65496 /*
65497@@ -1984,7 +1985,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
65498 pipe_double_lock(ipipe, opipe);
65499
65500 do {
65501- if (!opipe->readers) {
65502+ if (!atomic_read(&opipe->readers)) {
65503 send_sig(SIGPIPE, current, 0);
65504 if (!ret)
65505 ret = -EPIPE;
65506@@ -2029,7 +2030,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
65507 * return EAGAIN if we have the potential of some data in the
65508 * future, otherwise just return 0
65509 */
65510- if (!ret && ipipe->waiting_writers && (flags & SPLICE_F_NONBLOCK))
65511+ if (!ret && atomic_read(&ipipe->waiting_writers) && (flags & SPLICE_F_NONBLOCK))
65512 ret = -EAGAIN;
65513
65514 pipe_unlock(ipipe);
65515diff --git a/fs/stat.c b/fs/stat.c
65516index ae0c3ce..9ee641c 100644
65517--- a/fs/stat.c
65518+++ b/fs/stat.c
65519@@ -28,8 +28,13 @@ void generic_fillattr(struct inode *inode, struct kstat *stat)
65520 stat->gid = inode->i_gid;
65521 stat->rdev = inode->i_rdev;
65522 stat->size = i_size_read(inode);
65523- stat->atime = inode->i_atime;
65524- stat->mtime = inode->i_mtime;
65525+ if (is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
65526+ stat->atime = inode->i_ctime;
65527+ stat->mtime = inode->i_ctime;
65528+ } else {
65529+ stat->atime = inode->i_atime;
65530+ stat->mtime = inode->i_mtime;
65531+ }
65532 stat->ctime = inode->i_ctime;
65533 stat->blksize = (1 << inode->i_blkbits);
65534 stat->blocks = inode->i_blocks;
65535@@ -52,9 +57,16 @@ EXPORT_SYMBOL(generic_fillattr);
65536 int vfs_getattr_nosec(struct path *path, struct kstat *stat)
65537 {
65538 struct inode *inode = path->dentry->d_inode;
65539+ int retval;
65540
65541- if (inode->i_op->getattr)
65542- return inode->i_op->getattr(path->mnt, path->dentry, stat);
65543+ if (inode->i_op->getattr) {
65544+ retval = inode->i_op->getattr(path->mnt, path->dentry, stat);
65545+ if (!retval && is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
65546+ stat->atime = stat->ctime;
65547+ stat->mtime = stat->ctime;
65548+ }
65549+ return retval;
65550+ }
65551
65552 generic_fillattr(inode, stat);
65553 return 0;
65554diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
65555index ee0d761..b346c58 100644
65556--- a/fs/sysfs/dir.c
65557+++ b/fs/sysfs/dir.c
65558@@ -62,9 +62,16 @@ void sysfs_warn_dup(struct kernfs_node *parent, const char *name)
65559 int sysfs_create_dir_ns(struct kobject *kobj, const void *ns)
65560 {
65561 struct kernfs_node *parent, *kn;
65562+ const char *name;
65563+ umode_t mode = S_IRWXU | S_IRUGO | S_IXUGO;
65564+#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
65565+ const char *parent_name;
65566+#endif
65567
65568 BUG_ON(!kobj);
65569
65570+ name = kobject_name(kobj);
65571+
65572 if (kobj->parent)
65573 parent = kobj->parent->sd;
65574 else
65575@@ -73,11 +80,22 @@ int sysfs_create_dir_ns(struct kobject *kobj, const void *ns)
65576 if (!parent)
65577 return -ENOENT;
65578
65579- kn = kernfs_create_dir_ns(parent, kobject_name(kobj),
65580- S_IRWXU | S_IRUGO | S_IXUGO, kobj, ns);
65581+#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
65582+ parent_name = parent->name;
65583+ mode = S_IRWXU;
65584+
65585+ if ((!strcmp(parent_name, "") && (!strcmp(name, "devices") || !strcmp(name, "fs"))) ||
65586+ (!strcmp(parent_name, "devices") && !strcmp(name, "system")) ||
65587+ (!strcmp(parent_name, "fs") && (!strcmp(name, "selinux") || !strcmp(name, "fuse") || !strcmp(name, "ecryptfs"))) ||
65588+ (!strcmp(parent_name, "system") && !strcmp(name, "cpu")))
65589+ mode = S_IRWXU | S_IRUGO | S_IXUGO;
65590+#endif
65591+
65592+ kn = kernfs_create_dir_ns(parent, name,
65593+ mode, kobj, ns);
65594 if (IS_ERR(kn)) {
65595 if (PTR_ERR(kn) == -EEXIST)
65596- sysfs_warn_dup(parent, kobject_name(kobj));
65597+ sysfs_warn_dup(parent, name);
65598 return PTR_ERR(kn);
65599 }
65600
65601diff --git a/fs/sysv/sysv.h b/fs/sysv/sysv.h
65602index 69d4889..a810bd4 100644
65603--- a/fs/sysv/sysv.h
65604+++ b/fs/sysv/sysv.h
65605@@ -188,7 +188,7 @@ static inline u32 PDP_swab(u32 x)
65606 #endif
65607 }
65608
65609-static inline __u32 fs32_to_cpu(struct sysv_sb_info *sbi, __fs32 n)
65610+static inline __u32 __intentional_overflow(-1) fs32_to_cpu(struct sysv_sb_info *sbi, __fs32 n)
65611 {
65612 if (sbi->s_bytesex == BYTESEX_PDP)
65613 return PDP_swab((__force __u32)n);
65614diff --git a/fs/ubifs/io.c b/fs/ubifs/io.c
65615index e18b988..f1d4ad0f 100644
65616--- a/fs/ubifs/io.c
65617+++ b/fs/ubifs/io.c
65618@@ -155,7 +155,7 @@ int ubifs_leb_change(struct ubifs_info *c, int lnum, const void *buf, int len)
65619 return err;
65620 }
65621
65622-int ubifs_leb_unmap(struct ubifs_info *c, int lnum)
65623+int __intentional_overflow(-1) ubifs_leb_unmap(struct ubifs_info *c, int lnum)
65624 {
65625 int err;
65626
65627diff --git a/fs/udf/misc.c b/fs/udf/misc.c
65628index c175b4d..8f36a16 100644
65629--- a/fs/udf/misc.c
65630+++ b/fs/udf/misc.c
65631@@ -289,7 +289,7 @@ void udf_new_tag(char *data, uint16_t ident, uint16_t version, uint16_t snum,
65632
65633 u8 udf_tag_checksum(const struct tag *t)
65634 {
65635- u8 *data = (u8 *)t;
65636+ const u8 *data = (const u8 *)t;
65637 u8 checksum = 0;
65638 int i;
65639 for (i = 0; i < sizeof(struct tag); ++i)
65640diff --git a/fs/ufs/swab.h b/fs/ufs/swab.h
65641index 8d974c4..b82f6ec 100644
65642--- a/fs/ufs/swab.h
65643+++ b/fs/ufs/swab.h
65644@@ -22,7 +22,7 @@ enum {
65645 BYTESEX_BE
65646 };
65647
65648-static inline u64
65649+static inline u64 __intentional_overflow(-1)
65650 fs64_to_cpu(struct super_block *sbp, __fs64 n)
65651 {
65652 if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
65653@@ -40,7 +40,7 @@ cpu_to_fs64(struct super_block *sbp, u64 n)
65654 return (__force __fs64)cpu_to_be64(n);
65655 }
65656
65657-static inline u32
65658+static inline u32 __intentional_overflow(-1)
65659 fs32_to_cpu(struct super_block *sbp, __fs32 n)
65660 {
65661 if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
65662diff --git a/fs/utimes.c b/fs/utimes.c
65663index aa138d6..5f3a811 100644
65664--- a/fs/utimes.c
65665+++ b/fs/utimes.c
65666@@ -1,6 +1,7 @@
65667 #include <linux/compiler.h>
65668 #include <linux/file.h>
65669 #include <linux/fs.h>
65670+#include <linux/security.h>
65671 #include <linux/linkage.h>
65672 #include <linux/mount.h>
65673 #include <linux/namei.h>
65674@@ -103,6 +104,12 @@ static int utimes_common(struct path *path, struct timespec *times)
65675 }
65676 }
65677 retry_deleg:
65678+
65679+ if (!gr_acl_handle_utime(path->dentry, path->mnt)) {
65680+ error = -EACCES;
65681+ goto mnt_drop_write_and_out;
65682+ }
65683+
65684 mutex_lock(&inode->i_mutex);
65685 error = notify_change(path->dentry, &newattrs, &delegated_inode);
65686 mutex_unlock(&inode->i_mutex);
65687diff --git a/fs/xattr.c b/fs/xattr.c
65688index 3377dff..f394815 100644
65689--- a/fs/xattr.c
65690+++ b/fs/xattr.c
65691@@ -227,6 +227,27 @@ int vfs_xattr_cmp(struct dentry *dentry, const char *xattr_name,
65692 return rc;
65693 }
65694
65695+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
65696+ssize_t
65697+pax_getxattr(struct dentry *dentry, void *value, size_t size)
65698+{
65699+ struct inode *inode = dentry->d_inode;
65700+ ssize_t error;
65701+
65702+ error = inode_permission(inode, MAY_EXEC);
65703+ if (error)
65704+ return error;
65705+
65706+ if (inode->i_op->getxattr)
65707+ error = inode->i_op->getxattr(dentry, XATTR_NAME_PAX_FLAGS, value, size);
65708+ else
65709+ error = -EOPNOTSUPP;
65710+
65711+ return error;
65712+}
65713+EXPORT_SYMBOL(pax_getxattr);
65714+#endif
65715+
65716 ssize_t
65717 vfs_getxattr(struct dentry *dentry, const char *name, void *value, size_t size)
65718 {
65719@@ -319,7 +340,7 @@ EXPORT_SYMBOL_GPL(vfs_removexattr);
65720 * Extended attribute SET operations
65721 */
65722 static long
65723-setxattr(struct dentry *d, const char __user *name, const void __user *value,
65724+setxattr(struct path *path, const char __user *name, const void __user *value,
65725 size_t size, int flags)
65726 {
65727 int error;
65728@@ -355,7 +376,12 @@ setxattr(struct dentry *d, const char __user *name, const void __user *value,
65729 posix_acl_fix_xattr_from_user(kvalue, size);
65730 }
65731
65732- error = vfs_setxattr(d, kname, kvalue, size, flags);
65733+ if (!gr_acl_handle_setxattr(path->dentry, path->mnt)) {
65734+ error = -EACCES;
65735+ goto out;
65736+ }
65737+
65738+ error = vfs_setxattr(path->dentry, kname, kvalue, size, flags);
65739 out:
65740 if (vvalue)
65741 vfree(vvalue);
65742@@ -377,7 +403,7 @@ retry:
65743 return error;
65744 error = mnt_want_write(path.mnt);
65745 if (!error) {
65746- error = setxattr(path.dentry, name, value, size, flags);
65747+ error = setxattr(&path, name, value, size, flags);
65748 mnt_drop_write(path.mnt);
65749 }
65750 path_put(&path);
65751@@ -401,7 +427,7 @@ retry:
65752 return error;
65753 error = mnt_want_write(path.mnt);
65754 if (!error) {
65755- error = setxattr(path.dentry, name, value, size, flags);
65756+ error = setxattr(&path, name, value, size, flags);
65757 mnt_drop_write(path.mnt);
65758 }
65759 path_put(&path);
65760@@ -416,16 +442,14 @@ SYSCALL_DEFINE5(fsetxattr, int, fd, const char __user *, name,
65761 const void __user *,value, size_t, size, int, flags)
65762 {
65763 struct fd f = fdget(fd);
65764- struct dentry *dentry;
65765 int error = -EBADF;
65766
65767 if (!f.file)
65768 return error;
65769- dentry = f.file->f_path.dentry;
65770- audit_inode(NULL, dentry, 0);
65771+ audit_inode(NULL, f.file->f_path.dentry, 0);
65772 error = mnt_want_write_file(f.file);
65773 if (!error) {
65774- error = setxattr(dentry, name, value, size, flags);
65775+ error = setxattr(&f.file->f_path, name, value, size, flags);
65776 mnt_drop_write_file(f.file);
65777 }
65778 fdput(f);
65779@@ -626,7 +650,7 @@ SYSCALL_DEFINE3(flistxattr, int, fd, char __user *, list, size_t, size)
65780 * Extended attribute REMOVE operations
65781 */
65782 static long
65783-removexattr(struct dentry *d, const char __user *name)
65784+removexattr(struct path *path, const char __user *name)
65785 {
65786 int error;
65787 char kname[XATTR_NAME_MAX + 1];
65788@@ -637,7 +661,10 @@ removexattr(struct dentry *d, const char __user *name)
65789 if (error < 0)
65790 return error;
65791
65792- return vfs_removexattr(d, kname);
65793+ if (!gr_acl_handle_removexattr(path->dentry, path->mnt))
65794+ return -EACCES;
65795+
65796+ return vfs_removexattr(path->dentry, kname);
65797 }
65798
65799 SYSCALL_DEFINE2(removexattr, const char __user *, pathname,
65800@@ -652,7 +679,7 @@ retry:
65801 return error;
65802 error = mnt_want_write(path.mnt);
65803 if (!error) {
65804- error = removexattr(path.dentry, name);
65805+ error = removexattr(&path, name);
65806 mnt_drop_write(path.mnt);
65807 }
65808 path_put(&path);
65809@@ -675,7 +702,7 @@ retry:
65810 return error;
65811 error = mnt_want_write(path.mnt);
65812 if (!error) {
65813- error = removexattr(path.dentry, name);
65814+ error = removexattr(&path, name);
65815 mnt_drop_write(path.mnt);
65816 }
65817 path_put(&path);
65818@@ -689,16 +716,16 @@ retry:
65819 SYSCALL_DEFINE2(fremovexattr, int, fd, const char __user *, name)
65820 {
65821 struct fd f = fdget(fd);
65822- struct dentry *dentry;
65823+ struct path *path;
65824 int error = -EBADF;
65825
65826 if (!f.file)
65827 return error;
65828- dentry = f.file->f_path.dentry;
65829- audit_inode(NULL, dentry, 0);
65830+ path = &f.file->f_path;
65831+ audit_inode(NULL, path->dentry, 0);
65832 error = mnt_want_write_file(f.file);
65833 if (!error) {
65834- error = removexattr(dentry, name);
65835+ error = removexattr(path, name);
65836 mnt_drop_write_file(f.file);
65837 }
65838 fdput(f);
65839diff --git a/fs/xfs/xfs_bmap.c b/fs/xfs/xfs_bmap.c
65840index 152543c..d80c361 100644
65841--- a/fs/xfs/xfs_bmap.c
65842+++ b/fs/xfs/xfs_bmap.c
65843@@ -584,7 +584,7 @@ xfs_bmap_validate_ret(
65844
65845 #else
65846 #define xfs_bmap_check_leaf_extents(cur, ip, whichfork) do { } while (0)
65847-#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap)
65848+#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap) do { } while (0)
65849 #endif /* DEBUG */
65850
65851 /*
65852diff --git a/fs/xfs/xfs_dir2_readdir.c b/fs/xfs/xfs_dir2_readdir.c
65853index aead369..0dfecfd 100644
65854--- a/fs/xfs/xfs_dir2_readdir.c
65855+++ b/fs/xfs/xfs_dir2_readdir.c
65856@@ -160,7 +160,12 @@ xfs_dir2_sf_getdents(
65857 ino = dp->d_ops->sf_get_ino(sfp, sfep);
65858 filetype = dp->d_ops->sf_get_ftype(sfep);
65859 ctx->pos = off & 0x7fffffff;
65860- if (!dir_emit(ctx, (char *)sfep->name, sfep->namelen, ino,
65861+ if (dp->i_df.if_u1.if_data == dp->i_df.if_u2.if_inline_data) {
65862+ char name[sfep->namelen];
65863+ memcpy(name, sfep->name, sfep->namelen);
65864+ if (!dir_emit(ctx, name, sfep->namelen, ino, xfs_dir3_get_dtype(mp, filetype)))
65865+ return 0;
65866+ } else if (!dir_emit(ctx, (char *)sfep->name, sfep->namelen, ino,
65867 xfs_dir3_get_dtype(mp, filetype)))
65868 return 0;
65869 sfep = dp->d_ops->sf_nextentry(sfp, sfep);
65870diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
65871index bcfe612..aa399c0 100644
65872--- a/fs/xfs/xfs_ioctl.c
65873+++ b/fs/xfs/xfs_ioctl.c
65874@@ -122,7 +122,7 @@ xfs_find_handle(
65875 }
65876
65877 error = -EFAULT;
65878- if (copy_to_user(hreq->ohandle, &handle, hsize) ||
65879+ if (hsize > sizeof handle || copy_to_user(hreq->ohandle, &handle, hsize) ||
65880 copy_to_user(hreq->ohandlen, &hsize, sizeof(__s32)))
65881 goto out_put;
65882
65883diff --git a/grsecurity/Kconfig b/grsecurity/Kconfig
65884new file mode 100644
65885index 0000000..3abaf02
65886--- /dev/null
65887+++ b/grsecurity/Kconfig
65888@@ -0,0 +1,1161 @@
65889+#
65890+# grecurity configuration
65891+#
65892+menu "Memory Protections"
65893+depends on GRKERNSEC
65894+
65895+config GRKERNSEC_KMEM
65896+ bool "Deny reading/writing to /dev/kmem, /dev/mem, and /dev/port"
65897+ default y if GRKERNSEC_CONFIG_AUTO
65898+ select STRICT_DEVMEM if (X86 || ARM || TILE || S390)
65899+ help
65900+ If you say Y here, /dev/kmem and /dev/mem won't be allowed to
65901+ be written to or read from to modify or leak the contents of the running
65902+ kernel. /dev/port will also not be allowed to be opened, writing to
65903+ /dev/cpu/*/msr will be prevented, and support for kexec will be removed.
65904+ If you have module support disabled, enabling this will close up several
65905+ ways that are currently used to insert malicious code into the running
65906+ kernel.
65907+
65908+ Even with this feature enabled, we still highly recommend that
65909+ you use the RBAC system, as it is still possible for an attacker to
65910+ modify the running kernel through other more obscure methods.
65911+
65912+ It is highly recommended that you say Y here if you meet all the
65913+ conditions above.
65914+
65915+config GRKERNSEC_VM86
65916+ bool "Restrict VM86 mode"
65917+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
65918+ depends on X86_32
65919+
65920+ help
65921+ If you say Y here, only processes with CAP_SYS_RAWIO will be able to
65922+ make use of a special execution mode on 32bit x86 processors called
65923+ Virtual 8086 (VM86) mode. XFree86 may need vm86 mode for certain
65924+ video cards and will still work with this option enabled. The purpose
65925+ of the option is to prevent exploitation of emulation errors in
65926+ virtualization of vm86 mode like the one discovered in VMWare in 2009.
65927+ Nearly all users should be able to enable this option.
65928+
65929+config GRKERNSEC_IO
65930+ bool "Disable privileged I/O"
65931+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
65932+ depends on X86
65933+ select RTC_CLASS
65934+ select RTC_INTF_DEV
65935+ select RTC_DRV_CMOS
65936+
65937+ help
65938+ If you say Y here, all ioperm and iopl calls will return an error.
65939+ Ioperm and iopl can be used to modify the running kernel.
65940+ Unfortunately, some programs need this access to operate properly,
65941+ the most notable of which are XFree86 and hwclock. hwclock can be
65942+ remedied by having RTC support in the kernel, so real-time
65943+ clock support is enabled if this option is enabled, to ensure
65944+ that hwclock operates correctly. If hwclock still does not work,
65945+ either update udev or symlink /dev/rtc to /dev/rtc0.
65946+
65947+ If you're using XFree86 or a version of Xorg from 2012 or earlier,
65948+ you may not be able to boot into a graphical environment with this
65949+ option enabled. In this case, you should use the RBAC system instead.
65950+
65951+config GRKERNSEC_JIT_HARDEN
65952+ bool "Harden BPF JIT against spray attacks"
65953+ default y if GRKERNSEC_CONFIG_AUTO
65954+ depends on BPF_JIT && X86
65955+ help
65956+ If you say Y here, the native code generated by the kernel's Berkeley
65957+ Packet Filter (BPF) JIT engine will be hardened against JIT-spraying
65958+ attacks that attempt to fit attacker-beneficial instructions in
65959+ 32bit immediate fields of JIT-generated native instructions. The
65960+ attacker will generally aim to cause an unintended instruction sequence
65961+ of JIT-generated native code to execute by jumping into the middle of
65962+ a generated instruction. This feature effectively randomizes the 32bit
65963+ immediate constants present in the generated code to thwart such attacks.
65964+
65965+ If you're using KERNEXEC, it's recommended that you enable this option
65966+ to supplement the hardening of the kernel.
65967+
65968+config GRKERNSEC_PERF_HARDEN
65969+ bool "Disable unprivileged PERF_EVENTS usage by default"
65970+ default y if GRKERNSEC_CONFIG_AUTO
65971+ depends on PERF_EVENTS
65972+ help
65973+ If you say Y here, the range of acceptable values for the
65974+ /proc/sys/kernel/perf_event_paranoid sysctl will be expanded to allow and
65975+ default to a new value: 3. When the sysctl is set to this value, no
65976+ unprivileged use of the PERF_EVENTS syscall interface will be permitted.
65977+
65978+ Though PERF_EVENTS can be used legitimately for performance monitoring
65979+ and low-level application profiling, it is forced on regardless of
65980+ configuration, has been at fault for several vulnerabilities, and
65981+ creates new opportunities for side channels and other information leaks.
65982+
65983+ This feature puts PERF_EVENTS into a secure default state and permits
65984+ the administrator to change out of it temporarily if unprivileged
65985+ application profiling is needed.
65986+
65987+config GRKERNSEC_RAND_THREADSTACK
65988+ bool "Insert random gaps between thread stacks"
65989+ default y if GRKERNSEC_CONFIG_AUTO
65990+ depends on PAX_RANDMMAP && !PPC
65991+ help
65992+ If you say Y here, a random-sized gap will be enforced between allocated
65993+ thread stacks. Glibc's NPTL and other threading libraries that
65994+ pass MAP_STACK to the kernel for thread stack allocation are supported.
65995+ The implementation currently provides 8 bits of entropy for the gap.
65996+
65997+ Many distributions do not compile threaded remote services with the
65998+ -fstack-check argument to GCC, causing the variable-sized stack-based
65999+ allocator, alloca(), to not probe the stack on allocation. This
66000+ permits an unbounded alloca() to skip over any guard page and potentially
66001+ modify another thread's stack reliably. An enforced random gap
66002+ reduces the reliability of such an attack and increases the chance
66003+ that such a read/write to another thread's stack instead lands in
66004+ an unmapped area, causing a crash and triggering grsecurity's
66005+ anti-bruteforcing logic.
66006+
66007+config GRKERNSEC_PROC_MEMMAP
66008+ bool "Harden ASLR against information leaks and entropy reduction"
66009+ default y if (GRKERNSEC_CONFIG_AUTO || PAX_NOEXEC || PAX_ASLR)
66010+ depends on PAX_NOEXEC || PAX_ASLR
66011+ help
66012+ If you say Y here, the /proc/<pid>/maps and /proc/<pid>/stat files will
66013+ give no information about the addresses of its mappings if
66014+ PaX features that rely on random addresses are enabled on the task.
66015+ In addition to sanitizing this information and disabling other
66016+ dangerous sources of information, this option causes reads of sensitive
66017+ /proc/<pid> entries where the file descriptor was opened in a different
66018+ task than the one performing the read. Such attempts are logged.
66019+ This option also limits argv/env strings for suid/sgid binaries
66020+ to 512KB to prevent a complete exhaustion of the stack entropy provided
66021+ by ASLR. Finally, it places an 8MB stack resource limit on suid/sgid
66022+ binaries to prevent alternative mmap layouts from being abused.
66023+
66024+ If you use PaX it is essential that you say Y here as it closes up
66025+ several holes that make full ASLR useless locally.
66026+
66027+config GRKERNSEC_BRUTE
66028+ bool "Deter exploit bruteforcing"
66029+ default y if GRKERNSEC_CONFIG_AUTO
66030+ help
66031+ If you say Y here, attempts to bruteforce exploits against forking
66032+ daemons such as apache or sshd, as well as against suid/sgid binaries
66033+ will be deterred. When a child of a forking daemon is killed by PaX
66034+ or crashes due to an illegal instruction or other suspicious signal,
66035+ the parent process will be delayed 30 seconds upon every subsequent
66036+ fork until the administrator is able to assess the situation and
66037+ restart the daemon.
66038+ In the suid/sgid case, the attempt is logged, the user has all their
66039+ existing instances of the suid/sgid binary terminated and will
66040+ be unable to execute any suid/sgid binaries for 15 minutes.
66041+
66042+ It is recommended that you also enable signal logging in the auditing
66043+ section so that logs are generated when a process triggers a suspicious
66044+ signal.
66045+ If the sysctl option is enabled, a sysctl option with name
66046+ "deter_bruteforce" is created.
66047+
66048+config GRKERNSEC_MODHARDEN
66049+ bool "Harden module auto-loading"
66050+ default y if GRKERNSEC_CONFIG_AUTO
66051+ depends on MODULES
66052+ help
66053+ If you say Y here, module auto-loading in response to use of some
66054+ feature implemented by an unloaded module will be restricted to
66055+ root users. Enabling this option helps defend against attacks
66056+ by unprivileged users who abuse the auto-loading behavior to
66057+ cause a vulnerable module to load that is then exploited.
66058+
66059+ If this option prevents a legitimate use of auto-loading for a
66060+ non-root user, the administrator can execute modprobe manually
66061+ with the exact name of the module mentioned in the alert log.
66062+ Alternatively, the administrator can add the module to the list
66063+ of modules loaded at boot by modifying init scripts.
66064+
66065+ Modification of init scripts will most likely be needed on
66066+ Ubuntu servers with encrypted home directory support enabled,
66067+ as the first non-root user logging in will cause the ecb(aes),
66068+ ecb(aes)-all, cbc(aes), and cbc(aes)-all modules to be loaded.
66069+
66070+config GRKERNSEC_HIDESYM
66071+ bool "Hide kernel symbols"
66072+ default y if GRKERNSEC_CONFIG_AUTO
66073+ select PAX_USERCOPY_SLABS
66074+ help
66075+ If you say Y here, getting information on loaded modules, and
66076+ displaying all kernel symbols through a syscall will be restricted
66077+ to users with CAP_SYS_MODULE. For software compatibility reasons,
66078+ /proc/kallsyms will be restricted to the root user. The RBAC
66079+ system can hide that entry even from root.
66080+
66081+ This option also prevents leaking of kernel addresses through
66082+ several /proc entries.
66083+
66084+ Note that this option is only effective provided the following
66085+ conditions are met:
66086+ 1) The kernel using grsecurity is not precompiled by some distribution
66087+ 2) You have also enabled GRKERNSEC_DMESG
66088+ 3) You are using the RBAC system and hiding other files such as your
66089+ kernel image and System.map. Alternatively, enabling this option
66090+ causes the permissions on /boot, /lib/modules, and the kernel
66091+ source directory to change at compile time to prevent
66092+ reading by non-root users.
66093+ If the above conditions are met, this option will aid in providing a
66094+ useful protection against local kernel exploitation of overflows
66095+ and arbitrary read/write vulnerabilities.
66096+
66097+ It is highly recommended that you enable GRKERNSEC_PERF_HARDEN
66098+ in addition to this feature.
66099+
66100+config GRKERNSEC_RANDSTRUCT
66101+ bool "Randomize layout of sensitive kernel structures"
66102+ default y if GRKERNSEC_CONFIG_AUTO
66103+ select GRKERNSEC_HIDESYM
66104+ select MODVERSIONS if MODULES
66105+ help
66106+ If you say Y here, the layouts of a number of sensitive kernel
66107+ structures (task, fs, cred, etc) and all structures composed entirely
66108+ of function pointers (aka "ops" structs) will be randomized at compile-time.
66109+ This can introduce the requirement of an additional infoleak
66110+ vulnerability for exploits targeting these structure types.
66111+
66112+ Enabling this feature will introduce some performance impact, slightly
66113+ increase memory usage, and prevent the use of forensic tools like
66114+ Volatility against the system (unless the kernel source tree isn't
66115+ cleaned after kernel installation).
66116+
66117+ The seed used for compilation is located at tools/gcc/randomize_layout_seed.h.
66118+ It remains after a make clean to allow for external modules to be compiled
66119+ with the existing seed and will be removed by a make mrproper or
66120+ make distclean.
66121+
66122+ Note that the implementation requires gcc 4.6.4. or newer. You may need
66123+ to install the supporting headers explicitly in addition to the normal
66124+ gcc package.
66125+
66126+config GRKERNSEC_RANDSTRUCT_PERFORMANCE
66127+ bool "Use cacheline-aware structure randomization"
66128+ depends on GRKERNSEC_RANDSTRUCT
66129+ default y if GRKERNSEC_CONFIG_PRIORITY_PERF
66130+ help
66131+ If you say Y here, the RANDSTRUCT randomization will make a best effort
66132+ at restricting randomization to cacheline-sized groups of elements. It
66133+ will further not randomize bitfields in structures. This reduces the
66134+ performance hit of RANDSTRUCT at the cost of weakened randomization.
66135+
66136+config GRKERNSEC_KERN_LOCKOUT
66137+ bool "Active kernel exploit response"
66138+ default y if GRKERNSEC_CONFIG_AUTO
66139+ depends on X86 || ARM || PPC || SPARC
66140+ help
66141+ If you say Y here, when a PaX alert is triggered due to suspicious
66142+ activity in the kernel (from KERNEXEC/UDEREF/USERCOPY)
66143+ or an OOPS occurs due to bad memory accesses, instead of just
66144+ terminating the offending process (and potentially allowing
66145+ a subsequent exploit from the same user), we will take one of two
66146+ actions:
66147+ If the user was root, we will panic the system
66148+ If the user was non-root, we will log the attempt, terminate
66149+ all processes owned by the user, then prevent them from creating
66150+ any new processes until the system is restarted
66151+ This deters repeated kernel exploitation/bruteforcing attempts
66152+ and is useful for later forensics.
66153+
66154+config GRKERNSEC_OLD_ARM_USERLAND
66155+ bool "Old ARM userland compatibility"
66156+ depends on ARM && (CPU_V6 || CPU_V6K || CPU_V7)
66157+ help
66158+ If you say Y here, stubs of executable code to perform such operations
66159+ as "compare-exchange" will be placed at fixed locations in the ARM vector
66160+ table. This is unfortunately needed for old ARM userland meant to run
66161+ across a wide range of processors. Without this option enabled,
66162+ the get_tls and data memory barrier stubs will be emulated by the kernel,
66163+ which is enough for Linaro userlands or other userlands designed for v6
66164+ and newer ARM CPUs. It's recommended that you try without this option enabled
66165+ first, and only enable it if your userland does not boot (it will likely fail
66166+ at init time).
66167+
66168+endmenu
66169+menu "Role Based Access Control Options"
66170+depends on GRKERNSEC
66171+
66172+config GRKERNSEC_RBAC_DEBUG
66173+ bool
66174+
66175+config GRKERNSEC_NO_RBAC
66176+ bool "Disable RBAC system"
66177+ help
66178+ If you say Y here, the /dev/grsec device will be removed from the kernel,
66179+ preventing the RBAC system from being enabled. You should only say Y
66180+ here if you have no intention of using the RBAC system, so as to prevent
66181+ an attacker with root access from misusing the RBAC system to hide files
66182+ and processes when loadable module support and /dev/[k]mem have been
66183+ locked down.
66184+
66185+config GRKERNSEC_ACL_HIDEKERN
66186+ bool "Hide kernel processes"
66187+ help
66188+ If you say Y here, all kernel threads will be hidden to all
66189+ processes but those whose subject has the "view hidden processes"
66190+ flag.
66191+
66192+config GRKERNSEC_ACL_MAXTRIES
66193+ int "Maximum tries before password lockout"
66194+ default 3
66195+ help
66196+ This option enforces the maximum number of times a user can attempt
66197+ to authorize themselves with the grsecurity RBAC system before being
66198+ denied the ability to attempt authorization again for a specified time.
66199+ The lower the number, the harder it will be to brute-force a password.
66200+
66201+config GRKERNSEC_ACL_TIMEOUT
66202+ int "Time to wait after max password tries, in seconds"
66203+ default 30
66204+ help
66205+ This option specifies the time the user must wait after attempting to
66206+ authorize to the RBAC system with the maximum number of invalid
66207+ passwords. The higher the number, the harder it will be to brute-force
66208+ a password.
66209+
66210+endmenu
66211+menu "Filesystem Protections"
66212+depends on GRKERNSEC
66213+
66214+config GRKERNSEC_PROC
66215+ bool "Proc restrictions"
66216+ default y if GRKERNSEC_CONFIG_AUTO
66217+ help
66218+ If you say Y here, the permissions of the /proc filesystem
66219+ will be altered to enhance system security and privacy. You MUST
66220+ choose either a user only restriction or a user and group restriction.
66221+ Depending upon the option you choose, you can either restrict users to
66222+ see only the processes they themselves run, or choose a group that can
66223+ view all processes and files normally restricted to root if you choose
66224+ the "restrict to user only" option. NOTE: If you're running identd or
66225+ ntpd as a non-root user, you will have to run it as the group you
66226+ specify here.
66227+
66228+config GRKERNSEC_PROC_USER
66229+ bool "Restrict /proc to user only"
66230+ depends on GRKERNSEC_PROC
66231+ help
66232+ If you say Y here, non-root users will only be able to view their own
66233+ processes, and restricts them from viewing network-related information,
66234+ and viewing kernel symbol and module information.
66235+
66236+config GRKERNSEC_PROC_USERGROUP
66237+ bool "Allow special group"
66238+ default y if GRKERNSEC_CONFIG_AUTO
66239+ depends on GRKERNSEC_PROC && !GRKERNSEC_PROC_USER
66240+ help
66241+ If you say Y here, you will be able to select a group that will be
66242+ able to view all processes and network-related information. If you've
66243+ enabled GRKERNSEC_HIDESYM, kernel and symbol information may still
66244+ remain hidden. This option is useful if you want to run identd as
66245+ a non-root user. The group you select may also be chosen at boot time
66246+ via "grsec_proc_gid=" on the kernel commandline.
66247+
66248+config GRKERNSEC_PROC_GID
66249+ int "GID for special group"
66250+ depends on GRKERNSEC_PROC_USERGROUP
66251+ default 1001
66252+
66253+config GRKERNSEC_PROC_ADD
66254+ bool "Additional restrictions"
66255+ default y if GRKERNSEC_CONFIG_AUTO
66256+ depends on GRKERNSEC_PROC_USER || GRKERNSEC_PROC_USERGROUP
66257+ help
66258+ If you say Y here, additional restrictions will be placed on
66259+ /proc that keep normal users from viewing device information and
66260+ slabinfo information that could be useful for exploits.
66261+
66262+config GRKERNSEC_LINK
66263+ bool "Linking restrictions"
66264+ default y if GRKERNSEC_CONFIG_AUTO
66265+ help
66266+ If you say Y here, /tmp race exploits will be prevented, since users
66267+ will no longer be able to follow symlinks owned by other users in
66268+ world-writable +t directories (e.g. /tmp), unless the owner of the
66269+ symlink is the owner of the directory. users will also not be
66270+ able to hardlink to files they do not own. If the sysctl option is
66271+ enabled, a sysctl option with name "linking_restrictions" is created.
66272+
66273+config GRKERNSEC_SYMLINKOWN
66274+ bool "Kernel-enforced SymlinksIfOwnerMatch"
66275+ default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
66276+ help
66277+ Apache's SymlinksIfOwnerMatch option has an inherent race condition
66278+ that prevents it from being used as a security feature. As Apache
66279+ verifies the symlink by performing a stat() against the target of
66280+ the symlink before it is followed, an attacker can setup a symlink
66281+ to point to a same-owned file, then replace the symlink with one
66282+ that targets another user's file just after Apache "validates" the
66283+ symlink -- a classic TOCTOU race. If you say Y here, a complete,
66284+ race-free replacement for Apache's "SymlinksIfOwnerMatch" option
66285+ will be in place for the group you specify. If the sysctl option
66286+ is enabled, a sysctl option with name "enforce_symlinksifowner" is
66287+ created.
66288+
66289+config GRKERNSEC_SYMLINKOWN_GID
66290+ int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
66291+ depends on GRKERNSEC_SYMLINKOWN
66292+ default 1006
66293+ help
66294+ Setting this GID determines what group kernel-enforced
66295+ SymlinksIfOwnerMatch will be enabled for. If the sysctl option
66296+ is enabled, a sysctl option with name "symlinkown_gid" is created.
66297+
66298+config GRKERNSEC_FIFO
66299+ bool "FIFO restrictions"
66300+ default y if GRKERNSEC_CONFIG_AUTO
66301+ help
66302+ If you say Y here, users will not be able to write to FIFOs they don't
66303+ own in world-writable +t directories (e.g. /tmp), unless the owner of
66304+ the FIFO is the same owner of the directory it's held in. If the sysctl
66305+ option is enabled, a sysctl option with name "fifo_restrictions" is
66306+ created.
66307+
66308+config GRKERNSEC_SYSFS_RESTRICT
66309+ bool "Sysfs/debugfs restriction"
66310+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
66311+ depends on SYSFS
66312+ help
66313+ If you say Y here, sysfs (the pseudo-filesystem mounted at /sys) and
66314+ any filesystem normally mounted under it (e.g. debugfs) will be
66315+ mostly accessible only by root. These filesystems generally provide access
66316+ to hardware and debug information that isn't appropriate for unprivileged
66317+ users of the system. Sysfs and debugfs have also become a large source
66318+ of new vulnerabilities, ranging from infoleaks to local compromise.
66319+ There has been very little oversight with an eye toward security involved
66320+ in adding new exporters of information to these filesystems, so their
66321+ use is discouraged.
66322+ For reasons of compatibility, a few directories have been whitelisted
66323+ for access by non-root users:
66324+ /sys/fs/selinux
66325+ /sys/fs/fuse
66326+ /sys/devices/system/cpu
66327+
66328+config GRKERNSEC_ROFS
66329+ bool "Runtime read-only mount protection"
66330+ depends on SYSCTL
66331+ help
66332+ If you say Y here, a sysctl option with name "romount_protect" will
66333+ be created. By setting this option to 1 at runtime, filesystems
66334+ will be protected in the following ways:
66335+ * No new writable mounts will be allowed
66336+ * Existing read-only mounts won't be able to be remounted read/write
66337+ * Write operations will be denied on all block devices
66338+ This option acts independently of grsec_lock: once it is set to 1,
66339+ it cannot be turned off. Therefore, please be mindful of the resulting
66340+ behavior if this option is enabled in an init script on a read-only
66341+ filesystem.
66342+ Also be aware that as with other root-focused features, GRKERNSEC_KMEM
66343+ and GRKERNSEC_IO should be enabled and module loading disabled via
66344+ config or at runtime.
66345+ This feature is mainly intended for secure embedded systems.
66346+
66347+
66348+config GRKERNSEC_DEVICE_SIDECHANNEL
66349+ bool "Eliminate stat/notify-based device sidechannels"
66350+ default y if GRKERNSEC_CONFIG_AUTO
66351+ help
66352+ If you say Y here, timing analyses on block or character
66353+ devices like /dev/ptmx using stat or inotify/dnotify/fanotify
66354+ will be thwarted for unprivileged users. If a process without
66355+ CAP_MKNOD stats such a device, the last access and last modify times
66356+ will match the device's create time. No access or modify events
66357+ will be triggered through inotify/dnotify/fanotify for such devices.
66358+ This feature will prevent attacks that may at a minimum
66359+ allow an attacker to determine the administrator's password length.
66360+
66361+config GRKERNSEC_CHROOT
66362+ bool "Chroot jail restrictions"
66363+ default y if GRKERNSEC_CONFIG_AUTO
66364+ help
66365+ If you say Y here, you will be able to choose several options that will
66366+ make breaking out of a chrooted jail much more difficult. If you
66367+ encounter no software incompatibilities with the following options, it
66368+ is recommended that you enable each one.
66369+
66370+ Note that the chroot restrictions are not intended to apply to "chroots"
66371+ to directories that are simple bind mounts of the global root filesystem.
66372+ For several other reasons, a user shouldn't expect any significant
66373+ security by performing such a chroot.
66374+
66375+config GRKERNSEC_CHROOT_MOUNT
66376+ bool "Deny mounts"
66377+ default y if GRKERNSEC_CONFIG_AUTO
66378+ depends on GRKERNSEC_CHROOT
66379+ help
66380+ If you say Y here, processes inside a chroot will not be able to
66381+ mount or remount filesystems. If the sysctl option is enabled, a
66382+ sysctl option with name "chroot_deny_mount" is created.
66383+
66384+config GRKERNSEC_CHROOT_DOUBLE
66385+ bool "Deny double-chroots"
66386+ default y if GRKERNSEC_CONFIG_AUTO
66387+ depends on GRKERNSEC_CHROOT
66388+ help
66389+ If you say Y here, processes inside a chroot will not be able to chroot
66390+ again outside the chroot. This is a widely used method of breaking
66391+ out of a chroot jail and should not be allowed. If the sysctl
66392+ option is enabled, a sysctl option with name
66393+ "chroot_deny_chroot" is created.
66394+
66395+config GRKERNSEC_CHROOT_PIVOT
66396+ bool "Deny pivot_root in chroot"
66397+ default y if GRKERNSEC_CONFIG_AUTO
66398+ depends on GRKERNSEC_CHROOT
66399+ help
66400+ If you say Y here, processes inside a chroot will not be able to use
66401+ a function called pivot_root() that was introduced in Linux 2.3.41. It
66402+ works similar to chroot in that it changes the root filesystem. This
66403+ function could be misused in a chrooted process to attempt to break out
66404+ of the chroot, and therefore should not be allowed. If the sysctl
66405+ option is enabled, a sysctl option with name "chroot_deny_pivot" is
66406+ created.
66407+
66408+config GRKERNSEC_CHROOT_CHDIR
66409+ bool "Enforce chdir(\"/\") on all chroots"
66410+ default y if GRKERNSEC_CONFIG_AUTO
66411+ depends on GRKERNSEC_CHROOT
66412+ help
66413+ If you say Y here, the current working directory of all newly-chrooted
66414+ applications will be set to the the root directory of the chroot.
66415+ The man page on chroot(2) states:
66416+ Note that this call does not change the current working
66417+ directory, so that `.' can be outside the tree rooted at
66418+ `/'. In particular, the super-user can escape from a
66419+ `chroot jail' by doing `mkdir foo; chroot foo; cd ..'.
66420+
66421+ It is recommended that you say Y here, since it's not known to break
66422+ any software. If the sysctl option is enabled, a sysctl option with
66423+ name "chroot_enforce_chdir" is created.
66424+
66425+config GRKERNSEC_CHROOT_CHMOD
66426+ bool "Deny (f)chmod +s"
66427+ default y if GRKERNSEC_CONFIG_AUTO
66428+ depends on GRKERNSEC_CHROOT
66429+ help
66430+ If you say Y here, processes inside a chroot will not be able to chmod
66431+ or fchmod files to make them have suid or sgid bits. This protects
66432+ against another published method of breaking a chroot. If the sysctl
66433+ option is enabled, a sysctl option with name "chroot_deny_chmod" is
66434+ created.
66435+
66436+config GRKERNSEC_CHROOT_FCHDIR
66437+ bool "Deny fchdir out of chroot"
66438+ default y if GRKERNSEC_CONFIG_AUTO
66439+ depends on GRKERNSEC_CHROOT
66440+ help
66441+ If you say Y here, a well-known method of breaking chroots by fchdir'ing
66442+ to a file descriptor of the chrooting process that points to a directory
66443+ outside the filesystem will be stopped. If the sysctl option
66444+ is enabled, a sysctl option with name "chroot_deny_fchdir" is created.
66445+
66446+config GRKERNSEC_CHROOT_MKNOD
66447+ bool "Deny mknod"
66448+ default y if GRKERNSEC_CONFIG_AUTO
66449+ depends on GRKERNSEC_CHROOT
66450+ help
66451+ If you say Y here, processes inside a chroot will not be allowed to
66452+ mknod. The problem with using mknod inside a chroot is that it
66453+ would allow an attacker to create a device entry that is the same
66454+ as one on the physical root of your system, which could range from
66455+ anything from the console device to a device for your harddrive (which
66456+ they could then use to wipe the drive or steal data). It is recommended
66457+ that you say Y here, unless you run into software incompatibilities.
66458+ If the sysctl option is enabled, a sysctl option with name
66459+ "chroot_deny_mknod" is created.
66460+
66461+config GRKERNSEC_CHROOT_SHMAT
66462+ bool "Deny shmat() out of chroot"
66463+ default y if GRKERNSEC_CONFIG_AUTO
66464+ depends on GRKERNSEC_CHROOT
66465+ help
66466+ If you say Y here, processes inside a chroot will not be able to attach
66467+ to shared memory segments that were created outside of the chroot jail.
66468+ It is recommended that you say Y here. If the sysctl option is enabled,
66469+ a sysctl option with name "chroot_deny_shmat" is created.
66470+
66471+config GRKERNSEC_CHROOT_UNIX
66472+ bool "Deny access to abstract AF_UNIX sockets out of chroot"
66473+ default y if GRKERNSEC_CONFIG_AUTO
66474+ depends on GRKERNSEC_CHROOT
66475+ help
66476+ If you say Y here, processes inside a chroot will not be able to
66477+ connect to abstract (meaning not belonging to a filesystem) Unix
66478+ domain sockets that were bound outside of a chroot. It is recommended
66479+ that you say Y here. If the sysctl option is enabled, a sysctl option
66480+ with name "chroot_deny_unix" is created.
66481+
66482+config GRKERNSEC_CHROOT_FINDTASK
66483+ bool "Protect outside processes"
66484+ default y if GRKERNSEC_CONFIG_AUTO
66485+ depends on GRKERNSEC_CHROOT
66486+ help
66487+ If you say Y here, processes inside a chroot will not be able to
66488+ kill, send signals with fcntl, ptrace, capget, getpgid, setpgid,
66489+ getsid, or view any process outside of the chroot. If the sysctl
66490+ option is enabled, a sysctl option with name "chroot_findtask" is
66491+ created.
66492+
66493+config GRKERNSEC_CHROOT_NICE
66494+ bool "Restrict priority changes"
66495+ default y if GRKERNSEC_CONFIG_AUTO
66496+ depends on GRKERNSEC_CHROOT
66497+ help
66498+ If you say Y here, processes inside a chroot will not be able to raise
66499+ the priority of processes in the chroot, or alter the priority of
66500+ processes outside the chroot. This provides more security than simply
66501+ removing CAP_SYS_NICE from the process' capability set. If the
66502+ sysctl option is enabled, a sysctl option with name "chroot_restrict_nice"
66503+ is created.
66504+
66505+config GRKERNSEC_CHROOT_SYSCTL
66506+ bool "Deny sysctl writes"
66507+ default y if GRKERNSEC_CONFIG_AUTO
66508+ depends on GRKERNSEC_CHROOT
66509+ help
66510+ If you say Y here, an attacker in a chroot will not be able to
66511+ write to sysctl entries, either by sysctl(2) or through a /proc
66512+ interface. It is strongly recommended that you say Y here. If the
66513+ sysctl option is enabled, a sysctl option with name
66514+ "chroot_deny_sysctl" is created.
66515+
66516+config GRKERNSEC_CHROOT_CAPS
66517+ bool "Capability restrictions"
66518+ default y if GRKERNSEC_CONFIG_AUTO
66519+ depends on GRKERNSEC_CHROOT
66520+ help
66521+ If you say Y here, the capabilities on all processes within a
66522+ chroot jail will be lowered to stop module insertion, raw i/o,
66523+ system and net admin tasks, rebooting the system, modifying immutable
66524+ files, modifying IPC owned by another, and changing the system time.
66525+ This is left an option because it can break some apps. Disable this
66526+ if your chrooted apps are having problems performing those kinds of
66527+ tasks. If the sysctl option is enabled, a sysctl option with
66528+ name "chroot_caps" is created.
66529+
66530+config GRKERNSEC_CHROOT_INITRD
66531+ bool "Exempt initrd tasks from restrictions"
66532+ default y if GRKERNSEC_CONFIG_AUTO
66533+ depends on GRKERNSEC_CHROOT && BLK_DEV_INITRD
66534+ help
66535+ If you say Y here, tasks started prior to init will be exempted from
66536+ grsecurity's chroot restrictions. This option is mainly meant to
66537+ resolve Plymouth's performing privileged operations unnecessarily
66538+ in a chroot.
66539+
66540+endmenu
66541+menu "Kernel Auditing"
66542+depends on GRKERNSEC
66543+
66544+config GRKERNSEC_AUDIT_GROUP
66545+ bool "Single group for auditing"
66546+ help
66547+ If you say Y here, the exec and chdir logging features will only operate
66548+ on a group you specify. This option is recommended if you only want to
66549+ watch certain users instead of having a large amount of logs from the
66550+ entire system. If the sysctl option is enabled, a sysctl option with
66551+ name "audit_group" is created.
66552+
66553+config GRKERNSEC_AUDIT_GID
66554+ int "GID for auditing"
66555+ depends on GRKERNSEC_AUDIT_GROUP
66556+ default 1007
66557+
66558+config GRKERNSEC_EXECLOG
66559+ bool "Exec logging"
66560+ help
66561+ If you say Y here, all execve() calls will be logged (since the
66562+ other exec*() calls are frontends to execve(), all execution
66563+ will be logged). Useful for shell-servers that like to keep track
66564+ of their users. If the sysctl option is enabled, a sysctl option with
66565+ name "exec_logging" is created.
66566+ WARNING: This option when enabled will produce a LOT of logs, especially
66567+ on an active system.
66568+
66569+config GRKERNSEC_RESLOG
66570+ bool "Resource logging"
66571+ default y if GRKERNSEC_CONFIG_AUTO
66572+ help
66573+ If you say Y here, all attempts to overstep resource limits will
66574+ be logged with the resource name, the requested size, and the current
66575+ limit. It is highly recommended that you say Y here. If the sysctl
66576+ option is enabled, a sysctl option with name "resource_logging" is
66577+ created. If the RBAC system is enabled, the sysctl value is ignored.
66578+
66579+config GRKERNSEC_CHROOT_EXECLOG
66580+ bool "Log execs within chroot"
66581+ help
66582+ If you say Y here, all executions inside a chroot jail will be logged
66583+ to syslog. This can cause a large amount of logs if certain
66584+ applications (eg. djb's daemontools) are installed on the system, and
66585+ is therefore left as an option. If the sysctl option is enabled, a
66586+ sysctl option with name "chroot_execlog" is created.
66587+
66588+config GRKERNSEC_AUDIT_PTRACE
66589+ bool "Ptrace logging"
66590+ help
66591+ If you say Y here, all attempts to attach to a process via ptrace
66592+ will be logged. If the sysctl option is enabled, a sysctl option
66593+ with name "audit_ptrace" is created.
66594+
66595+config GRKERNSEC_AUDIT_CHDIR
66596+ bool "Chdir logging"
66597+ help
66598+ If you say Y here, all chdir() calls will be logged. If the sysctl
66599+ option is enabled, a sysctl option with name "audit_chdir" is created.
66600+
66601+config GRKERNSEC_AUDIT_MOUNT
66602+ bool "(Un)Mount logging"
66603+ help
66604+ If you say Y here, all mounts and unmounts will be logged. If the
66605+ sysctl option is enabled, a sysctl option with name "audit_mount" is
66606+ created.
66607+
66608+config GRKERNSEC_SIGNAL
66609+ bool "Signal logging"
66610+ default y if GRKERNSEC_CONFIG_AUTO
66611+ help
66612+ If you say Y here, certain important signals will be logged, such as
66613+ SIGSEGV, which will as a result inform you of when a error in a program
66614+ occurred, which in some cases could mean a possible exploit attempt.
66615+ If the sysctl option is enabled, a sysctl option with name
66616+ "signal_logging" is created.
66617+
66618+config GRKERNSEC_FORKFAIL
66619+ bool "Fork failure logging"
66620+ help
66621+ If you say Y here, all failed fork() attempts will be logged.
66622+ This could suggest a fork bomb, or someone attempting to overstep
66623+ their process limit. If the sysctl option is enabled, a sysctl option
66624+ with name "forkfail_logging" is created.
66625+
66626+config GRKERNSEC_TIME
66627+ bool "Time change logging"
66628+ default y if GRKERNSEC_CONFIG_AUTO
66629+ help
66630+ If you say Y here, any changes of the system clock will be logged.
66631+ If the sysctl option is enabled, a sysctl option with name
66632+ "timechange_logging" is created.
66633+
66634+config GRKERNSEC_PROC_IPADDR
66635+ bool "/proc/<pid>/ipaddr support"
66636+ default y if GRKERNSEC_CONFIG_AUTO
66637+ help
66638+ If you say Y here, a new entry will be added to each /proc/<pid>
66639+ directory that contains the IP address of the person using the task.
66640+ The IP is carried across local TCP and AF_UNIX stream sockets.
66641+ This information can be useful for IDS/IPSes to perform remote response
66642+ to a local attack. The entry is readable by only the owner of the
66643+ process (and root if he has CAP_DAC_OVERRIDE, which can be removed via
66644+ the RBAC system), and thus does not create privacy concerns.
66645+
66646+config GRKERNSEC_RWXMAP_LOG
66647+ bool 'Denied RWX mmap/mprotect logging'
66648+ default y if GRKERNSEC_CONFIG_AUTO
66649+ depends on PAX_MPROTECT && !PAX_EMUPLT && !PAX_EMUSIGRT
66650+ help
66651+ If you say Y here, calls to mmap() and mprotect() with explicit
66652+ usage of PROT_WRITE and PROT_EXEC together will be logged when
66653+ denied by the PAX_MPROTECT feature. This feature will also
66654+ log other problematic scenarios that can occur when PAX_MPROTECT
66655+ is enabled on a binary, like textrels and PT_GNU_STACK. If the
66656+ sysctl option is enabled, a sysctl option with name "rwxmap_logging"
66657+ is created.
66658+
66659+endmenu
66660+
66661+menu "Executable Protections"
66662+depends on GRKERNSEC
66663+
66664+config GRKERNSEC_DMESG
66665+ bool "Dmesg(8) restriction"
66666+ default y if GRKERNSEC_CONFIG_AUTO
66667+ help
66668+ If you say Y here, non-root users will not be able to use dmesg(8)
66669+ to view the contents of the kernel's circular log buffer.
66670+ The kernel's log buffer often contains kernel addresses and other
66671+ identifying information useful to an attacker in fingerprinting a
66672+ system for a targeted exploit.
66673+ If the sysctl option is enabled, a sysctl option with name "dmesg" is
66674+ created.
66675+
66676+config GRKERNSEC_HARDEN_PTRACE
66677+ bool "Deter ptrace-based process snooping"
66678+ default y if GRKERNSEC_CONFIG_AUTO
66679+ help
66680+ If you say Y here, TTY sniffers and other malicious monitoring
66681+ programs implemented through ptrace will be defeated. If you
66682+ have been using the RBAC system, this option has already been
66683+ enabled for several years for all users, with the ability to make
66684+ fine-grained exceptions.
66685+
66686+ This option only affects the ability of non-root users to ptrace
66687+ processes that are not a descendent of the ptracing process.
66688+ This means that strace ./binary and gdb ./binary will still work,
66689+ but attaching to arbitrary processes will not. If the sysctl
66690+ option is enabled, a sysctl option with name "harden_ptrace" is
66691+ created.
66692+
66693+config GRKERNSEC_PTRACE_READEXEC
66694+ bool "Require read access to ptrace sensitive binaries"
66695+ default y if GRKERNSEC_CONFIG_AUTO
66696+ help
66697+ If you say Y here, unprivileged users will not be able to ptrace unreadable
66698+ binaries. This option is useful in environments that
66699+ remove the read bits (e.g. file mode 4711) from suid binaries to
66700+ prevent infoleaking of their contents. This option adds
66701+ consistency to the use of that file mode, as the binary could normally
66702+ be read out when run without privileges while ptracing.
66703+
66704+ If the sysctl option is enabled, a sysctl option with name "ptrace_readexec"
66705+ is created.
66706+
66707+config GRKERNSEC_SETXID
66708+ bool "Enforce consistent multithreaded privileges"
66709+ default y if GRKERNSEC_CONFIG_AUTO
66710+ depends on (X86 || SPARC64 || PPC || ARM || MIPS)
66711+ help
66712+ If you say Y here, a change from a root uid to a non-root uid
66713+ in a multithreaded application will cause the resulting uids,
66714+ gids, supplementary groups, and capabilities in that thread
66715+ to be propagated to the other threads of the process. In most
66716+ cases this is unnecessary, as glibc will emulate this behavior
66717+ on behalf of the application. Other libcs do not act in the
66718+ same way, allowing the other threads of the process to continue
66719+ running with root privileges. If the sysctl option is enabled,
66720+ a sysctl option with name "consistent_setxid" is created.
66721+
66722+config GRKERNSEC_HARDEN_IPC
66723+ bool "Disallow access to overly-permissive IPC objects"
66724+ default y if GRKERNSEC_CONFIG_AUTO
66725+ depends on SYSVIPC
66726+ help
66727+ If you say Y here, access to overly-permissive IPC objects (shared
66728+ memory, message queues, and semaphores) will be denied for processes
66729+ given the following criteria beyond normal permission checks:
66730+ 1) If the IPC object is world-accessible and the euid doesn't match
66731+ that of the creator or current uid for the IPC object
66732+ 2) If the IPC object is group-accessible and the egid doesn't
66733+ match that of the creator or current gid for the IPC object
66734+ It's a common error to grant too much permission to these objects,
66735+ with impact ranging from denial of service and information leaking to
66736+ privilege escalation. This feature was developed in response to
66737+ research by Tim Brown:
66738+ http://labs.portcullis.co.uk/whitepapers/memory-squatting-attacks-on-system-v-shared-memory/
66739+ who found hundreds of such insecure usages. Processes with
66740+ CAP_IPC_OWNER are still permitted to access these IPC objects.
66741+ If the sysctl option is enabled, a sysctl option with name
66742+ "harden_ipc" is created.
66743+
66744+config GRKERNSEC_TPE
66745+ bool "Trusted Path Execution (TPE)"
66746+ default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
66747+ help
66748+ If you say Y here, you will be able to choose a gid to add to the
66749+ supplementary groups of users you want to mark as "untrusted."
66750+ These users will not be able to execute any files that are not in
66751+ root-owned directories writable only by root. If the sysctl option
66752+ is enabled, a sysctl option with name "tpe" is created.
66753+
66754+config GRKERNSEC_TPE_ALL
66755+ bool "Partially restrict all non-root users"
66756+ depends on GRKERNSEC_TPE
66757+ help
66758+ If you say Y here, all non-root users will be covered under
66759+ a weaker TPE restriction. This is separate from, and in addition to,
66760+ the main TPE options that you have selected elsewhere. Thus, if a
66761+ "trusted" GID is chosen, this restriction applies to even that GID.
66762+ Under this restriction, all non-root users will only be allowed to
66763+ execute files in directories they own that are not group or
66764+ world-writable, or in directories owned by root and writable only by
66765+ root. If the sysctl option is enabled, a sysctl option with name
66766+ "tpe_restrict_all" is created.
66767+
66768+config GRKERNSEC_TPE_INVERT
66769+ bool "Invert GID option"
66770+ depends on GRKERNSEC_TPE
66771+ help
66772+ If you say Y here, the group you specify in the TPE configuration will
66773+ decide what group TPE restrictions will be *disabled* for. This
66774+ option is useful if you want TPE restrictions to be applied to most
66775+ users on the system. If the sysctl option is enabled, a sysctl option
66776+ with name "tpe_invert" is created. Unlike other sysctl options, this
66777+ entry will default to on for backward-compatibility.
66778+
66779+config GRKERNSEC_TPE_GID
66780+ int
66781+ default GRKERNSEC_TPE_UNTRUSTED_GID if (GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT)
66782+ default GRKERNSEC_TPE_TRUSTED_GID if (GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT)
66783+
66784+config GRKERNSEC_TPE_UNTRUSTED_GID
66785+ int "GID for TPE-untrusted users"
66786+ depends on GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
66787+ default 1005
66788+ help
66789+ Setting this GID determines what group TPE restrictions will be
66790+ *enabled* for. If the sysctl option is enabled, a sysctl option
66791+ with name "tpe_gid" is created.
66792+
66793+config GRKERNSEC_TPE_TRUSTED_GID
66794+ int "GID for TPE-trusted users"
66795+ depends on GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
66796+ default 1005
66797+ help
66798+ Setting this GID determines what group TPE restrictions will be
66799+ *disabled* for. If the sysctl option is enabled, a sysctl option
66800+ with name "tpe_gid" is created.
66801+
66802+endmenu
66803+menu "Network Protections"
66804+depends on GRKERNSEC
66805+
66806+config GRKERNSEC_RANDNET
66807+ bool "Larger entropy pools"
66808+ default y if GRKERNSEC_CONFIG_AUTO
66809+ help
66810+ If you say Y here, the entropy pools used for many features of Linux
66811+ and grsecurity will be doubled in size. Since several grsecurity
66812+ features use additional randomness, it is recommended that you say Y
66813+ here. Saying Y here has a similar effect as modifying
66814+ /proc/sys/kernel/random/poolsize.
66815+
66816+config GRKERNSEC_BLACKHOLE
66817+ bool "TCP/UDP blackhole and LAST_ACK DoS prevention"
66818+ default y if GRKERNSEC_CONFIG_AUTO
66819+ depends on NET
66820+ help
66821+ If you say Y here, neither TCP resets nor ICMP
66822+ destination-unreachable packets will be sent in response to packets
66823+ sent to ports for which no associated listening process exists.
66824+ This feature supports both IPV4 and IPV6 and exempts the
66825+ loopback interface from blackholing. Enabling this feature
66826+ makes a host more resilient to DoS attacks and reduces network
66827+ visibility against scanners.
66828+
66829+ The blackhole feature as-implemented is equivalent to the FreeBSD
66830+ blackhole feature, as it prevents RST responses to all packets, not
66831+ just SYNs. Under most application behavior this causes no
66832+ problems, but applications (like haproxy) may not close certain
66833+ connections in a way that cleanly terminates them on the remote
66834+ end, leaving the remote host in LAST_ACK state. Because of this
66835+ side-effect and to prevent intentional LAST_ACK DoSes, this
66836+ feature also adds automatic mitigation against such attacks.
66837+ The mitigation drastically reduces the amount of time a socket
66838+ can spend in LAST_ACK state. If you're using haproxy and not
66839+ all servers it connects to have this option enabled, consider
66840+ disabling this feature on the haproxy host.
66841+
66842+ If the sysctl option is enabled, two sysctl options with names
66843+ "ip_blackhole" and "lastack_retries" will be created.
66844+ While "ip_blackhole" takes the standard zero/non-zero on/off
66845+ toggle, "lastack_retries" uses the same kinds of values as
66846+ "tcp_retries1" and "tcp_retries2". The default value of 4
66847+ prevents a socket from lasting more than 45 seconds in LAST_ACK
66848+ state.
66849+
66850+config GRKERNSEC_NO_SIMULT_CONNECT
66851+ bool "Disable TCP Simultaneous Connect"
66852+ default y if GRKERNSEC_CONFIG_AUTO
66853+ depends on NET
66854+ help
66855+ If you say Y here, a feature by Willy Tarreau will be enabled that
66856+ removes a weakness in Linux's strict implementation of TCP that
66857+ allows two clients to connect to each other without either entering
66858+ a listening state. The weakness allows an attacker to easily prevent
66859+ a client from connecting to a known server provided the source port
66860+ for the connection is guessed correctly.
66861+
66862+ As the weakness could be used to prevent an antivirus or IPS from
66863+ fetching updates, or prevent an SSL gateway from fetching a CRL,
66864+ it should be eliminated by enabling this option. Though Linux is
66865+ one of few operating systems supporting simultaneous connect, it
66866+ has no legitimate use in practice and is rarely supported by firewalls.
66867+
66868+config GRKERNSEC_SOCKET
66869+ bool "Socket restrictions"
66870+ depends on NET
66871+ help
66872+ If you say Y here, you will be able to choose from several options.
66873+ If you assign a GID on your system and add it to the supplementary
66874+ groups of users you want to restrict socket access to, this patch
66875+ will perform up to three things, based on the option(s) you choose.
66876+
66877+config GRKERNSEC_SOCKET_ALL
66878+ bool "Deny any sockets to group"
66879+ depends on GRKERNSEC_SOCKET
66880+ help
66881+ If you say Y here, you will be able to choose a GID of whose users will
66882+ be unable to connect to other hosts from your machine or run server
66883+ applications from your machine. If the sysctl option is enabled, a
66884+ sysctl option with name "socket_all" is created.
66885+
66886+config GRKERNSEC_SOCKET_ALL_GID
66887+ int "GID to deny all sockets for"
66888+ depends on GRKERNSEC_SOCKET_ALL
66889+ default 1004
66890+ help
66891+ Here you can choose the GID to disable socket access for. Remember to
66892+ add the users you want socket access disabled for to the GID
66893+ specified here. If the sysctl option is enabled, a sysctl option
66894+ with name "socket_all_gid" is created.
66895+
66896+config GRKERNSEC_SOCKET_CLIENT
66897+ bool "Deny client sockets to group"
66898+ depends on GRKERNSEC_SOCKET
66899+ help
66900+ If you say Y here, you will be able to choose a GID of whose users will
66901+ be unable to connect to other hosts from your machine, but will be
66902+ able to run servers. If this option is enabled, all users in the group
66903+ you specify will have to use passive mode when initiating ftp transfers
66904+ from the shell on your machine. If the sysctl option is enabled, a
66905+ sysctl option with name "socket_client" is created.
66906+
66907+config GRKERNSEC_SOCKET_CLIENT_GID
66908+ int "GID to deny client sockets for"
66909+ depends on GRKERNSEC_SOCKET_CLIENT
66910+ default 1003
66911+ help
66912+ Here you can choose the GID to disable client socket access for.
66913+ Remember to add the users you want client socket access disabled for to
66914+ the GID specified here. If the sysctl option is enabled, a sysctl
66915+ option with name "socket_client_gid" is created.
66916+
66917+config GRKERNSEC_SOCKET_SERVER
66918+ bool "Deny server sockets to group"
66919+ depends on GRKERNSEC_SOCKET
66920+ help
66921+ If you say Y here, you will be able to choose a GID of whose users will
66922+ be unable to run server applications from your machine. If the sysctl
66923+ option is enabled, a sysctl option with name "socket_server" is created.
66924+
66925+config GRKERNSEC_SOCKET_SERVER_GID
66926+ int "GID to deny server sockets for"
66927+ depends on GRKERNSEC_SOCKET_SERVER
66928+ default 1002
66929+ help
66930+ Here you can choose the GID to disable server socket access for.
66931+ Remember to add the users you want server socket access disabled for to
66932+ the GID specified here. If the sysctl option is enabled, a sysctl
66933+ option with name "socket_server_gid" is created.
66934+
66935+endmenu
66936+
66937+menu "Physical Protections"
66938+depends on GRKERNSEC
66939+
66940+config GRKERNSEC_DENYUSB
66941+ bool "Deny new USB connections after toggle"
66942+ default y if GRKERNSEC_CONFIG_AUTO
66943+ depends on SYSCTL && USB_SUPPORT
66944+ help
66945+ If you say Y here, a new sysctl option with name "deny_new_usb"
66946+ will be created. Setting its value to 1 will prevent any new
66947+ USB devices from being recognized by the OS. Any attempted USB
66948+ device insertion will be logged. This option is intended to be
66949+ used against custom USB devices designed to exploit vulnerabilities
66950+ in various USB device drivers.
66951+
66952+ For greatest effectiveness, this sysctl should be set after any
66953+ relevant init scripts. This option is safe to enable in distros
66954+ as each user can choose whether or not to toggle the sysctl.
66955+
66956+config GRKERNSEC_DENYUSB_FORCE
66957+ bool "Reject all USB devices not connected at boot"
66958+ select USB
66959+ depends on GRKERNSEC_DENYUSB
66960+ help
66961+ If you say Y here, a variant of GRKERNSEC_DENYUSB will be enabled
66962+ that doesn't involve a sysctl entry. This option should only be
66963+ enabled if you're sure you want to deny all new USB connections
66964+ at runtime and don't want to modify init scripts. This should not
66965+ be enabled by distros. It forces the core USB code to be built
66966+ into the kernel image so that all devices connected at boot time
66967+ can be recognized and new USB device connections can be prevented
66968+ prior to init running.
66969+
66970+endmenu
66971+
66972+menu "Sysctl Support"
66973+depends on GRKERNSEC && SYSCTL
66974+
66975+config GRKERNSEC_SYSCTL
66976+ bool "Sysctl support"
66977+ default y if GRKERNSEC_CONFIG_AUTO
66978+ help
66979+ If you say Y here, you will be able to change the options that
66980+ grsecurity runs with at bootup, without having to recompile your
66981+ kernel. You can echo values to files in /proc/sys/kernel/grsecurity
66982+ to enable (1) or disable (0) various features. All the sysctl entries
66983+ are mutable until the "grsec_lock" entry is set to a non-zero value.
66984+ All features enabled in the kernel configuration are disabled at boot
66985+ if you do not say Y to the "Turn on features by default" option.
66986+ All options should be set at startup, and the grsec_lock entry should
66987+ be set to a non-zero value after all the options are set.
66988+ *THIS IS EXTREMELY IMPORTANT*
66989+
66990+config GRKERNSEC_SYSCTL_DISTRO
66991+ bool "Extra sysctl support for distro makers (READ HELP)"
66992+ depends on GRKERNSEC_SYSCTL && GRKERNSEC_IO
66993+ help
66994+ If you say Y here, additional sysctl options will be created
66995+ for features that affect processes running as root. Therefore,
66996+ it is critical when using this option that the grsec_lock entry be
66997+ enabled after boot. Only distros with prebuilt kernel packages
66998+ with this option enabled that can ensure grsec_lock is enabled
66999+ after boot should use this option.
67000+ *Failure to set grsec_lock after boot makes all grsec features
67001+ this option covers useless*
67002+
67003+ Currently this option creates the following sysctl entries:
67004+ "Disable Privileged I/O": "disable_priv_io"
67005+
67006+config GRKERNSEC_SYSCTL_ON
67007+ bool "Turn on features by default"
67008+ default y if GRKERNSEC_CONFIG_AUTO
67009+ depends on GRKERNSEC_SYSCTL
67010+ help
67011+ If you say Y here, instead of having all features enabled in the
67012+ kernel configuration disabled at boot time, the features will be
67013+ enabled at boot time. It is recommended you say Y here unless
67014+ there is some reason you would want all sysctl-tunable features to
67015+ be disabled by default. As mentioned elsewhere, it is important
67016+ to enable the grsec_lock entry once you have finished modifying
67017+ the sysctl entries.
67018+
67019+endmenu
67020+menu "Logging Options"
67021+depends on GRKERNSEC
67022+
67023+config GRKERNSEC_FLOODTIME
67024+ int "Seconds in between log messages (minimum)"
67025+ default 10
67026+ help
67027+ This option allows you to enforce the number of seconds between
67028+ grsecurity log messages. The default should be suitable for most
67029+ people, however, if you choose to change it, choose a value small enough
67030+ to allow informative logs to be produced, but large enough to
67031+ prevent flooding.
67032+
67033+ Setting both this value and GRKERNSEC_FLOODBURST to 0 will disable
67034+ any rate limiting on grsecurity log messages.
67035+
67036+config GRKERNSEC_FLOODBURST
67037+ int "Number of messages in a burst (maximum)"
67038+ default 6
67039+ help
67040+ This option allows you to choose the maximum number of messages allowed
67041+ within the flood time interval you chose in a separate option. The
67042+ default should be suitable for most people, however if you find that
67043+ many of your logs are being interpreted as flooding, you may want to
67044+ raise this value.
67045+
67046+ Setting both this value and GRKERNSEC_FLOODTIME to 0 will disable
67047+ any rate limiting on grsecurity log messages.
67048+
67049+endmenu
67050diff --git a/grsecurity/Makefile b/grsecurity/Makefile
67051new file mode 100644
67052index 0000000..30ababb
67053--- /dev/null
67054+++ b/grsecurity/Makefile
67055@@ -0,0 +1,54 @@
67056+# grsecurity – access control and security hardening for Linux
67057+# All code in this directory and various hooks located throughout the Linux kernel are
67058+# Copyright (C) 2001-2014 Bradley Spengler, Open Source Security, Inc.
67059+# http://www.grsecurity.net spender@grsecurity.net
67060+#
67061+# This program is free software; you can redistribute it and/or
67062+# modify it under the terms of the GNU General Public License version 2
67063+# as published by the Free Software Foundation.
67064+#
67065+# This program is distributed in the hope that it will be useful,
67066+# but WITHOUT ANY WARRANTY; without even the implied warranty of
67067+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
67068+# GNU General Public License for more details.
67069+#
67070+# You should have received a copy of the GNU General Public License
67071+# along with this program; if not, write to the Free Software
67072+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
67073+
67074+KBUILD_CFLAGS += -Werror
67075+
67076+obj-y = grsec_chdir.o grsec_chroot.o grsec_exec.o grsec_fifo.o grsec_fork.o \
67077+ grsec_mount.o grsec_sig.o grsec_sysctl.o \
67078+ grsec_time.o grsec_tpe.o grsec_link.o grsec_pax.o grsec_ptrace.o \
67079+ grsec_usb.o grsec_ipc.o grsec_proc.o
67080+
67081+obj-$(CONFIG_GRKERNSEC) += grsec_init.o grsum.o gracl.o gracl_segv.o \
67082+ gracl_cap.o gracl_alloc.o gracl_shm.o grsec_mem.o gracl_fs.o \
67083+ gracl_learn.o grsec_log.o gracl_policy.o
67084+ifdef CONFIG_COMPAT
67085+obj-$(CONFIG_GRKERNSEC) += gracl_compat.o
67086+endif
67087+
67088+obj-$(CONFIG_GRKERNSEC_RESLOG) += gracl_res.o
67089+
67090+ifdef CONFIG_NET
67091+obj-y += grsec_sock.o
67092+obj-$(CONFIG_GRKERNSEC) += gracl_ip.o
67093+endif
67094+
67095+ifndef CONFIG_GRKERNSEC
67096+obj-y += grsec_disabled.o
67097+endif
67098+
67099+ifdef CONFIG_GRKERNSEC_HIDESYM
67100+extra-y := grsec_hidesym.o
67101+$(obj)/grsec_hidesym.o:
67102+ @-chmod -f 500 /boot
67103+ @-chmod -f 500 /lib/modules
67104+ @-chmod -f 500 /lib64/modules
67105+ @-chmod -f 500 /lib32/modules
67106+ @-chmod -f 700 .
67107+ @-chmod -f 700 $(objtree)
67108+ @echo ' grsec: protected kernel image paths'
67109+endif
67110diff --git a/grsecurity/gracl.c b/grsecurity/gracl.c
67111new file mode 100644
67112index 0000000..e56396f
67113--- /dev/null
67114+++ b/grsecurity/gracl.c
67115@@ -0,0 +1,2679 @@
67116+#include <linux/kernel.h>
67117+#include <linux/module.h>
67118+#include <linux/sched.h>
67119+#include <linux/mm.h>
67120+#include <linux/file.h>
67121+#include <linux/fs.h>
67122+#include <linux/namei.h>
67123+#include <linux/mount.h>
67124+#include <linux/tty.h>
67125+#include <linux/proc_fs.h>
67126+#include <linux/lglock.h>
67127+#include <linux/slab.h>
67128+#include <linux/vmalloc.h>
67129+#include <linux/types.h>
67130+#include <linux/sysctl.h>
67131+#include <linux/netdevice.h>
67132+#include <linux/ptrace.h>
67133+#include <linux/gracl.h>
67134+#include <linux/gralloc.h>
67135+#include <linux/security.h>
67136+#include <linux/grinternal.h>
67137+#include <linux/pid_namespace.h>
67138+#include <linux/stop_machine.h>
67139+#include <linux/fdtable.h>
67140+#include <linux/percpu.h>
67141+#include <linux/lglock.h>
67142+#include <linux/hugetlb.h>
67143+#include <linux/posix-timers.h>
67144+#include <linux/prefetch.h>
67145+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
67146+#include <linux/magic.h>
67147+#include <linux/pagemap.h>
67148+#include "../fs/btrfs/async-thread.h"
67149+#include "../fs/btrfs/ctree.h"
67150+#include "../fs/btrfs/btrfs_inode.h"
67151+#endif
67152+#include "../fs/mount.h"
67153+
67154+#include <asm/uaccess.h>
67155+#include <asm/errno.h>
67156+#include <asm/mman.h>
67157+
67158+#define FOR_EACH_ROLE_START(role) \
67159+ role = running_polstate.role_list; \
67160+ while (role) {
67161+
67162+#define FOR_EACH_ROLE_END(role) \
67163+ role = role->prev; \
67164+ }
67165+
67166+extern struct path gr_real_root;
67167+
67168+static struct gr_policy_state running_polstate;
67169+struct gr_policy_state *polstate = &running_polstate;
67170+extern struct gr_alloc_state *current_alloc_state;
67171+
67172+extern char *gr_shared_page[4];
67173+DEFINE_RWLOCK(gr_inode_lock);
67174+
67175+static unsigned int gr_status __read_only = GR_STATUS_INIT;
67176+
67177+#ifdef CONFIG_NET
67178+extern struct vfsmount *sock_mnt;
67179+#endif
67180+
67181+extern struct vfsmount *pipe_mnt;
67182+extern struct vfsmount *shm_mnt;
67183+
67184+#ifdef CONFIG_HUGETLBFS
67185+extern struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
67186+#endif
67187+
67188+extern u16 acl_sp_role_value;
67189+extern struct acl_object_label *fakefs_obj_rw;
67190+extern struct acl_object_label *fakefs_obj_rwx;
67191+
67192+int gr_acl_is_enabled(void)
67193+{
67194+ return (gr_status & GR_READY);
67195+}
67196+
67197+void gr_enable_rbac_system(void)
67198+{
67199+ pax_open_kernel();
67200+ gr_status |= GR_READY;
67201+ pax_close_kernel();
67202+}
67203+
67204+int gr_rbac_disable(void *unused)
67205+{
67206+ pax_open_kernel();
67207+ gr_status &= ~GR_READY;
67208+ pax_close_kernel();
67209+
67210+ return 0;
67211+}
67212+
67213+static inline dev_t __get_dev(const struct dentry *dentry)
67214+{
67215+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
67216+ if (dentry->d_sb->s_magic == BTRFS_SUPER_MAGIC)
67217+ return BTRFS_I(dentry->d_inode)->root->anon_dev;
67218+ else
67219+#endif
67220+ return dentry->d_sb->s_dev;
67221+}
67222+
67223+dev_t gr_get_dev_from_dentry(struct dentry *dentry)
67224+{
67225+ return __get_dev(dentry);
67226+}
67227+
67228+static char gr_task_roletype_to_char(struct task_struct *task)
67229+{
67230+ switch (task->role->roletype &
67231+ (GR_ROLE_DEFAULT | GR_ROLE_USER | GR_ROLE_GROUP |
67232+ GR_ROLE_SPECIAL)) {
67233+ case GR_ROLE_DEFAULT:
67234+ return 'D';
67235+ case GR_ROLE_USER:
67236+ return 'U';
67237+ case GR_ROLE_GROUP:
67238+ return 'G';
67239+ case GR_ROLE_SPECIAL:
67240+ return 'S';
67241+ }
67242+
67243+ return 'X';
67244+}
67245+
67246+char gr_roletype_to_char(void)
67247+{
67248+ return gr_task_roletype_to_char(current);
67249+}
67250+
67251+__inline__ int
67252+gr_acl_tpe_check(void)
67253+{
67254+ if (unlikely(!(gr_status & GR_READY)))
67255+ return 0;
67256+ if (current->role->roletype & GR_ROLE_TPE)
67257+ return 1;
67258+ else
67259+ return 0;
67260+}
67261+
67262+int
67263+gr_handle_rawio(const struct inode *inode)
67264+{
67265+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
67266+ if (inode && (S_ISBLK(inode->i_mode) || (S_ISCHR(inode->i_mode) && imajor(inode) == RAW_MAJOR)) &&
67267+ grsec_enable_chroot_caps && proc_is_chrooted(current) &&
67268+ !capable(CAP_SYS_RAWIO))
67269+ return 1;
67270+#endif
67271+ return 0;
67272+}
67273+
67274+int
67275+gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb)
67276+{
67277+ if (likely(lena != lenb))
67278+ return 0;
67279+
67280+ return !memcmp(a, b, lena);
67281+}
67282+
67283+static int prepend(char **buffer, int *buflen, const char *str, int namelen)
67284+{
67285+ *buflen -= namelen;
67286+ if (*buflen < 0)
67287+ return -ENAMETOOLONG;
67288+ *buffer -= namelen;
67289+ memcpy(*buffer, str, namelen);
67290+ return 0;
67291+}
67292+
67293+static int prepend_name(char **buffer, int *buflen, struct qstr *name)
67294+{
67295+ return prepend(buffer, buflen, name->name, name->len);
67296+}
67297+
67298+static int prepend_path(const struct path *path, struct path *root,
67299+ char **buffer, int *buflen)
67300+{
67301+ struct dentry *dentry = path->dentry;
67302+ struct vfsmount *vfsmnt = path->mnt;
67303+ struct mount *mnt = real_mount(vfsmnt);
67304+ bool slash = false;
67305+ int error = 0;
67306+
67307+ while (dentry != root->dentry || vfsmnt != root->mnt) {
67308+ struct dentry * parent;
67309+
67310+ if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) {
67311+ /* Global root? */
67312+ if (!mnt_has_parent(mnt)) {
67313+ goto out;
67314+ }
67315+ dentry = mnt->mnt_mountpoint;
67316+ mnt = mnt->mnt_parent;
67317+ vfsmnt = &mnt->mnt;
67318+ continue;
67319+ }
67320+ parent = dentry->d_parent;
67321+ prefetch(parent);
67322+ spin_lock(&dentry->d_lock);
67323+ error = prepend_name(buffer, buflen, &dentry->d_name);
67324+ spin_unlock(&dentry->d_lock);
67325+ if (!error)
67326+ error = prepend(buffer, buflen, "/", 1);
67327+ if (error)
67328+ break;
67329+
67330+ slash = true;
67331+ dentry = parent;
67332+ }
67333+
67334+out:
67335+ if (!error && !slash)
67336+ error = prepend(buffer, buflen, "/", 1);
67337+
67338+ return error;
67339+}
67340+
67341+/* this must be called with mount_lock and rename_lock held */
67342+
67343+static char *__our_d_path(const struct path *path, struct path *root,
67344+ char *buf, int buflen)
67345+{
67346+ char *res = buf + buflen;
67347+ int error;
67348+
67349+ prepend(&res, &buflen, "\0", 1);
67350+ error = prepend_path(path, root, &res, &buflen);
67351+ if (error)
67352+ return ERR_PTR(error);
67353+
67354+ return res;
67355+}
67356+
67357+static char *
67358+gen_full_path(struct path *path, struct path *root, char *buf, int buflen)
67359+{
67360+ char *retval;
67361+
67362+ retval = __our_d_path(path, root, buf, buflen);
67363+ if (unlikely(IS_ERR(retval)))
67364+ retval = strcpy(buf, "<path too long>");
67365+ else if (unlikely(retval[1] == '/' && retval[2] == '\0'))
67366+ retval[1] = '\0';
67367+
67368+ return retval;
67369+}
67370+
67371+static char *
67372+__d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
67373+ char *buf, int buflen)
67374+{
67375+ struct path path;
67376+ char *res;
67377+
67378+ path.dentry = (struct dentry *)dentry;
67379+ path.mnt = (struct vfsmount *)vfsmnt;
67380+
67381+ /* we can use gr_real_root.dentry, gr_real_root.mnt, because this is only called
67382+ by the RBAC system */
67383+ res = gen_full_path(&path, &gr_real_root, buf, buflen);
67384+
67385+ return res;
67386+}
67387+
67388+static char *
67389+d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
67390+ char *buf, int buflen)
67391+{
67392+ char *res;
67393+ struct path path;
67394+ struct path root;
67395+ struct task_struct *reaper = init_pid_ns.child_reaper;
67396+
67397+ path.dentry = (struct dentry *)dentry;
67398+ path.mnt = (struct vfsmount *)vfsmnt;
67399+
67400+ /* we can't use gr_real_root.dentry, gr_real_root.mnt, because they belong only to the RBAC system */
67401+ get_fs_root(reaper->fs, &root);
67402+
67403+ read_seqlock_excl(&mount_lock);
67404+ write_seqlock(&rename_lock);
67405+ res = gen_full_path(&path, &root, buf, buflen);
67406+ write_sequnlock(&rename_lock);
67407+ read_sequnlock_excl(&mount_lock);
67408+
67409+ path_put(&root);
67410+ return res;
67411+}
67412+
67413+char *
67414+gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
67415+{
67416+ char *ret;
67417+ read_seqlock_excl(&mount_lock);
67418+ write_seqlock(&rename_lock);
67419+ ret = __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
67420+ PAGE_SIZE);
67421+ write_sequnlock(&rename_lock);
67422+ read_sequnlock_excl(&mount_lock);
67423+ return ret;
67424+}
67425+
67426+static char *
67427+gr_to_proc_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
67428+{
67429+ char *ret;
67430+ char *buf;
67431+ int buflen;
67432+
67433+ read_seqlock_excl(&mount_lock);
67434+ write_seqlock(&rename_lock);
67435+ buf = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
67436+ ret = __d_real_path(dentry, mnt, buf, PAGE_SIZE - 6);
67437+ buflen = (int)(ret - buf);
67438+ if (buflen >= 5)
67439+ prepend(&ret, &buflen, "/proc", 5);
67440+ else
67441+ ret = strcpy(buf, "<path too long>");
67442+ write_sequnlock(&rename_lock);
67443+ read_sequnlock_excl(&mount_lock);
67444+ return ret;
67445+}
67446+
67447+char *
67448+gr_to_filename_nolock(const struct dentry *dentry, const struct vfsmount *mnt)
67449+{
67450+ return __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
67451+ PAGE_SIZE);
67452+}
67453+
67454+char *
67455+gr_to_filename(const struct dentry *dentry, const struct vfsmount *mnt)
67456+{
67457+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
67458+ PAGE_SIZE);
67459+}
67460+
67461+char *
67462+gr_to_filename1(const struct dentry *dentry, const struct vfsmount *mnt)
67463+{
67464+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[1], smp_processor_id()),
67465+ PAGE_SIZE);
67466+}
67467+
67468+char *
67469+gr_to_filename2(const struct dentry *dentry, const struct vfsmount *mnt)
67470+{
67471+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[2], smp_processor_id()),
67472+ PAGE_SIZE);
67473+}
67474+
67475+char *
67476+gr_to_filename3(const struct dentry *dentry, const struct vfsmount *mnt)
67477+{
67478+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[3], smp_processor_id()),
67479+ PAGE_SIZE);
67480+}
67481+
67482+__inline__ __u32
67483+to_gr_audit(const __u32 reqmode)
67484+{
67485+ /* masks off auditable permission flags, then shifts them to create
67486+ auditing flags, and adds the special case of append auditing if
67487+ we're requesting write */
67488+ return (((reqmode & ~GR_AUDITS) << 10) | ((reqmode & GR_WRITE) ? GR_AUDIT_APPEND : 0));
67489+}
67490+
67491+struct acl_role_label *
67492+__lookup_acl_role_label(const struct gr_policy_state *state, const struct task_struct *task, const uid_t uid,
67493+ const gid_t gid)
67494+{
67495+ unsigned int index = gr_rhash(uid, GR_ROLE_USER, state->acl_role_set.r_size);
67496+ struct acl_role_label *match;
67497+ struct role_allowed_ip *ipp;
67498+ unsigned int x;
67499+ u32 curr_ip = task->signal->saved_ip;
67500+
67501+ match = state->acl_role_set.r_hash[index];
67502+
67503+ while (match) {
67504+ if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_USER)) == (GR_ROLE_DOMAIN | GR_ROLE_USER)) {
67505+ for (x = 0; x < match->domain_child_num; x++) {
67506+ if (match->domain_children[x] == uid)
67507+ goto found;
67508+ }
67509+ } else if (match->uidgid == uid && match->roletype & GR_ROLE_USER)
67510+ break;
67511+ match = match->next;
67512+ }
67513+found:
67514+ if (match == NULL) {
67515+ try_group:
67516+ index = gr_rhash(gid, GR_ROLE_GROUP, state->acl_role_set.r_size);
67517+ match = state->acl_role_set.r_hash[index];
67518+
67519+ while (match) {
67520+ if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) == (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) {
67521+ for (x = 0; x < match->domain_child_num; x++) {
67522+ if (match->domain_children[x] == gid)
67523+ goto found2;
67524+ }
67525+ } else if (match->uidgid == gid && match->roletype & GR_ROLE_GROUP)
67526+ break;
67527+ match = match->next;
67528+ }
67529+found2:
67530+ if (match == NULL)
67531+ match = state->default_role;
67532+ if (match->allowed_ips == NULL)
67533+ return match;
67534+ else {
67535+ for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
67536+ if (likely
67537+ ((ntohl(curr_ip) & ipp->netmask) ==
67538+ (ntohl(ipp->addr) & ipp->netmask)))
67539+ return match;
67540+ }
67541+ match = state->default_role;
67542+ }
67543+ } else if (match->allowed_ips == NULL) {
67544+ return match;
67545+ } else {
67546+ for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
67547+ if (likely
67548+ ((ntohl(curr_ip) & ipp->netmask) ==
67549+ (ntohl(ipp->addr) & ipp->netmask)))
67550+ return match;
67551+ }
67552+ goto try_group;
67553+ }
67554+
67555+ return match;
67556+}
67557+
67558+static struct acl_role_label *
67559+lookup_acl_role_label(const struct task_struct *task, const uid_t uid,
67560+ const gid_t gid)
67561+{
67562+ return __lookup_acl_role_label(&running_polstate, task, uid, gid);
67563+}
67564+
67565+struct acl_subject_label *
67566+lookup_acl_subj_label(const ino_t ino, const dev_t dev,
67567+ const struct acl_role_label *role)
67568+{
67569+ unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
67570+ struct acl_subject_label *match;
67571+
67572+ match = role->subj_hash[index];
67573+
67574+ while (match && (match->inode != ino || match->device != dev ||
67575+ (match->mode & GR_DELETED))) {
67576+ match = match->next;
67577+ }
67578+
67579+ if (match && !(match->mode & GR_DELETED))
67580+ return match;
67581+ else
67582+ return NULL;
67583+}
67584+
67585+struct acl_subject_label *
67586+lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev,
67587+ const struct acl_role_label *role)
67588+{
67589+ unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
67590+ struct acl_subject_label *match;
67591+
67592+ match = role->subj_hash[index];
67593+
67594+ while (match && (match->inode != ino || match->device != dev ||
67595+ !(match->mode & GR_DELETED))) {
67596+ match = match->next;
67597+ }
67598+
67599+ if (match && (match->mode & GR_DELETED))
67600+ return match;
67601+ else
67602+ return NULL;
67603+}
67604+
67605+static struct acl_object_label *
67606+lookup_acl_obj_label(const ino_t ino, const dev_t dev,
67607+ const struct acl_subject_label *subj)
67608+{
67609+ unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
67610+ struct acl_object_label *match;
67611+
67612+ match = subj->obj_hash[index];
67613+
67614+ while (match && (match->inode != ino || match->device != dev ||
67615+ (match->mode & GR_DELETED))) {
67616+ match = match->next;
67617+ }
67618+
67619+ if (match && !(match->mode & GR_DELETED))
67620+ return match;
67621+ else
67622+ return NULL;
67623+}
67624+
67625+static struct acl_object_label *
67626+lookup_acl_obj_label_create(const ino_t ino, const dev_t dev,
67627+ const struct acl_subject_label *subj)
67628+{
67629+ unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
67630+ struct acl_object_label *match;
67631+
67632+ match = subj->obj_hash[index];
67633+
67634+ while (match && (match->inode != ino || match->device != dev ||
67635+ !(match->mode & GR_DELETED))) {
67636+ match = match->next;
67637+ }
67638+
67639+ if (match && (match->mode & GR_DELETED))
67640+ return match;
67641+
67642+ match = subj->obj_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 name_entry *
67656+__lookup_name_entry(const struct gr_policy_state *state, const char *name)
67657+{
67658+ unsigned int len = strlen(name);
67659+ unsigned int key = full_name_hash(name, len);
67660+ unsigned int index = key % state->name_set.n_size;
67661+ struct name_entry *match;
67662+
67663+ match = state->name_set.n_hash[index];
67664+
67665+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len)))
67666+ match = match->next;
67667+
67668+ return match;
67669+}
67670+
67671+static struct name_entry *
67672+lookup_name_entry(const char *name)
67673+{
67674+ return __lookup_name_entry(&running_polstate, name);
67675+}
67676+
67677+static struct name_entry *
67678+lookup_name_entry_create(const char *name)
67679+{
67680+ unsigned int len = strlen(name);
67681+ unsigned int key = full_name_hash(name, len);
67682+ unsigned int index = key % running_polstate.name_set.n_size;
67683+ struct name_entry *match;
67684+
67685+ match = running_polstate.name_set.n_hash[index];
67686+
67687+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
67688+ !match->deleted))
67689+ match = match->next;
67690+
67691+ if (match && match->deleted)
67692+ return match;
67693+
67694+ match = running_polstate.name_set.n_hash[index];
67695+
67696+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
67697+ match->deleted))
67698+ match = match->next;
67699+
67700+ if (match && !match->deleted)
67701+ return match;
67702+ else
67703+ return NULL;
67704+}
67705+
67706+static struct inodev_entry *
67707+lookup_inodev_entry(const ino_t ino, const dev_t dev)
67708+{
67709+ unsigned int index = gr_fhash(ino, dev, running_polstate.inodev_set.i_size);
67710+ struct inodev_entry *match;
67711+
67712+ match = running_polstate.inodev_set.i_hash[index];
67713+
67714+ while (match && (match->nentry->inode != ino || match->nentry->device != dev))
67715+ match = match->next;
67716+
67717+ return match;
67718+}
67719+
67720+void
67721+__insert_inodev_entry(const struct gr_policy_state *state, struct inodev_entry *entry)
67722+{
67723+ unsigned int index = gr_fhash(entry->nentry->inode, entry->nentry->device,
67724+ state->inodev_set.i_size);
67725+ struct inodev_entry **curr;
67726+
67727+ entry->prev = NULL;
67728+
67729+ curr = &state->inodev_set.i_hash[index];
67730+ if (*curr != NULL)
67731+ (*curr)->prev = entry;
67732+
67733+ entry->next = *curr;
67734+ *curr = entry;
67735+
67736+ return;
67737+}
67738+
67739+static void
67740+insert_inodev_entry(struct inodev_entry *entry)
67741+{
67742+ __insert_inodev_entry(&running_polstate, entry);
67743+}
67744+
67745+void
67746+insert_acl_obj_label(struct acl_object_label *obj,
67747+ struct acl_subject_label *subj)
67748+{
67749+ unsigned int index =
67750+ gr_fhash(obj->inode, obj->device, subj->obj_hash_size);
67751+ struct acl_object_label **curr;
67752+
67753+ obj->prev = NULL;
67754+
67755+ curr = &subj->obj_hash[index];
67756+ if (*curr != NULL)
67757+ (*curr)->prev = obj;
67758+
67759+ obj->next = *curr;
67760+ *curr = obj;
67761+
67762+ return;
67763+}
67764+
67765+void
67766+insert_acl_subj_label(struct acl_subject_label *obj,
67767+ struct acl_role_label *role)
67768+{
67769+ unsigned int index = gr_fhash(obj->inode, obj->device, role->subj_hash_size);
67770+ struct acl_subject_label **curr;
67771+
67772+ obj->prev = NULL;
67773+
67774+ curr = &role->subj_hash[index];
67775+ if (*curr != NULL)
67776+ (*curr)->prev = obj;
67777+
67778+ obj->next = *curr;
67779+ *curr = obj;
67780+
67781+ return;
67782+}
67783+
67784+/* derived from glibc fnmatch() 0: match, 1: no match*/
67785+
67786+static int
67787+glob_match(const char *p, const char *n)
67788+{
67789+ char c;
67790+
67791+ while ((c = *p++) != '\0') {
67792+ switch (c) {
67793+ case '?':
67794+ if (*n == '\0')
67795+ return 1;
67796+ else if (*n == '/')
67797+ return 1;
67798+ break;
67799+ case '\\':
67800+ if (*n != c)
67801+ return 1;
67802+ break;
67803+ case '*':
67804+ for (c = *p++; c == '?' || c == '*'; c = *p++) {
67805+ if (*n == '/')
67806+ return 1;
67807+ else if (c == '?') {
67808+ if (*n == '\0')
67809+ return 1;
67810+ else
67811+ ++n;
67812+ }
67813+ }
67814+ if (c == '\0') {
67815+ return 0;
67816+ } else {
67817+ const char *endp;
67818+
67819+ if ((endp = strchr(n, '/')) == NULL)
67820+ endp = n + strlen(n);
67821+
67822+ if (c == '[') {
67823+ for (--p; n < endp; ++n)
67824+ if (!glob_match(p, n))
67825+ return 0;
67826+ } else if (c == '/') {
67827+ while (*n != '\0' && *n != '/')
67828+ ++n;
67829+ if (*n == '/' && !glob_match(p, n + 1))
67830+ return 0;
67831+ } else {
67832+ for (--p; n < endp; ++n)
67833+ if (*n == c && !glob_match(p, n))
67834+ return 0;
67835+ }
67836+
67837+ return 1;
67838+ }
67839+ case '[':
67840+ {
67841+ int not;
67842+ char cold;
67843+
67844+ if (*n == '\0' || *n == '/')
67845+ return 1;
67846+
67847+ not = (*p == '!' || *p == '^');
67848+ if (not)
67849+ ++p;
67850+
67851+ c = *p++;
67852+ for (;;) {
67853+ unsigned char fn = (unsigned char)*n;
67854+
67855+ if (c == '\0')
67856+ return 1;
67857+ else {
67858+ if (c == fn)
67859+ goto matched;
67860+ cold = c;
67861+ c = *p++;
67862+
67863+ if (c == '-' && *p != ']') {
67864+ unsigned char cend = *p++;
67865+
67866+ if (cend == '\0')
67867+ return 1;
67868+
67869+ if (cold <= fn && fn <= cend)
67870+ goto matched;
67871+
67872+ c = *p++;
67873+ }
67874+ }
67875+
67876+ if (c == ']')
67877+ break;
67878+ }
67879+ if (!not)
67880+ return 1;
67881+ break;
67882+ matched:
67883+ while (c != ']') {
67884+ if (c == '\0')
67885+ return 1;
67886+
67887+ c = *p++;
67888+ }
67889+ if (not)
67890+ return 1;
67891+ }
67892+ break;
67893+ default:
67894+ if (c != *n)
67895+ return 1;
67896+ }
67897+
67898+ ++n;
67899+ }
67900+
67901+ if (*n == '\0')
67902+ return 0;
67903+
67904+ if (*n == '/')
67905+ return 0;
67906+
67907+ return 1;
67908+}
67909+
67910+static struct acl_object_label *
67911+chk_glob_label(struct acl_object_label *globbed,
67912+ const struct dentry *dentry, const struct vfsmount *mnt, char **path)
67913+{
67914+ struct acl_object_label *tmp;
67915+
67916+ if (*path == NULL)
67917+ *path = gr_to_filename_nolock(dentry, mnt);
67918+
67919+ tmp = globbed;
67920+
67921+ while (tmp) {
67922+ if (!glob_match(tmp->filename, *path))
67923+ return tmp;
67924+ tmp = tmp->next;
67925+ }
67926+
67927+ return NULL;
67928+}
67929+
67930+static struct acl_object_label *
67931+__full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
67932+ const ino_t curr_ino, const dev_t curr_dev,
67933+ const struct acl_subject_label *subj, char **path, const int checkglob)
67934+{
67935+ struct acl_subject_label *tmpsubj;
67936+ struct acl_object_label *retval;
67937+ struct acl_object_label *retval2;
67938+
67939+ tmpsubj = (struct acl_subject_label *) subj;
67940+ read_lock(&gr_inode_lock);
67941+ do {
67942+ retval = lookup_acl_obj_label(curr_ino, curr_dev, tmpsubj);
67943+ if (retval) {
67944+ if (checkglob && retval->globbed) {
67945+ retval2 = chk_glob_label(retval->globbed, orig_dentry, orig_mnt, path);
67946+ if (retval2)
67947+ retval = retval2;
67948+ }
67949+ break;
67950+ }
67951+ } while ((tmpsubj = tmpsubj->parent_subject));
67952+ read_unlock(&gr_inode_lock);
67953+
67954+ return retval;
67955+}
67956+
67957+static __inline__ struct acl_object_label *
67958+full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
67959+ struct dentry *curr_dentry,
67960+ const struct acl_subject_label *subj, char **path, const int checkglob)
67961+{
67962+ int newglob = checkglob;
67963+ ino_t inode;
67964+ dev_t device;
67965+
67966+ /* if we aren't checking a subdirectory of the original path yet, don't do glob checking
67967+ as we don't want a / * rule to match instead of the / object
67968+ don't do this for create lookups that call this function though, since they're looking up
67969+ on the parent and thus need globbing checks on all paths
67970+ */
67971+ if (orig_dentry == curr_dentry && newglob != GR_CREATE_GLOB)
67972+ newglob = GR_NO_GLOB;
67973+
67974+ spin_lock(&curr_dentry->d_lock);
67975+ inode = curr_dentry->d_inode->i_ino;
67976+ device = __get_dev(curr_dentry);
67977+ spin_unlock(&curr_dentry->d_lock);
67978+
67979+ return __full_lookup(orig_dentry, orig_mnt, inode, device, subj, path, newglob);
67980+}
67981+
67982+#ifdef CONFIG_HUGETLBFS
67983+static inline bool
67984+is_hugetlbfs_mnt(const struct vfsmount *mnt)
67985+{
67986+ int i;
67987+ for (i = 0; i < HUGE_MAX_HSTATE; i++) {
67988+ if (unlikely(hugetlbfs_vfsmount[i] == mnt))
67989+ return true;
67990+ }
67991+
67992+ return false;
67993+}
67994+#endif
67995+
67996+static struct acl_object_label *
67997+__chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
67998+ const struct acl_subject_label *subj, char *path, const int checkglob)
67999+{
68000+ struct dentry *dentry = (struct dentry *) l_dentry;
68001+ struct vfsmount *mnt = (struct vfsmount *) l_mnt;
68002+ struct mount *real_mnt = real_mount(mnt);
68003+ struct acl_object_label *retval;
68004+ struct dentry *parent;
68005+
68006+ read_seqlock_excl(&mount_lock);
68007+ write_seqlock(&rename_lock);
68008+
68009+ if (unlikely((mnt == shm_mnt && dentry->d_inode->i_nlink == 0) || mnt == pipe_mnt ||
68010+#ifdef CONFIG_NET
68011+ mnt == sock_mnt ||
68012+#endif
68013+#ifdef CONFIG_HUGETLBFS
68014+ (is_hugetlbfs_mnt(mnt) && dentry->d_inode->i_nlink == 0) ||
68015+#endif
68016+ /* ignore Eric Biederman */
68017+ IS_PRIVATE(l_dentry->d_inode))) {
68018+ retval = (subj->mode & GR_SHMEXEC) ? fakefs_obj_rwx : fakefs_obj_rw;
68019+ goto out;
68020+ }
68021+
68022+ for (;;) {
68023+ if (dentry == gr_real_root.dentry && mnt == gr_real_root.mnt)
68024+ break;
68025+
68026+ if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
68027+ if (!mnt_has_parent(real_mnt))
68028+ break;
68029+
68030+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
68031+ if (retval != NULL)
68032+ goto out;
68033+
68034+ dentry = real_mnt->mnt_mountpoint;
68035+ real_mnt = real_mnt->mnt_parent;
68036+ mnt = &real_mnt->mnt;
68037+ continue;
68038+ }
68039+
68040+ parent = dentry->d_parent;
68041+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
68042+ if (retval != NULL)
68043+ goto out;
68044+
68045+ dentry = parent;
68046+ }
68047+
68048+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
68049+
68050+ /* gr_real_root is pinned so we don't have to hold a reference */
68051+ if (retval == NULL)
68052+ retval = full_lookup(l_dentry, l_mnt, gr_real_root.dentry, subj, &path, checkglob);
68053+out:
68054+ write_sequnlock(&rename_lock);
68055+ read_sequnlock_excl(&mount_lock);
68056+
68057+ BUG_ON(retval == NULL);
68058+
68059+ return retval;
68060+}
68061+
68062+static __inline__ struct acl_object_label *
68063+chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
68064+ const struct acl_subject_label *subj)
68065+{
68066+ char *path = NULL;
68067+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_REG_GLOB);
68068+}
68069+
68070+static __inline__ struct acl_object_label *
68071+chk_obj_label_noglob(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
68072+ const struct acl_subject_label *subj)
68073+{
68074+ char *path = NULL;
68075+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_NO_GLOB);
68076+}
68077+
68078+static __inline__ struct acl_object_label *
68079+chk_obj_create_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
68080+ const struct acl_subject_label *subj, char *path)
68081+{
68082+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_CREATE_GLOB);
68083+}
68084+
68085+struct acl_subject_label *
68086+chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
68087+ const struct acl_role_label *role)
68088+{
68089+ struct dentry *dentry = (struct dentry *) l_dentry;
68090+ struct vfsmount *mnt = (struct vfsmount *) l_mnt;
68091+ struct mount *real_mnt = real_mount(mnt);
68092+ struct acl_subject_label *retval;
68093+ struct dentry *parent;
68094+
68095+ read_seqlock_excl(&mount_lock);
68096+ write_seqlock(&rename_lock);
68097+
68098+ for (;;) {
68099+ if (dentry == gr_real_root.dentry && mnt == gr_real_root.mnt)
68100+ break;
68101+ if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
68102+ if (!mnt_has_parent(real_mnt))
68103+ break;
68104+
68105+ spin_lock(&dentry->d_lock);
68106+ read_lock(&gr_inode_lock);
68107+ retval =
68108+ lookup_acl_subj_label(dentry->d_inode->i_ino,
68109+ __get_dev(dentry), role);
68110+ read_unlock(&gr_inode_lock);
68111+ spin_unlock(&dentry->d_lock);
68112+ if (retval != NULL)
68113+ goto out;
68114+
68115+ dentry = real_mnt->mnt_mountpoint;
68116+ real_mnt = real_mnt->mnt_parent;
68117+ mnt = &real_mnt->mnt;
68118+ continue;
68119+ }
68120+
68121+ spin_lock(&dentry->d_lock);
68122+ read_lock(&gr_inode_lock);
68123+ retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
68124+ __get_dev(dentry), role);
68125+ read_unlock(&gr_inode_lock);
68126+ parent = dentry->d_parent;
68127+ spin_unlock(&dentry->d_lock);
68128+
68129+ if (retval != NULL)
68130+ goto out;
68131+
68132+ dentry = parent;
68133+ }
68134+
68135+ spin_lock(&dentry->d_lock);
68136+ read_lock(&gr_inode_lock);
68137+ retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
68138+ __get_dev(dentry), role);
68139+ read_unlock(&gr_inode_lock);
68140+ spin_unlock(&dentry->d_lock);
68141+
68142+ if (unlikely(retval == NULL)) {
68143+ /* gr_real_root is pinned, we don't need to hold a reference */
68144+ read_lock(&gr_inode_lock);
68145+ retval = lookup_acl_subj_label(gr_real_root.dentry->d_inode->i_ino,
68146+ __get_dev(gr_real_root.dentry), role);
68147+ read_unlock(&gr_inode_lock);
68148+ }
68149+out:
68150+ write_sequnlock(&rename_lock);
68151+ read_sequnlock_excl(&mount_lock);
68152+
68153+ BUG_ON(retval == NULL);
68154+
68155+ return retval;
68156+}
68157+
68158+void
68159+assign_special_role(const char *rolename)
68160+{
68161+ struct acl_object_label *obj;
68162+ struct acl_role_label *r;
68163+ struct acl_role_label *assigned = NULL;
68164+ struct task_struct *tsk;
68165+ struct file *filp;
68166+
68167+ FOR_EACH_ROLE_START(r)
68168+ if (!strcmp(rolename, r->rolename) &&
68169+ (r->roletype & GR_ROLE_SPECIAL)) {
68170+ assigned = r;
68171+ break;
68172+ }
68173+ FOR_EACH_ROLE_END(r)
68174+
68175+ if (!assigned)
68176+ return;
68177+
68178+ read_lock(&tasklist_lock);
68179+ read_lock(&grsec_exec_file_lock);
68180+
68181+ tsk = current->real_parent;
68182+ if (tsk == NULL)
68183+ goto out_unlock;
68184+
68185+ filp = tsk->exec_file;
68186+ if (filp == NULL)
68187+ goto out_unlock;
68188+
68189+ tsk->is_writable = 0;
68190+ tsk->inherited = 0;
68191+
68192+ tsk->acl_sp_role = 1;
68193+ tsk->acl_role_id = ++acl_sp_role_value;
68194+ tsk->role = assigned;
68195+ tsk->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role);
68196+
68197+ /* ignore additional mmap checks for processes that are writable
68198+ by the default ACL */
68199+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, running_polstate.default_role->root_label);
68200+ if (unlikely(obj->mode & GR_WRITE))
68201+ tsk->is_writable = 1;
68202+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role->root_label);
68203+ if (unlikely(obj->mode & GR_WRITE))
68204+ tsk->is_writable = 1;
68205+
68206+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
68207+ printk(KERN_ALERT "Assigning special role:%s subject:%s to process (%s:%d)\n", tsk->role->rolename,
68208+ tsk->acl->filename, tsk->comm, task_pid_nr(tsk));
68209+#endif
68210+
68211+out_unlock:
68212+ read_unlock(&grsec_exec_file_lock);
68213+ read_unlock(&tasklist_lock);
68214+ return;
68215+}
68216+
68217+
68218+static void
68219+gr_log_learn(const struct dentry *dentry, const struct vfsmount *mnt, const __u32 mode)
68220+{
68221+ struct task_struct *task = current;
68222+ const struct cred *cred = current_cred();
68223+
68224+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
68225+ GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
68226+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
68227+ 1UL, 1UL, gr_to_filename(dentry, mnt), (unsigned long) mode, &task->signal->saved_ip);
68228+
68229+ return;
68230+}
68231+
68232+static void
68233+gr_log_learn_uid_change(const kuid_t real, const kuid_t effective, const kuid_t fs)
68234+{
68235+ struct task_struct *task = current;
68236+ const struct cred *cred = current_cred();
68237+
68238+ security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
68239+ GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
68240+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
68241+ 'u', GR_GLOBAL_UID(real), GR_GLOBAL_UID(effective), GR_GLOBAL_UID(fs), &task->signal->saved_ip);
68242+
68243+ return;
68244+}
68245+
68246+static void
68247+gr_log_learn_gid_change(const kgid_t real, const kgid_t effective, const kgid_t fs)
68248+{
68249+ struct task_struct *task = current;
68250+ const struct cred *cred = current_cred();
68251+
68252+ security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
68253+ GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
68254+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
68255+ 'g', GR_GLOBAL_GID(real), GR_GLOBAL_GID(effective), GR_GLOBAL_GID(fs), &task->signal->saved_ip);
68256+
68257+ return;
68258+}
68259+
68260+static void
68261+gr_set_proc_res(struct task_struct *task)
68262+{
68263+ struct acl_subject_label *proc;
68264+ unsigned short i;
68265+
68266+ proc = task->acl;
68267+
68268+ if (proc->mode & (GR_LEARN | GR_INHERITLEARN))
68269+ return;
68270+
68271+ for (i = 0; i < RLIM_NLIMITS; i++) {
68272+ if (!(proc->resmask & (1U << i)))
68273+ continue;
68274+
68275+ task->signal->rlim[i].rlim_cur = proc->res[i].rlim_cur;
68276+ task->signal->rlim[i].rlim_max = proc->res[i].rlim_max;
68277+
68278+ if (i == RLIMIT_CPU)
68279+ update_rlimit_cpu(task, proc->res[i].rlim_cur);
68280+ }
68281+
68282+ return;
68283+}
68284+
68285+/* both of the below must be called with
68286+ rcu_read_lock();
68287+ read_lock(&tasklist_lock);
68288+ read_lock(&grsec_exec_file_lock);
68289+*/
68290+
68291+struct acl_subject_label *__gr_get_subject_for_task(const struct gr_policy_state *state, struct task_struct *task, const char *filename)
68292+{
68293+ char *tmpname;
68294+ struct acl_subject_label *tmpsubj;
68295+ struct file *filp;
68296+ struct name_entry *nmatch;
68297+
68298+ filp = task->exec_file;
68299+ if (filp == NULL)
68300+ return NULL;
68301+
68302+ /* the following is to apply the correct subject
68303+ on binaries running when the RBAC system
68304+ is enabled, when the binaries have been
68305+ replaced or deleted since their execution
68306+ -----
68307+ when the RBAC system starts, the inode/dev
68308+ from exec_file will be one the RBAC system
68309+ is unaware of. It only knows the inode/dev
68310+ of the present file on disk, or the absence
68311+ of it.
68312+ */
68313+
68314+ if (filename)
68315+ nmatch = __lookup_name_entry(state, filename);
68316+ else {
68317+ preempt_disable();
68318+ tmpname = gr_to_filename_rbac(filp->f_path.dentry, filp->f_path.mnt);
68319+
68320+ nmatch = __lookup_name_entry(state, tmpname);
68321+ preempt_enable();
68322+ }
68323+ tmpsubj = NULL;
68324+ if (nmatch) {
68325+ if (nmatch->deleted)
68326+ tmpsubj = lookup_acl_subj_label_deleted(nmatch->inode, nmatch->device, task->role);
68327+ else
68328+ tmpsubj = lookup_acl_subj_label(nmatch->inode, nmatch->device, task->role);
68329+ }
68330+ /* this also works for the reload case -- if we don't match a potentially inherited subject
68331+ then we fall back to a normal lookup based on the binary's ino/dev
68332+ */
68333+ if (tmpsubj == NULL)
68334+ tmpsubj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, task->role);
68335+
68336+ return tmpsubj;
68337+}
68338+
68339+static struct acl_subject_label *gr_get_subject_for_task(struct task_struct *task, const char *filename)
68340+{
68341+ return __gr_get_subject_for_task(&running_polstate, task, filename);
68342+}
68343+
68344+void __gr_apply_subject_to_task(const struct gr_policy_state *state, struct task_struct *task, struct acl_subject_label *subj)
68345+{
68346+ struct acl_object_label *obj;
68347+ struct file *filp;
68348+
68349+ filp = task->exec_file;
68350+
68351+ task->acl = subj;
68352+ task->is_writable = 0;
68353+ /* ignore additional mmap checks for processes that are writable
68354+ by the default ACL */
68355+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, state->default_role->root_label);
68356+ if (unlikely(obj->mode & GR_WRITE))
68357+ task->is_writable = 1;
68358+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
68359+ if (unlikely(obj->mode & GR_WRITE))
68360+ task->is_writable = 1;
68361+
68362+ gr_set_proc_res(task);
68363+
68364+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
68365+ 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);
68366+#endif
68367+}
68368+
68369+static void gr_apply_subject_to_task(struct task_struct *task, struct acl_subject_label *subj)
68370+{
68371+ __gr_apply_subject_to_task(&running_polstate, task, subj);
68372+}
68373+
68374+__u32
68375+gr_search_file(const struct dentry * dentry, const __u32 mode,
68376+ const struct vfsmount * mnt)
68377+{
68378+ __u32 retval = mode;
68379+ struct acl_subject_label *curracl;
68380+ struct acl_object_label *currobj;
68381+
68382+ if (unlikely(!(gr_status & GR_READY)))
68383+ return (mode & ~GR_AUDITS);
68384+
68385+ curracl = current->acl;
68386+
68387+ currobj = chk_obj_label(dentry, mnt, curracl);
68388+ retval = currobj->mode & mode;
68389+
68390+ /* if we're opening a specified transfer file for writing
68391+ (e.g. /dev/initctl), then transfer our role to init
68392+ */
68393+ if (unlikely(currobj->mode & GR_INIT_TRANSFER && retval & GR_WRITE &&
68394+ current->role->roletype & GR_ROLE_PERSIST)) {
68395+ struct task_struct *task = init_pid_ns.child_reaper;
68396+
68397+ if (task->role != current->role) {
68398+ struct acl_subject_label *subj;
68399+
68400+ task->acl_sp_role = 0;
68401+ task->acl_role_id = current->acl_role_id;
68402+ task->role = current->role;
68403+ rcu_read_lock();
68404+ read_lock(&grsec_exec_file_lock);
68405+ subj = gr_get_subject_for_task(task, NULL);
68406+ gr_apply_subject_to_task(task, subj);
68407+ read_unlock(&grsec_exec_file_lock);
68408+ rcu_read_unlock();
68409+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_INIT_TRANSFER_MSG);
68410+ }
68411+ }
68412+
68413+ if (unlikely
68414+ ((curracl->mode & (GR_LEARN | GR_INHERITLEARN)) && !(mode & GR_NOPTRACE)
68415+ && (retval != (mode & ~(GR_AUDITS | GR_SUPPRESS))))) {
68416+ __u32 new_mode = mode;
68417+
68418+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
68419+
68420+ retval = new_mode;
68421+
68422+ if (new_mode & GR_EXEC && curracl->mode & GR_INHERITLEARN)
68423+ new_mode |= GR_INHERIT;
68424+
68425+ if (!(mode & GR_NOLEARN))
68426+ gr_log_learn(dentry, mnt, new_mode);
68427+ }
68428+
68429+ return retval;
68430+}
68431+
68432+struct acl_object_label *gr_get_create_object(const struct dentry *new_dentry,
68433+ const struct dentry *parent,
68434+ const struct vfsmount *mnt)
68435+{
68436+ struct name_entry *match;
68437+ struct acl_object_label *matchpo;
68438+ struct acl_subject_label *curracl;
68439+ char *path;
68440+
68441+ if (unlikely(!(gr_status & GR_READY)))
68442+ return NULL;
68443+
68444+ preempt_disable();
68445+ path = gr_to_filename_rbac(new_dentry, mnt);
68446+ match = lookup_name_entry_create(path);
68447+
68448+ curracl = current->acl;
68449+
68450+ if (match) {
68451+ read_lock(&gr_inode_lock);
68452+ matchpo = lookup_acl_obj_label_create(match->inode, match->device, curracl);
68453+ read_unlock(&gr_inode_lock);
68454+
68455+ if (matchpo) {
68456+ preempt_enable();
68457+ return matchpo;
68458+ }
68459+ }
68460+
68461+ // lookup parent
68462+
68463+ matchpo = chk_obj_create_label(parent, mnt, curracl, path);
68464+
68465+ preempt_enable();
68466+ return matchpo;
68467+}
68468+
68469+__u32
68470+gr_check_create(const struct dentry * new_dentry, const struct dentry * parent,
68471+ const struct vfsmount * mnt, const __u32 mode)
68472+{
68473+ struct acl_object_label *matchpo;
68474+ __u32 retval;
68475+
68476+ if (unlikely(!(gr_status & GR_READY)))
68477+ return (mode & ~GR_AUDITS);
68478+
68479+ matchpo = gr_get_create_object(new_dentry, parent, mnt);
68480+
68481+ retval = matchpo->mode & mode;
68482+
68483+ if ((retval != (mode & ~(GR_AUDITS | GR_SUPPRESS)))
68484+ && (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
68485+ __u32 new_mode = mode;
68486+
68487+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
68488+
68489+ gr_log_learn(new_dentry, mnt, new_mode);
68490+ return new_mode;
68491+ }
68492+
68493+ return retval;
68494+}
68495+
68496+__u32
68497+gr_check_link(const struct dentry * new_dentry,
68498+ const struct dentry * parent_dentry,
68499+ const struct vfsmount * parent_mnt,
68500+ const struct dentry * old_dentry, const struct vfsmount * old_mnt)
68501+{
68502+ struct acl_object_label *obj;
68503+ __u32 oldmode, newmode;
68504+ __u32 needmode;
68505+ __u32 checkmodes = GR_FIND | GR_APPEND | GR_WRITE | GR_EXEC | GR_SETID | GR_READ |
68506+ GR_DELETE | GR_INHERIT;
68507+
68508+ if (unlikely(!(gr_status & GR_READY)))
68509+ return (GR_CREATE | GR_LINK);
68510+
68511+ obj = chk_obj_label(old_dentry, old_mnt, current->acl);
68512+ oldmode = obj->mode;
68513+
68514+ obj = gr_get_create_object(new_dentry, parent_dentry, parent_mnt);
68515+ newmode = obj->mode;
68516+
68517+ needmode = newmode & checkmodes;
68518+
68519+ // old name for hardlink must have at least the permissions of the new name
68520+ if ((oldmode & needmode) != needmode)
68521+ goto bad;
68522+
68523+ // if old name had restrictions/auditing, make sure the new name does as well
68524+ needmode = oldmode & (GR_NOPTRACE | GR_PTRACERD | GR_INHERIT | GR_AUDITS);
68525+
68526+ // don't allow hardlinking of suid/sgid/fcapped files without permission
68527+ if (is_privileged_binary(old_dentry))
68528+ needmode |= GR_SETID;
68529+
68530+ if ((newmode & needmode) != needmode)
68531+ goto bad;
68532+
68533+ // enforce minimum permissions
68534+ if ((newmode & (GR_CREATE | GR_LINK)) == (GR_CREATE | GR_LINK))
68535+ return newmode;
68536+bad:
68537+ needmode = oldmode;
68538+ if (is_privileged_binary(old_dentry))
68539+ needmode |= GR_SETID;
68540+
68541+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) {
68542+ gr_log_learn(old_dentry, old_mnt, needmode | GR_CREATE | GR_LINK);
68543+ return (GR_CREATE | GR_LINK);
68544+ } else if (newmode & GR_SUPPRESS)
68545+ return GR_SUPPRESS;
68546+ else
68547+ return 0;
68548+}
68549+
68550+int
68551+gr_check_hidden_task(const struct task_struct *task)
68552+{
68553+ if (unlikely(!(gr_status & GR_READY)))
68554+ return 0;
68555+
68556+ if (!(task->acl->mode & GR_PROCFIND) && !(current->acl->mode & GR_VIEW))
68557+ return 1;
68558+
68559+ return 0;
68560+}
68561+
68562+int
68563+gr_check_protected_task(const struct task_struct *task)
68564+{
68565+ if (unlikely(!(gr_status & GR_READY) || !task))
68566+ return 0;
68567+
68568+ if ((task->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
68569+ task->acl != current->acl)
68570+ return 1;
68571+
68572+ return 0;
68573+}
68574+
68575+int
68576+gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
68577+{
68578+ struct task_struct *p;
68579+ int ret = 0;
68580+
68581+ if (unlikely(!(gr_status & GR_READY) || !pid))
68582+ return ret;
68583+
68584+ read_lock(&tasklist_lock);
68585+ do_each_pid_task(pid, type, p) {
68586+ if ((p->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
68587+ p->acl != current->acl) {
68588+ ret = 1;
68589+ goto out;
68590+ }
68591+ } while_each_pid_task(pid, type, p);
68592+out:
68593+ read_unlock(&tasklist_lock);
68594+
68595+ return ret;
68596+}
68597+
68598+void
68599+gr_copy_label(struct task_struct *tsk)
68600+{
68601+ struct task_struct *p = current;
68602+
68603+ tsk->inherited = p->inherited;
68604+ tsk->acl_sp_role = 0;
68605+ tsk->acl_role_id = p->acl_role_id;
68606+ tsk->acl = p->acl;
68607+ tsk->role = p->role;
68608+ tsk->signal->used_accept = 0;
68609+ tsk->signal->curr_ip = p->signal->curr_ip;
68610+ tsk->signal->saved_ip = p->signal->saved_ip;
68611+ if (p->exec_file)
68612+ get_file(p->exec_file);
68613+ tsk->exec_file = p->exec_file;
68614+ tsk->is_writable = p->is_writable;
68615+ if (unlikely(p->signal->used_accept)) {
68616+ p->signal->curr_ip = 0;
68617+ p->signal->saved_ip = 0;
68618+ }
68619+
68620+ return;
68621+}
68622+
68623+extern int gr_process_kernel_setuid_ban(struct user_struct *user);
68624+
68625+int
68626+gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs)
68627+{
68628+ unsigned int i;
68629+ __u16 num;
68630+ uid_t *uidlist;
68631+ uid_t curuid;
68632+ int realok = 0;
68633+ int effectiveok = 0;
68634+ int fsok = 0;
68635+ uid_t globalreal, globaleffective, globalfs;
68636+
68637+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT)
68638+ struct user_struct *user;
68639+
68640+ if (!uid_valid(real))
68641+ goto skipit;
68642+
68643+ /* find user based on global namespace */
68644+
68645+ globalreal = GR_GLOBAL_UID(real);
68646+
68647+ user = find_user(make_kuid(&init_user_ns, globalreal));
68648+ if (user == NULL)
68649+ goto skipit;
68650+
68651+ if (gr_process_kernel_setuid_ban(user)) {
68652+ /* for find_user */
68653+ free_uid(user);
68654+ return 1;
68655+ }
68656+
68657+ /* for find_user */
68658+ free_uid(user);
68659+
68660+skipit:
68661+#endif
68662+
68663+ if (unlikely(!(gr_status & GR_READY)))
68664+ return 0;
68665+
68666+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
68667+ gr_log_learn_uid_change(real, effective, fs);
68668+
68669+ num = current->acl->user_trans_num;
68670+ uidlist = current->acl->user_transitions;
68671+
68672+ if (uidlist == NULL)
68673+ return 0;
68674+
68675+ if (!uid_valid(real)) {
68676+ realok = 1;
68677+ globalreal = (uid_t)-1;
68678+ } else {
68679+ globalreal = GR_GLOBAL_UID(real);
68680+ }
68681+ if (!uid_valid(effective)) {
68682+ effectiveok = 1;
68683+ globaleffective = (uid_t)-1;
68684+ } else {
68685+ globaleffective = GR_GLOBAL_UID(effective);
68686+ }
68687+ if (!uid_valid(fs)) {
68688+ fsok = 1;
68689+ globalfs = (uid_t)-1;
68690+ } else {
68691+ globalfs = GR_GLOBAL_UID(fs);
68692+ }
68693+
68694+ if (current->acl->user_trans_type & GR_ID_ALLOW) {
68695+ for (i = 0; i < num; i++) {
68696+ curuid = uidlist[i];
68697+ if (globalreal == curuid)
68698+ realok = 1;
68699+ if (globaleffective == curuid)
68700+ effectiveok = 1;
68701+ if (globalfs == curuid)
68702+ fsok = 1;
68703+ }
68704+ } else if (current->acl->user_trans_type & GR_ID_DENY) {
68705+ for (i = 0; i < num; i++) {
68706+ curuid = uidlist[i];
68707+ if (globalreal == curuid)
68708+ break;
68709+ if (globaleffective == curuid)
68710+ break;
68711+ if (globalfs == curuid)
68712+ break;
68713+ }
68714+ /* not in deny list */
68715+ if (i == num) {
68716+ realok = 1;
68717+ effectiveok = 1;
68718+ fsok = 1;
68719+ }
68720+ }
68721+
68722+ if (realok && effectiveok && fsok)
68723+ return 0;
68724+ else {
68725+ gr_log_int(GR_DONT_AUDIT, GR_USRCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : globalfs) : globaleffective) : globalreal);
68726+ return 1;
68727+ }
68728+}
68729+
68730+int
68731+gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs)
68732+{
68733+ unsigned int i;
68734+ __u16 num;
68735+ gid_t *gidlist;
68736+ gid_t curgid;
68737+ int realok = 0;
68738+ int effectiveok = 0;
68739+ int fsok = 0;
68740+ gid_t globalreal, globaleffective, globalfs;
68741+
68742+ if (unlikely(!(gr_status & GR_READY)))
68743+ return 0;
68744+
68745+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
68746+ gr_log_learn_gid_change(real, effective, fs);
68747+
68748+ num = current->acl->group_trans_num;
68749+ gidlist = current->acl->group_transitions;
68750+
68751+ if (gidlist == NULL)
68752+ return 0;
68753+
68754+ if (!gid_valid(real)) {
68755+ realok = 1;
68756+ globalreal = (gid_t)-1;
68757+ } else {
68758+ globalreal = GR_GLOBAL_GID(real);
68759+ }
68760+ if (!gid_valid(effective)) {
68761+ effectiveok = 1;
68762+ globaleffective = (gid_t)-1;
68763+ } else {
68764+ globaleffective = GR_GLOBAL_GID(effective);
68765+ }
68766+ if (!gid_valid(fs)) {
68767+ fsok = 1;
68768+ globalfs = (gid_t)-1;
68769+ } else {
68770+ globalfs = GR_GLOBAL_GID(fs);
68771+ }
68772+
68773+ if (current->acl->group_trans_type & GR_ID_ALLOW) {
68774+ for (i = 0; i < num; i++) {
68775+ curgid = gidlist[i];
68776+ if (globalreal == curgid)
68777+ realok = 1;
68778+ if (globaleffective == curgid)
68779+ effectiveok = 1;
68780+ if (globalfs == curgid)
68781+ fsok = 1;
68782+ }
68783+ } else if (current->acl->group_trans_type & GR_ID_DENY) {
68784+ for (i = 0; i < num; i++) {
68785+ curgid = gidlist[i];
68786+ if (globalreal == curgid)
68787+ break;
68788+ if (globaleffective == curgid)
68789+ break;
68790+ if (globalfs == curgid)
68791+ break;
68792+ }
68793+ /* not in deny list */
68794+ if (i == num) {
68795+ realok = 1;
68796+ effectiveok = 1;
68797+ fsok = 1;
68798+ }
68799+ }
68800+
68801+ if (realok && effectiveok && fsok)
68802+ return 0;
68803+ else {
68804+ gr_log_int(GR_DONT_AUDIT, GR_GRPCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : globalfs) : globaleffective) : globalreal);
68805+ return 1;
68806+ }
68807+}
68808+
68809+extern int gr_acl_is_capable(const int cap);
68810+
68811+void
68812+gr_set_role_label(struct task_struct *task, const kuid_t kuid, const kgid_t kgid)
68813+{
68814+ struct acl_role_label *role = task->role;
68815+ struct acl_subject_label *subj = NULL;
68816+ struct acl_object_label *obj;
68817+ struct file *filp;
68818+ uid_t uid;
68819+ gid_t gid;
68820+
68821+ if (unlikely(!(gr_status & GR_READY)))
68822+ return;
68823+
68824+ uid = GR_GLOBAL_UID(kuid);
68825+ gid = GR_GLOBAL_GID(kgid);
68826+
68827+ filp = task->exec_file;
68828+
68829+ /* kernel process, we'll give them the kernel role */
68830+ if (unlikely(!filp)) {
68831+ task->role = running_polstate.kernel_role;
68832+ task->acl = running_polstate.kernel_role->root_label;
68833+ return;
68834+ } else if (!task->role || !(task->role->roletype & GR_ROLE_SPECIAL)) {
68835+ /* save the current ip at time of role lookup so that the proper
68836+ IP will be learned for role_allowed_ip */
68837+ task->signal->saved_ip = task->signal->curr_ip;
68838+ role = lookup_acl_role_label(task, uid, gid);
68839+ }
68840+
68841+ /* don't change the role if we're not a privileged process */
68842+ if (role && task->role != role &&
68843+ (((role->roletype & GR_ROLE_USER) && !gr_acl_is_capable(CAP_SETUID)) ||
68844+ ((role->roletype & GR_ROLE_GROUP) && !gr_acl_is_capable(CAP_SETGID))))
68845+ return;
68846+
68847+ /* perform subject lookup in possibly new role
68848+ we can use this result below in the case where role == task->role
68849+ */
68850+ subj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, role);
68851+
68852+ /* if we changed uid/gid, but result in the same role
68853+ and are using inheritance, don't lose the inherited subject
68854+ if current subject is other than what normal lookup
68855+ would result in, we arrived via inheritance, don't
68856+ lose subject
68857+ */
68858+ if (role != task->role || (!(task->acl->mode & GR_INHERITLEARN) &&
68859+ (subj == task->acl)))
68860+ task->acl = subj;
68861+
68862+ /* leave task->inherited unaffected */
68863+
68864+ task->role = role;
68865+
68866+ task->is_writable = 0;
68867+
68868+ /* ignore additional mmap checks for processes that are writable
68869+ by the default ACL */
68870+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, running_polstate.default_role->root_label);
68871+ if (unlikely(obj->mode & GR_WRITE))
68872+ task->is_writable = 1;
68873+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
68874+ if (unlikely(obj->mode & GR_WRITE))
68875+ task->is_writable = 1;
68876+
68877+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
68878+ 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);
68879+#endif
68880+
68881+ gr_set_proc_res(task);
68882+
68883+ return;
68884+}
68885+
68886+int
68887+gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
68888+ const int unsafe_flags)
68889+{
68890+ struct task_struct *task = current;
68891+ struct acl_subject_label *newacl;
68892+ struct acl_object_label *obj;
68893+ __u32 retmode;
68894+
68895+ if (unlikely(!(gr_status & GR_READY)))
68896+ return 0;
68897+
68898+ newacl = chk_subj_label(dentry, mnt, task->role);
68899+
68900+ /* special handling for if we did an strace -f -p <pid> from an admin role, where pid then
68901+ did an exec
68902+ */
68903+ rcu_read_lock();
68904+ read_lock(&tasklist_lock);
68905+ if (task->ptrace && task->parent && ((task->parent->role->roletype & GR_ROLE_GOD) ||
68906+ (task->parent->acl->mode & GR_POVERRIDE))) {
68907+ read_unlock(&tasklist_lock);
68908+ rcu_read_unlock();
68909+ goto skip_check;
68910+ }
68911+ read_unlock(&tasklist_lock);
68912+ rcu_read_unlock();
68913+
68914+ if (unsafe_flags && !(task->acl->mode & GR_POVERRIDE) && (task->acl != newacl) &&
68915+ !(task->role->roletype & GR_ROLE_GOD) &&
68916+ !gr_search_file(dentry, GR_PTRACERD, mnt) &&
68917+ !(task->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
68918+ if (unsafe_flags & LSM_UNSAFE_SHARE)
68919+ gr_log_fs_generic(GR_DONT_AUDIT, GR_UNSAFESHARE_EXEC_ACL_MSG, dentry, mnt);
68920+ else
68921+ gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_EXEC_ACL_MSG, dentry, mnt);
68922+ return -EACCES;
68923+ }
68924+
68925+skip_check:
68926+
68927+ obj = chk_obj_label(dentry, mnt, task->acl);
68928+ retmode = obj->mode & (GR_INHERIT | GR_AUDIT_INHERIT);
68929+
68930+ if (!(task->acl->mode & GR_INHERITLEARN) &&
68931+ ((newacl->mode & GR_LEARN) || !(retmode & GR_INHERIT))) {
68932+ if (obj->nested)
68933+ task->acl = obj->nested;
68934+ else
68935+ task->acl = newacl;
68936+ task->inherited = 0;
68937+ } else {
68938+ task->inherited = 1;
68939+ if (retmode & GR_INHERIT && retmode & GR_AUDIT_INHERIT)
68940+ gr_log_str_fs(GR_DO_AUDIT, GR_INHERIT_ACL_MSG, task->acl->filename, dentry, mnt);
68941+ }
68942+
68943+ task->is_writable = 0;
68944+
68945+ /* ignore additional mmap checks for processes that are writable
68946+ by the default ACL */
68947+ obj = chk_obj_label(dentry, mnt, running_polstate.default_role->root_label);
68948+ if (unlikely(obj->mode & GR_WRITE))
68949+ task->is_writable = 1;
68950+ obj = chk_obj_label(dentry, mnt, task->role->root_label);
68951+ if (unlikely(obj->mode & GR_WRITE))
68952+ task->is_writable = 1;
68953+
68954+ gr_set_proc_res(task);
68955+
68956+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
68957+ 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);
68958+#endif
68959+ return 0;
68960+}
68961+
68962+/* always called with valid inodev ptr */
68963+static void
68964+do_handle_delete(struct inodev_entry *inodev, const ino_t ino, const dev_t dev)
68965+{
68966+ struct acl_object_label *matchpo;
68967+ struct acl_subject_label *matchps;
68968+ struct acl_subject_label *subj;
68969+ struct acl_role_label *role;
68970+ unsigned int x;
68971+
68972+ FOR_EACH_ROLE_START(role)
68973+ FOR_EACH_SUBJECT_START(role, subj, x)
68974+ if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
68975+ matchpo->mode |= GR_DELETED;
68976+ FOR_EACH_SUBJECT_END(subj,x)
68977+ FOR_EACH_NESTED_SUBJECT_START(role, subj)
68978+ /* nested subjects aren't in the role's subj_hash table */
68979+ if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
68980+ matchpo->mode |= GR_DELETED;
68981+ FOR_EACH_NESTED_SUBJECT_END(subj)
68982+ if ((matchps = lookup_acl_subj_label(ino, dev, role)) != NULL)
68983+ matchps->mode |= GR_DELETED;
68984+ FOR_EACH_ROLE_END(role)
68985+
68986+ inodev->nentry->deleted = 1;
68987+
68988+ return;
68989+}
68990+
68991+void
68992+gr_handle_delete(const ino_t ino, const dev_t dev)
68993+{
68994+ struct inodev_entry *inodev;
68995+
68996+ if (unlikely(!(gr_status & GR_READY)))
68997+ return;
68998+
68999+ write_lock(&gr_inode_lock);
69000+ inodev = lookup_inodev_entry(ino, dev);
69001+ if (inodev != NULL)
69002+ do_handle_delete(inodev, ino, dev);
69003+ write_unlock(&gr_inode_lock);
69004+
69005+ return;
69006+}
69007+
69008+static void
69009+update_acl_obj_label(const ino_t oldinode, const dev_t olddevice,
69010+ const ino_t newinode, const dev_t newdevice,
69011+ struct acl_subject_label *subj)
69012+{
69013+ unsigned int index = gr_fhash(oldinode, olddevice, subj->obj_hash_size);
69014+ struct acl_object_label *match;
69015+
69016+ match = subj->obj_hash[index];
69017+
69018+ while (match && (match->inode != oldinode ||
69019+ match->device != olddevice ||
69020+ !(match->mode & GR_DELETED)))
69021+ match = match->next;
69022+
69023+ if (match && (match->inode == oldinode)
69024+ && (match->device == olddevice)
69025+ && (match->mode & GR_DELETED)) {
69026+ if (match->prev == NULL) {
69027+ subj->obj_hash[index] = match->next;
69028+ if (match->next != NULL)
69029+ match->next->prev = NULL;
69030+ } else {
69031+ match->prev->next = match->next;
69032+ if (match->next != NULL)
69033+ match->next->prev = match->prev;
69034+ }
69035+ match->prev = NULL;
69036+ match->next = NULL;
69037+ match->inode = newinode;
69038+ match->device = newdevice;
69039+ match->mode &= ~GR_DELETED;
69040+
69041+ insert_acl_obj_label(match, subj);
69042+ }
69043+
69044+ return;
69045+}
69046+
69047+static void
69048+update_acl_subj_label(const ino_t oldinode, const dev_t olddevice,
69049+ const ino_t newinode, const dev_t newdevice,
69050+ struct acl_role_label *role)
69051+{
69052+ unsigned int index = gr_fhash(oldinode, olddevice, role->subj_hash_size);
69053+ struct acl_subject_label *match;
69054+
69055+ match = role->subj_hash[index];
69056+
69057+ while (match && (match->inode != oldinode ||
69058+ match->device != olddevice ||
69059+ !(match->mode & GR_DELETED)))
69060+ match = match->next;
69061+
69062+ if (match && (match->inode == oldinode)
69063+ && (match->device == olddevice)
69064+ && (match->mode & GR_DELETED)) {
69065+ if (match->prev == NULL) {
69066+ role->subj_hash[index] = match->next;
69067+ if (match->next != NULL)
69068+ match->next->prev = NULL;
69069+ } else {
69070+ match->prev->next = match->next;
69071+ if (match->next != NULL)
69072+ match->next->prev = match->prev;
69073+ }
69074+ match->prev = NULL;
69075+ match->next = NULL;
69076+ match->inode = newinode;
69077+ match->device = newdevice;
69078+ match->mode &= ~GR_DELETED;
69079+
69080+ insert_acl_subj_label(match, role);
69081+ }
69082+
69083+ return;
69084+}
69085+
69086+static void
69087+update_inodev_entry(const ino_t oldinode, const dev_t olddevice,
69088+ const ino_t newinode, const dev_t newdevice)
69089+{
69090+ unsigned int index = gr_fhash(oldinode, olddevice, running_polstate.inodev_set.i_size);
69091+ struct inodev_entry *match;
69092+
69093+ match = running_polstate.inodev_set.i_hash[index];
69094+
69095+ while (match && (match->nentry->inode != oldinode ||
69096+ match->nentry->device != olddevice || !match->nentry->deleted))
69097+ match = match->next;
69098+
69099+ if (match && (match->nentry->inode == oldinode)
69100+ && (match->nentry->device == olddevice) &&
69101+ match->nentry->deleted) {
69102+ if (match->prev == NULL) {
69103+ running_polstate.inodev_set.i_hash[index] = match->next;
69104+ if (match->next != NULL)
69105+ match->next->prev = NULL;
69106+ } else {
69107+ match->prev->next = match->next;
69108+ if (match->next != NULL)
69109+ match->next->prev = match->prev;
69110+ }
69111+ match->prev = NULL;
69112+ match->next = NULL;
69113+ match->nentry->inode = newinode;
69114+ match->nentry->device = newdevice;
69115+ match->nentry->deleted = 0;
69116+
69117+ insert_inodev_entry(match);
69118+ }
69119+
69120+ return;
69121+}
69122+
69123+static void
69124+__do_handle_create(const struct name_entry *matchn, ino_t ino, dev_t dev)
69125+{
69126+ struct acl_subject_label *subj;
69127+ struct acl_role_label *role;
69128+ unsigned int x;
69129+
69130+ FOR_EACH_ROLE_START(role)
69131+ update_acl_subj_label(matchn->inode, matchn->device, ino, dev, role);
69132+
69133+ FOR_EACH_NESTED_SUBJECT_START(role, subj)
69134+ if ((subj->inode == ino) && (subj->device == dev)) {
69135+ subj->inode = ino;
69136+ subj->device = dev;
69137+ }
69138+ /* nested subjects aren't in the role's subj_hash table */
69139+ update_acl_obj_label(matchn->inode, matchn->device,
69140+ ino, dev, subj);
69141+ FOR_EACH_NESTED_SUBJECT_END(subj)
69142+ FOR_EACH_SUBJECT_START(role, subj, x)
69143+ update_acl_obj_label(matchn->inode, matchn->device,
69144+ ino, dev, subj);
69145+ FOR_EACH_SUBJECT_END(subj,x)
69146+ FOR_EACH_ROLE_END(role)
69147+
69148+ update_inodev_entry(matchn->inode, matchn->device, ino, dev);
69149+
69150+ return;
69151+}
69152+
69153+static void
69154+do_handle_create(const struct name_entry *matchn, const struct dentry *dentry,
69155+ const struct vfsmount *mnt)
69156+{
69157+ ino_t ino = dentry->d_inode->i_ino;
69158+ dev_t dev = __get_dev(dentry);
69159+
69160+ __do_handle_create(matchn, ino, dev);
69161+
69162+ return;
69163+}
69164+
69165+void
69166+gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
69167+{
69168+ struct name_entry *matchn;
69169+
69170+ if (unlikely(!(gr_status & GR_READY)))
69171+ return;
69172+
69173+ preempt_disable();
69174+ matchn = lookup_name_entry(gr_to_filename_rbac(dentry, mnt));
69175+
69176+ if (unlikely((unsigned long)matchn)) {
69177+ write_lock(&gr_inode_lock);
69178+ do_handle_create(matchn, dentry, mnt);
69179+ write_unlock(&gr_inode_lock);
69180+ }
69181+ preempt_enable();
69182+
69183+ return;
69184+}
69185+
69186+void
69187+gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
69188+{
69189+ struct name_entry *matchn;
69190+
69191+ if (unlikely(!(gr_status & GR_READY)))
69192+ return;
69193+
69194+ preempt_disable();
69195+ matchn = lookup_name_entry(gr_to_proc_filename_rbac(dentry, init_pid_ns.proc_mnt));
69196+
69197+ if (unlikely((unsigned long)matchn)) {
69198+ write_lock(&gr_inode_lock);
69199+ __do_handle_create(matchn, inode->i_ino, inode->i_sb->s_dev);
69200+ write_unlock(&gr_inode_lock);
69201+ }
69202+ preempt_enable();
69203+
69204+ return;
69205+}
69206+
69207+void
69208+gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
69209+ struct dentry *old_dentry,
69210+ struct dentry *new_dentry,
69211+ struct vfsmount *mnt, const __u8 replace)
69212+{
69213+ struct name_entry *matchn;
69214+ struct inodev_entry *inodev;
69215+ struct inode *inode = new_dentry->d_inode;
69216+ ino_t old_ino = old_dentry->d_inode->i_ino;
69217+ dev_t old_dev = __get_dev(old_dentry);
69218+
69219+ /* vfs_rename swaps the name and parent link for old_dentry and
69220+ new_dentry
69221+ at this point, old_dentry has the new name, parent link, and inode
69222+ for the renamed file
69223+ if a file is being replaced by a rename, new_dentry has the inode
69224+ and name for the replaced file
69225+ */
69226+
69227+ if (unlikely(!(gr_status & GR_READY)))
69228+ return;
69229+
69230+ preempt_disable();
69231+ matchn = lookup_name_entry(gr_to_filename_rbac(old_dentry, mnt));
69232+
69233+ /* we wouldn't have to check d_inode if it weren't for
69234+ NFS silly-renaming
69235+ */
69236+
69237+ write_lock(&gr_inode_lock);
69238+ if (unlikely(replace && inode)) {
69239+ ino_t new_ino = inode->i_ino;
69240+ dev_t new_dev = __get_dev(new_dentry);
69241+
69242+ inodev = lookup_inodev_entry(new_ino, new_dev);
69243+ if (inodev != NULL && ((inode->i_nlink <= 1) || S_ISDIR(inode->i_mode)))
69244+ do_handle_delete(inodev, new_ino, new_dev);
69245+ }
69246+
69247+ inodev = lookup_inodev_entry(old_ino, old_dev);
69248+ if (inodev != NULL && ((old_dentry->d_inode->i_nlink <= 1) || S_ISDIR(old_dentry->d_inode->i_mode)))
69249+ do_handle_delete(inodev, old_ino, old_dev);
69250+
69251+ if (unlikely((unsigned long)matchn))
69252+ do_handle_create(matchn, old_dentry, mnt);
69253+
69254+ write_unlock(&gr_inode_lock);
69255+ preempt_enable();
69256+
69257+ return;
69258+}
69259+
69260+#if defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC)
69261+static const unsigned long res_learn_bumps[GR_NLIMITS] = {
69262+ [RLIMIT_CPU] = GR_RLIM_CPU_BUMP,
69263+ [RLIMIT_FSIZE] = GR_RLIM_FSIZE_BUMP,
69264+ [RLIMIT_DATA] = GR_RLIM_DATA_BUMP,
69265+ [RLIMIT_STACK] = GR_RLIM_STACK_BUMP,
69266+ [RLIMIT_CORE] = GR_RLIM_CORE_BUMP,
69267+ [RLIMIT_RSS] = GR_RLIM_RSS_BUMP,
69268+ [RLIMIT_NPROC] = GR_RLIM_NPROC_BUMP,
69269+ [RLIMIT_NOFILE] = GR_RLIM_NOFILE_BUMP,
69270+ [RLIMIT_MEMLOCK] = GR_RLIM_MEMLOCK_BUMP,
69271+ [RLIMIT_AS] = GR_RLIM_AS_BUMP,
69272+ [RLIMIT_LOCKS] = GR_RLIM_LOCKS_BUMP,
69273+ [RLIMIT_SIGPENDING] = GR_RLIM_SIGPENDING_BUMP,
69274+ [RLIMIT_MSGQUEUE] = GR_RLIM_MSGQUEUE_BUMP,
69275+ [RLIMIT_NICE] = GR_RLIM_NICE_BUMP,
69276+ [RLIMIT_RTPRIO] = GR_RLIM_RTPRIO_BUMP,
69277+ [RLIMIT_RTTIME] = GR_RLIM_RTTIME_BUMP
69278+};
69279+
69280+void
69281+gr_learn_resource(const struct task_struct *task,
69282+ const int res, const unsigned long wanted, const int gt)
69283+{
69284+ struct acl_subject_label *acl;
69285+ const struct cred *cred;
69286+
69287+ if (unlikely((gr_status & GR_READY) &&
69288+ task->acl && (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))))
69289+ goto skip_reslog;
69290+
69291+ gr_log_resource(task, res, wanted, gt);
69292+skip_reslog:
69293+
69294+ if (unlikely(!(gr_status & GR_READY) || !wanted || res >= GR_NLIMITS))
69295+ return;
69296+
69297+ acl = task->acl;
69298+
69299+ if (likely(!acl || !(acl->mode & (GR_LEARN | GR_INHERITLEARN)) ||
69300+ !(acl->resmask & (1U << (unsigned short) res))))
69301+ return;
69302+
69303+ if (wanted >= acl->res[res].rlim_cur) {
69304+ unsigned long res_add;
69305+
69306+ res_add = wanted + res_learn_bumps[res];
69307+
69308+ acl->res[res].rlim_cur = res_add;
69309+
69310+ if (wanted > acl->res[res].rlim_max)
69311+ acl->res[res].rlim_max = res_add;
69312+
69313+ /* only log the subject filename, since resource logging is supported for
69314+ single-subject learning only */
69315+ rcu_read_lock();
69316+ cred = __task_cred(task);
69317+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
69318+ task->role->roletype, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), acl->filename,
69319+ acl->filename, acl->res[res].rlim_cur, acl->res[res].rlim_max,
69320+ "", (unsigned long) res, &task->signal->saved_ip);
69321+ rcu_read_unlock();
69322+ }
69323+
69324+ return;
69325+}
69326+EXPORT_SYMBOL_GPL(gr_learn_resource);
69327+#endif
69328+
69329+#if defined(CONFIG_PAX_HAVE_ACL_FLAGS) && (defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR))
69330+void
69331+pax_set_initial_flags(struct linux_binprm *bprm)
69332+{
69333+ struct task_struct *task = current;
69334+ struct acl_subject_label *proc;
69335+ unsigned long flags;
69336+
69337+ if (unlikely(!(gr_status & GR_READY)))
69338+ return;
69339+
69340+ flags = pax_get_flags(task);
69341+
69342+ proc = task->acl;
69343+
69344+ if (proc->pax_flags & GR_PAX_DISABLE_PAGEEXEC)
69345+ flags &= ~MF_PAX_PAGEEXEC;
69346+ if (proc->pax_flags & GR_PAX_DISABLE_SEGMEXEC)
69347+ flags &= ~MF_PAX_SEGMEXEC;
69348+ if (proc->pax_flags & GR_PAX_DISABLE_RANDMMAP)
69349+ flags &= ~MF_PAX_RANDMMAP;
69350+ if (proc->pax_flags & GR_PAX_DISABLE_EMUTRAMP)
69351+ flags &= ~MF_PAX_EMUTRAMP;
69352+ if (proc->pax_flags & GR_PAX_DISABLE_MPROTECT)
69353+ flags &= ~MF_PAX_MPROTECT;
69354+
69355+ if (proc->pax_flags & GR_PAX_ENABLE_PAGEEXEC)
69356+ flags |= MF_PAX_PAGEEXEC;
69357+ if (proc->pax_flags & GR_PAX_ENABLE_SEGMEXEC)
69358+ flags |= MF_PAX_SEGMEXEC;
69359+ if (proc->pax_flags & GR_PAX_ENABLE_RANDMMAP)
69360+ flags |= MF_PAX_RANDMMAP;
69361+ if (proc->pax_flags & GR_PAX_ENABLE_EMUTRAMP)
69362+ flags |= MF_PAX_EMUTRAMP;
69363+ if (proc->pax_flags & GR_PAX_ENABLE_MPROTECT)
69364+ flags |= MF_PAX_MPROTECT;
69365+
69366+ pax_set_flags(task, flags);
69367+
69368+ return;
69369+}
69370+#endif
69371+
69372+int
69373+gr_handle_proc_ptrace(struct task_struct *task)
69374+{
69375+ struct file *filp;
69376+ struct task_struct *tmp = task;
69377+ struct task_struct *curtemp = current;
69378+ __u32 retmode;
69379+
69380+#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
69381+ if (unlikely(!(gr_status & GR_READY)))
69382+ return 0;
69383+#endif
69384+
69385+ read_lock(&tasklist_lock);
69386+ read_lock(&grsec_exec_file_lock);
69387+ filp = task->exec_file;
69388+
69389+ while (task_pid_nr(tmp) > 0) {
69390+ if (tmp == curtemp)
69391+ break;
69392+ tmp = tmp->real_parent;
69393+ }
69394+
69395+ if (!filp || (task_pid_nr(tmp) == 0 && ((grsec_enable_harden_ptrace && gr_is_global_nonroot(current_uid()) && !(gr_status & GR_READY)) ||
69396+ ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE))))) {
69397+ read_unlock(&grsec_exec_file_lock);
69398+ read_unlock(&tasklist_lock);
69399+ return 1;
69400+ }
69401+
69402+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
69403+ if (!(gr_status & GR_READY)) {
69404+ read_unlock(&grsec_exec_file_lock);
69405+ read_unlock(&tasklist_lock);
69406+ return 0;
69407+ }
69408+#endif
69409+
69410+ retmode = gr_search_file(filp->f_path.dentry, GR_NOPTRACE, filp->f_path.mnt);
69411+ read_unlock(&grsec_exec_file_lock);
69412+ read_unlock(&tasklist_lock);
69413+
69414+ if (retmode & GR_NOPTRACE)
69415+ return 1;
69416+
69417+ if (!(current->acl->mode & GR_POVERRIDE) && !(current->role->roletype & GR_ROLE_GOD)
69418+ && (current->acl != task->acl || (current->acl != current->role->root_label
69419+ && task_pid_nr(current) != task_pid_nr(task))))
69420+ return 1;
69421+
69422+ return 0;
69423+}
69424+
69425+void task_grsec_rbac(struct seq_file *m, struct task_struct *p)
69426+{
69427+ if (unlikely(!(gr_status & GR_READY)))
69428+ return;
69429+
69430+ if (!(current->role->roletype & GR_ROLE_GOD))
69431+ return;
69432+
69433+ seq_printf(m, "RBAC:\t%.64s:%c:%.950s\n",
69434+ p->role->rolename, gr_task_roletype_to_char(p),
69435+ p->acl->filename);
69436+}
69437+
69438+int
69439+gr_handle_ptrace(struct task_struct *task, const long request)
69440+{
69441+ struct task_struct *tmp = task;
69442+ struct task_struct *curtemp = current;
69443+ __u32 retmode;
69444+
69445+#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
69446+ if (unlikely(!(gr_status & GR_READY)))
69447+ return 0;
69448+#endif
69449+ if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
69450+ read_lock(&tasklist_lock);
69451+ while (task_pid_nr(tmp) > 0) {
69452+ if (tmp == curtemp)
69453+ break;
69454+ tmp = tmp->real_parent;
69455+ }
69456+
69457+ if (task_pid_nr(tmp) == 0 && ((grsec_enable_harden_ptrace && gr_is_global_nonroot(current_uid()) && !(gr_status & GR_READY)) ||
69458+ ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE)))) {
69459+ read_unlock(&tasklist_lock);
69460+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
69461+ return 1;
69462+ }
69463+ read_unlock(&tasklist_lock);
69464+ }
69465+
69466+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
69467+ if (!(gr_status & GR_READY))
69468+ return 0;
69469+#endif
69470+
69471+ read_lock(&grsec_exec_file_lock);
69472+ if (unlikely(!task->exec_file)) {
69473+ read_unlock(&grsec_exec_file_lock);
69474+ return 0;
69475+ }
69476+
69477+ retmode = gr_search_file(task->exec_file->f_path.dentry, GR_PTRACERD | GR_NOPTRACE, task->exec_file->f_path.mnt);
69478+ read_unlock(&grsec_exec_file_lock);
69479+
69480+ if (retmode & GR_NOPTRACE) {
69481+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
69482+ return 1;
69483+ }
69484+
69485+ if (retmode & GR_PTRACERD) {
69486+ switch (request) {
69487+ case PTRACE_SEIZE:
69488+ case PTRACE_POKETEXT:
69489+ case PTRACE_POKEDATA:
69490+ case PTRACE_POKEUSR:
69491+#if !defined(CONFIG_PPC32) && !defined(CONFIG_PPC64) && !defined(CONFIG_PARISC) && !defined(CONFIG_ALPHA) && !defined(CONFIG_IA64)
69492+ case PTRACE_SETREGS:
69493+ case PTRACE_SETFPREGS:
69494+#endif
69495+#ifdef CONFIG_X86
69496+ case PTRACE_SETFPXREGS:
69497+#endif
69498+#ifdef CONFIG_ALTIVEC
69499+ case PTRACE_SETVRREGS:
69500+#endif
69501+ return 1;
69502+ default:
69503+ return 0;
69504+ }
69505+ } else if (!(current->acl->mode & GR_POVERRIDE) &&
69506+ !(current->role->roletype & GR_ROLE_GOD) &&
69507+ (current->acl != task->acl)) {
69508+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
69509+ return 1;
69510+ }
69511+
69512+ return 0;
69513+}
69514+
69515+static int is_writable_mmap(const struct file *filp)
69516+{
69517+ struct task_struct *task = current;
69518+ struct acl_object_label *obj, *obj2;
69519+
69520+ if (gr_status & GR_READY && !(task->acl->mode & GR_OVERRIDE) &&
69521+ !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))) {
69522+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, running_polstate.default_role->root_label);
69523+ obj2 = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt,
69524+ task->role->root_label);
69525+ if (unlikely((obj->mode & GR_WRITE) || (obj2->mode & GR_WRITE))) {
69526+ gr_log_fs_generic(GR_DONT_AUDIT, GR_WRITLIB_ACL_MSG, filp->f_path.dentry, filp->f_path.mnt);
69527+ return 1;
69528+ }
69529+ }
69530+ return 0;
69531+}
69532+
69533+int
69534+gr_acl_handle_mmap(const struct file *file, const unsigned long prot)
69535+{
69536+ __u32 mode;
69537+
69538+ if (unlikely(!file || !(prot & PROT_EXEC)))
69539+ return 1;
69540+
69541+ if (is_writable_mmap(file))
69542+ return 0;
69543+
69544+ mode =
69545+ gr_search_file(file->f_path.dentry,
69546+ GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
69547+ file->f_path.mnt);
69548+
69549+ if (!gr_tpe_allow(file))
69550+ return 0;
69551+
69552+ if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
69553+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
69554+ return 0;
69555+ } else if (unlikely(!(mode & GR_EXEC))) {
69556+ return 0;
69557+ } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
69558+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
69559+ return 1;
69560+ }
69561+
69562+ return 1;
69563+}
69564+
69565+int
69566+gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
69567+{
69568+ __u32 mode;
69569+
69570+ if (unlikely(!file || !(prot & PROT_EXEC)))
69571+ return 1;
69572+
69573+ if (is_writable_mmap(file))
69574+ return 0;
69575+
69576+ mode =
69577+ gr_search_file(file->f_path.dentry,
69578+ GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
69579+ file->f_path.mnt);
69580+
69581+ if (!gr_tpe_allow(file))
69582+ return 0;
69583+
69584+ if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
69585+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
69586+ return 0;
69587+ } else if (unlikely(!(mode & GR_EXEC))) {
69588+ return 0;
69589+ } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
69590+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
69591+ return 1;
69592+ }
69593+
69594+ return 1;
69595+}
69596+
69597+void
69598+gr_acl_handle_psacct(struct task_struct *task, const long code)
69599+{
69600+ unsigned long runtime, cputime;
69601+ cputime_t utime, stime;
69602+ unsigned int wday, cday;
69603+ __u8 whr, chr;
69604+ __u8 wmin, cmin;
69605+ __u8 wsec, csec;
69606+ struct timespec timeval;
69607+
69608+ if (unlikely(!(gr_status & GR_READY) || !task->acl ||
69609+ !(task->acl->mode & GR_PROCACCT)))
69610+ return;
69611+
69612+ do_posix_clock_monotonic_gettime(&timeval);
69613+ runtime = timeval.tv_sec - task->start_time.tv_sec;
69614+ wday = runtime / (60 * 60 * 24);
69615+ runtime -= wday * (60 * 60 * 24);
69616+ whr = runtime / (60 * 60);
69617+ runtime -= whr * (60 * 60);
69618+ wmin = runtime / 60;
69619+ runtime -= wmin * 60;
69620+ wsec = runtime;
69621+
69622+ task_cputime(task, &utime, &stime);
69623+ cputime = cputime_to_secs(utime + stime);
69624+ cday = cputime / (60 * 60 * 24);
69625+ cputime -= cday * (60 * 60 * 24);
69626+ chr = cputime / (60 * 60);
69627+ cputime -= chr * (60 * 60);
69628+ cmin = cputime / 60;
69629+ cputime -= cmin * 60;
69630+ csec = cputime;
69631+
69632+ gr_log_procacct(GR_DO_AUDIT, GR_ACL_PROCACCT_MSG, task, wday, whr, wmin, wsec, cday, chr, cmin, csec, code);
69633+
69634+ return;
69635+}
69636+
69637+#ifdef CONFIG_TASKSTATS
69638+int gr_is_taskstats_denied(int pid)
69639+{
69640+ struct task_struct *task;
69641+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
69642+ const struct cred *cred;
69643+#endif
69644+ int ret = 0;
69645+
69646+ /* restrict taskstats viewing to un-chrooted root users
69647+ who have the 'view' subject flag if the RBAC system is enabled
69648+ */
69649+
69650+ rcu_read_lock();
69651+ read_lock(&tasklist_lock);
69652+ task = find_task_by_vpid(pid);
69653+ if (task) {
69654+#ifdef CONFIG_GRKERNSEC_CHROOT
69655+ if (proc_is_chrooted(task))
69656+ ret = -EACCES;
69657+#endif
69658+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
69659+ cred = __task_cred(task);
69660+#ifdef CONFIG_GRKERNSEC_PROC_USER
69661+ if (gr_is_global_nonroot(cred->uid))
69662+ ret = -EACCES;
69663+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
69664+ if (gr_is_global_nonroot(cred->uid) && !groups_search(cred->group_info, grsec_proc_gid))
69665+ ret = -EACCES;
69666+#endif
69667+#endif
69668+ if (gr_status & GR_READY) {
69669+ if (!(task->acl->mode & GR_VIEW))
69670+ ret = -EACCES;
69671+ }
69672+ } else
69673+ ret = -ENOENT;
69674+
69675+ read_unlock(&tasklist_lock);
69676+ rcu_read_unlock();
69677+
69678+ return ret;
69679+}
69680+#endif
69681+
69682+/* AUXV entries are filled via a descendant of search_binary_handler
69683+ after we've already applied the subject for the target
69684+*/
69685+int gr_acl_enable_at_secure(void)
69686+{
69687+ if (unlikely(!(gr_status & GR_READY)))
69688+ return 0;
69689+
69690+ if (current->acl->mode & GR_ATSECURE)
69691+ return 1;
69692+
69693+ return 0;
69694+}
69695+
69696+int gr_acl_handle_filldir(const struct file *file, const char *name, const unsigned int namelen, const ino_t ino)
69697+{
69698+ struct task_struct *task = current;
69699+ struct dentry *dentry = file->f_path.dentry;
69700+ struct vfsmount *mnt = file->f_path.mnt;
69701+ struct acl_object_label *obj, *tmp;
69702+ struct acl_subject_label *subj;
69703+ unsigned int bufsize;
69704+ int is_not_root;
69705+ char *path;
69706+ dev_t dev = __get_dev(dentry);
69707+
69708+ if (unlikely(!(gr_status & GR_READY)))
69709+ return 1;
69710+
69711+ if (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))
69712+ return 1;
69713+
69714+ /* ignore Eric Biederman */
69715+ if (IS_PRIVATE(dentry->d_inode))
69716+ return 1;
69717+
69718+ subj = task->acl;
69719+ read_lock(&gr_inode_lock);
69720+ do {
69721+ obj = lookup_acl_obj_label(ino, dev, subj);
69722+ if (obj != NULL) {
69723+ read_unlock(&gr_inode_lock);
69724+ return (obj->mode & GR_FIND) ? 1 : 0;
69725+ }
69726+ } while ((subj = subj->parent_subject));
69727+ read_unlock(&gr_inode_lock);
69728+
69729+ /* this is purely an optimization since we're looking for an object
69730+ for the directory we're doing a readdir on
69731+ if it's possible for any globbed object to match the entry we're
69732+ filling into the directory, then the object we find here will be
69733+ an anchor point with attached globbed objects
69734+ */
69735+ obj = chk_obj_label_noglob(dentry, mnt, task->acl);
69736+ if (obj->globbed == NULL)
69737+ return (obj->mode & GR_FIND) ? 1 : 0;
69738+
69739+ is_not_root = ((obj->filename[0] == '/') &&
69740+ (obj->filename[1] == '\0')) ? 0 : 1;
69741+ bufsize = PAGE_SIZE - namelen - is_not_root;
69742+
69743+ /* check bufsize > PAGE_SIZE || bufsize == 0 */
69744+ if (unlikely((bufsize - 1) > (PAGE_SIZE - 1)))
69745+ return 1;
69746+
69747+ preempt_disable();
69748+ path = d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
69749+ bufsize);
69750+
69751+ bufsize = strlen(path);
69752+
69753+ /* if base is "/", don't append an additional slash */
69754+ if (is_not_root)
69755+ *(path + bufsize) = '/';
69756+ memcpy(path + bufsize + is_not_root, name, namelen);
69757+ *(path + bufsize + namelen + is_not_root) = '\0';
69758+
69759+ tmp = obj->globbed;
69760+ while (tmp) {
69761+ if (!glob_match(tmp->filename, path)) {
69762+ preempt_enable();
69763+ return (tmp->mode & GR_FIND) ? 1 : 0;
69764+ }
69765+ tmp = tmp->next;
69766+ }
69767+ preempt_enable();
69768+ return (obj->mode & GR_FIND) ? 1 : 0;
69769+}
69770+
69771+void gr_put_exec_file(struct task_struct *task)
69772+{
69773+ struct file *filp;
69774+
69775+ write_lock(&grsec_exec_file_lock);
69776+ filp = task->exec_file;
69777+ task->exec_file = NULL;
69778+ write_unlock(&grsec_exec_file_lock);
69779+
69780+ if (filp)
69781+ fput(filp);
69782+
69783+ return;
69784+}
69785+
69786+
69787+#ifdef CONFIG_NETFILTER_XT_MATCH_GRADM_MODULE
69788+EXPORT_SYMBOL_GPL(gr_acl_is_enabled);
69789+#endif
69790+#ifdef CONFIG_SECURITY
69791+EXPORT_SYMBOL_GPL(gr_check_user_change);
69792+EXPORT_SYMBOL_GPL(gr_check_group_change);
69793+#endif
69794+
69795diff --git a/grsecurity/gracl_alloc.c b/grsecurity/gracl_alloc.c
69796new file mode 100644
69797index 0000000..18ffbbd
69798--- /dev/null
69799+++ b/grsecurity/gracl_alloc.c
69800@@ -0,0 +1,105 @@
69801+#include <linux/kernel.h>
69802+#include <linux/mm.h>
69803+#include <linux/slab.h>
69804+#include <linux/vmalloc.h>
69805+#include <linux/gracl.h>
69806+#include <linux/grsecurity.h>
69807+
69808+static struct gr_alloc_state __current_alloc_state = { 1, 1, NULL };
69809+struct gr_alloc_state *current_alloc_state = &__current_alloc_state;
69810+
69811+static __inline__ int
69812+alloc_pop(void)
69813+{
69814+ if (current_alloc_state->alloc_stack_next == 1)
69815+ return 0;
69816+
69817+ kfree(current_alloc_state->alloc_stack[current_alloc_state->alloc_stack_next - 2]);
69818+
69819+ current_alloc_state->alloc_stack_next--;
69820+
69821+ return 1;
69822+}
69823+
69824+static __inline__ int
69825+alloc_push(void *buf)
69826+{
69827+ if (current_alloc_state->alloc_stack_next >= current_alloc_state->alloc_stack_size)
69828+ return 1;
69829+
69830+ current_alloc_state->alloc_stack[current_alloc_state->alloc_stack_next - 1] = buf;
69831+
69832+ current_alloc_state->alloc_stack_next++;
69833+
69834+ return 0;
69835+}
69836+
69837+void *
69838+acl_alloc(unsigned long len)
69839+{
69840+ void *ret = NULL;
69841+
69842+ if (!len || len > PAGE_SIZE)
69843+ goto out;
69844+
69845+ ret = kmalloc(len, GFP_KERNEL);
69846+
69847+ if (ret) {
69848+ if (alloc_push(ret)) {
69849+ kfree(ret);
69850+ ret = NULL;
69851+ }
69852+ }
69853+
69854+out:
69855+ return ret;
69856+}
69857+
69858+void *
69859+acl_alloc_num(unsigned long num, unsigned long len)
69860+{
69861+ if (!len || (num > (PAGE_SIZE / len)))
69862+ return NULL;
69863+
69864+ return acl_alloc(num * len);
69865+}
69866+
69867+void
69868+acl_free_all(void)
69869+{
69870+ if (!current_alloc_state->alloc_stack)
69871+ return;
69872+
69873+ while (alloc_pop()) ;
69874+
69875+ if (current_alloc_state->alloc_stack) {
69876+ if ((current_alloc_state->alloc_stack_size * sizeof (void *)) <= PAGE_SIZE)
69877+ kfree(current_alloc_state->alloc_stack);
69878+ else
69879+ vfree(current_alloc_state->alloc_stack);
69880+ }
69881+
69882+ current_alloc_state->alloc_stack = NULL;
69883+ current_alloc_state->alloc_stack_size = 1;
69884+ current_alloc_state->alloc_stack_next = 1;
69885+
69886+ return;
69887+}
69888+
69889+int
69890+acl_alloc_stack_init(unsigned long size)
69891+{
69892+ if ((size * sizeof (void *)) <= PAGE_SIZE)
69893+ current_alloc_state->alloc_stack =
69894+ (void **) kmalloc(size * sizeof (void *), GFP_KERNEL);
69895+ else
69896+ current_alloc_state->alloc_stack = (void **) vmalloc(size * sizeof (void *));
69897+
69898+ current_alloc_state->alloc_stack_size = size;
69899+ current_alloc_state->alloc_stack_next = 1;
69900+
69901+ if (!current_alloc_state->alloc_stack)
69902+ return 0;
69903+ else
69904+ return 1;
69905+}
69906diff --git a/grsecurity/gracl_cap.c b/grsecurity/gracl_cap.c
69907new file mode 100644
69908index 0000000..bdd51ea
69909--- /dev/null
69910+++ b/grsecurity/gracl_cap.c
69911@@ -0,0 +1,110 @@
69912+#include <linux/kernel.h>
69913+#include <linux/module.h>
69914+#include <linux/sched.h>
69915+#include <linux/gracl.h>
69916+#include <linux/grsecurity.h>
69917+#include <linux/grinternal.h>
69918+
69919+extern const char *captab_log[];
69920+extern int captab_log_entries;
69921+
69922+int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
69923+{
69924+ struct acl_subject_label *curracl;
69925+ kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
69926+ kernel_cap_t cap_audit = __cap_empty_set;
69927+
69928+ if (!gr_acl_is_enabled())
69929+ return 1;
69930+
69931+ curracl = task->acl;
69932+
69933+ cap_drop = curracl->cap_lower;
69934+ cap_mask = curracl->cap_mask;
69935+ cap_audit = curracl->cap_invert_audit;
69936+
69937+ while ((curracl = curracl->parent_subject)) {
69938+ /* if the cap isn't specified in the current computed mask but is specified in the
69939+ current level subject, and is lowered in the current level subject, then add
69940+ it to the set of dropped capabilities
69941+ otherwise, add the current level subject's mask to the current computed mask
69942+ */
69943+ if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
69944+ cap_raise(cap_mask, cap);
69945+ if (cap_raised(curracl->cap_lower, cap))
69946+ cap_raise(cap_drop, cap);
69947+ if (cap_raised(curracl->cap_invert_audit, cap))
69948+ cap_raise(cap_audit, cap);
69949+ }
69950+ }
69951+
69952+ if (!cap_raised(cap_drop, cap)) {
69953+ if (cap_raised(cap_audit, cap))
69954+ gr_log_cap(GR_DO_AUDIT, GR_CAP_ACL_MSG2, task, captab_log[cap]);
69955+ return 1;
69956+ }
69957+
69958+ curracl = task->acl;
69959+
69960+ if ((curracl->mode & (GR_LEARN | GR_INHERITLEARN))
69961+ && cap_raised(cred->cap_effective, cap)) {
69962+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
69963+ task->role->roletype, GR_GLOBAL_UID(cred->uid),
69964+ GR_GLOBAL_GID(cred->gid), task->exec_file ?
69965+ gr_to_filename(task->exec_file->f_path.dentry,
69966+ task->exec_file->f_path.mnt) : curracl->filename,
69967+ curracl->filename, 0UL,
69968+ 0UL, "", (unsigned long) cap, &task->signal->saved_ip);
69969+ return 1;
69970+ }
69971+
69972+ if ((cap >= 0) && (cap < captab_log_entries) && cap_raised(cred->cap_effective, cap) && !cap_raised(cap_audit, cap))
69973+ gr_log_cap(GR_DONT_AUDIT, GR_CAP_ACL_MSG, task, captab_log[cap]);
69974+
69975+ return 0;
69976+}
69977+
69978+int
69979+gr_acl_is_capable(const int cap)
69980+{
69981+ return gr_task_acl_is_capable(current, current_cred(), cap);
69982+}
69983+
69984+int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap)
69985+{
69986+ struct acl_subject_label *curracl;
69987+ kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
69988+
69989+ if (!gr_acl_is_enabled())
69990+ return 1;
69991+
69992+ curracl = task->acl;
69993+
69994+ cap_drop = curracl->cap_lower;
69995+ cap_mask = curracl->cap_mask;
69996+
69997+ while ((curracl = curracl->parent_subject)) {
69998+ /* if the cap isn't specified in the current computed mask but is specified in the
69999+ current level subject, and is lowered in the current level subject, then add
70000+ it to the set of dropped capabilities
70001+ otherwise, add the current level subject's mask to the current computed mask
70002+ */
70003+ if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
70004+ cap_raise(cap_mask, cap);
70005+ if (cap_raised(curracl->cap_lower, cap))
70006+ cap_raise(cap_drop, cap);
70007+ }
70008+ }
70009+
70010+ if (!cap_raised(cap_drop, cap))
70011+ return 1;
70012+
70013+ return 0;
70014+}
70015+
70016+int
70017+gr_acl_is_capable_nolog(const int cap)
70018+{
70019+ return gr_task_acl_is_capable_nolog(current, cap);
70020+}
70021+
70022diff --git a/grsecurity/gracl_compat.c b/grsecurity/gracl_compat.c
70023new file mode 100644
70024index 0000000..ca25605
70025--- /dev/null
70026+++ b/grsecurity/gracl_compat.c
70027@@ -0,0 +1,270 @@
70028+#include <linux/kernel.h>
70029+#include <linux/gracl.h>
70030+#include <linux/compat.h>
70031+#include <linux/gracl_compat.h>
70032+
70033+#include <asm/uaccess.h>
70034+
70035+int copy_gr_arg_wrapper_compat(const char *buf, struct gr_arg_wrapper *uwrap)
70036+{
70037+ struct gr_arg_wrapper_compat uwrapcompat;
70038+
70039+ if (copy_from_user(&uwrapcompat, buf, sizeof(uwrapcompat)))
70040+ return -EFAULT;
70041+
70042+ if (((uwrapcompat.version != GRSECURITY_VERSION) &&
70043+ (uwrapcompat.version != 0x2901)) ||
70044+ (uwrapcompat.size != sizeof(struct gr_arg_compat)))
70045+ return -EINVAL;
70046+
70047+ uwrap->arg = compat_ptr(uwrapcompat.arg);
70048+ uwrap->version = uwrapcompat.version;
70049+ uwrap->size = sizeof(struct gr_arg);
70050+
70051+ return 0;
70052+}
70053+
70054+int copy_gr_arg_compat(const struct gr_arg __user *buf, struct gr_arg *arg)
70055+{
70056+ struct gr_arg_compat argcompat;
70057+
70058+ if (copy_from_user(&argcompat, buf, sizeof(argcompat)))
70059+ return -EFAULT;
70060+
70061+ arg->role_db.r_table = compat_ptr(argcompat.role_db.r_table);
70062+ arg->role_db.num_pointers = argcompat.role_db.num_pointers;
70063+ arg->role_db.num_roles = argcompat.role_db.num_roles;
70064+ arg->role_db.num_domain_children = argcompat.role_db.num_domain_children;
70065+ arg->role_db.num_subjects = argcompat.role_db.num_subjects;
70066+ arg->role_db.num_objects = argcompat.role_db.num_objects;
70067+
70068+ memcpy(&arg->pw, &argcompat.pw, sizeof(arg->pw));
70069+ memcpy(&arg->salt, &argcompat.salt, sizeof(arg->salt));
70070+ memcpy(&arg->sum, &argcompat.sum, sizeof(arg->sum));
70071+ memcpy(&arg->sp_role, &argcompat.sp_role, sizeof(arg->sp_role));
70072+ arg->sprole_pws = compat_ptr(argcompat.sprole_pws);
70073+ arg->segv_device = argcompat.segv_device;
70074+ arg->segv_inode = argcompat.segv_inode;
70075+ arg->segv_uid = argcompat.segv_uid;
70076+ arg->num_sprole_pws = argcompat.num_sprole_pws;
70077+ arg->mode = argcompat.mode;
70078+
70079+ return 0;
70080+}
70081+
70082+int copy_acl_object_label_compat(struct acl_object_label *obj, const struct acl_object_label *userp)
70083+{
70084+ struct acl_object_label_compat objcompat;
70085+
70086+ if (copy_from_user(&objcompat, userp, sizeof(objcompat)))
70087+ return -EFAULT;
70088+
70089+ obj->filename = compat_ptr(objcompat.filename);
70090+ obj->inode = objcompat.inode;
70091+ obj->device = objcompat.device;
70092+ obj->mode = objcompat.mode;
70093+
70094+ obj->nested = compat_ptr(objcompat.nested);
70095+ obj->globbed = compat_ptr(objcompat.globbed);
70096+
70097+ obj->prev = compat_ptr(objcompat.prev);
70098+ obj->next = compat_ptr(objcompat.next);
70099+
70100+ return 0;
70101+}
70102+
70103+int copy_acl_subject_label_compat(struct acl_subject_label *subj, const struct acl_subject_label *userp)
70104+{
70105+ unsigned int i;
70106+ struct acl_subject_label_compat subjcompat;
70107+
70108+ if (copy_from_user(&subjcompat, userp, sizeof(subjcompat)))
70109+ return -EFAULT;
70110+
70111+ subj->filename = compat_ptr(subjcompat.filename);
70112+ subj->inode = subjcompat.inode;
70113+ subj->device = subjcompat.device;
70114+ subj->mode = subjcompat.mode;
70115+ subj->cap_mask = subjcompat.cap_mask;
70116+ subj->cap_lower = subjcompat.cap_lower;
70117+ subj->cap_invert_audit = subjcompat.cap_invert_audit;
70118+
70119+ for (i = 0; i < GR_NLIMITS; i++) {
70120+ if (subjcompat.res[i].rlim_cur == COMPAT_RLIM_INFINITY)
70121+ subj->res[i].rlim_cur = RLIM_INFINITY;
70122+ else
70123+ subj->res[i].rlim_cur = subjcompat.res[i].rlim_cur;
70124+ if (subjcompat.res[i].rlim_max == COMPAT_RLIM_INFINITY)
70125+ subj->res[i].rlim_max = RLIM_INFINITY;
70126+ else
70127+ subj->res[i].rlim_max = subjcompat.res[i].rlim_max;
70128+ }
70129+ subj->resmask = subjcompat.resmask;
70130+
70131+ subj->user_trans_type = subjcompat.user_trans_type;
70132+ subj->group_trans_type = subjcompat.group_trans_type;
70133+ subj->user_transitions = compat_ptr(subjcompat.user_transitions);
70134+ subj->group_transitions = compat_ptr(subjcompat.group_transitions);
70135+ subj->user_trans_num = subjcompat.user_trans_num;
70136+ subj->group_trans_num = subjcompat.group_trans_num;
70137+
70138+ memcpy(&subj->sock_families, &subjcompat.sock_families, sizeof(subj->sock_families));
70139+ memcpy(&subj->ip_proto, &subjcompat.ip_proto, sizeof(subj->ip_proto));
70140+ subj->ip_type = subjcompat.ip_type;
70141+ subj->ips = compat_ptr(subjcompat.ips);
70142+ subj->ip_num = subjcompat.ip_num;
70143+ subj->inaddr_any_override = subjcompat.inaddr_any_override;
70144+
70145+ subj->crashes = subjcompat.crashes;
70146+ subj->expires = subjcompat.expires;
70147+
70148+ subj->parent_subject = compat_ptr(subjcompat.parent_subject);
70149+ subj->hash = compat_ptr(subjcompat.hash);
70150+ subj->prev = compat_ptr(subjcompat.prev);
70151+ subj->next = compat_ptr(subjcompat.next);
70152+
70153+ subj->obj_hash = compat_ptr(subjcompat.obj_hash);
70154+ subj->obj_hash_size = subjcompat.obj_hash_size;
70155+ subj->pax_flags = subjcompat.pax_flags;
70156+
70157+ return 0;
70158+}
70159+
70160+int copy_acl_role_label_compat(struct acl_role_label *role, const struct acl_role_label *userp)
70161+{
70162+ struct acl_role_label_compat rolecompat;
70163+
70164+ if (copy_from_user(&rolecompat, userp, sizeof(rolecompat)))
70165+ return -EFAULT;
70166+
70167+ role->rolename = compat_ptr(rolecompat.rolename);
70168+ role->uidgid = rolecompat.uidgid;
70169+ role->roletype = rolecompat.roletype;
70170+
70171+ role->auth_attempts = rolecompat.auth_attempts;
70172+ role->expires = rolecompat.expires;
70173+
70174+ role->root_label = compat_ptr(rolecompat.root_label);
70175+ role->hash = compat_ptr(rolecompat.hash);
70176+
70177+ role->prev = compat_ptr(rolecompat.prev);
70178+ role->next = compat_ptr(rolecompat.next);
70179+
70180+ role->transitions = compat_ptr(rolecompat.transitions);
70181+ role->allowed_ips = compat_ptr(rolecompat.allowed_ips);
70182+ role->domain_children = compat_ptr(rolecompat.domain_children);
70183+ role->domain_child_num = rolecompat.domain_child_num;
70184+
70185+ role->umask = rolecompat.umask;
70186+
70187+ role->subj_hash = compat_ptr(rolecompat.subj_hash);
70188+ role->subj_hash_size = rolecompat.subj_hash_size;
70189+
70190+ return 0;
70191+}
70192+
70193+int copy_role_allowed_ip_compat(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp)
70194+{
70195+ struct role_allowed_ip_compat roleip_compat;
70196+
70197+ if (copy_from_user(&roleip_compat, userp, sizeof(roleip_compat)))
70198+ return -EFAULT;
70199+
70200+ roleip->addr = roleip_compat.addr;
70201+ roleip->netmask = roleip_compat.netmask;
70202+
70203+ roleip->prev = compat_ptr(roleip_compat.prev);
70204+ roleip->next = compat_ptr(roleip_compat.next);
70205+
70206+ return 0;
70207+}
70208+
70209+int copy_role_transition_compat(struct role_transition *trans, const struct role_transition *userp)
70210+{
70211+ struct role_transition_compat trans_compat;
70212+
70213+ if (copy_from_user(&trans_compat, userp, sizeof(trans_compat)))
70214+ return -EFAULT;
70215+
70216+ trans->rolename = compat_ptr(trans_compat.rolename);
70217+
70218+ trans->prev = compat_ptr(trans_compat.prev);
70219+ trans->next = compat_ptr(trans_compat.next);
70220+
70221+ return 0;
70222+
70223+}
70224+
70225+int copy_gr_hash_struct_compat(struct gr_hash_struct *hash, const struct gr_hash_struct *userp)
70226+{
70227+ struct gr_hash_struct_compat hash_compat;
70228+
70229+ if (copy_from_user(&hash_compat, userp, sizeof(hash_compat)))
70230+ return -EFAULT;
70231+
70232+ hash->table = compat_ptr(hash_compat.table);
70233+ hash->nametable = compat_ptr(hash_compat.nametable);
70234+ hash->first = compat_ptr(hash_compat.first);
70235+
70236+ hash->table_size = hash_compat.table_size;
70237+ hash->used_size = hash_compat.used_size;
70238+
70239+ hash->type = hash_compat.type;
70240+
70241+ return 0;
70242+}
70243+
70244+int copy_pointer_from_array_compat(void *ptr, unsigned long idx, const void *userp)
70245+{
70246+ compat_uptr_t ptrcompat;
70247+
70248+ if (copy_from_user(&ptrcompat, userp + (idx * sizeof(ptrcompat)), sizeof(ptrcompat)))
70249+ return -EFAULT;
70250+
70251+ *(void **)ptr = compat_ptr(ptrcompat);
70252+
70253+ return 0;
70254+}
70255+
70256+int copy_acl_ip_label_compat(struct acl_ip_label *ip, const struct acl_ip_label *userp)
70257+{
70258+ struct acl_ip_label_compat ip_compat;
70259+
70260+ if (copy_from_user(&ip_compat, userp, sizeof(ip_compat)))
70261+ return -EFAULT;
70262+
70263+ ip->iface = compat_ptr(ip_compat.iface);
70264+ ip->addr = ip_compat.addr;
70265+ ip->netmask = ip_compat.netmask;
70266+ ip->low = ip_compat.low;
70267+ ip->high = ip_compat.high;
70268+ ip->mode = ip_compat.mode;
70269+ ip->type = ip_compat.type;
70270+
70271+ memcpy(&ip->proto, &ip_compat.proto, sizeof(ip->proto));
70272+
70273+ ip->prev = compat_ptr(ip_compat.prev);
70274+ ip->next = compat_ptr(ip_compat.next);
70275+
70276+ return 0;
70277+}
70278+
70279+int copy_sprole_pw_compat(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp)
70280+{
70281+ struct sprole_pw_compat pw_compat;
70282+
70283+ if (copy_from_user(&pw_compat, (const void *)userp + (sizeof(pw_compat) * idx), sizeof(pw_compat)))
70284+ return -EFAULT;
70285+
70286+ pw->rolename = compat_ptr(pw_compat.rolename);
70287+ memcpy(&pw->salt, pw_compat.salt, sizeof(pw->salt));
70288+ memcpy(&pw->sum, pw_compat.sum, sizeof(pw->sum));
70289+
70290+ return 0;
70291+}
70292+
70293+size_t get_gr_arg_wrapper_size_compat(void)
70294+{
70295+ return sizeof(struct gr_arg_wrapper_compat);
70296+}
70297+
70298diff --git a/grsecurity/gracl_fs.c b/grsecurity/gracl_fs.c
70299new file mode 100644
70300index 0000000..a89b1f4
70301--- /dev/null
70302+++ b/grsecurity/gracl_fs.c
70303@@ -0,0 +1,437 @@
70304+#include <linux/kernel.h>
70305+#include <linux/sched.h>
70306+#include <linux/types.h>
70307+#include <linux/fs.h>
70308+#include <linux/file.h>
70309+#include <linux/stat.h>
70310+#include <linux/grsecurity.h>
70311+#include <linux/grinternal.h>
70312+#include <linux/gracl.h>
70313+
70314+umode_t
70315+gr_acl_umask(void)
70316+{
70317+ if (unlikely(!gr_acl_is_enabled()))
70318+ return 0;
70319+
70320+ return current->role->umask;
70321+}
70322+
70323+__u32
70324+gr_acl_handle_hidden_file(const struct dentry * dentry,
70325+ const struct vfsmount * mnt)
70326+{
70327+ __u32 mode;
70328+
70329+ if (unlikely(d_is_negative(dentry)))
70330+ return GR_FIND;
70331+
70332+ mode =
70333+ gr_search_file(dentry, GR_FIND | GR_AUDIT_FIND | GR_SUPPRESS, mnt);
70334+
70335+ if (unlikely(mode & GR_FIND && mode & GR_AUDIT_FIND)) {
70336+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
70337+ return mode;
70338+ } else if (unlikely(!(mode & GR_FIND) && !(mode & GR_SUPPRESS))) {
70339+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
70340+ return 0;
70341+ } else if (unlikely(!(mode & GR_FIND)))
70342+ return 0;
70343+
70344+ return GR_FIND;
70345+}
70346+
70347+__u32
70348+gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
70349+ int acc_mode)
70350+{
70351+ __u32 reqmode = GR_FIND;
70352+ __u32 mode;
70353+
70354+ if (unlikely(d_is_negative(dentry)))
70355+ return reqmode;
70356+
70357+ if (acc_mode & MAY_APPEND)
70358+ reqmode |= GR_APPEND;
70359+ else if (acc_mode & MAY_WRITE)
70360+ reqmode |= GR_WRITE;
70361+ if ((acc_mode & MAY_READ) && !S_ISDIR(dentry->d_inode->i_mode))
70362+ reqmode |= GR_READ;
70363+
70364+ mode =
70365+ gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
70366+ mnt);
70367+
70368+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
70369+ gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
70370+ reqmode & GR_READ ? " reading" : "",
70371+ reqmode & GR_WRITE ? " writing" : reqmode &
70372+ GR_APPEND ? " appending" : "");
70373+ return reqmode;
70374+ } else
70375+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
70376+ {
70377+ gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
70378+ reqmode & GR_READ ? " reading" : "",
70379+ reqmode & GR_WRITE ? " writing" : reqmode &
70380+ GR_APPEND ? " appending" : "");
70381+ return 0;
70382+ } else if (unlikely((mode & reqmode) != reqmode))
70383+ return 0;
70384+
70385+ return reqmode;
70386+}
70387+
70388+__u32
70389+gr_acl_handle_creat(const struct dentry * dentry,
70390+ const struct dentry * p_dentry,
70391+ const struct vfsmount * p_mnt, int open_flags, int acc_mode,
70392+ const int imode)
70393+{
70394+ __u32 reqmode = GR_WRITE | GR_CREATE;
70395+ __u32 mode;
70396+
70397+ if (acc_mode & MAY_APPEND)
70398+ reqmode |= GR_APPEND;
70399+ // if a directory was required or the directory already exists, then
70400+ // don't count this open as a read
70401+ if ((acc_mode & MAY_READ) &&
70402+ !((open_flags & O_DIRECTORY) || (dentry->d_inode && S_ISDIR(dentry->d_inode->i_mode))))
70403+ reqmode |= GR_READ;
70404+ if ((open_flags & O_CREAT) &&
70405+ ((imode & S_ISUID) || ((imode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
70406+ reqmode |= GR_SETID;
70407+
70408+ mode =
70409+ gr_check_create(dentry, p_dentry, p_mnt,
70410+ reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
70411+
70412+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
70413+ gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
70414+ reqmode & GR_READ ? " reading" : "",
70415+ reqmode & GR_WRITE ? " writing" : reqmode &
70416+ GR_APPEND ? " appending" : "");
70417+ return reqmode;
70418+ } else
70419+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
70420+ {
70421+ gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
70422+ reqmode & GR_READ ? " reading" : "",
70423+ reqmode & GR_WRITE ? " writing" : reqmode &
70424+ GR_APPEND ? " appending" : "");
70425+ return 0;
70426+ } else if (unlikely((mode & reqmode) != reqmode))
70427+ return 0;
70428+
70429+ return reqmode;
70430+}
70431+
70432+__u32
70433+gr_acl_handle_access(const struct dentry * dentry, const struct vfsmount * mnt,
70434+ const int fmode)
70435+{
70436+ __u32 mode, reqmode = GR_FIND;
70437+
70438+ if ((fmode & S_IXOTH) && !S_ISDIR(dentry->d_inode->i_mode))
70439+ reqmode |= GR_EXEC;
70440+ if (fmode & S_IWOTH)
70441+ reqmode |= GR_WRITE;
70442+ if (fmode & S_IROTH)
70443+ reqmode |= GR_READ;
70444+
70445+ mode =
70446+ gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
70447+ mnt);
70448+
70449+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
70450+ gr_log_fs_rbac_mode3(GR_DO_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
70451+ reqmode & GR_READ ? " reading" : "",
70452+ reqmode & GR_WRITE ? " writing" : "",
70453+ reqmode & GR_EXEC ? " executing" : "");
70454+ return reqmode;
70455+ } else
70456+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
70457+ {
70458+ gr_log_fs_rbac_mode3(GR_DONT_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
70459+ reqmode & GR_READ ? " reading" : "",
70460+ reqmode & GR_WRITE ? " writing" : "",
70461+ reqmode & GR_EXEC ? " executing" : "");
70462+ return 0;
70463+ } else if (unlikely((mode & reqmode) != reqmode))
70464+ return 0;
70465+
70466+ return reqmode;
70467+}
70468+
70469+static __u32 generic_fs_handler(const struct dentry *dentry, const struct vfsmount *mnt, __u32 reqmode, const char *fmt)
70470+{
70471+ __u32 mode;
70472+
70473+ mode = gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS, mnt);
70474+
70475+ if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
70476+ gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, dentry, mnt);
70477+ return mode;
70478+ } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
70479+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, dentry, mnt);
70480+ return 0;
70481+ } else if (unlikely((mode & (reqmode)) != (reqmode)))
70482+ return 0;
70483+
70484+ return (reqmode);
70485+}
70486+
70487+__u32
70488+gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
70489+{
70490+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_RMDIR_ACL_MSG);
70491+}
70492+
70493+__u32
70494+gr_acl_handle_unlink(const struct dentry *dentry, const struct vfsmount *mnt)
70495+{
70496+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_UNLINK_ACL_MSG);
70497+}
70498+
70499+__u32
70500+gr_acl_handle_truncate(const struct dentry *dentry, const struct vfsmount *mnt)
70501+{
70502+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_TRUNCATE_ACL_MSG);
70503+}
70504+
70505+__u32
70506+gr_acl_handle_utime(const struct dentry *dentry, const struct vfsmount *mnt)
70507+{
70508+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_ATIME_ACL_MSG);
70509+}
70510+
70511+__u32
70512+gr_acl_handle_chmod(const struct dentry *dentry, const struct vfsmount *mnt,
70513+ umode_t *modeptr)
70514+{
70515+ umode_t mode;
70516+
70517+ *modeptr &= ~gr_acl_umask();
70518+ mode = *modeptr;
70519+
70520+ if (unlikely(dentry->d_inode && S_ISSOCK(dentry->d_inode->i_mode)))
70521+ return 1;
70522+
70523+ if (unlikely(dentry->d_inode && !S_ISDIR(dentry->d_inode->i_mode) &&
70524+ ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))) {
70525+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
70526+ GR_CHMOD_ACL_MSG);
70527+ } else {
70528+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHMOD_ACL_MSG);
70529+ }
70530+}
70531+
70532+__u32
70533+gr_acl_handle_chown(const struct dentry *dentry, const struct vfsmount *mnt)
70534+{
70535+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHOWN_ACL_MSG);
70536+}
70537+
70538+__u32
70539+gr_acl_handle_setxattr(const struct dentry *dentry, const struct vfsmount *mnt)
70540+{
70541+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_SETXATTR_ACL_MSG);
70542+}
70543+
70544+__u32
70545+gr_acl_handle_removexattr(const struct dentry *dentry, const struct vfsmount *mnt)
70546+{
70547+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_REMOVEXATTR_ACL_MSG);
70548+}
70549+
70550+__u32
70551+gr_acl_handle_execve(const struct dentry *dentry, const struct vfsmount *mnt)
70552+{
70553+ return generic_fs_handler(dentry, mnt, GR_EXEC, GR_EXEC_ACL_MSG);
70554+}
70555+
70556+__u32
70557+gr_acl_handle_unix(const struct dentry *dentry, const struct vfsmount *mnt)
70558+{
70559+ return generic_fs_handler(dentry, mnt, GR_READ | GR_WRITE,
70560+ GR_UNIXCONNECT_ACL_MSG);
70561+}
70562+
70563+/* hardlinks require at minimum create and link permission,
70564+ any additional privilege required is based on the
70565+ privilege of the file being linked to
70566+*/
70567+__u32
70568+gr_acl_handle_link(const struct dentry * new_dentry,
70569+ const struct dentry * parent_dentry,
70570+ const struct vfsmount * parent_mnt,
70571+ const struct dentry * old_dentry,
70572+ const struct vfsmount * old_mnt, const struct filename *to)
70573+{
70574+ __u32 mode;
70575+ __u32 needmode = GR_CREATE | GR_LINK;
70576+ __u32 needaudit = GR_AUDIT_CREATE | GR_AUDIT_LINK;
70577+
70578+ mode =
70579+ gr_check_link(new_dentry, parent_dentry, parent_mnt, old_dentry,
70580+ old_mnt);
70581+
70582+ if (unlikely(((mode & needmode) == needmode) && (mode & needaudit))) {
70583+ gr_log_fs_rbac_str(GR_DO_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
70584+ return mode;
70585+ } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
70586+ gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
70587+ return 0;
70588+ } else if (unlikely((mode & needmode) != needmode))
70589+ return 0;
70590+
70591+ return 1;
70592+}
70593+
70594+__u32
70595+gr_acl_handle_symlink(const struct dentry * new_dentry,
70596+ const struct dentry * parent_dentry,
70597+ const struct vfsmount * parent_mnt, const struct filename *from)
70598+{
70599+ __u32 needmode = GR_WRITE | GR_CREATE;
70600+ __u32 mode;
70601+
70602+ mode =
70603+ gr_check_create(new_dentry, parent_dentry, parent_mnt,
70604+ GR_CREATE | GR_AUDIT_CREATE |
70605+ GR_WRITE | GR_AUDIT_WRITE | GR_SUPPRESS);
70606+
70607+ if (unlikely(mode & GR_WRITE && mode & GR_AUDITS)) {
70608+ gr_log_fs_str_rbac(GR_DO_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
70609+ return mode;
70610+ } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
70611+ gr_log_fs_str_rbac(GR_DONT_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
70612+ return 0;
70613+ } else if (unlikely((mode & needmode) != needmode))
70614+ return 0;
70615+
70616+ return (GR_WRITE | GR_CREATE);
70617+}
70618+
70619+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)
70620+{
70621+ __u32 mode;
70622+
70623+ mode = gr_check_create(new_dentry, parent_dentry, parent_mnt, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
70624+
70625+ if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
70626+ gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, new_dentry, parent_mnt);
70627+ return mode;
70628+ } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
70629+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, new_dentry, parent_mnt);
70630+ return 0;
70631+ } else if (unlikely((mode & (reqmode)) != (reqmode)))
70632+ return 0;
70633+
70634+ return (reqmode);
70635+}
70636+
70637+__u32
70638+gr_acl_handle_mknod(const struct dentry * new_dentry,
70639+ const struct dentry * parent_dentry,
70640+ const struct vfsmount * parent_mnt,
70641+ const int mode)
70642+{
70643+ __u32 reqmode = GR_WRITE | GR_CREATE;
70644+ if (unlikely((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
70645+ reqmode |= GR_SETID;
70646+
70647+ return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
70648+ reqmode, GR_MKNOD_ACL_MSG);
70649+}
70650+
70651+__u32
70652+gr_acl_handle_mkdir(const struct dentry *new_dentry,
70653+ const struct dentry *parent_dentry,
70654+ const struct vfsmount *parent_mnt)
70655+{
70656+ return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
70657+ GR_WRITE | GR_CREATE, GR_MKDIR_ACL_MSG);
70658+}
70659+
70660+#define RENAME_CHECK_SUCCESS(old, new) \
70661+ (((old & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)) && \
70662+ ((new & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)))
70663+
70664+int
70665+gr_acl_handle_rename(struct dentry *new_dentry,
70666+ struct dentry *parent_dentry,
70667+ const struct vfsmount *parent_mnt,
70668+ struct dentry *old_dentry,
70669+ struct inode *old_parent_inode,
70670+ struct vfsmount *old_mnt, const struct filename *newname)
70671+{
70672+ __u32 comp1, comp2;
70673+ int error = 0;
70674+
70675+ if (unlikely(!gr_acl_is_enabled()))
70676+ return 0;
70677+
70678+ if (d_is_negative(new_dentry)) {
70679+ comp1 = gr_check_create(new_dentry, parent_dentry, parent_mnt,
70680+ GR_READ | GR_WRITE | GR_CREATE | GR_AUDIT_READ |
70681+ GR_AUDIT_WRITE | GR_AUDIT_CREATE | GR_SUPPRESS);
70682+ comp2 = gr_search_file(old_dentry, GR_READ | GR_WRITE |
70683+ GR_DELETE | GR_AUDIT_DELETE |
70684+ GR_AUDIT_READ | GR_AUDIT_WRITE |
70685+ GR_SUPPRESS, old_mnt);
70686+ } else {
70687+ comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
70688+ GR_CREATE | GR_DELETE |
70689+ GR_AUDIT_CREATE | GR_AUDIT_DELETE |
70690+ GR_AUDIT_READ | GR_AUDIT_WRITE |
70691+ GR_SUPPRESS, parent_mnt);
70692+ comp2 =
70693+ gr_search_file(old_dentry,
70694+ GR_READ | GR_WRITE | GR_AUDIT_READ |
70695+ GR_DELETE | GR_AUDIT_DELETE |
70696+ GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
70697+ }
70698+
70699+ if (RENAME_CHECK_SUCCESS(comp1, comp2) &&
70700+ ((comp1 & GR_AUDITS) || (comp2 & GR_AUDITS)))
70701+ gr_log_fs_rbac_str(GR_DO_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
70702+ else if (!RENAME_CHECK_SUCCESS(comp1, comp2) && !(comp1 & GR_SUPPRESS)
70703+ && !(comp2 & GR_SUPPRESS)) {
70704+ gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
70705+ error = -EACCES;
70706+ } else if (unlikely(!RENAME_CHECK_SUCCESS(comp1, comp2)))
70707+ error = -EACCES;
70708+
70709+ return error;
70710+}
70711+
70712+void
70713+gr_acl_handle_exit(void)
70714+{
70715+ u16 id;
70716+ char *rolename;
70717+
70718+ if (unlikely(current->acl_sp_role && gr_acl_is_enabled() &&
70719+ !(current->role->roletype & GR_ROLE_PERSIST))) {
70720+ id = current->acl_role_id;
70721+ rolename = current->role->rolename;
70722+ gr_set_acls(1);
70723+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLEL_ACL_MSG, rolename, id);
70724+ }
70725+
70726+ gr_put_exec_file(current);
70727+ return;
70728+}
70729+
70730+int
70731+gr_acl_handle_procpidmem(const struct task_struct *task)
70732+{
70733+ if (unlikely(!gr_acl_is_enabled()))
70734+ return 0;
70735+
70736+ if (task != current && task->acl->mode & GR_PROTPROCFD)
70737+ return -EACCES;
70738+
70739+ return 0;
70740+}
70741diff --git a/grsecurity/gracl_ip.c b/grsecurity/gracl_ip.c
70742new file mode 100644
70743index 0000000..f056b81
70744--- /dev/null
70745+++ b/grsecurity/gracl_ip.c
70746@@ -0,0 +1,386 @@
70747+#include <linux/kernel.h>
70748+#include <asm/uaccess.h>
70749+#include <asm/errno.h>
70750+#include <net/sock.h>
70751+#include <linux/file.h>
70752+#include <linux/fs.h>
70753+#include <linux/net.h>
70754+#include <linux/in.h>
70755+#include <linux/skbuff.h>
70756+#include <linux/ip.h>
70757+#include <linux/udp.h>
70758+#include <linux/types.h>
70759+#include <linux/sched.h>
70760+#include <linux/netdevice.h>
70761+#include <linux/inetdevice.h>
70762+#include <linux/gracl.h>
70763+#include <linux/grsecurity.h>
70764+#include <linux/grinternal.h>
70765+
70766+#define GR_BIND 0x01
70767+#define GR_CONNECT 0x02
70768+#define GR_INVERT 0x04
70769+#define GR_BINDOVERRIDE 0x08
70770+#define GR_CONNECTOVERRIDE 0x10
70771+#define GR_SOCK_FAMILY 0x20
70772+
70773+static const char * gr_protocols[IPPROTO_MAX] = {
70774+ "ip", "icmp", "igmp", "ggp", "ipencap", "st", "tcp", "cbt",
70775+ "egp", "igp", "bbn-rcc", "nvp", "pup", "argus", "emcon", "xnet",
70776+ "chaos", "udp", "mux", "dcn", "hmp", "prm", "xns-idp", "trunk-1",
70777+ "trunk-2", "leaf-1", "leaf-2", "rdp", "irtp", "iso-tp4", "netblt", "mfe-nsp",
70778+ "merit-inp", "sep", "3pc", "idpr", "xtp", "ddp", "idpr-cmtp", "tp++",
70779+ "il", "ipv6", "sdrp", "ipv6-route", "ipv6-frag", "idrp", "rsvp", "gre",
70780+ "mhrp", "bna", "ipv6-crypt", "ipv6-auth", "i-nlsp", "swipe", "narp", "mobile",
70781+ "tlsp", "skip", "ipv6-icmp", "ipv6-nonxt", "ipv6-opts", "unknown:61", "cftp", "unknown:63",
70782+ "sat-expak", "kryptolan", "rvd", "ippc", "unknown:68", "sat-mon", "visa", "ipcv",
70783+ "cpnx", "cphb", "wsn", "pvp", "br-sat-mon", "sun-nd", "wb-mon", "wb-expak",
70784+ "iso-ip", "vmtp", "secure-vmtp", "vines", "ttp", "nfsnet-igp", "dgp", "tcf",
70785+ "eigrp", "ospf", "sprite-rpc", "larp", "mtp", "ax.25", "ipip", "micp",
70786+ "scc-sp", "etherip", "encap", "unknown:99", "gmtp", "ifmp", "pnni", "pim",
70787+ "aris", "scps", "qnx", "a/n", "ipcomp", "snp", "compaq-peer", "ipx-in-ip",
70788+ "vrrp", "pgm", "unknown:114", "l2tp", "ddx", "iatp", "stp", "srp",
70789+ "uti", "smp", "sm", "ptp", "isis", "fire", "crtp", "crdup",
70790+ "sscopmce", "iplt", "sps", "pipe", "sctp", "fc", "unkown:134", "unknown:135",
70791+ "unknown:136", "unknown:137", "unknown:138", "unknown:139", "unknown:140", "unknown:141", "unknown:142", "unknown:143",
70792+ "unknown:144", "unknown:145", "unknown:146", "unknown:147", "unknown:148", "unknown:149", "unknown:150", "unknown:151",
70793+ "unknown:152", "unknown:153", "unknown:154", "unknown:155", "unknown:156", "unknown:157", "unknown:158", "unknown:159",
70794+ "unknown:160", "unknown:161", "unknown:162", "unknown:163", "unknown:164", "unknown:165", "unknown:166", "unknown:167",
70795+ "unknown:168", "unknown:169", "unknown:170", "unknown:171", "unknown:172", "unknown:173", "unknown:174", "unknown:175",
70796+ "unknown:176", "unknown:177", "unknown:178", "unknown:179", "unknown:180", "unknown:181", "unknown:182", "unknown:183",
70797+ "unknown:184", "unknown:185", "unknown:186", "unknown:187", "unknown:188", "unknown:189", "unknown:190", "unknown:191",
70798+ "unknown:192", "unknown:193", "unknown:194", "unknown:195", "unknown:196", "unknown:197", "unknown:198", "unknown:199",
70799+ "unknown:200", "unknown:201", "unknown:202", "unknown:203", "unknown:204", "unknown:205", "unknown:206", "unknown:207",
70800+ "unknown:208", "unknown:209", "unknown:210", "unknown:211", "unknown:212", "unknown:213", "unknown:214", "unknown:215",
70801+ "unknown:216", "unknown:217", "unknown:218", "unknown:219", "unknown:220", "unknown:221", "unknown:222", "unknown:223",
70802+ "unknown:224", "unknown:225", "unknown:226", "unknown:227", "unknown:228", "unknown:229", "unknown:230", "unknown:231",
70803+ "unknown:232", "unknown:233", "unknown:234", "unknown:235", "unknown:236", "unknown:237", "unknown:238", "unknown:239",
70804+ "unknown:240", "unknown:241", "unknown:242", "unknown:243", "unknown:244", "unknown:245", "unknown:246", "unknown:247",
70805+ "unknown:248", "unknown:249", "unknown:250", "unknown:251", "unknown:252", "unknown:253", "unknown:254", "unknown:255",
70806+ };
70807+
70808+static const char * gr_socktypes[SOCK_MAX] = {
70809+ "unknown:0", "stream", "dgram", "raw", "rdm", "seqpacket", "unknown:6",
70810+ "unknown:7", "unknown:8", "unknown:9", "packet"
70811+ };
70812+
70813+static const char * gr_sockfamilies[AF_MAX+1] = {
70814+ "unspec", "unix", "inet", "ax25", "ipx", "appletalk", "netrom", "bridge", "atmpvc", "x25",
70815+ "inet6", "rose", "decnet", "netbeui", "security", "key", "netlink", "packet", "ash",
70816+ "econet", "atmsvc", "rds", "sna", "irda", "ppox", "wanpipe", "llc", "fam_27", "fam_28",
70817+ "tipc", "bluetooth", "iucv", "rxrpc", "isdn", "phonet", "ieee802154", "ciaf"
70818+ };
70819+
70820+const char *
70821+gr_proto_to_name(unsigned char proto)
70822+{
70823+ return gr_protocols[proto];
70824+}
70825+
70826+const char *
70827+gr_socktype_to_name(unsigned char type)
70828+{
70829+ return gr_socktypes[type];
70830+}
70831+
70832+const char *
70833+gr_sockfamily_to_name(unsigned char family)
70834+{
70835+ return gr_sockfamilies[family];
70836+}
70837+
70838+extern const struct net_proto_family __rcu *net_families[NPROTO] __read_mostly;
70839+
70840+int
70841+gr_search_socket(const int domain, const int type, const int protocol)
70842+{
70843+ struct acl_subject_label *curr;
70844+ const struct cred *cred = current_cred();
70845+
70846+ if (unlikely(!gr_acl_is_enabled()))
70847+ goto exit;
70848+
70849+ if ((domain < 0) || (type < 0) || (protocol < 0) ||
70850+ (domain >= AF_MAX) || (type >= SOCK_MAX) || (protocol >= IPPROTO_MAX))
70851+ goto exit; // let the kernel handle it
70852+
70853+ curr = current->acl;
70854+
70855+ if (curr->sock_families[domain / 32] & (1U << (domain % 32))) {
70856+ /* the family is allowed, if this is PF_INET allow it only if
70857+ the extra sock type/protocol checks pass */
70858+ if (domain == PF_INET)
70859+ goto inet_check;
70860+ goto exit;
70861+ } else {
70862+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
70863+ __u32 fakeip = 0;
70864+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
70865+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
70866+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
70867+ gr_to_filename(current->exec_file->f_path.dentry,
70868+ current->exec_file->f_path.mnt) :
70869+ curr->filename, curr->filename,
70870+ &fakeip, domain, 0, 0, GR_SOCK_FAMILY,
70871+ &current->signal->saved_ip);
70872+ goto exit;
70873+ }
70874+ goto exit_fail;
70875+ }
70876+
70877+inet_check:
70878+ /* the rest of this checking is for IPv4 only */
70879+ if (!curr->ips)
70880+ goto exit;
70881+
70882+ if ((curr->ip_type & (1U << type)) &&
70883+ (curr->ip_proto[protocol / 32] & (1U << (protocol % 32))))
70884+ goto exit;
70885+
70886+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
70887+ /* we don't place acls on raw sockets , and sometimes
70888+ dgram/ip sockets are opened for ioctl and not
70889+ bind/connect, so we'll fake a bind learn log */
70890+ if (type == SOCK_RAW || type == SOCK_PACKET) {
70891+ __u32 fakeip = 0;
70892+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
70893+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
70894+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
70895+ gr_to_filename(current->exec_file->f_path.dentry,
70896+ current->exec_file->f_path.mnt) :
70897+ curr->filename, curr->filename,
70898+ &fakeip, 0, type,
70899+ protocol, GR_CONNECT, &current->signal->saved_ip);
70900+ } else if ((type == SOCK_DGRAM) && (protocol == IPPROTO_IP)) {
70901+ __u32 fakeip = 0;
70902+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
70903+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
70904+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
70905+ gr_to_filename(current->exec_file->f_path.dentry,
70906+ current->exec_file->f_path.mnt) :
70907+ curr->filename, curr->filename,
70908+ &fakeip, 0, type,
70909+ protocol, GR_BIND, &current->signal->saved_ip);
70910+ }
70911+ /* we'll log when they use connect or bind */
70912+ goto exit;
70913+ }
70914+
70915+exit_fail:
70916+ if (domain == PF_INET)
70917+ gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(domain),
70918+ gr_socktype_to_name(type), gr_proto_to_name(protocol));
70919+ else if (rcu_access_pointer(net_families[domain]) != NULL)
70920+ gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(domain),
70921+ gr_socktype_to_name(type), protocol);
70922+
70923+ return 0;
70924+exit:
70925+ return 1;
70926+}
70927+
70928+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)
70929+{
70930+ if ((ip->mode & mode) &&
70931+ (ip_port >= ip->low) &&
70932+ (ip_port <= ip->high) &&
70933+ ((ntohl(ip_addr) & our_netmask) ==
70934+ (ntohl(our_addr) & our_netmask))
70935+ && (ip->proto[protocol / 32] & (1U << (protocol % 32)))
70936+ && (ip->type & (1U << type))) {
70937+ if (ip->mode & GR_INVERT)
70938+ return 2; // specifically denied
70939+ else
70940+ return 1; // allowed
70941+ }
70942+
70943+ return 0; // not specifically allowed, may continue parsing
70944+}
70945+
70946+static int
70947+gr_search_connectbind(const int full_mode, struct sock *sk,
70948+ struct sockaddr_in *addr, const int type)
70949+{
70950+ char iface[IFNAMSIZ] = {0};
70951+ struct acl_subject_label *curr;
70952+ struct acl_ip_label *ip;
70953+ struct inet_sock *isk;
70954+ struct net_device *dev;
70955+ struct in_device *idev;
70956+ unsigned long i;
70957+ int ret;
70958+ int mode = full_mode & (GR_BIND | GR_CONNECT);
70959+ __u32 ip_addr = 0;
70960+ __u32 our_addr;
70961+ __u32 our_netmask;
70962+ char *p;
70963+ __u16 ip_port = 0;
70964+ const struct cred *cred = current_cred();
70965+
70966+ if (unlikely(!gr_acl_is_enabled() || sk->sk_family != PF_INET))
70967+ return 0;
70968+
70969+ curr = current->acl;
70970+ isk = inet_sk(sk);
70971+
70972+ /* INADDR_ANY overriding for binds, inaddr_any_override is already in network order */
70973+ if ((full_mode & GR_BINDOVERRIDE) && addr->sin_addr.s_addr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0)
70974+ addr->sin_addr.s_addr = curr->inaddr_any_override;
70975+ if ((full_mode & GR_CONNECT) && isk->inet_saddr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0) {
70976+ struct sockaddr_in saddr;
70977+ int err;
70978+
70979+ saddr.sin_family = AF_INET;
70980+ saddr.sin_addr.s_addr = curr->inaddr_any_override;
70981+ saddr.sin_port = isk->inet_sport;
70982+
70983+ err = security_socket_bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
70984+ if (err)
70985+ return err;
70986+
70987+ err = sk->sk_socket->ops->bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
70988+ if (err)
70989+ return err;
70990+ }
70991+
70992+ if (!curr->ips)
70993+ return 0;
70994+
70995+ ip_addr = addr->sin_addr.s_addr;
70996+ ip_port = ntohs(addr->sin_port);
70997+
70998+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
70999+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
71000+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
71001+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
71002+ gr_to_filename(current->exec_file->f_path.dentry,
71003+ current->exec_file->f_path.mnt) :
71004+ curr->filename, curr->filename,
71005+ &ip_addr, ip_port, type,
71006+ sk->sk_protocol, mode, &current->signal->saved_ip);
71007+ return 0;
71008+ }
71009+
71010+ for (i = 0; i < curr->ip_num; i++) {
71011+ ip = *(curr->ips + i);
71012+ if (ip->iface != NULL) {
71013+ strncpy(iface, ip->iface, IFNAMSIZ - 1);
71014+ p = strchr(iface, ':');
71015+ if (p != NULL)
71016+ *p = '\0';
71017+ dev = dev_get_by_name(sock_net(sk), iface);
71018+ if (dev == NULL)
71019+ continue;
71020+ idev = in_dev_get(dev);
71021+ if (idev == NULL) {
71022+ dev_put(dev);
71023+ continue;
71024+ }
71025+ rcu_read_lock();
71026+ for_ifa(idev) {
71027+ if (!strcmp(ip->iface, ifa->ifa_label)) {
71028+ our_addr = ifa->ifa_address;
71029+ our_netmask = 0xffffffff;
71030+ ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
71031+ if (ret == 1) {
71032+ rcu_read_unlock();
71033+ in_dev_put(idev);
71034+ dev_put(dev);
71035+ return 0;
71036+ } else if (ret == 2) {
71037+ rcu_read_unlock();
71038+ in_dev_put(idev);
71039+ dev_put(dev);
71040+ goto denied;
71041+ }
71042+ }
71043+ } endfor_ifa(idev);
71044+ rcu_read_unlock();
71045+ in_dev_put(idev);
71046+ dev_put(dev);
71047+ } else {
71048+ our_addr = ip->addr;
71049+ our_netmask = ip->netmask;
71050+ ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
71051+ if (ret == 1)
71052+ return 0;
71053+ else if (ret == 2)
71054+ goto denied;
71055+ }
71056+ }
71057+
71058+denied:
71059+ if (mode == GR_BIND)
71060+ 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));
71061+ else if (mode == GR_CONNECT)
71062+ 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));
71063+
71064+ return -EACCES;
71065+}
71066+
71067+int
71068+gr_search_connect(struct socket *sock, struct sockaddr_in *addr)
71069+{
71070+ /* always allow disconnection of dgram sockets with connect */
71071+ if (addr->sin_family == AF_UNSPEC)
71072+ return 0;
71073+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sock->sk, addr, sock->type);
71074+}
71075+
71076+int
71077+gr_search_bind(struct socket *sock, struct sockaddr_in *addr)
71078+{
71079+ return gr_search_connectbind(GR_BIND | GR_BINDOVERRIDE, sock->sk, addr, sock->type);
71080+}
71081+
71082+int gr_search_listen(struct socket *sock)
71083+{
71084+ struct sock *sk = sock->sk;
71085+ struct sockaddr_in addr;
71086+
71087+ addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
71088+ addr.sin_port = inet_sk(sk)->inet_sport;
71089+
71090+ return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
71091+}
71092+
71093+int gr_search_accept(struct socket *sock)
71094+{
71095+ struct sock *sk = sock->sk;
71096+ struct sockaddr_in addr;
71097+
71098+ addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
71099+ addr.sin_port = inet_sk(sk)->inet_sport;
71100+
71101+ return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
71102+}
71103+
71104+int
71105+gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr)
71106+{
71107+ if (addr)
71108+ return gr_search_connectbind(GR_CONNECT, sk, addr, SOCK_DGRAM);
71109+ else {
71110+ struct sockaddr_in sin;
71111+ const struct inet_sock *inet = inet_sk(sk);
71112+
71113+ sin.sin_addr.s_addr = inet->inet_daddr;
71114+ sin.sin_port = inet->inet_dport;
71115+
71116+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
71117+ }
71118+}
71119+
71120+int
71121+gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb)
71122+{
71123+ struct sockaddr_in sin;
71124+
71125+ if (unlikely(skb->len < sizeof (struct udphdr)))
71126+ return 0; // skip this packet
71127+
71128+ sin.sin_addr.s_addr = ip_hdr(skb)->saddr;
71129+ sin.sin_port = udp_hdr(skb)->source;
71130+
71131+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
71132+}
71133diff --git a/grsecurity/gracl_learn.c b/grsecurity/gracl_learn.c
71134new file mode 100644
71135index 0000000..25f54ef
71136--- /dev/null
71137+++ b/grsecurity/gracl_learn.c
71138@@ -0,0 +1,207 @@
71139+#include <linux/kernel.h>
71140+#include <linux/mm.h>
71141+#include <linux/sched.h>
71142+#include <linux/poll.h>
71143+#include <linux/string.h>
71144+#include <linux/file.h>
71145+#include <linux/types.h>
71146+#include <linux/vmalloc.h>
71147+#include <linux/grinternal.h>
71148+
71149+extern ssize_t write_grsec_handler(struct file * file, const char __user * buf,
71150+ size_t count, loff_t *ppos);
71151+extern int gr_acl_is_enabled(void);
71152+
71153+static DECLARE_WAIT_QUEUE_HEAD(learn_wait);
71154+static int gr_learn_attached;
71155+
71156+/* use a 512k buffer */
71157+#define LEARN_BUFFER_SIZE (512 * 1024)
71158+
71159+static DEFINE_SPINLOCK(gr_learn_lock);
71160+static DEFINE_MUTEX(gr_learn_user_mutex);
71161+
71162+/* we need to maintain two buffers, so that the kernel context of grlearn
71163+ uses a semaphore around the userspace copying, and the other kernel contexts
71164+ use a spinlock when copying into the buffer, since they cannot sleep
71165+*/
71166+static char *learn_buffer;
71167+static char *learn_buffer_user;
71168+static int learn_buffer_len;
71169+static int learn_buffer_user_len;
71170+
71171+static ssize_t
71172+read_learn(struct file *file, char __user * buf, size_t count, loff_t * ppos)
71173+{
71174+ DECLARE_WAITQUEUE(wait, current);
71175+ ssize_t retval = 0;
71176+
71177+ add_wait_queue(&learn_wait, &wait);
71178+ set_current_state(TASK_INTERRUPTIBLE);
71179+ do {
71180+ mutex_lock(&gr_learn_user_mutex);
71181+ spin_lock(&gr_learn_lock);
71182+ if (learn_buffer_len)
71183+ break;
71184+ spin_unlock(&gr_learn_lock);
71185+ mutex_unlock(&gr_learn_user_mutex);
71186+ if (file->f_flags & O_NONBLOCK) {
71187+ retval = -EAGAIN;
71188+ goto out;
71189+ }
71190+ if (signal_pending(current)) {
71191+ retval = -ERESTARTSYS;
71192+ goto out;
71193+ }
71194+
71195+ schedule();
71196+ } while (1);
71197+
71198+ memcpy(learn_buffer_user, learn_buffer, learn_buffer_len);
71199+ learn_buffer_user_len = learn_buffer_len;
71200+ retval = learn_buffer_len;
71201+ learn_buffer_len = 0;
71202+
71203+ spin_unlock(&gr_learn_lock);
71204+
71205+ if (copy_to_user(buf, learn_buffer_user, learn_buffer_user_len))
71206+ retval = -EFAULT;
71207+
71208+ mutex_unlock(&gr_learn_user_mutex);
71209+out:
71210+ set_current_state(TASK_RUNNING);
71211+ remove_wait_queue(&learn_wait, &wait);
71212+ return retval;
71213+}
71214+
71215+static unsigned int
71216+poll_learn(struct file * file, poll_table * wait)
71217+{
71218+ poll_wait(file, &learn_wait, wait);
71219+
71220+ if (learn_buffer_len)
71221+ return (POLLIN | POLLRDNORM);
71222+
71223+ return 0;
71224+}
71225+
71226+void
71227+gr_clear_learn_entries(void)
71228+{
71229+ char *tmp;
71230+
71231+ mutex_lock(&gr_learn_user_mutex);
71232+ spin_lock(&gr_learn_lock);
71233+ tmp = learn_buffer;
71234+ learn_buffer = NULL;
71235+ spin_unlock(&gr_learn_lock);
71236+ if (tmp)
71237+ vfree(tmp);
71238+ if (learn_buffer_user != NULL) {
71239+ vfree(learn_buffer_user);
71240+ learn_buffer_user = NULL;
71241+ }
71242+ learn_buffer_len = 0;
71243+ mutex_unlock(&gr_learn_user_mutex);
71244+
71245+ return;
71246+}
71247+
71248+void
71249+gr_add_learn_entry(const char *fmt, ...)
71250+{
71251+ va_list args;
71252+ unsigned int len;
71253+
71254+ if (!gr_learn_attached)
71255+ return;
71256+
71257+ spin_lock(&gr_learn_lock);
71258+
71259+ /* leave a gap at the end so we know when it's "full" but don't have to
71260+ compute the exact length of the string we're trying to append
71261+ */
71262+ if (learn_buffer_len > LEARN_BUFFER_SIZE - 16384) {
71263+ spin_unlock(&gr_learn_lock);
71264+ wake_up_interruptible(&learn_wait);
71265+ return;
71266+ }
71267+ if (learn_buffer == NULL) {
71268+ spin_unlock(&gr_learn_lock);
71269+ return;
71270+ }
71271+
71272+ va_start(args, fmt);
71273+ len = vsnprintf(learn_buffer + learn_buffer_len, LEARN_BUFFER_SIZE - learn_buffer_len, fmt, args);
71274+ va_end(args);
71275+
71276+ learn_buffer_len += len + 1;
71277+
71278+ spin_unlock(&gr_learn_lock);
71279+ wake_up_interruptible(&learn_wait);
71280+
71281+ return;
71282+}
71283+
71284+static int
71285+open_learn(struct inode *inode, struct file *file)
71286+{
71287+ if (file->f_mode & FMODE_READ && gr_learn_attached)
71288+ return -EBUSY;
71289+ if (file->f_mode & FMODE_READ) {
71290+ int retval = 0;
71291+ mutex_lock(&gr_learn_user_mutex);
71292+ if (learn_buffer == NULL)
71293+ learn_buffer = vmalloc(LEARN_BUFFER_SIZE);
71294+ if (learn_buffer_user == NULL)
71295+ learn_buffer_user = vmalloc(LEARN_BUFFER_SIZE);
71296+ if (learn_buffer == NULL) {
71297+ retval = -ENOMEM;
71298+ goto out_error;
71299+ }
71300+ if (learn_buffer_user == NULL) {
71301+ retval = -ENOMEM;
71302+ goto out_error;
71303+ }
71304+ learn_buffer_len = 0;
71305+ learn_buffer_user_len = 0;
71306+ gr_learn_attached = 1;
71307+out_error:
71308+ mutex_unlock(&gr_learn_user_mutex);
71309+ return retval;
71310+ }
71311+ return 0;
71312+}
71313+
71314+static int
71315+close_learn(struct inode *inode, struct file *file)
71316+{
71317+ if (file->f_mode & FMODE_READ) {
71318+ char *tmp = NULL;
71319+ mutex_lock(&gr_learn_user_mutex);
71320+ spin_lock(&gr_learn_lock);
71321+ tmp = learn_buffer;
71322+ learn_buffer = NULL;
71323+ spin_unlock(&gr_learn_lock);
71324+ if (tmp)
71325+ vfree(tmp);
71326+ if (learn_buffer_user != NULL) {
71327+ vfree(learn_buffer_user);
71328+ learn_buffer_user = NULL;
71329+ }
71330+ learn_buffer_len = 0;
71331+ learn_buffer_user_len = 0;
71332+ gr_learn_attached = 0;
71333+ mutex_unlock(&gr_learn_user_mutex);
71334+ }
71335+
71336+ return 0;
71337+}
71338+
71339+const struct file_operations grsec_fops = {
71340+ .read = read_learn,
71341+ .write = write_grsec_handler,
71342+ .open = open_learn,
71343+ .release = close_learn,
71344+ .poll = poll_learn,
71345+};
71346diff --git a/grsecurity/gracl_policy.c b/grsecurity/gracl_policy.c
71347new file mode 100644
71348index 0000000..361a099
71349--- /dev/null
71350+++ b/grsecurity/gracl_policy.c
71351@@ -0,0 +1,1782 @@
71352+#include <linux/kernel.h>
71353+#include <linux/module.h>
71354+#include <linux/sched.h>
71355+#include <linux/mm.h>
71356+#include <linux/file.h>
71357+#include <linux/fs.h>
71358+#include <linux/namei.h>
71359+#include <linux/mount.h>
71360+#include <linux/tty.h>
71361+#include <linux/proc_fs.h>
71362+#include <linux/lglock.h>
71363+#include <linux/slab.h>
71364+#include <linux/vmalloc.h>
71365+#include <linux/types.h>
71366+#include <linux/sysctl.h>
71367+#include <linux/netdevice.h>
71368+#include <linux/ptrace.h>
71369+#include <linux/gracl.h>
71370+#include <linux/gralloc.h>
71371+#include <linux/security.h>
71372+#include <linux/grinternal.h>
71373+#include <linux/pid_namespace.h>
71374+#include <linux/stop_machine.h>
71375+#include <linux/fdtable.h>
71376+#include <linux/percpu.h>
71377+#include <linux/lglock.h>
71378+#include <linux/hugetlb.h>
71379+#include <linux/posix-timers.h>
71380+#include "../fs/mount.h"
71381+
71382+#include <asm/uaccess.h>
71383+#include <asm/errno.h>
71384+#include <asm/mman.h>
71385+
71386+extern struct gr_policy_state *polstate;
71387+
71388+#define FOR_EACH_ROLE_START(role) \
71389+ role = polstate->role_list; \
71390+ while (role) {
71391+
71392+#define FOR_EACH_ROLE_END(role) \
71393+ role = role->prev; \
71394+ }
71395+
71396+struct path gr_real_root;
71397+
71398+extern struct gr_alloc_state *current_alloc_state;
71399+
71400+u16 acl_sp_role_value;
71401+
71402+static DEFINE_MUTEX(gr_dev_mutex);
71403+
71404+extern int chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum);
71405+extern void gr_clear_learn_entries(void);
71406+
71407+static struct gr_arg gr_usermode;
71408+static unsigned char gr_system_salt[GR_SALT_LEN];
71409+static unsigned char gr_system_sum[GR_SHA_LEN];
71410+
71411+static unsigned int gr_auth_attempts = 0;
71412+static unsigned long gr_auth_expires = 0UL;
71413+
71414+struct acl_object_label *fakefs_obj_rw;
71415+struct acl_object_label *fakefs_obj_rwx;
71416+
71417+extern int gr_init_uidset(void);
71418+extern void gr_free_uidset(void);
71419+extern void gr_remove_uid(uid_t uid);
71420+extern int gr_find_uid(uid_t uid);
71421+
71422+extern struct acl_subject_label *__gr_get_subject_for_task(const struct gr_policy_state *state, struct task_struct *task, const char *filename);
71423+extern void __gr_apply_subject_to_task(struct gr_policy_state *state, struct task_struct *task, struct acl_subject_label *subj);
71424+extern int gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb);
71425+extern void __insert_inodev_entry(const struct gr_policy_state *state, struct inodev_entry *entry);
71426+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);
71427+extern void insert_acl_obj_label(struct acl_object_label *obj, struct acl_subject_label *subj);
71428+extern void insert_acl_subj_label(struct acl_subject_label *obj, struct acl_role_label *role);
71429+extern struct name_entry * __lookup_name_entry(const struct gr_policy_state *state, const char *name);
71430+extern char *gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt);
71431+extern struct acl_subject_label *lookup_acl_subj_label(const ino_t ino, const dev_t dev, const struct acl_role_label *role);
71432+extern struct acl_subject_label *lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev, const struct acl_role_label *role);
71433+extern void assign_special_role(const char *rolename);
71434+extern struct acl_subject_label *chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt, const struct acl_role_label *role);
71435+extern int gr_rbac_disable(void *unused);
71436+extern void gr_enable_rbac_system(void);
71437+
71438+static int copy_acl_object_label_normal(struct acl_object_label *obj, const struct acl_object_label *userp)
71439+{
71440+ if (copy_from_user(obj, userp, sizeof(struct acl_object_label)))
71441+ return -EFAULT;
71442+
71443+ return 0;
71444+}
71445+
71446+static int copy_acl_ip_label_normal(struct acl_ip_label *ip, const struct acl_ip_label *userp)
71447+{
71448+ if (copy_from_user(ip, userp, sizeof(struct acl_ip_label)))
71449+ return -EFAULT;
71450+
71451+ return 0;
71452+}
71453+
71454+static int copy_acl_subject_label_normal(struct acl_subject_label *subj, const struct acl_subject_label *userp)
71455+{
71456+ if (copy_from_user(subj, userp, sizeof(struct acl_subject_label)))
71457+ return -EFAULT;
71458+
71459+ return 0;
71460+}
71461+
71462+static int copy_acl_role_label_normal(struct acl_role_label *role, const struct acl_role_label *userp)
71463+{
71464+ if (copy_from_user(role, userp, sizeof(struct acl_role_label)))
71465+ return -EFAULT;
71466+
71467+ return 0;
71468+}
71469+
71470+static int copy_role_allowed_ip_normal(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp)
71471+{
71472+ if (copy_from_user(roleip, userp, sizeof(struct role_allowed_ip)))
71473+ return -EFAULT;
71474+
71475+ return 0;
71476+}
71477+
71478+static int copy_sprole_pw_normal(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp)
71479+{
71480+ if (copy_from_user(pw, userp + idx, sizeof(struct sprole_pw)))
71481+ return -EFAULT;
71482+
71483+ return 0;
71484+}
71485+
71486+static int copy_gr_hash_struct_normal(struct gr_hash_struct *hash, const struct gr_hash_struct *userp)
71487+{
71488+ if (copy_from_user(hash, userp, sizeof(struct gr_hash_struct)))
71489+ return -EFAULT;
71490+
71491+ return 0;
71492+}
71493+
71494+static int copy_role_transition_normal(struct role_transition *trans, const struct role_transition *userp)
71495+{
71496+ if (copy_from_user(trans, userp, sizeof(struct role_transition)))
71497+ return -EFAULT;
71498+
71499+ return 0;
71500+}
71501+
71502+int copy_pointer_from_array_normal(void *ptr, unsigned long idx, const void *userp)
71503+{
71504+ if (copy_from_user(ptr, userp + (idx * sizeof(void *)), sizeof(void *)))
71505+ return -EFAULT;
71506+
71507+ return 0;
71508+}
71509+
71510+static int copy_gr_arg_wrapper_normal(const char __user *buf, struct gr_arg_wrapper *uwrap)
71511+{
71512+ if (copy_from_user(uwrap, buf, sizeof (struct gr_arg_wrapper)))
71513+ return -EFAULT;
71514+
71515+ if (((uwrap->version != GRSECURITY_VERSION) &&
71516+ (uwrap->version != 0x2901)) ||
71517+ (uwrap->size != sizeof(struct gr_arg)))
71518+ return -EINVAL;
71519+
71520+ return 0;
71521+}
71522+
71523+static int copy_gr_arg_normal(const struct gr_arg __user *buf, struct gr_arg *arg)
71524+{
71525+ if (copy_from_user(arg, buf, sizeof (struct gr_arg)))
71526+ return -EFAULT;
71527+
71528+ return 0;
71529+}
71530+
71531+static size_t get_gr_arg_wrapper_size_normal(void)
71532+{
71533+ return sizeof(struct gr_arg_wrapper);
71534+}
71535+
71536+#ifdef CONFIG_COMPAT
71537+extern int copy_gr_arg_wrapper_compat(const char *buf, struct gr_arg_wrapper *uwrap);
71538+extern int copy_gr_arg_compat(const struct gr_arg __user *buf, struct gr_arg *arg);
71539+extern int copy_acl_object_label_compat(struct acl_object_label *obj, const struct acl_object_label *userp);
71540+extern int copy_acl_subject_label_compat(struct acl_subject_label *subj, const struct acl_subject_label *userp);
71541+extern int copy_acl_role_label_compat(struct acl_role_label *role, const struct acl_role_label *userp);
71542+extern int copy_role_allowed_ip_compat(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp);
71543+extern int copy_role_transition_compat(struct role_transition *trans, const struct role_transition *userp);
71544+extern int copy_gr_hash_struct_compat(struct gr_hash_struct *hash, const struct gr_hash_struct *userp);
71545+extern int copy_pointer_from_array_compat(void *ptr, unsigned long idx, const void *userp);
71546+extern int copy_acl_ip_label_compat(struct acl_ip_label *ip, const struct acl_ip_label *userp);
71547+extern int copy_sprole_pw_compat(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp);
71548+extern size_t get_gr_arg_wrapper_size_compat(void);
71549+
71550+int (* copy_gr_arg_wrapper)(const char *buf, struct gr_arg_wrapper *uwrap) __read_only;
71551+int (* copy_gr_arg)(const struct gr_arg *buf, struct gr_arg *arg) __read_only;
71552+int (* copy_acl_object_label)(struct acl_object_label *obj, const struct acl_object_label *userp) __read_only;
71553+int (* copy_acl_subject_label)(struct acl_subject_label *subj, const struct acl_subject_label *userp) __read_only;
71554+int (* copy_acl_role_label)(struct acl_role_label *role, const struct acl_role_label *userp) __read_only;
71555+int (* copy_acl_ip_label)(struct acl_ip_label *ip, const struct acl_ip_label *userp) __read_only;
71556+int (* copy_pointer_from_array)(void *ptr, unsigned long idx, const void *userp) __read_only;
71557+int (* copy_sprole_pw)(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp) __read_only;
71558+int (* copy_gr_hash_struct)(struct gr_hash_struct *hash, const struct gr_hash_struct *userp) __read_only;
71559+int (* copy_role_transition)(struct role_transition *trans, const struct role_transition *userp) __read_only;
71560+int (* copy_role_allowed_ip)(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp) __read_only;
71561+size_t (* get_gr_arg_wrapper_size)(void) __read_only;
71562+
71563+#else
71564+#define copy_gr_arg_wrapper copy_gr_arg_wrapper_normal
71565+#define copy_gr_arg copy_gr_arg_normal
71566+#define copy_gr_hash_struct copy_gr_hash_struct_normal
71567+#define copy_acl_object_label copy_acl_object_label_normal
71568+#define copy_acl_subject_label copy_acl_subject_label_normal
71569+#define copy_acl_role_label copy_acl_role_label_normal
71570+#define copy_acl_ip_label copy_acl_ip_label_normal
71571+#define copy_pointer_from_array copy_pointer_from_array_normal
71572+#define copy_sprole_pw copy_sprole_pw_normal
71573+#define copy_role_transition copy_role_transition_normal
71574+#define copy_role_allowed_ip copy_role_allowed_ip_normal
71575+#define get_gr_arg_wrapper_size get_gr_arg_wrapper_size_normal
71576+#endif
71577+
71578+static struct acl_subject_label *
71579+lookup_subject_map(const struct acl_subject_label *userp)
71580+{
71581+ unsigned int index = gr_shash(userp, polstate->subj_map_set.s_size);
71582+ struct subject_map *match;
71583+
71584+ match = polstate->subj_map_set.s_hash[index];
71585+
71586+ while (match && match->user != userp)
71587+ match = match->next;
71588+
71589+ if (match != NULL)
71590+ return match->kernel;
71591+ else
71592+ return NULL;
71593+}
71594+
71595+static void
71596+insert_subj_map_entry(struct subject_map *subjmap)
71597+{
71598+ unsigned int index = gr_shash(subjmap->user, polstate->subj_map_set.s_size);
71599+ struct subject_map **curr;
71600+
71601+ subjmap->prev = NULL;
71602+
71603+ curr = &polstate->subj_map_set.s_hash[index];
71604+ if (*curr != NULL)
71605+ (*curr)->prev = subjmap;
71606+
71607+ subjmap->next = *curr;
71608+ *curr = subjmap;
71609+
71610+ return;
71611+}
71612+
71613+static void
71614+__insert_acl_role_label(struct acl_role_label *role, uid_t uidgid)
71615+{
71616+ unsigned int index =
71617+ gr_rhash(uidgid, role->roletype & (GR_ROLE_USER | GR_ROLE_GROUP), polstate->acl_role_set.r_size);
71618+ struct acl_role_label **curr;
71619+ struct acl_role_label *tmp, *tmp2;
71620+
71621+ curr = &polstate->acl_role_set.r_hash[index];
71622+
71623+ /* simple case, slot is empty, just set it to our role */
71624+ if (*curr == NULL) {
71625+ *curr = role;
71626+ } else {
71627+ /* example:
71628+ 1 -> 2 -> 3 (adding 2 -> 3 to here)
71629+ 2 -> 3
71630+ */
71631+ /* first check to see if we can already be reached via this slot */
71632+ tmp = *curr;
71633+ while (tmp && tmp != role)
71634+ tmp = tmp->next;
71635+ if (tmp == role) {
71636+ /* we don't need to add ourselves to this slot's chain */
71637+ return;
71638+ }
71639+ /* we need to add ourselves to this chain, two cases */
71640+ if (role->next == NULL) {
71641+ /* simple case, append the current chain to our role */
71642+ role->next = *curr;
71643+ *curr = role;
71644+ } else {
71645+ /* 1 -> 2 -> 3 -> 4
71646+ 2 -> 3 -> 4
71647+ 3 -> 4 (adding 1 -> 2 -> 3 -> 4 to here)
71648+ */
71649+ /* trickier case: walk our role's chain until we find
71650+ the role for the start of the current slot's chain */
71651+ tmp = role;
71652+ tmp2 = *curr;
71653+ while (tmp->next && tmp->next != tmp2)
71654+ tmp = tmp->next;
71655+ if (tmp->next == tmp2) {
71656+ /* from example above, we found 3, so just
71657+ replace this slot's chain with ours */
71658+ *curr = role;
71659+ } else {
71660+ /* we didn't find a subset of our role's chain
71661+ in the current slot's chain, so append their
71662+ chain to ours, and set us as the first role in
71663+ the slot's chain
71664+
71665+ we could fold this case with the case above,
71666+ but making it explicit for clarity
71667+ */
71668+ tmp->next = tmp2;
71669+ *curr = role;
71670+ }
71671+ }
71672+ }
71673+
71674+ return;
71675+}
71676+
71677+static void
71678+insert_acl_role_label(struct acl_role_label *role)
71679+{
71680+ int i;
71681+
71682+ if (polstate->role_list == NULL) {
71683+ polstate->role_list = role;
71684+ role->prev = NULL;
71685+ } else {
71686+ role->prev = polstate->role_list;
71687+ polstate->role_list = role;
71688+ }
71689+
71690+ /* used for hash chains */
71691+ role->next = NULL;
71692+
71693+ if (role->roletype & GR_ROLE_DOMAIN) {
71694+ for (i = 0; i < role->domain_child_num; i++)
71695+ __insert_acl_role_label(role, role->domain_children[i]);
71696+ } else
71697+ __insert_acl_role_label(role, role->uidgid);
71698+}
71699+
71700+static int
71701+insert_name_entry(char *name, const ino_t inode, const dev_t device, __u8 deleted)
71702+{
71703+ struct name_entry **curr, *nentry;
71704+ struct inodev_entry *ientry;
71705+ unsigned int len = strlen(name);
71706+ unsigned int key = full_name_hash(name, len);
71707+ unsigned int index = key % polstate->name_set.n_size;
71708+
71709+ curr = &polstate->name_set.n_hash[index];
71710+
71711+ while (*curr && ((*curr)->key != key || !gr_streq((*curr)->name, name, (*curr)->len, len)))
71712+ curr = &((*curr)->next);
71713+
71714+ if (*curr != NULL)
71715+ return 1;
71716+
71717+ nentry = acl_alloc(sizeof (struct name_entry));
71718+ if (nentry == NULL)
71719+ return 0;
71720+ ientry = acl_alloc(sizeof (struct inodev_entry));
71721+ if (ientry == NULL)
71722+ return 0;
71723+ ientry->nentry = nentry;
71724+
71725+ nentry->key = key;
71726+ nentry->name = name;
71727+ nentry->inode = inode;
71728+ nentry->device = device;
71729+ nentry->len = len;
71730+ nentry->deleted = deleted;
71731+
71732+ nentry->prev = NULL;
71733+ curr = &polstate->name_set.n_hash[index];
71734+ if (*curr != NULL)
71735+ (*curr)->prev = nentry;
71736+ nentry->next = *curr;
71737+ *curr = nentry;
71738+
71739+ /* insert us into the table searchable by inode/dev */
71740+ __insert_inodev_entry(polstate, ientry);
71741+
71742+ return 1;
71743+}
71744+
71745+/* allocating chained hash tables, so optimal size is where lambda ~ 1 */
71746+
71747+static void *
71748+create_table(__u32 * len, int elementsize)
71749+{
71750+ unsigned int table_sizes[] = {
71751+ 7, 13, 31, 61, 127, 251, 509, 1021, 2039, 4093, 8191, 16381,
71752+ 32749, 65521, 131071, 262139, 524287, 1048573, 2097143,
71753+ 4194301, 8388593, 16777213, 33554393, 67108859
71754+ };
71755+ void *newtable = NULL;
71756+ unsigned int pwr = 0;
71757+
71758+ while ((pwr < ((sizeof (table_sizes) / sizeof (table_sizes[0])) - 1)) &&
71759+ table_sizes[pwr] <= *len)
71760+ pwr++;
71761+
71762+ if (table_sizes[pwr] <= *len || (table_sizes[pwr] > ULONG_MAX / elementsize))
71763+ return newtable;
71764+
71765+ if ((table_sizes[pwr] * elementsize) <= PAGE_SIZE)
71766+ newtable =
71767+ kmalloc(table_sizes[pwr] * elementsize, GFP_KERNEL);
71768+ else
71769+ newtable = vmalloc(table_sizes[pwr] * elementsize);
71770+
71771+ *len = table_sizes[pwr];
71772+
71773+ return newtable;
71774+}
71775+
71776+static int
71777+init_variables(const struct gr_arg *arg, bool reload)
71778+{
71779+ struct task_struct *reaper = init_pid_ns.child_reaper;
71780+ unsigned int stacksize;
71781+
71782+ polstate->subj_map_set.s_size = arg->role_db.num_subjects;
71783+ polstate->acl_role_set.r_size = arg->role_db.num_roles + arg->role_db.num_domain_children;
71784+ polstate->name_set.n_size = arg->role_db.num_objects;
71785+ polstate->inodev_set.i_size = arg->role_db.num_objects;
71786+
71787+ if (!polstate->subj_map_set.s_size || !polstate->acl_role_set.r_size ||
71788+ !polstate->name_set.n_size || !polstate->inodev_set.i_size)
71789+ return 1;
71790+
71791+ if (!reload) {
71792+ if (!gr_init_uidset())
71793+ return 1;
71794+ }
71795+
71796+ /* set up the stack that holds allocation info */
71797+
71798+ stacksize = arg->role_db.num_pointers + 5;
71799+
71800+ if (!acl_alloc_stack_init(stacksize))
71801+ return 1;
71802+
71803+ if (!reload) {
71804+ /* grab reference for the real root dentry and vfsmount */
71805+ get_fs_root(reaper->fs, &gr_real_root);
71806+
71807+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
71808+ 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);
71809+#endif
71810+
71811+ fakefs_obj_rw = kzalloc(sizeof(struct acl_object_label), GFP_KERNEL);
71812+ if (fakefs_obj_rw == NULL)
71813+ return 1;
71814+ fakefs_obj_rw->mode = GR_FIND | GR_READ | GR_WRITE;
71815+
71816+ fakefs_obj_rwx = kzalloc(sizeof(struct acl_object_label), GFP_KERNEL);
71817+ if (fakefs_obj_rwx == NULL)
71818+ return 1;
71819+ fakefs_obj_rwx->mode = GR_FIND | GR_READ | GR_WRITE | GR_EXEC;
71820+ }
71821+
71822+ polstate->subj_map_set.s_hash =
71823+ (struct subject_map **) create_table(&polstate->subj_map_set.s_size, sizeof(void *));
71824+ polstate->acl_role_set.r_hash =
71825+ (struct acl_role_label **) create_table(&polstate->acl_role_set.r_size, sizeof(void *));
71826+ polstate->name_set.n_hash = (struct name_entry **) create_table(&polstate->name_set.n_size, sizeof(void *));
71827+ polstate->inodev_set.i_hash =
71828+ (struct inodev_entry **) create_table(&polstate->inodev_set.i_size, sizeof(void *));
71829+
71830+ if (!polstate->subj_map_set.s_hash || !polstate->acl_role_set.r_hash ||
71831+ !polstate->name_set.n_hash || !polstate->inodev_set.i_hash)
71832+ return 1;
71833+
71834+ memset(polstate->subj_map_set.s_hash, 0,
71835+ sizeof(struct subject_map *) * polstate->subj_map_set.s_size);
71836+ memset(polstate->acl_role_set.r_hash, 0,
71837+ sizeof (struct acl_role_label *) * polstate->acl_role_set.r_size);
71838+ memset(polstate->name_set.n_hash, 0,
71839+ sizeof (struct name_entry *) * polstate->name_set.n_size);
71840+ memset(polstate->inodev_set.i_hash, 0,
71841+ sizeof (struct inodev_entry *) * polstate->inodev_set.i_size);
71842+
71843+ return 0;
71844+}
71845+
71846+/* free information not needed after startup
71847+ currently contains user->kernel pointer mappings for subjects
71848+*/
71849+
71850+static void
71851+free_init_variables(void)
71852+{
71853+ __u32 i;
71854+
71855+ if (polstate->subj_map_set.s_hash) {
71856+ for (i = 0; i < polstate->subj_map_set.s_size; i++) {
71857+ if (polstate->subj_map_set.s_hash[i]) {
71858+ kfree(polstate->subj_map_set.s_hash[i]);
71859+ polstate->subj_map_set.s_hash[i] = NULL;
71860+ }
71861+ }
71862+
71863+ if ((polstate->subj_map_set.s_size * sizeof (struct subject_map *)) <=
71864+ PAGE_SIZE)
71865+ kfree(polstate->subj_map_set.s_hash);
71866+ else
71867+ vfree(polstate->subj_map_set.s_hash);
71868+ }
71869+
71870+ return;
71871+}
71872+
71873+static void
71874+free_variables(bool reload)
71875+{
71876+ struct acl_subject_label *s;
71877+ struct acl_role_label *r;
71878+ struct task_struct *task, *task2;
71879+ unsigned int x;
71880+
71881+ if (!reload) {
71882+ gr_clear_learn_entries();
71883+
71884+ read_lock(&tasklist_lock);
71885+ do_each_thread(task2, task) {
71886+ task->acl_sp_role = 0;
71887+ task->acl_role_id = 0;
71888+ task->inherited = 0;
71889+ task->acl = NULL;
71890+ task->role = NULL;
71891+ } while_each_thread(task2, task);
71892+ read_unlock(&tasklist_lock);
71893+
71894+ kfree(fakefs_obj_rw);
71895+ fakefs_obj_rw = NULL;
71896+ kfree(fakefs_obj_rwx);
71897+ fakefs_obj_rwx = NULL;
71898+
71899+ /* release the reference to the real root dentry and vfsmount */
71900+ path_put(&gr_real_root);
71901+ memset(&gr_real_root, 0, sizeof(gr_real_root));
71902+ }
71903+
71904+ /* free all object hash tables */
71905+
71906+ FOR_EACH_ROLE_START(r)
71907+ if (r->subj_hash == NULL)
71908+ goto next_role;
71909+ FOR_EACH_SUBJECT_START(r, s, x)
71910+ if (s->obj_hash == NULL)
71911+ break;
71912+ if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
71913+ kfree(s->obj_hash);
71914+ else
71915+ vfree(s->obj_hash);
71916+ FOR_EACH_SUBJECT_END(s, x)
71917+ FOR_EACH_NESTED_SUBJECT_START(r, s)
71918+ if (s->obj_hash == NULL)
71919+ break;
71920+ if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
71921+ kfree(s->obj_hash);
71922+ else
71923+ vfree(s->obj_hash);
71924+ FOR_EACH_NESTED_SUBJECT_END(s)
71925+ if ((r->subj_hash_size * sizeof (struct acl_subject_label *)) <= PAGE_SIZE)
71926+ kfree(r->subj_hash);
71927+ else
71928+ vfree(r->subj_hash);
71929+ r->subj_hash = NULL;
71930+next_role:
71931+ FOR_EACH_ROLE_END(r)
71932+
71933+ acl_free_all();
71934+
71935+ if (polstate->acl_role_set.r_hash) {
71936+ if ((polstate->acl_role_set.r_size * sizeof (struct acl_role_label *)) <=
71937+ PAGE_SIZE)
71938+ kfree(polstate->acl_role_set.r_hash);
71939+ else
71940+ vfree(polstate->acl_role_set.r_hash);
71941+ }
71942+ if (polstate->name_set.n_hash) {
71943+ if ((polstate->name_set.n_size * sizeof (struct name_entry *)) <=
71944+ PAGE_SIZE)
71945+ kfree(polstate->name_set.n_hash);
71946+ else
71947+ vfree(polstate->name_set.n_hash);
71948+ }
71949+
71950+ if (polstate->inodev_set.i_hash) {
71951+ if ((polstate->inodev_set.i_size * sizeof (struct inodev_entry *)) <=
71952+ PAGE_SIZE)
71953+ kfree(polstate->inodev_set.i_hash);
71954+ else
71955+ vfree(polstate->inodev_set.i_hash);
71956+ }
71957+
71958+ if (!reload)
71959+ gr_free_uidset();
71960+
71961+ memset(&polstate->name_set, 0, sizeof (struct name_db));
71962+ memset(&polstate->inodev_set, 0, sizeof (struct inodev_db));
71963+ memset(&polstate->acl_role_set, 0, sizeof (struct acl_role_db));
71964+ memset(&polstate->subj_map_set, 0, sizeof (struct acl_subj_map_db));
71965+
71966+ polstate->default_role = NULL;
71967+ polstate->kernel_role = NULL;
71968+ polstate->role_list = NULL;
71969+
71970+ return;
71971+}
71972+
71973+static struct acl_subject_label *
71974+do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied);
71975+
71976+static int alloc_and_copy_string(char **name, unsigned int maxlen)
71977+{
71978+ unsigned int len = strnlen_user(*name, maxlen);
71979+ char *tmp;
71980+
71981+ if (!len || len >= maxlen)
71982+ return -EINVAL;
71983+
71984+ if ((tmp = (char *) acl_alloc(len)) == NULL)
71985+ return -ENOMEM;
71986+
71987+ if (copy_from_user(tmp, *name, len))
71988+ return -EFAULT;
71989+
71990+ tmp[len-1] = '\0';
71991+ *name = tmp;
71992+
71993+ return 0;
71994+}
71995+
71996+static int
71997+copy_user_glob(struct acl_object_label *obj)
71998+{
71999+ struct acl_object_label *g_tmp, **guser;
72000+ int error;
72001+
72002+ if (obj->globbed == NULL)
72003+ return 0;
72004+
72005+ guser = &obj->globbed;
72006+ while (*guser) {
72007+ g_tmp = (struct acl_object_label *)
72008+ acl_alloc(sizeof (struct acl_object_label));
72009+ if (g_tmp == NULL)
72010+ return -ENOMEM;
72011+
72012+ if (copy_acl_object_label(g_tmp, *guser))
72013+ return -EFAULT;
72014+
72015+ error = alloc_and_copy_string(&g_tmp->filename, PATH_MAX);
72016+ if (error)
72017+ return error;
72018+
72019+ *guser = g_tmp;
72020+ guser = &(g_tmp->next);
72021+ }
72022+
72023+ return 0;
72024+}
72025+
72026+static int
72027+copy_user_objs(struct acl_object_label *userp, struct acl_subject_label *subj,
72028+ struct acl_role_label *role)
72029+{
72030+ struct acl_object_label *o_tmp;
72031+ int ret;
72032+
72033+ while (userp) {
72034+ if ((o_tmp = (struct acl_object_label *)
72035+ acl_alloc(sizeof (struct acl_object_label))) == NULL)
72036+ return -ENOMEM;
72037+
72038+ if (copy_acl_object_label(o_tmp, userp))
72039+ return -EFAULT;
72040+
72041+ userp = o_tmp->prev;
72042+
72043+ ret = alloc_and_copy_string(&o_tmp->filename, PATH_MAX);
72044+ if (ret)
72045+ return ret;
72046+
72047+ insert_acl_obj_label(o_tmp, subj);
72048+ if (!insert_name_entry(o_tmp->filename, o_tmp->inode,
72049+ o_tmp->device, (o_tmp->mode & GR_DELETED) ? 1 : 0))
72050+ return -ENOMEM;
72051+
72052+ ret = copy_user_glob(o_tmp);
72053+ if (ret)
72054+ return ret;
72055+
72056+ if (o_tmp->nested) {
72057+ int already_copied;
72058+
72059+ o_tmp->nested = do_copy_user_subj(o_tmp->nested, role, &already_copied);
72060+ if (IS_ERR(o_tmp->nested))
72061+ return PTR_ERR(o_tmp->nested);
72062+
72063+ /* insert into nested subject list if we haven't copied this one yet
72064+ to prevent duplicate entries */
72065+ if (!already_copied) {
72066+ o_tmp->nested->next = role->hash->first;
72067+ role->hash->first = o_tmp->nested;
72068+ }
72069+ }
72070+ }
72071+
72072+ return 0;
72073+}
72074+
72075+static __u32
72076+count_user_subjs(struct acl_subject_label *userp)
72077+{
72078+ struct acl_subject_label s_tmp;
72079+ __u32 num = 0;
72080+
72081+ while (userp) {
72082+ if (copy_acl_subject_label(&s_tmp, userp))
72083+ break;
72084+
72085+ userp = s_tmp.prev;
72086+ }
72087+
72088+ return num;
72089+}
72090+
72091+static int
72092+copy_user_allowedips(struct acl_role_label *rolep)
72093+{
72094+ struct role_allowed_ip *ruserip, *rtmp = NULL, *rlast;
72095+
72096+ ruserip = rolep->allowed_ips;
72097+
72098+ while (ruserip) {
72099+ rlast = rtmp;
72100+
72101+ if ((rtmp = (struct role_allowed_ip *)
72102+ acl_alloc(sizeof (struct role_allowed_ip))) == NULL)
72103+ return -ENOMEM;
72104+
72105+ if (copy_role_allowed_ip(rtmp, ruserip))
72106+ return -EFAULT;
72107+
72108+ ruserip = rtmp->prev;
72109+
72110+ if (!rlast) {
72111+ rtmp->prev = NULL;
72112+ rolep->allowed_ips = rtmp;
72113+ } else {
72114+ rlast->next = rtmp;
72115+ rtmp->prev = rlast;
72116+ }
72117+
72118+ if (!ruserip)
72119+ rtmp->next = NULL;
72120+ }
72121+
72122+ return 0;
72123+}
72124+
72125+static int
72126+copy_user_transitions(struct acl_role_label *rolep)
72127+{
72128+ struct role_transition *rusertp, *rtmp = NULL, *rlast;
72129+ int error;
72130+
72131+ rusertp = rolep->transitions;
72132+
72133+ while (rusertp) {
72134+ rlast = rtmp;
72135+
72136+ if ((rtmp = (struct role_transition *)
72137+ acl_alloc(sizeof (struct role_transition))) == NULL)
72138+ return -ENOMEM;
72139+
72140+ if (copy_role_transition(rtmp, rusertp))
72141+ return -EFAULT;
72142+
72143+ rusertp = rtmp->prev;
72144+
72145+ error = alloc_and_copy_string(&rtmp->rolename, GR_SPROLE_LEN);
72146+ if (error)
72147+ return error;
72148+
72149+ if (!rlast) {
72150+ rtmp->prev = NULL;
72151+ rolep->transitions = rtmp;
72152+ } else {
72153+ rlast->next = rtmp;
72154+ rtmp->prev = rlast;
72155+ }
72156+
72157+ if (!rusertp)
72158+ rtmp->next = NULL;
72159+ }
72160+
72161+ return 0;
72162+}
72163+
72164+static __u32 count_user_objs(const struct acl_object_label __user *userp)
72165+{
72166+ struct acl_object_label o_tmp;
72167+ __u32 num = 0;
72168+
72169+ while (userp) {
72170+ if (copy_acl_object_label(&o_tmp, userp))
72171+ break;
72172+
72173+ userp = o_tmp.prev;
72174+ num++;
72175+ }
72176+
72177+ return num;
72178+}
72179+
72180+static struct acl_subject_label *
72181+do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied)
72182+{
72183+ struct acl_subject_label *s_tmp = NULL, *s_tmp2;
72184+ __u32 num_objs;
72185+ struct acl_ip_label **i_tmp, *i_utmp2;
72186+ struct gr_hash_struct ghash;
72187+ struct subject_map *subjmap;
72188+ unsigned int i_num;
72189+ int err;
72190+
72191+ if (already_copied != NULL)
72192+ *already_copied = 0;
72193+
72194+ s_tmp = lookup_subject_map(userp);
72195+
72196+ /* we've already copied this subject into the kernel, just return
72197+ the reference to it, and don't copy it over again
72198+ */
72199+ if (s_tmp) {
72200+ if (already_copied != NULL)
72201+ *already_copied = 1;
72202+ return(s_tmp);
72203+ }
72204+
72205+ if ((s_tmp = (struct acl_subject_label *)
72206+ acl_alloc(sizeof (struct acl_subject_label))) == NULL)
72207+ return ERR_PTR(-ENOMEM);
72208+
72209+ subjmap = (struct subject_map *)kmalloc(sizeof (struct subject_map), GFP_KERNEL);
72210+ if (subjmap == NULL)
72211+ return ERR_PTR(-ENOMEM);
72212+
72213+ subjmap->user = userp;
72214+ subjmap->kernel = s_tmp;
72215+ insert_subj_map_entry(subjmap);
72216+
72217+ if (copy_acl_subject_label(s_tmp, userp))
72218+ return ERR_PTR(-EFAULT);
72219+
72220+ err = alloc_and_copy_string(&s_tmp->filename, PATH_MAX);
72221+ if (err)
72222+ return ERR_PTR(err);
72223+
72224+ if (!strcmp(s_tmp->filename, "/"))
72225+ role->root_label = s_tmp;
72226+
72227+ if (copy_gr_hash_struct(&ghash, s_tmp->hash))
72228+ return ERR_PTR(-EFAULT);
72229+
72230+ /* copy user and group transition tables */
72231+
72232+ if (s_tmp->user_trans_num) {
72233+ uid_t *uidlist;
72234+
72235+ uidlist = (uid_t *)acl_alloc_num(s_tmp->user_trans_num, sizeof(uid_t));
72236+ if (uidlist == NULL)
72237+ return ERR_PTR(-ENOMEM);
72238+ if (copy_from_user(uidlist, s_tmp->user_transitions, s_tmp->user_trans_num * sizeof(uid_t)))
72239+ return ERR_PTR(-EFAULT);
72240+
72241+ s_tmp->user_transitions = uidlist;
72242+ }
72243+
72244+ if (s_tmp->group_trans_num) {
72245+ gid_t *gidlist;
72246+
72247+ gidlist = (gid_t *)acl_alloc_num(s_tmp->group_trans_num, sizeof(gid_t));
72248+ if (gidlist == NULL)
72249+ return ERR_PTR(-ENOMEM);
72250+ if (copy_from_user(gidlist, s_tmp->group_transitions, s_tmp->group_trans_num * sizeof(gid_t)))
72251+ return ERR_PTR(-EFAULT);
72252+
72253+ s_tmp->group_transitions = gidlist;
72254+ }
72255+
72256+ /* set up object hash table */
72257+ num_objs = count_user_objs(ghash.first);
72258+
72259+ s_tmp->obj_hash_size = num_objs;
72260+ s_tmp->obj_hash =
72261+ (struct acl_object_label **)
72262+ create_table(&(s_tmp->obj_hash_size), sizeof(void *));
72263+
72264+ if (!s_tmp->obj_hash)
72265+ return ERR_PTR(-ENOMEM);
72266+
72267+ memset(s_tmp->obj_hash, 0,
72268+ s_tmp->obj_hash_size *
72269+ sizeof (struct acl_object_label *));
72270+
72271+ /* add in objects */
72272+ err = copy_user_objs(ghash.first, s_tmp, role);
72273+
72274+ if (err)
72275+ return ERR_PTR(err);
72276+
72277+ /* set pointer for parent subject */
72278+ if (s_tmp->parent_subject) {
72279+ s_tmp2 = do_copy_user_subj(s_tmp->parent_subject, role, NULL);
72280+
72281+ if (IS_ERR(s_tmp2))
72282+ return s_tmp2;
72283+
72284+ s_tmp->parent_subject = s_tmp2;
72285+ }
72286+
72287+ /* add in ip acls */
72288+
72289+ if (!s_tmp->ip_num) {
72290+ s_tmp->ips = NULL;
72291+ goto insert;
72292+ }
72293+
72294+ i_tmp =
72295+ (struct acl_ip_label **) acl_alloc_num(s_tmp->ip_num,
72296+ sizeof (struct acl_ip_label *));
72297+
72298+ if (!i_tmp)
72299+ return ERR_PTR(-ENOMEM);
72300+
72301+ for (i_num = 0; i_num < s_tmp->ip_num; i_num++) {
72302+ *(i_tmp + i_num) =
72303+ (struct acl_ip_label *)
72304+ acl_alloc(sizeof (struct acl_ip_label));
72305+ if (!*(i_tmp + i_num))
72306+ return ERR_PTR(-ENOMEM);
72307+
72308+ if (copy_pointer_from_array(&i_utmp2, i_num, s_tmp->ips))
72309+ return ERR_PTR(-EFAULT);
72310+
72311+ if (copy_acl_ip_label(*(i_tmp + i_num), i_utmp2))
72312+ return ERR_PTR(-EFAULT);
72313+
72314+ if ((*(i_tmp + i_num))->iface == NULL)
72315+ continue;
72316+
72317+ err = alloc_and_copy_string(&(*(i_tmp + i_num))->iface, IFNAMSIZ);
72318+ if (err)
72319+ return ERR_PTR(err);
72320+ }
72321+
72322+ s_tmp->ips = i_tmp;
72323+
72324+insert:
72325+ if (!insert_name_entry(s_tmp->filename, s_tmp->inode,
72326+ s_tmp->device, (s_tmp->mode & GR_DELETED) ? 1 : 0))
72327+ return ERR_PTR(-ENOMEM);
72328+
72329+ return s_tmp;
72330+}
72331+
72332+static int
72333+copy_user_subjs(struct acl_subject_label *userp, struct acl_role_label *role)
72334+{
72335+ struct acl_subject_label s_pre;
72336+ struct acl_subject_label * ret;
72337+ int err;
72338+
72339+ while (userp) {
72340+ if (copy_acl_subject_label(&s_pre, userp))
72341+ return -EFAULT;
72342+
72343+ ret = do_copy_user_subj(userp, role, NULL);
72344+
72345+ err = PTR_ERR(ret);
72346+ if (IS_ERR(ret))
72347+ return err;
72348+
72349+ insert_acl_subj_label(ret, role);
72350+
72351+ userp = s_pre.prev;
72352+ }
72353+
72354+ return 0;
72355+}
72356+
72357+static int
72358+copy_user_acl(struct gr_arg *arg)
72359+{
72360+ struct acl_role_label *r_tmp = NULL, **r_utmp, *r_utmp2;
72361+ struct acl_subject_label *subj_list;
72362+ struct sprole_pw *sptmp;
72363+ struct gr_hash_struct *ghash;
72364+ uid_t *domainlist;
72365+ unsigned int r_num;
72366+ int err = 0;
72367+ __u16 i;
72368+ __u32 num_subjs;
72369+
72370+ /* we need a default and kernel role */
72371+ if (arg->role_db.num_roles < 2)
72372+ return -EINVAL;
72373+
72374+ /* copy special role authentication info from userspace */
72375+
72376+ polstate->num_sprole_pws = arg->num_sprole_pws;
72377+ polstate->acl_special_roles = (struct sprole_pw **) acl_alloc_num(polstate->num_sprole_pws, sizeof(struct sprole_pw *));
72378+
72379+ if (!polstate->acl_special_roles && polstate->num_sprole_pws)
72380+ return -ENOMEM;
72381+
72382+ for (i = 0; i < polstate->num_sprole_pws; i++) {
72383+ sptmp = (struct sprole_pw *) acl_alloc(sizeof(struct sprole_pw));
72384+ if (!sptmp)
72385+ return -ENOMEM;
72386+ if (copy_sprole_pw(sptmp, i, arg->sprole_pws))
72387+ return -EFAULT;
72388+
72389+ err = alloc_and_copy_string((char **)&sptmp->rolename, GR_SPROLE_LEN);
72390+ if (err)
72391+ return err;
72392+
72393+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
72394+ printk(KERN_ALERT "Copying special role %s\n", sptmp->rolename);
72395+#endif
72396+
72397+ polstate->acl_special_roles[i] = sptmp;
72398+ }
72399+
72400+ r_utmp = (struct acl_role_label **) arg->role_db.r_table;
72401+
72402+ for (r_num = 0; r_num < arg->role_db.num_roles; r_num++) {
72403+ r_tmp = acl_alloc(sizeof (struct acl_role_label));
72404+
72405+ if (!r_tmp)
72406+ return -ENOMEM;
72407+
72408+ if (copy_pointer_from_array(&r_utmp2, r_num, r_utmp))
72409+ return -EFAULT;
72410+
72411+ if (copy_acl_role_label(r_tmp, r_utmp2))
72412+ return -EFAULT;
72413+
72414+ err = alloc_and_copy_string(&r_tmp->rolename, GR_SPROLE_LEN);
72415+ if (err)
72416+ return err;
72417+
72418+ if (!strcmp(r_tmp->rolename, "default")
72419+ && (r_tmp->roletype & GR_ROLE_DEFAULT)) {
72420+ polstate->default_role = r_tmp;
72421+ } else if (!strcmp(r_tmp->rolename, ":::kernel:::")) {
72422+ polstate->kernel_role = r_tmp;
72423+ }
72424+
72425+ if ((ghash = (struct gr_hash_struct *) acl_alloc(sizeof(struct gr_hash_struct))) == NULL)
72426+ return -ENOMEM;
72427+
72428+ if (copy_gr_hash_struct(ghash, r_tmp->hash))
72429+ return -EFAULT;
72430+
72431+ r_tmp->hash = ghash;
72432+
72433+ num_subjs = count_user_subjs(r_tmp->hash->first);
72434+
72435+ r_tmp->subj_hash_size = num_subjs;
72436+ r_tmp->subj_hash =
72437+ (struct acl_subject_label **)
72438+ create_table(&(r_tmp->subj_hash_size), sizeof(void *));
72439+
72440+ if (!r_tmp->subj_hash)
72441+ return -ENOMEM;
72442+
72443+ err = copy_user_allowedips(r_tmp);
72444+ if (err)
72445+ return err;
72446+
72447+ /* copy domain info */
72448+ if (r_tmp->domain_children != NULL) {
72449+ domainlist = acl_alloc_num(r_tmp->domain_child_num, sizeof(uid_t));
72450+ if (domainlist == NULL)
72451+ return -ENOMEM;
72452+
72453+ if (copy_from_user(domainlist, r_tmp->domain_children, r_tmp->domain_child_num * sizeof(uid_t)))
72454+ return -EFAULT;
72455+
72456+ r_tmp->domain_children = domainlist;
72457+ }
72458+
72459+ err = copy_user_transitions(r_tmp);
72460+ if (err)
72461+ return err;
72462+
72463+ memset(r_tmp->subj_hash, 0,
72464+ r_tmp->subj_hash_size *
72465+ sizeof (struct acl_subject_label *));
72466+
72467+ /* acquire the list of subjects, then NULL out
72468+ the list prior to parsing the subjects for this role,
72469+ as during this parsing the list is replaced with a list
72470+ of *nested* subjects for the role
72471+ */
72472+ subj_list = r_tmp->hash->first;
72473+
72474+ /* set nested subject list to null */
72475+ r_tmp->hash->first = NULL;
72476+
72477+ err = copy_user_subjs(subj_list, r_tmp);
72478+
72479+ if (err)
72480+ return err;
72481+
72482+ insert_acl_role_label(r_tmp);
72483+ }
72484+
72485+ if (polstate->default_role == NULL || polstate->kernel_role == NULL)
72486+ return -EINVAL;
72487+
72488+ return err;
72489+}
72490+
72491+static int gracl_reload_apply_policies(void *reload)
72492+{
72493+ struct gr_reload_state *reload_state = (struct gr_reload_state *)reload;
72494+ struct task_struct *task, *task2;
72495+ struct acl_role_label *role, *rtmp;
72496+ struct acl_subject_label *subj;
72497+ const struct cred *cred;
72498+ int role_applied;
72499+ int ret = 0;
72500+
72501+ memcpy(&reload_state->oldpolicy, reload_state->oldpolicy_ptr, sizeof(struct gr_policy_state));
72502+ memcpy(&reload_state->oldalloc, reload_state->oldalloc_ptr, sizeof(struct gr_alloc_state));
72503+
72504+ /* first make sure we'll be able to apply the new policy cleanly */
72505+ do_each_thread(task2, task) {
72506+ if (task->exec_file == NULL)
72507+ continue;
72508+ role_applied = 0;
72509+ if (!reload_state->oldmode && task->role->roletype & GR_ROLE_SPECIAL) {
72510+ /* preserve special roles */
72511+ FOR_EACH_ROLE_START(role)
72512+ if ((role->roletype & GR_ROLE_SPECIAL) && !strcmp(task->role->rolename, role->rolename)) {
72513+ rtmp = task->role;
72514+ task->role = role;
72515+ role_applied = 1;
72516+ break;
72517+ }
72518+ FOR_EACH_ROLE_END(role)
72519+ }
72520+ if (!role_applied) {
72521+ cred = __task_cred(task);
72522+ rtmp = task->role;
72523+ task->role = __lookup_acl_role_label(polstate, task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
72524+ }
72525+ /* this handles non-nested inherited subjects, nested subjects will still
72526+ be dropped currently */
72527+ subj = __gr_get_subject_for_task(polstate, task, task->acl->filename);
72528+ task->tmpacl = __gr_get_subject_for_task(polstate, task, NULL);
72529+ /* change the role back so that we've made no modifications to the policy */
72530+ task->role = rtmp;
72531+
72532+ if (subj == NULL || task->tmpacl == NULL) {
72533+ ret = -EINVAL;
72534+ goto out;
72535+ }
72536+ } while_each_thread(task2, task);
72537+
72538+ /* now actually apply the policy */
72539+
72540+ do_each_thread(task2, task) {
72541+ if (task->exec_file) {
72542+ role_applied = 0;
72543+ if (!reload_state->oldmode && task->role->roletype & GR_ROLE_SPECIAL) {
72544+ /* preserve special roles */
72545+ FOR_EACH_ROLE_START(role)
72546+ if ((role->roletype & GR_ROLE_SPECIAL) && !strcmp(task->role->rolename, role->rolename)) {
72547+ task->role = role;
72548+ role_applied = 1;
72549+ break;
72550+ }
72551+ FOR_EACH_ROLE_END(role)
72552+ }
72553+ if (!role_applied) {
72554+ cred = __task_cred(task);
72555+ task->role = __lookup_acl_role_label(polstate, task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
72556+ }
72557+ /* this handles non-nested inherited subjects, nested subjects will still
72558+ be dropped currently */
72559+ if (!reload_state->oldmode && task->inherited)
72560+ subj = __gr_get_subject_for_task(polstate, task, task->acl->filename);
72561+ else {
72562+ /* looked up and tagged to the task previously */
72563+ subj = task->tmpacl;
72564+ }
72565+ /* subj will be non-null */
72566+ __gr_apply_subject_to_task(polstate, task, subj);
72567+ if (reload_state->oldmode) {
72568+ task->acl_role_id = 0;
72569+ task->acl_sp_role = 0;
72570+ task->inherited = 0;
72571+ }
72572+ } else {
72573+ // it's a kernel process
72574+ task->role = polstate->kernel_role;
72575+ task->acl = polstate->kernel_role->root_label;
72576+#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
72577+ task->acl->mode &= ~GR_PROCFIND;
72578+#endif
72579+ }
72580+ } while_each_thread(task2, task);
72581+
72582+ memcpy(reload_state->oldpolicy_ptr, &reload_state->newpolicy, sizeof(struct gr_policy_state));
72583+ memcpy(reload_state->oldalloc_ptr, &reload_state->newalloc, sizeof(struct gr_alloc_state));
72584+
72585+out:
72586+
72587+ return ret;
72588+}
72589+
72590+static int gracl_reload(struct gr_arg *args, unsigned char oldmode)
72591+{
72592+ struct gr_reload_state new_reload_state = { };
72593+ int err;
72594+
72595+ new_reload_state.oldpolicy_ptr = polstate;
72596+ new_reload_state.oldalloc_ptr = current_alloc_state;
72597+ new_reload_state.oldmode = oldmode;
72598+
72599+ current_alloc_state = &new_reload_state.newalloc;
72600+ polstate = &new_reload_state.newpolicy;
72601+
72602+ /* everything relevant is now saved off, copy in the new policy */
72603+ if (init_variables(args, true)) {
72604+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
72605+ err = -ENOMEM;
72606+ goto error;
72607+ }
72608+
72609+ err = copy_user_acl(args);
72610+ free_init_variables();
72611+ if (err)
72612+ goto error;
72613+ /* the new policy is copied in, with the old policy available via saved_state
72614+ first go through applying roles, making sure to preserve special roles
72615+ then apply new subjects, making sure to preserve inherited and nested subjects,
72616+ though currently only inherited subjects will be preserved
72617+ */
72618+ err = stop_machine(gracl_reload_apply_policies, &new_reload_state, NULL);
72619+ if (err)
72620+ goto error;
72621+
72622+ /* we've now applied the new policy, so restore the old policy state to free it */
72623+ polstate = &new_reload_state.oldpolicy;
72624+ current_alloc_state = &new_reload_state.oldalloc;
72625+ free_variables(true);
72626+
72627+ /* oldpolicy/oldalloc_ptr point to the new policy/alloc states as they were copied
72628+ to running_polstate/current_alloc_state inside stop_machine
72629+ */
72630+ err = 0;
72631+ goto out;
72632+error:
72633+ /* on error of loading the new policy, we'll just keep the previous
72634+ policy set around
72635+ */
72636+ free_variables(true);
72637+
72638+ /* doesn't affect runtime, but maintains consistent state */
72639+out:
72640+ polstate = new_reload_state.oldpolicy_ptr;
72641+ current_alloc_state = new_reload_state.oldalloc_ptr;
72642+
72643+ return err;
72644+}
72645+
72646+static int
72647+gracl_init(struct gr_arg *args)
72648+{
72649+ int error = 0;
72650+
72651+ memcpy(&gr_system_salt, args->salt, sizeof(gr_system_salt));
72652+ memcpy(&gr_system_sum, args->sum, sizeof(gr_system_sum));
72653+
72654+ if (init_variables(args, false)) {
72655+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
72656+ error = -ENOMEM;
72657+ goto out;
72658+ }
72659+
72660+ error = copy_user_acl(args);
72661+ free_init_variables();
72662+ if (error)
72663+ goto out;
72664+
72665+ error = gr_set_acls(0);
72666+ if (error)
72667+ goto out;
72668+
72669+ gr_enable_rbac_system();
72670+
72671+ return 0;
72672+
72673+out:
72674+ free_variables(false);
72675+ return error;
72676+}
72677+
72678+static int
72679+lookup_special_role_auth(__u16 mode, const char *rolename, unsigned char **salt,
72680+ unsigned char **sum)
72681+{
72682+ struct acl_role_label *r;
72683+ struct role_allowed_ip *ipp;
72684+ struct role_transition *trans;
72685+ unsigned int i;
72686+ int found = 0;
72687+ u32 curr_ip = current->signal->curr_ip;
72688+
72689+ current->signal->saved_ip = curr_ip;
72690+
72691+ /* check transition table */
72692+
72693+ for (trans = current->role->transitions; trans; trans = trans->next) {
72694+ if (!strcmp(rolename, trans->rolename)) {
72695+ found = 1;
72696+ break;
72697+ }
72698+ }
72699+
72700+ if (!found)
72701+ return 0;
72702+
72703+ /* handle special roles that do not require authentication
72704+ and check ip */
72705+
72706+ FOR_EACH_ROLE_START(r)
72707+ if (!strcmp(rolename, r->rolename) &&
72708+ (r->roletype & GR_ROLE_SPECIAL)) {
72709+ found = 0;
72710+ if (r->allowed_ips != NULL) {
72711+ for (ipp = r->allowed_ips; ipp; ipp = ipp->next) {
72712+ if ((ntohl(curr_ip) & ipp->netmask) ==
72713+ (ntohl(ipp->addr) & ipp->netmask))
72714+ found = 1;
72715+ }
72716+ } else
72717+ found = 2;
72718+ if (!found)
72719+ return 0;
72720+
72721+ if (((mode == GR_SPROLE) && (r->roletype & GR_ROLE_NOPW)) ||
72722+ ((mode == GR_SPROLEPAM) && (r->roletype & GR_ROLE_PAM))) {
72723+ *salt = NULL;
72724+ *sum = NULL;
72725+ return 1;
72726+ }
72727+ }
72728+ FOR_EACH_ROLE_END(r)
72729+
72730+ for (i = 0; i < polstate->num_sprole_pws; i++) {
72731+ if (!strcmp(rolename, polstate->acl_special_roles[i]->rolename)) {
72732+ *salt = polstate->acl_special_roles[i]->salt;
72733+ *sum = polstate->acl_special_roles[i]->sum;
72734+ return 1;
72735+ }
72736+ }
72737+
72738+ return 0;
72739+}
72740+
72741+int gr_check_secure_terminal(struct task_struct *task)
72742+{
72743+ struct task_struct *p, *p2, *p3;
72744+ struct files_struct *files;
72745+ struct fdtable *fdt;
72746+ struct file *our_file = NULL, *file;
72747+ int i;
72748+
72749+ if (task->signal->tty == NULL)
72750+ return 1;
72751+
72752+ files = get_files_struct(task);
72753+ if (files != NULL) {
72754+ rcu_read_lock();
72755+ fdt = files_fdtable(files);
72756+ for (i=0; i < fdt->max_fds; i++) {
72757+ file = fcheck_files(files, i);
72758+ if (file && (our_file == NULL) && (file->private_data == task->signal->tty)) {
72759+ get_file(file);
72760+ our_file = file;
72761+ }
72762+ }
72763+ rcu_read_unlock();
72764+ put_files_struct(files);
72765+ }
72766+
72767+ if (our_file == NULL)
72768+ return 1;
72769+
72770+ read_lock(&tasklist_lock);
72771+ do_each_thread(p2, p) {
72772+ files = get_files_struct(p);
72773+ if (files == NULL ||
72774+ (p->signal && p->signal->tty == task->signal->tty)) {
72775+ if (files != NULL)
72776+ put_files_struct(files);
72777+ continue;
72778+ }
72779+ rcu_read_lock();
72780+ fdt = files_fdtable(files);
72781+ for (i=0; i < fdt->max_fds; i++) {
72782+ file = fcheck_files(files, i);
72783+ if (file && S_ISCHR(file->f_path.dentry->d_inode->i_mode) &&
72784+ file->f_path.dentry->d_inode->i_rdev == our_file->f_path.dentry->d_inode->i_rdev) {
72785+ p3 = task;
72786+ while (task_pid_nr(p3) > 0) {
72787+ if (p3 == p)
72788+ break;
72789+ p3 = p3->real_parent;
72790+ }
72791+ if (p3 == p)
72792+ break;
72793+ gr_log_ttysniff(GR_DONT_AUDIT_GOOD, GR_TTYSNIFF_ACL_MSG, p);
72794+ gr_handle_alertkill(p);
72795+ rcu_read_unlock();
72796+ put_files_struct(files);
72797+ read_unlock(&tasklist_lock);
72798+ fput(our_file);
72799+ return 0;
72800+ }
72801+ }
72802+ rcu_read_unlock();
72803+ put_files_struct(files);
72804+ } while_each_thread(p2, p);
72805+ read_unlock(&tasklist_lock);
72806+
72807+ fput(our_file);
72808+ return 1;
72809+}
72810+
72811+ssize_t
72812+write_grsec_handler(struct file *file, const char __user * buf, size_t count, loff_t *ppos)
72813+{
72814+ struct gr_arg_wrapper uwrap;
72815+ unsigned char *sprole_salt = NULL;
72816+ unsigned char *sprole_sum = NULL;
72817+ int error = 0;
72818+ int error2 = 0;
72819+ size_t req_count = 0;
72820+ unsigned char oldmode = 0;
72821+
72822+ mutex_lock(&gr_dev_mutex);
72823+
72824+ if (gr_acl_is_enabled() && !(current->acl->mode & GR_KERNELAUTH)) {
72825+ error = -EPERM;
72826+ goto out;
72827+ }
72828+
72829+#ifdef CONFIG_COMPAT
72830+ pax_open_kernel();
72831+ if (is_compat_task()) {
72832+ copy_gr_arg_wrapper = &copy_gr_arg_wrapper_compat;
72833+ copy_gr_arg = &copy_gr_arg_compat;
72834+ copy_acl_object_label = &copy_acl_object_label_compat;
72835+ copy_acl_subject_label = &copy_acl_subject_label_compat;
72836+ copy_acl_role_label = &copy_acl_role_label_compat;
72837+ copy_acl_ip_label = &copy_acl_ip_label_compat;
72838+ copy_role_allowed_ip = &copy_role_allowed_ip_compat;
72839+ copy_role_transition = &copy_role_transition_compat;
72840+ copy_sprole_pw = &copy_sprole_pw_compat;
72841+ copy_gr_hash_struct = &copy_gr_hash_struct_compat;
72842+ copy_pointer_from_array = &copy_pointer_from_array_compat;
72843+ get_gr_arg_wrapper_size = &get_gr_arg_wrapper_size_compat;
72844+ } else {
72845+ copy_gr_arg_wrapper = &copy_gr_arg_wrapper_normal;
72846+ copy_gr_arg = &copy_gr_arg_normal;
72847+ copy_acl_object_label = &copy_acl_object_label_normal;
72848+ copy_acl_subject_label = &copy_acl_subject_label_normal;
72849+ copy_acl_role_label = &copy_acl_role_label_normal;
72850+ copy_acl_ip_label = &copy_acl_ip_label_normal;
72851+ copy_role_allowed_ip = &copy_role_allowed_ip_normal;
72852+ copy_role_transition = &copy_role_transition_normal;
72853+ copy_sprole_pw = &copy_sprole_pw_normal;
72854+ copy_gr_hash_struct = &copy_gr_hash_struct_normal;
72855+ copy_pointer_from_array = &copy_pointer_from_array_normal;
72856+ get_gr_arg_wrapper_size = &get_gr_arg_wrapper_size_normal;
72857+ }
72858+ pax_close_kernel();
72859+#endif
72860+
72861+ req_count = get_gr_arg_wrapper_size();
72862+
72863+ if (count != req_count) {
72864+ gr_log_int_int(GR_DONT_AUDIT_GOOD, GR_DEV_ACL_MSG, (int)count, (int)req_count);
72865+ error = -EINVAL;
72866+ goto out;
72867+ }
72868+
72869+
72870+ if (gr_auth_expires && time_after_eq(get_seconds(), gr_auth_expires)) {
72871+ gr_auth_expires = 0;
72872+ gr_auth_attempts = 0;
72873+ }
72874+
72875+ error = copy_gr_arg_wrapper(buf, &uwrap);
72876+ if (error)
72877+ goto out;
72878+
72879+ error = copy_gr_arg(uwrap.arg, &gr_usermode);
72880+ if (error)
72881+ goto out;
72882+
72883+ if (gr_usermode.mode != GR_SPROLE && gr_usermode.mode != GR_SPROLEPAM &&
72884+ gr_auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
72885+ time_after(gr_auth_expires, get_seconds())) {
72886+ error = -EBUSY;
72887+ goto out;
72888+ }
72889+
72890+ /* if non-root trying to do anything other than use a special role,
72891+ do not attempt authentication, do not count towards authentication
72892+ locking
72893+ */
72894+
72895+ if (gr_usermode.mode != GR_SPROLE && gr_usermode.mode != GR_STATUS &&
72896+ gr_usermode.mode != GR_UNSPROLE && gr_usermode.mode != GR_SPROLEPAM &&
72897+ gr_is_global_nonroot(current_uid())) {
72898+ error = -EPERM;
72899+ goto out;
72900+ }
72901+
72902+ /* ensure pw and special role name are null terminated */
72903+
72904+ gr_usermode.pw[GR_PW_LEN - 1] = '\0';
72905+ gr_usermode.sp_role[GR_SPROLE_LEN - 1] = '\0';
72906+
72907+ /* Okay.
72908+ * We have our enough of the argument structure..(we have yet
72909+ * to copy_from_user the tables themselves) . Copy the tables
72910+ * only if we need them, i.e. for loading operations. */
72911+
72912+ switch (gr_usermode.mode) {
72913+ case GR_STATUS:
72914+ if (gr_acl_is_enabled()) {
72915+ error = 1;
72916+ if (!gr_check_secure_terminal(current))
72917+ error = 3;
72918+ } else
72919+ error = 2;
72920+ goto out;
72921+ case GR_SHUTDOWN:
72922+ if (gr_acl_is_enabled() && !(chkpw(&gr_usermode, (unsigned char *)&gr_system_salt, (unsigned char *)&gr_system_sum))) {
72923+ stop_machine(gr_rbac_disable, NULL, NULL);
72924+ free_variables(false);
72925+ memset(&gr_usermode, 0, sizeof(gr_usermode));
72926+ memset(&gr_system_salt, 0, sizeof(gr_system_salt));
72927+ memset(&gr_system_sum, 0, sizeof(gr_system_sum));
72928+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTS_ACL_MSG);
72929+ } else if (gr_acl_is_enabled()) {
72930+ gr_log_noargs(GR_DONT_AUDIT, GR_SHUTF_ACL_MSG);
72931+ error = -EPERM;
72932+ } else {
72933+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTI_ACL_MSG);
72934+ error = -EAGAIN;
72935+ }
72936+ break;
72937+ case GR_ENABLE:
72938+ if (!gr_acl_is_enabled() && !(error2 = gracl_init(&gr_usermode)))
72939+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_ENABLE_ACL_MSG, GR_VERSION);
72940+ else {
72941+ if (gr_acl_is_enabled())
72942+ error = -EAGAIN;
72943+ else
72944+ error = error2;
72945+ gr_log_str(GR_DONT_AUDIT, GR_ENABLEF_ACL_MSG, GR_VERSION);
72946+ }
72947+ break;
72948+ case GR_OLDRELOAD:
72949+ oldmode = 1;
72950+ case GR_RELOAD:
72951+ if (!gr_acl_is_enabled()) {
72952+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOADI_ACL_MSG, GR_VERSION);
72953+ error = -EAGAIN;
72954+ } else if (!(chkpw(&gr_usermode, (unsigned char *)&gr_system_salt, (unsigned char *)&gr_system_sum))) {
72955+ error2 = gracl_reload(&gr_usermode, oldmode);
72956+ if (!error2)
72957+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOAD_ACL_MSG, GR_VERSION);
72958+ else {
72959+ gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
72960+ error = error2;
72961+ }
72962+ } else {
72963+ gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
72964+ error = -EPERM;
72965+ }
72966+ break;
72967+ case GR_SEGVMOD:
72968+ if (unlikely(!gr_acl_is_enabled())) {
72969+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODI_ACL_MSG);
72970+ error = -EAGAIN;
72971+ break;
72972+ }
72973+
72974+ if (!(chkpw(&gr_usermode, (unsigned char *)&gr_system_salt, (unsigned char *)&gr_system_sum))) {
72975+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODS_ACL_MSG);
72976+ if (gr_usermode.segv_device && gr_usermode.segv_inode) {
72977+ struct acl_subject_label *segvacl;
72978+ segvacl =
72979+ lookup_acl_subj_label(gr_usermode.segv_inode,
72980+ gr_usermode.segv_device,
72981+ current->role);
72982+ if (segvacl) {
72983+ segvacl->crashes = 0;
72984+ segvacl->expires = 0;
72985+ }
72986+ } else if (gr_find_uid(gr_usermode.segv_uid) >= 0) {
72987+ gr_remove_uid(gr_usermode.segv_uid);
72988+ }
72989+ } else {
72990+ gr_log_noargs(GR_DONT_AUDIT, GR_SEGVMODF_ACL_MSG);
72991+ error = -EPERM;
72992+ }
72993+ break;
72994+ case GR_SPROLE:
72995+ case GR_SPROLEPAM:
72996+ if (unlikely(!gr_acl_is_enabled())) {
72997+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SPROLEI_ACL_MSG);
72998+ error = -EAGAIN;
72999+ break;
73000+ }
73001+
73002+ if (current->role->expires && time_after_eq(get_seconds(), current->role->expires)) {
73003+ current->role->expires = 0;
73004+ current->role->auth_attempts = 0;
73005+ }
73006+
73007+ if (current->role->auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
73008+ time_after(current->role->expires, get_seconds())) {
73009+ error = -EBUSY;
73010+ goto out;
73011+ }
73012+
73013+ if (lookup_special_role_auth
73014+ (gr_usermode.mode, gr_usermode.sp_role, &sprole_salt, &sprole_sum)
73015+ && ((!sprole_salt && !sprole_sum)
73016+ || !(chkpw(&gr_usermode, sprole_salt, sprole_sum)))) {
73017+ char *p = "";
73018+ assign_special_role(gr_usermode.sp_role);
73019+ read_lock(&tasklist_lock);
73020+ if (current->real_parent)
73021+ p = current->real_parent->role->rolename;
73022+ read_unlock(&tasklist_lock);
73023+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLES_ACL_MSG,
73024+ p, acl_sp_role_value);
73025+ } else {
73026+ gr_log_str(GR_DONT_AUDIT, GR_SPROLEF_ACL_MSG, gr_usermode.sp_role);
73027+ error = -EPERM;
73028+ if(!(current->role->auth_attempts++))
73029+ current->role->expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
73030+
73031+ goto out;
73032+ }
73033+ break;
73034+ case GR_UNSPROLE:
73035+ if (unlikely(!gr_acl_is_enabled())) {
73036+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_UNSPROLEI_ACL_MSG);
73037+ error = -EAGAIN;
73038+ break;
73039+ }
73040+
73041+ if (current->role->roletype & GR_ROLE_SPECIAL) {
73042+ char *p = "";
73043+ int i = 0;
73044+
73045+ read_lock(&tasklist_lock);
73046+ if (current->real_parent) {
73047+ p = current->real_parent->role->rolename;
73048+ i = current->real_parent->acl_role_id;
73049+ }
73050+ read_unlock(&tasklist_lock);
73051+
73052+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_UNSPROLES_ACL_MSG, p, i);
73053+ gr_set_acls(1);
73054+ } else {
73055+ error = -EPERM;
73056+ goto out;
73057+ }
73058+ break;
73059+ default:
73060+ gr_log_int(GR_DONT_AUDIT, GR_INVMODE_ACL_MSG, gr_usermode.mode);
73061+ error = -EINVAL;
73062+ break;
73063+ }
73064+
73065+ if (error != -EPERM)
73066+ goto out;
73067+
73068+ if(!(gr_auth_attempts++))
73069+ gr_auth_expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
73070+
73071+ out:
73072+ mutex_unlock(&gr_dev_mutex);
73073+
73074+ if (!error)
73075+ error = req_count;
73076+
73077+ return error;
73078+}
73079+
73080+int
73081+gr_set_acls(const int type)
73082+{
73083+ struct task_struct *task, *task2;
73084+ struct acl_role_label *role = current->role;
73085+ struct acl_subject_label *subj;
73086+ __u16 acl_role_id = current->acl_role_id;
73087+ const struct cred *cred;
73088+ int ret;
73089+
73090+ rcu_read_lock();
73091+ read_lock(&tasklist_lock);
73092+ read_lock(&grsec_exec_file_lock);
73093+ do_each_thread(task2, task) {
73094+ /* check to see if we're called from the exit handler,
73095+ if so, only replace ACLs that have inherited the admin
73096+ ACL */
73097+
73098+ if (type && (task->role != role ||
73099+ task->acl_role_id != acl_role_id))
73100+ continue;
73101+
73102+ task->acl_role_id = 0;
73103+ task->acl_sp_role = 0;
73104+ task->inherited = 0;
73105+
73106+ if (task->exec_file) {
73107+ cred = __task_cred(task);
73108+ task->role = __lookup_acl_role_label(polstate, task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
73109+ subj = __gr_get_subject_for_task(polstate, task, NULL);
73110+ if (subj == NULL) {
73111+ ret = -EINVAL;
73112+ read_unlock(&grsec_exec_file_lock);
73113+ read_unlock(&tasklist_lock);
73114+ rcu_read_unlock();
73115+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_DEFACL_MSG, task->comm, task_pid_nr(task));
73116+ return ret;
73117+ }
73118+ __gr_apply_subject_to_task(polstate, task, subj);
73119+ } else {
73120+ // it's a kernel process
73121+ task->role = polstate->kernel_role;
73122+ task->acl = polstate->kernel_role->root_label;
73123+#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
73124+ task->acl->mode &= ~GR_PROCFIND;
73125+#endif
73126+ }
73127+ } while_each_thread(task2, task);
73128+ read_unlock(&grsec_exec_file_lock);
73129+ read_unlock(&tasklist_lock);
73130+ rcu_read_unlock();
73131+
73132+ return 0;
73133+}
73134diff --git a/grsecurity/gracl_res.c b/grsecurity/gracl_res.c
73135new file mode 100644
73136index 0000000..39645c9
73137--- /dev/null
73138+++ b/grsecurity/gracl_res.c
73139@@ -0,0 +1,68 @@
73140+#include <linux/kernel.h>
73141+#include <linux/sched.h>
73142+#include <linux/gracl.h>
73143+#include <linux/grinternal.h>
73144+
73145+static const char *restab_log[] = {
73146+ [RLIMIT_CPU] = "RLIMIT_CPU",
73147+ [RLIMIT_FSIZE] = "RLIMIT_FSIZE",
73148+ [RLIMIT_DATA] = "RLIMIT_DATA",
73149+ [RLIMIT_STACK] = "RLIMIT_STACK",
73150+ [RLIMIT_CORE] = "RLIMIT_CORE",
73151+ [RLIMIT_RSS] = "RLIMIT_RSS",
73152+ [RLIMIT_NPROC] = "RLIMIT_NPROC",
73153+ [RLIMIT_NOFILE] = "RLIMIT_NOFILE",
73154+ [RLIMIT_MEMLOCK] = "RLIMIT_MEMLOCK",
73155+ [RLIMIT_AS] = "RLIMIT_AS",
73156+ [RLIMIT_LOCKS] = "RLIMIT_LOCKS",
73157+ [RLIMIT_SIGPENDING] = "RLIMIT_SIGPENDING",
73158+ [RLIMIT_MSGQUEUE] = "RLIMIT_MSGQUEUE",
73159+ [RLIMIT_NICE] = "RLIMIT_NICE",
73160+ [RLIMIT_RTPRIO] = "RLIMIT_RTPRIO",
73161+ [RLIMIT_RTTIME] = "RLIMIT_RTTIME",
73162+ [GR_CRASH_RES] = "RLIMIT_CRASH"
73163+};
73164+
73165+void
73166+gr_log_resource(const struct task_struct *task,
73167+ const int res, const unsigned long wanted, const int gt)
73168+{
73169+ const struct cred *cred;
73170+ unsigned long rlim;
73171+
73172+ if (!gr_acl_is_enabled() && !grsec_resource_logging)
73173+ return;
73174+
73175+ // not yet supported resource
73176+ if (unlikely(!restab_log[res]))
73177+ return;
73178+
73179+ if (res == RLIMIT_CPU || res == RLIMIT_RTTIME)
73180+ rlim = task_rlimit_max(task, res);
73181+ else
73182+ rlim = task_rlimit(task, res);
73183+
73184+ if (likely((rlim == RLIM_INFINITY) || (gt && wanted <= rlim) || (!gt && wanted < rlim)))
73185+ return;
73186+
73187+ rcu_read_lock();
73188+ cred = __task_cred(task);
73189+
73190+ if (res == RLIMIT_NPROC &&
73191+ (cap_raised(cred->cap_effective, CAP_SYS_ADMIN) ||
73192+ cap_raised(cred->cap_effective, CAP_SYS_RESOURCE)))
73193+ goto out_rcu_unlock;
73194+ else if (res == RLIMIT_MEMLOCK &&
73195+ cap_raised(cred->cap_effective, CAP_IPC_LOCK))
73196+ goto out_rcu_unlock;
73197+ else if (res == RLIMIT_NICE && cap_raised(cred->cap_effective, CAP_SYS_NICE))
73198+ goto out_rcu_unlock;
73199+ rcu_read_unlock();
73200+
73201+ gr_log_res_ulong2_str(GR_DONT_AUDIT, GR_RESOURCE_MSG, task, wanted, restab_log[res], rlim);
73202+
73203+ return;
73204+out_rcu_unlock:
73205+ rcu_read_unlock();
73206+ return;
73207+}
73208diff --git a/grsecurity/gracl_segv.c b/grsecurity/gracl_segv.c
73209new file mode 100644
73210index 0000000..2040e61
73211--- /dev/null
73212+++ b/grsecurity/gracl_segv.c
73213@@ -0,0 +1,313 @@
73214+#include <linux/kernel.h>
73215+#include <linux/mm.h>
73216+#include <asm/uaccess.h>
73217+#include <asm/errno.h>
73218+#include <asm/mman.h>
73219+#include <net/sock.h>
73220+#include <linux/file.h>
73221+#include <linux/fs.h>
73222+#include <linux/net.h>
73223+#include <linux/in.h>
73224+#include <linux/slab.h>
73225+#include <linux/types.h>
73226+#include <linux/sched.h>
73227+#include <linux/timer.h>
73228+#include <linux/gracl.h>
73229+#include <linux/grsecurity.h>
73230+#include <linux/grinternal.h>
73231+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
73232+#include <linux/magic.h>
73233+#include <linux/pagemap.h>
73234+#include "../fs/btrfs/async-thread.h"
73235+#include "../fs/btrfs/ctree.h"
73236+#include "../fs/btrfs/btrfs_inode.h"
73237+#endif
73238+
73239+static struct crash_uid *uid_set;
73240+static unsigned short uid_used;
73241+static DEFINE_SPINLOCK(gr_uid_lock);
73242+extern rwlock_t gr_inode_lock;
73243+extern struct acl_subject_label *
73244+ lookup_acl_subj_label(const ino_t inode, const dev_t dev,
73245+ struct acl_role_label *role);
73246+
73247+static inline dev_t __get_dev(const struct dentry *dentry)
73248+{
73249+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
73250+ if (dentry->d_sb->s_magic == BTRFS_SUPER_MAGIC)
73251+ return BTRFS_I(dentry->d_inode)->root->anon_dev;
73252+ else
73253+#endif
73254+ return dentry->d_sb->s_dev;
73255+}
73256+
73257+int
73258+gr_init_uidset(void)
73259+{
73260+ uid_set =
73261+ kmalloc(GR_UIDTABLE_MAX * sizeof (struct crash_uid), GFP_KERNEL);
73262+ uid_used = 0;
73263+
73264+ return uid_set ? 1 : 0;
73265+}
73266+
73267+void
73268+gr_free_uidset(void)
73269+{
73270+ if (uid_set) {
73271+ struct crash_uid *tmpset;
73272+ spin_lock(&gr_uid_lock);
73273+ tmpset = uid_set;
73274+ uid_set = NULL;
73275+ uid_used = 0;
73276+ spin_unlock(&gr_uid_lock);
73277+ if (tmpset)
73278+ kfree(tmpset);
73279+ }
73280+
73281+ return;
73282+}
73283+
73284+int
73285+gr_find_uid(const uid_t uid)
73286+{
73287+ struct crash_uid *tmp = uid_set;
73288+ uid_t buid;
73289+ int low = 0, high = uid_used - 1, mid;
73290+
73291+ while (high >= low) {
73292+ mid = (low + high) >> 1;
73293+ buid = tmp[mid].uid;
73294+ if (buid == uid)
73295+ return mid;
73296+ if (buid > uid)
73297+ high = mid - 1;
73298+ if (buid < uid)
73299+ low = mid + 1;
73300+ }
73301+
73302+ return -1;
73303+}
73304+
73305+static __inline__ void
73306+gr_insertsort(void)
73307+{
73308+ unsigned short i, j;
73309+ struct crash_uid index;
73310+
73311+ for (i = 1; i < uid_used; i++) {
73312+ index = uid_set[i];
73313+ j = i;
73314+ while ((j > 0) && uid_set[j - 1].uid > index.uid) {
73315+ uid_set[j] = uid_set[j - 1];
73316+ j--;
73317+ }
73318+ uid_set[j] = index;
73319+ }
73320+
73321+ return;
73322+}
73323+
73324+static __inline__ void
73325+gr_insert_uid(const kuid_t kuid, const unsigned long expires)
73326+{
73327+ int loc;
73328+ uid_t uid = GR_GLOBAL_UID(kuid);
73329+
73330+ if (uid_used == GR_UIDTABLE_MAX)
73331+ return;
73332+
73333+ loc = gr_find_uid(uid);
73334+
73335+ if (loc >= 0) {
73336+ uid_set[loc].expires = expires;
73337+ return;
73338+ }
73339+
73340+ uid_set[uid_used].uid = uid;
73341+ uid_set[uid_used].expires = expires;
73342+ uid_used++;
73343+
73344+ gr_insertsort();
73345+
73346+ return;
73347+}
73348+
73349+void
73350+gr_remove_uid(const unsigned short loc)
73351+{
73352+ unsigned short i;
73353+
73354+ for (i = loc + 1; i < uid_used; i++)
73355+ uid_set[i - 1] = uid_set[i];
73356+
73357+ uid_used--;
73358+
73359+ return;
73360+}
73361+
73362+int
73363+gr_check_crash_uid(const kuid_t kuid)
73364+{
73365+ int loc;
73366+ int ret = 0;
73367+ uid_t uid;
73368+
73369+ if (unlikely(!gr_acl_is_enabled()))
73370+ return 0;
73371+
73372+ uid = GR_GLOBAL_UID(kuid);
73373+
73374+ spin_lock(&gr_uid_lock);
73375+ loc = gr_find_uid(uid);
73376+
73377+ if (loc < 0)
73378+ goto out_unlock;
73379+
73380+ if (time_before_eq(uid_set[loc].expires, get_seconds()))
73381+ gr_remove_uid(loc);
73382+ else
73383+ ret = 1;
73384+
73385+out_unlock:
73386+ spin_unlock(&gr_uid_lock);
73387+ return ret;
73388+}
73389+
73390+static __inline__ int
73391+proc_is_setxid(const struct cred *cred)
73392+{
73393+ if (!uid_eq(cred->uid, cred->euid) || !uid_eq(cred->uid, cred->suid) ||
73394+ !uid_eq(cred->uid, cred->fsuid))
73395+ return 1;
73396+ if (!gid_eq(cred->gid, cred->egid) || !gid_eq(cred->gid, cred->sgid) ||
73397+ !gid_eq(cred->gid, cred->fsgid))
73398+ return 1;
73399+
73400+ return 0;
73401+}
73402+
73403+extern int gr_fake_force_sig(int sig, struct task_struct *t);
73404+
73405+void
73406+gr_handle_crash(struct task_struct *task, const int sig)
73407+{
73408+ struct acl_subject_label *curr;
73409+ struct task_struct *tsk, *tsk2;
73410+ const struct cred *cred;
73411+ const struct cred *cred2;
73412+
73413+ if (sig != SIGSEGV && sig != SIGKILL && sig != SIGBUS && sig != SIGILL)
73414+ return;
73415+
73416+ if (unlikely(!gr_acl_is_enabled()))
73417+ return;
73418+
73419+ curr = task->acl;
73420+
73421+ if (!(curr->resmask & (1U << GR_CRASH_RES)))
73422+ return;
73423+
73424+ if (time_before_eq(curr->expires, get_seconds())) {
73425+ curr->expires = 0;
73426+ curr->crashes = 0;
73427+ }
73428+
73429+ curr->crashes++;
73430+
73431+ if (!curr->expires)
73432+ curr->expires = get_seconds() + curr->res[GR_CRASH_RES].rlim_max;
73433+
73434+ if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
73435+ time_after(curr->expires, get_seconds())) {
73436+ rcu_read_lock();
73437+ cred = __task_cred(task);
73438+ if (gr_is_global_nonroot(cred->uid) && proc_is_setxid(cred)) {
73439+ gr_log_crash1(GR_DONT_AUDIT, GR_SEGVSTART_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
73440+ spin_lock(&gr_uid_lock);
73441+ gr_insert_uid(cred->uid, curr->expires);
73442+ spin_unlock(&gr_uid_lock);
73443+ curr->expires = 0;
73444+ curr->crashes = 0;
73445+ read_lock(&tasklist_lock);
73446+ do_each_thread(tsk2, tsk) {
73447+ cred2 = __task_cred(tsk);
73448+ if (tsk != task && uid_eq(cred2->uid, cred->uid))
73449+ gr_fake_force_sig(SIGKILL, tsk);
73450+ } while_each_thread(tsk2, tsk);
73451+ read_unlock(&tasklist_lock);
73452+ } else {
73453+ gr_log_crash2(GR_DONT_AUDIT, GR_SEGVNOSUID_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
73454+ read_lock(&tasklist_lock);
73455+ read_lock(&grsec_exec_file_lock);
73456+ do_each_thread(tsk2, tsk) {
73457+ if (likely(tsk != task)) {
73458+ // if this thread has the same subject as the one that triggered
73459+ // RES_CRASH and it's the same binary, kill it
73460+ if (tsk->acl == task->acl && gr_is_same_file(tsk->exec_file, task->exec_file))
73461+ gr_fake_force_sig(SIGKILL, tsk);
73462+ }
73463+ } while_each_thread(tsk2, tsk);
73464+ read_unlock(&grsec_exec_file_lock);
73465+ read_unlock(&tasklist_lock);
73466+ }
73467+ rcu_read_unlock();
73468+ }
73469+
73470+ return;
73471+}
73472+
73473+int
73474+gr_check_crash_exec(const struct file *filp)
73475+{
73476+ struct acl_subject_label *curr;
73477+
73478+ if (unlikely(!gr_acl_is_enabled()))
73479+ return 0;
73480+
73481+ read_lock(&gr_inode_lock);
73482+ curr = lookup_acl_subj_label(filp->f_path.dentry->d_inode->i_ino,
73483+ __get_dev(filp->f_path.dentry),
73484+ current->role);
73485+ read_unlock(&gr_inode_lock);
73486+
73487+ if (!curr || !(curr->resmask & (1U << GR_CRASH_RES)) ||
73488+ (!curr->crashes && !curr->expires))
73489+ return 0;
73490+
73491+ if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
73492+ time_after(curr->expires, get_seconds()))
73493+ return 1;
73494+ else if (time_before_eq(curr->expires, get_seconds())) {
73495+ curr->crashes = 0;
73496+ curr->expires = 0;
73497+ }
73498+
73499+ return 0;
73500+}
73501+
73502+void
73503+gr_handle_alertkill(struct task_struct *task)
73504+{
73505+ struct acl_subject_label *curracl;
73506+ __u32 curr_ip;
73507+ struct task_struct *p, *p2;
73508+
73509+ if (unlikely(!gr_acl_is_enabled()))
73510+ return;
73511+
73512+ curracl = task->acl;
73513+ curr_ip = task->signal->curr_ip;
73514+
73515+ if ((curracl->mode & GR_KILLIPPROC) && curr_ip) {
73516+ read_lock(&tasklist_lock);
73517+ do_each_thread(p2, p) {
73518+ if (p->signal->curr_ip == curr_ip)
73519+ gr_fake_force_sig(SIGKILL, p);
73520+ } while_each_thread(p2, p);
73521+ read_unlock(&tasklist_lock);
73522+ } else if (curracl->mode & GR_KILLPROC)
73523+ gr_fake_force_sig(SIGKILL, task);
73524+
73525+ return;
73526+}
73527diff --git a/grsecurity/gracl_shm.c b/grsecurity/gracl_shm.c
73528new file mode 100644
73529index 0000000..98011b0
73530--- /dev/null
73531+++ b/grsecurity/gracl_shm.c
73532@@ -0,0 +1,40 @@
73533+#include <linux/kernel.h>
73534+#include <linux/mm.h>
73535+#include <linux/sched.h>
73536+#include <linux/file.h>
73537+#include <linux/ipc.h>
73538+#include <linux/gracl.h>
73539+#include <linux/grsecurity.h>
73540+#include <linux/grinternal.h>
73541+
73542+int
73543+gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
73544+ const time_t shm_createtime, const kuid_t cuid, const int shmid)
73545+{
73546+ struct task_struct *task;
73547+
73548+ if (!gr_acl_is_enabled())
73549+ return 1;
73550+
73551+ rcu_read_lock();
73552+ read_lock(&tasklist_lock);
73553+
73554+ task = find_task_by_vpid(shm_cprid);
73555+
73556+ if (unlikely(!task))
73557+ task = find_task_by_vpid(shm_lapid);
73558+
73559+ if (unlikely(task && (time_before_eq((unsigned long)task->start_time.tv_sec, (unsigned long)shm_createtime) ||
73560+ (task_pid_nr(task) == shm_lapid)) &&
73561+ (task->acl->mode & GR_PROTSHM) &&
73562+ (task->acl != current->acl))) {
73563+ read_unlock(&tasklist_lock);
73564+ rcu_read_unlock();
73565+ gr_log_int3(GR_DONT_AUDIT, GR_SHMAT_ACL_MSG, GR_GLOBAL_UID(cuid), shm_cprid, shmid);
73566+ return 0;
73567+ }
73568+ read_unlock(&tasklist_lock);
73569+ rcu_read_unlock();
73570+
73571+ return 1;
73572+}
73573diff --git a/grsecurity/grsec_chdir.c b/grsecurity/grsec_chdir.c
73574new file mode 100644
73575index 0000000..bc0be01
73576--- /dev/null
73577+++ b/grsecurity/grsec_chdir.c
73578@@ -0,0 +1,19 @@
73579+#include <linux/kernel.h>
73580+#include <linux/sched.h>
73581+#include <linux/fs.h>
73582+#include <linux/file.h>
73583+#include <linux/grsecurity.h>
73584+#include <linux/grinternal.h>
73585+
73586+void
73587+gr_log_chdir(const struct dentry *dentry, const struct vfsmount *mnt)
73588+{
73589+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
73590+ if ((grsec_enable_chdir && grsec_enable_group &&
73591+ in_group_p(grsec_audit_gid)) || (grsec_enable_chdir &&
73592+ !grsec_enable_group)) {
73593+ gr_log_fs_generic(GR_DO_AUDIT, GR_CHDIR_AUDIT_MSG, dentry, mnt);
73594+ }
73595+#endif
73596+ return;
73597+}
73598diff --git a/grsecurity/grsec_chroot.c b/grsecurity/grsec_chroot.c
73599new file mode 100644
73600index 0000000..651d6c2
73601--- /dev/null
73602+++ b/grsecurity/grsec_chroot.c
73603@@ -0,0 +1,370 @@
73604+#include <linux/kernel.h>
73605+#include <linux/module.h>
73606+#include <linux/sched.h>
73607+#include <linux/file.h>
73608+#include <linux/fs.h>
73609+#include <linux/mount.h>
73610+#include <linux/types.h>
73611+#include "../fs/mount.h"
73612+#include <linux/grsecurity.h>
73613+#include <linux/grinternal.h>
73614+
73615+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
73616+int gr_init_ran;
73617+#endif
73618+
73619+void gr_set_chroot_entries(struct task_struct *task, const struct path *path)
73620+{
73621+#ifdef CONFIG_GRKERNSEC
73622+ if (task_pid_nr(task) > 1 && path->dentry != init_task.fs->root.dentry &&
73623+ path->dentry != task->nsproxy->mnt_ns->root->mnt.mnt_root
73624+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
73625+ && gr_init_ran
73626+#endif
73627+ )
73628+ task->gr_is_chrooted = 1;
73629+ else {
73630+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
73631+ if (task_pid_nr(task) == 1 && !gr_init_ran)
73632+ gr_init_ran = 1;
73633+#endif
73634+ task->gr_is_chrooted = 0;
73635+ }
73636+
73637+ task->gr_chroot_dentry = path->dentry;
73638+#endif
73639+ return;
73640+}
73641+
73642+void gr_clear_chroot_entries(struct task_struct *task)
73643+{
73644+#ifdef CONFIG_GRKERNSEC
73645+ task->gr_is_chrooted = 0;
73646+ task->gr_chroot_dentry = NULL;
73647+#endif
73648+ return;
73649+}
73650+
73651+int
73652+gr_handle_chroot_unix(const pid_t pid)
73653+{
73654+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
73655+ struct task_struct *p;
73656+
73657+ if (unlikely(!grsec_enable_chroot_unix))
73658+ return 1;
73659+
73660+ if (likely(!proc_is_chrooted(current)))
73661+ return 1;
73662+
73663+ rcu_read_lock();
73664+ read_lock(&tasklist_lock);
73665+ p = find_task_by_vpid_unrestricted(pid);
73666+ if (unlikely(p && !have_same_root(current, p))) {
73667+ read_unlock(&tasklist_lock);
73668+ rcu_read_unlock();
73669+ gr_log_noargs(GR_DONT_AUDIT, GR_UNIX_CHROOT_MSG);
73670+ return 0;
73671+ }
73672+ read_unlock(&tasklist_lock);
73673+ rcu_read_unlock();
73674+#endif
73675+ return 1;
73676+}
73677+
73678+int
73679+gr_handle_chroot_nice(void)
73680+{
73681+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
73682+ if (grsec_enable_chroot_nice && proc_is_chrooted(current)) {
73683+ gr_log_noargs(GR_DONT_AUDIT, GR_NICE_CHROOT_MSG);
73684+ return -EPERM;
73685+ }
73686+#endif
73687+ return 0;
73688+}
73689+
73690+int
73691+gr_handle_chroot_setpriority(struct task_struct *p, const int niceval)
73692+{
73693+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
73694+ if (grsec_enable_chroot_nice && (niceval < task_nice(p))
73695+ && proc_is_chrooted(current)) {
73696+ gr_log_str_int(GR_DONT_AUDIT, GR_PRIORITY_CHROOT_MSG, p->comm, task_pid_nr(p));
73697+ return -EACCES;
73698+ }
73699+#endif
73700+ return 0;
73701+}
73702+
73703+int
73704+gr_handle_chroot_fowner(struct pid *pid, enum pid_type type)
73705+{
73706+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
73707+ struct task_struct *p;
73708+ int ret = 0;
73709+ if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || !pid)
73710+ return ret;
73711+
73712+ read_lock(&tasklist_lock);
73713+ do_each_pid_task(pid, type, p) {
73714+ if (!have_same_root(current, p)) {
73715+ ret = 1;
73716+ goto out;
73717+ }
73718+ } while_each_pid_task(pid, type, p);
73719+out:
73720+ read_unlock(&tasklist_lock);
73721+ return ret;
73722+#endif
73723+ return 0;
73724+}
73725+
73726+int
73727+gr_pid_is_chrooted(struct task_struct *p)
73728+{
73729+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
73730+ if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || p == NULL)
73731+ return 0;
73732+
73733+ if ((p->exit_state & (EXIT_ZOMBIE | EXIT_DEAD)) ||
73734+ !have_same_root(current, p)) {
73735+ return 1;
73736+ }
73737+#endif
73738+ return 0;
73739+}
73740+
73741+EXPORT_SYMBOL_GPL(gr_pid_is_chrooted);
73742+
73743+#if defined(CONFIG_GRKERNSEC_CHROOT_DOUBLE) || defined(CONFIG_GRKERNSEC_CHROOT_FCHDIR)
73744+int gr_is_outside_chroot(const struct dentry *u_dentry, const struct vfsmount *u_mnt)
73745+{
73746+ struct path path, currentroot;
73747+ int ret = 0;
73748+
73749+ path.dentry = (struct dentry *)u_dentry;
73750+ path.mnt = (struct vfsmount *)u_mnt;
73751+ get_fs_root(current->fs, &currentroot);
73752+ if (path_is_under(&path, &currentroot))
73753+ ret = 1;
73754+ path_put(&currentroot);
73755+
73756+ return ret;
73757+}
73758+#endif
73759+
73760+int
73761+gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt)
73762+{
73763+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
73764+ if (!grsec_enable_chroot_fchdir)
73765+ return 1;
73766+
73767+ if (!proc_is_chrooted(current))
73768+ return 1;
73769+ else if (!gr_is_outside_chroot(u_dentry, u_mnt)) {
73770+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_FCHDIR_MSG, u_dentry, u_mnt);
73771+ return 0;
73772+ }
73773+#endif
73774+ return 1;
73775+}
73776+
73777+int
73778+gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
73779+ const time_t shm_createtime)
73780+{
73781+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
73782+ struct task_struct *p;
73783+ time_t starttime;
73784+
73785+ if (unlikely(!grsec_enable_chroot_shmat))
73786+ return 1;
73787+
73788+ if (likely(!proc_is_chrooted(current)))
73789+ return 1;
73790+
73791+ rcu_read_lock();
73792+ read_lock(&tasklist_lock);
73793+
73794+ if ((p = find_task_by_vpid_unrestricted(shm_cprid))) {
73795+ starttime = p->start_time.tv_sec;
73796+ if (time_before_eq((unsigned long)starttime, (unsigned long)shm_createtime)) {
73797+ if (have_same_root(current, p)) {
73798+ goto allow;
73799+ } else {
73800+ read_unlock(&tasklist_lock);
73801+ rcu_read_unlock();
73802+ gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
73803+ return 0;
73804+ }
73805+ }
73806+ /* creator exited, pid reuse, fall through to next check */
73807+ }
73808+ if ((p = find_task_by_vpid_unrestricted(shm_lapid))) {
73809+ if (unlikely(!have_same_root(current, p))) {
73810+ read_unlock(&tasklist_lock);
73811+ rcu_read_unlock();
73812+ gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
73813+ return 0;
73814+ }
73815+ }
73816+
73817+allow:
73818+ read_unlock(&tasklist_lock);
73819+ rcu_read_unlock();
73820+#endif
73821+ return 1;
73822+}
73823+
73824+void
73825+gr_log_chroot_exec(const struct dentry *dentry, const struct vfsmount *mnt)
73826+{
73827+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
73828+ if (grsec_enable_chroot_execlog && proc_is_chrooted(current))
73829+ gr_log_fs_generic(GR_DO_AUDIT, GR_EXEC_CHROOT_MSG, dentry, mnt);
73830+#endif
73831+ return;
73832+}
73833+
73834+int
73835+gr_handle_chroot_mknod(const struct dentry *dentry,
73836+ const struct vfsmount *mnt, const int mode)
73837+{
73838+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
73839+ if (grsec_enable_chroot_mknod && !S_ISFIFO(mode) && !S_ISREG(mode) &&
73840+ proc_is_chrooted(current)) {
73841+ gr_log_fs_generic(GR_DONT_AUDIT, GR_MKNOD_CHROOT_MSG, dentry, mnt);
73842+ return -EPERM;
73843+ }
73844+#endif
73845+ return 0;
73846+}
73847+
73848+int
73849+gr_handle_chroot_mount(const struct dentry *dentry,
73850+ const struct vfsmount *mnt, const char *dev_name)
73851+{
73852+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
73853+ if (grsec_enable_chroot_mount && proc_is_chrooted(current)) {
73854+ gr_log_str_fs(GR_DONT_AUDIT, GR_MOUNT_CHROOT_MSG, dev_name ? dev_name : "none", dentry, mnt);
73855+ return -EPERM;
73856+ }
73857+#endif
73858+ return 0;
73859+}
73860+
73861+int
73862+gr_handle_chroot_pivot(void)
73863+{
73864+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
73865+ if (grsec_enable_chroot_pivot && proc_is_chrooted(current)) {
73866+ gr_log_noargs(GR_DONT_AUDIT, GR_PIVOT_CHROOT_MSG);
73867+ return -EPERM;
73868+ }
73869+#endif
73870+ return 0;
73871+}
73872+
73873+int
73874+gr_handle_chroot_chroot(const struct dentry *dentry, const struct vfsmount *mnt)
73875+{
73876+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
73877+ if (grsec_enable_chroot_double && proc_is_chrooted(current) &&
73878+ !gr_is_outside_chroot(dentry, mnt)) {
73879+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_CHROOT_MSG, dentry, mnt);
73880+ return -EPERM;
73881+ }
73882+#endif
73883+ return 0;
73884+}
73885+
73886+extern const char *captab_log[];
73887+extern int captab_log_entries;
73888+
73889+int
73890+gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
73891+{
73892+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
73893+ if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
73894+ kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
73895+ if (cap_raised(chroot_caps, cap)) {
73896+ if (cap_raised(cred->cap_effective, cap) && cap < captab_log_entries) {
73897+ gr_log_cap(GR_DONT_AUDIT, GR_CAP_CHROOT_MSG, task, captab_log[cap]);
73898+ }
73899+ return 0;
73900+ }
73901+ }
73902+#endif
73903+ return 1;
73904+}
73905+
73906+int
73907+gr_chroot_is_capable(const int cap)
73908+{
73909+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
73910+ return gr_task_chroot_is_capable(current, current_cred(), cap);
73911+#endif
73912+ return 1;
73913+}
73914+
73915+int
73916+gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap)
73917+{
73918+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
73919+ if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
73920+ kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
73921+ if (cap_raised(chroot_caps, cap)) {
73922+ return 0;
73923+ }
73924+ }
73925+#endif
73926+ return 1;
73927+}
73928+
73929+int
73930+gr_chroot_is_capable_nolog(const int cap)
73931+{
73932+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
73933+ return gr_task_chroot_is_capable_nolog(current, cap);
73934+#endif
73935+ return 1;
73936+}
73937+
73938+int
73939+gr_handle_chroot_sysctl(const int op)
73940+{
73941+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
73942+ if (grsec_enable_chroot_sysctl && (op & MAY_WRITE) &&
73943+ proc_is_chrooted(current))
73944+ return -EACCES;
73945+#endif
73946+ return 0;
73947+}
73948+
73949+void
73950+gr_handle_chroot_chdir(const struct path *path)
73951+{
73952+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
73953+ if (grsec_enable_chroot_chdir)
73954+ set_fs_pwd(current->fs, path);
73955+#endif
73956+ return;
73957+}
73958+
73959+int
73960+gr_handle_chroot_chmod(const struct dentry *dentry,
73961+ const struct vfsmount *mnt, const int mode)
73962+{
73963+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
73964+ /* allow chmod +s on directories, but not files */
73965+ if (grsec_enable_chroot_chmod && !S_ISDIR(dentry->d_inode->i_mode) &&
73966+ ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))) &&
73967+ proc_is_chrooted(current)) {
73968+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHMOD_CHROOT_MSG, dentry, mnt);
73969+ return -EPERM;
73970+ }
73971+#endif
73972+ return 0;
73973+}
73974diff --git a/grsecurity/grsec_disabled.c b/grsecurity/grsec_disabled.c
73975new file mode 100644
73976index 0000000..4d6fce8
73977--- /dev/null
73978+++ b/grsecurity/grsec_disabled.c
73979@@ -0,0 +1,433 @@
73980+#include <linux/kernel.h>
73981+#include <linux/module.h>
73982+#include <linux/sched.h>
73983+#include <linux/file.h>
73984+#include <linux/fs.h>
73985+#include <linux/kdev_t.h>
73986+#include <linux/net.h>
73987+#include <linux/in.h>
73988+#include <linux/ip.h>
73989+#include <linux/skbuff.h>
73990+#include <linux/sysctl.h>
73991+
73992+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
73993+void
73994+pax_set_initial_flags(struct linux_binprm *bprm)
73995+{
73996+ return;
73997+}
73998+#endif
73999+
74000+#ifdef CONFIG_SYSCTL
74001+__u32
74002+gr_handle_sysctl(const struct ctl_table * table, const int op)
74003+{
74004+ return 0;
74005+}
74006+#endif
74007+
74008+#ifdef CONFIG_TASKSTATS
74009+int gr_is_taskstats_denied(int pid)
74010+{
74011+ return 0;
74012+}
74013+#endif
74014+
74015+int
74016+gr_acl_is_enabled(void)
74017+{
74018+ return 0;
74019+}
74020+
74021+void
74022+gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
74023+{
74024+ return;
74025+}
74026+
74027+int
74028+gr_handle_rawio(const struct inode *inode)
74029+{
74030+ return 0;
74031+}
74032+
74033+void
74034+gr_acl_handle_psacct(struct task_struct *task, const long code)
74035+{
74036+ return;
74037+}
74038+
74039+int
74040+gr_handle_ptrace(struct task_struct *task, const long request)
74041+{
74042+ return 0;
74043+}
74044+
74045+int
74046+gr_handle_proc_ptrace(struct task_struct *task)
74047+{
74048+ return 0;
74049+}
74050+
74051+int
74052+gr_set_acls(const int type)
74053+{
74054+ return 0;
74055+}
74056+
74057+int
74058+gr_check_hidden_task(const struct task_struct *tsk)
74059+{
74060+ return 0;
74061+}
74062+
74063+int
74064+gr_check_protected_task(const struct task_struct *task)
74065+{
74066+ return 0;
74067+}
74068+
74069+int
74070+gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
74071+{
74072+ return 0;
74073+}
74074+
74075+void
74076+gr_copy_label(struct task_struct *tsk)
74077+{
74078+ return;
74079+}
74080+
74081+void
74082+gr_set_pax_flags(struct task_struct *task)
74083+{
74084+ return;
74085+}
74086+
74087+int
74088+gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
74089+ const int unsafe_share)
74090+{
74091+ return 0;
74092+}
74093+
74094+void
74095+gr_handle_delete(const ino_t ino, const dev_t dev)
74096+{
74097+ return;
74098+}
74099+
74100+void
74101+gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
74102+{
74103+ return;
74104+}
74105+
74106+void
74107+gr_handle_crash(struct task_struct *task, const int sig)
74108+{
74109+ return;
74110+}
74111+
74112+int
74113+gr_check_crash_exec(const struct file *filp)
74114+{
74115+ return 0;
74116+}
74117+
74118+int
74119+gr_check_crash_uid(const kuid_t uid)
74120+{
74121+ return 0;
74122+}
74123+
74124+void
74125+gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
74126+ struct dentry *old_dentry,
74127+ struct dentry *new_dentry,
74128+ struct vfsmount *mnt, const __u8 replace)
74129+{
74130+ return;
74131+}
74132+
74133+int
74134+gr_search_socket(const int family, const int type, const int protocol)
74135+{
74136+ return 1;
74137+}
74138+
74139+int
74140+gr_search_connectbind(const int mode, const struct socket *sock,
74141+ const struct sockaddr_in *addr)
74142+{
74143+ return 0;
74144+}
74145+
74146+void
74147+gr_handle_alertkill(struct task_struct *task)
74148+{
74149+ return;
74150+}
74151+
74152+__u32
74153+gr_acl_handle_execve(const struct dentry * dentry, const struct vfsmount * mnt)
74154+{
74155+ return 1;
74156+}
74157+
74158+__u32
74159+gr_acl_handle_hidden_file(const struct dentry * dentry,
74160+ const struct vfsmount * mnt)
74161+{
74162+ return 1;
74163+}
74164+
74165+__u32
74166+gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
74167+ int acc_mode)
74168+{
74169+ return 1;
74170+}
74171+
74172+__u32
74173+gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
74174+{
74175+ return 1;
74176+}
74177+
74178+__u32
74179+gr_acl_handle_unlink(const struct dentry * dentry, const struct vfsmount * mnt)
74180+{
74181+ return 1;
74182+}
74183+
74184+int
74185+gr_acl_handle_mmap(const struct file *file, const unsigned long prot,
74186+ unsigned int *vm_flags)
74187+{
74188+ return 1;
74189+}
74190+
74191+__u32
74192+gr_acl_handle_truncate(const struct dentry * dentry,
74193+ const struct vfsmount * mnt)
74194+{
74195+ return 1;
74196+}
74197+
74198+__u32
74199+gr_acl_handle_utime(const struct dentry * dentry, const struct vfsmount * mnt)
74200+{
74201+ return 1;
74202+}
74203+
74204+__u32
74205+gr_acl_handle_access(const struct dentry * dentry,
74206+ const struct vfsmount * mnt, const int fmode)
74207+{
74208+ return 1;
74209+}
74210+
74211+__u32
74212+gr_acl_handle_chmod(const struct dentry * dentry, const struct vfsmount * mnt,
74213+ umode_t *mode)
74214+{
74215+ return 1;
74216+}
74217+
74218+__u32
74219+gr_acl_handle_chown(const struct dentry * dentry, const struct vfsmount * mnt)
74220+{
74221+ return 1;
74222+}
74223+
74224+__u32
74225+gr_acl_handle_setxattr(const struct dentry * dentry, const struct vfsmount * mnt)
74226+{
74227+ return 1;
74228+}
74229+
74230+__u32
74231+gr_acl_handle_removexattr(const struct dentry * dentry, const struct vfsmount * mnt)
74232+{
74233+ return 1;
74234+}
74235+
74236+void
74237+grsecurity_init(void)
74238+{
74239+ return;
74240+}
74241+
74242+umode_t gr_acl_umask(void)
74243+{
74244+ return 0;
74245+}
74246+
74247+__u32
74248+gr_acl_handle_mknod(const struct dentry * new_dentry,
74249+ const struct dentry * parent_dentry,
74250+ const struct vfsmount * parent_mnt,
74251+ const int mode)
74252+{
74253+ return 1;
74254+}
74255+
74256+__u32
74257+gr_acl_handle_mkdir(const struct dentry * new_dentry,
74258+ const struct dentry * parent_dentry,
74259+ const struct vfsmount * parent_mnt)
74260+{
74261+ return 1;
74262+}
74263+
74264+__u32
74265+gr_acl_handle_symlink(const struct dentry * new_dentry,
74266+ const struct dentry * parent_dentry,
74267+ const struct vfsmount * parent_mnt, const struct filename *from)
74268+{
74269+ return 1;
74270+}
74271+
74272+__u32
74273+gr_acl_handle_link(const struct dentry * new_dentry,
74274+ const struct dentry * parent_dentry,
74275+ const struct vfsmount * parent_mnt,
74276+ const struct dentry * old_dentry,
74277+ const struct vfsmount * old_mnt, const struct filename *to)
74278+{
74279+ return 1;
74280+}
74281+
74282+int
74283+gr_acl_handle_rename(const struct dentry *new_dentry,
74284+ const struct dentry *parent_dentry,
74285+ const struct vfsmount *parent_mnt,
74286+ const struct dentry *old_dentry,
74287+ const struct inode *old_parent_inode,
74288+ const struct vfsmount *old_mnt, const struct filename *newname)
74289+{
74290+ return 0;
74291+}
74292+
74293+int
74294+gr_acl_handle_filldir(const struct file *file, const char *name,
74295+ const int namelen, const ino_t ino)
74296+{
74297+ return 1;
74298+}
74299+
74300+int
74301+gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
74302+ const time_t shm_createtime, const kuid_t cuid, const int shmid)
74303+{
74304+ return 1;
74305+}
74306+
74307+int
74308+gr_search_bind(const struct socket *sock, const struct sockaddr_in *addr)
74309+{
74310+ return 0;
74311+}
74312+
74313+int
74314+gr_search_accept(const struct socket *sock)
74315+{
74316+ return 0;
74317+}
74318+
74319+int
74320+gr_search_listen(const struct socket *sock)
74321+{
74322+ return 0;
74323+}
74324+
74325+int
74326+gr_search_connect(const struct socket *sock, const struct sockaddr_in *addr)
74327+{
74328+ return 0;
74329+}
74330+
74331+__u32
74332+gr_acl_handle_unix(const struct dentry * dentry, const struct vfsmount * mnt)
74333+{
74334+ return 1;
74335+}
74336+
74337+__u32
74338+gr_acl_handle_creat(const struct dentry * dentry,
74339+ const struct dentry * p_dentry,
74340+ const struct vfsmount * p_mnt, int open_flags, int acc_mode,
74341+ const int imode)
74342+{
74343+ return 1;
74344+}
74345+
74346+void
74347+gr_acl_handle_exit(void)
74348+{
74349+ return;
74350+}
74351+
74352+int
74353+gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
74354+{
74355+ return 1;
74356+}
74357+
74358+void
74359+gr_set_role_label(const kuid_t uid, const kgid_t gid)
74360+{
74361+ return;
74362+}
74363+
74364+int
74365+gr_acl_handle_procpidmem(const struct task_struct *task)
74366+{
74367+ return 0;
74368+}
74369+
74370+int
74371+gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb)
74372+{
74373+ return 0;
74374+}
74375+
74376+int
74377+gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr)
74378+{
74379+ return 0;
74380+}
74381+
74382+int
74383+gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs)
74384+{
74385+ return 0;
74386+}
74387+
74388+int
74389+gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs)
74390+{
74391+ return 0;
74392+}
74393+
74394+int gr_acl_enable_at_secure(void)
74395+{
74396+ return 0;
74397+}
74398+
74399+dev_t gr_get_dev_from_dentry(struct dentry *dentry)
74400+{
74401+ return dentry->d_sb->s_dev;
74402+}
74403+
74404+void gr_put_exec_file(struct task_struct *task)
74405+{
74406+ return;
74407+}
74408+
74409+#ifdef CONFIG_SECURITY
74410+EXPORT_SYMBOL_GPL(gr_check_user_change);
74411+EXPORT_SYMBOL_GPL(gr_check_group_change);
74412+#endif
74413diff --git a/grsecurity/grsec_exec.c b/grsecurity/grsec_exec.c
74414new file mode 100644
74415index 0000000..f35f454
74416--- /dev/null
74417+++ b/grsecurity/grsec_exec.c
74418@@ -0,0 +1,187 @@
74419+#include <linux/kernel.h>
74420+#include <linux/sched.h>
74421+#include <linux/file.h>
74422+#include <linux/binfmts.h>
74423+#include <linux/fs.h>
74424+#include <linux/types.h>
74425+#include <linux/grdefs.h>
74426+#include <linux/grsecurity.h>
74427+#include <linux/grinternal.h>
74428+#include <linux/capability.h>
74429+#include <linux/module.h>
74430+#include <linux/compat.h>
74431+
74432+#include <asm/uaccess.h>
74433+
74434+#ifdef CONFIG_GRKERNSEC_EXECLOG
74435+static char gr_exec_arg_buf[132];
74436+static DEFINE_MUTEX(gr_exec_arg_mutex);
74437+#endif
74438+
74439+struct user_arg_ptr {
74440+#ifdef CONFIG_COMPAT
74441+ bool is_compat;
74442+#endif
74443+ union {
74444+ const char __user *const __user *native;
74445+#ifdef CONFIG_COMPAT
74446+ const compat_uptr_t __user *compat;
74447+#endif
74448+ } ptr;
74449+};
74450+
74451+extern const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr);
74452+
74453+void
74454+gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv)
74455+{
74456+#ifdef CONFIG_GRKERNSEC_EXECLOG
74457+ char *grarg = gr_exec_arg_buf;
74458+ unsigned int i, x, execlen = 0;
74459+ char c;
74460+
74461+ if (!((grsec_enable_execlog && grsec_enable_group &&
74462+ in_group_p(grsec_audit_gid))
74463+ || (grsec_enable_execlog && !grsec_enable_group)))
74464+ return;
74465+
74466+ mutex_lock(&gr_exec_arg_mutex);
74467+ memset(grarg, 0, sizeof(gr_exec_arg_buf));
74468+
74469+ for (i = 0; i < bprm->argc && execlen < 128; i++) {
74470+ const char __user *p;
74471+ unsigned int len;
74472+
74473+ p = get_user_arg_ptr(argv, i);
74474+ if (IS_ERR(p))
74475+ goto log;
74476+
74477+ len = strnlen_user(p, 128 - execlen);
74478+ if (len > 128 - execlen)
74479+ len = 128 - execlen;
74480+ else if (len > 0)
74481+ len--;
74482+ if (copy_from_user(grarg + execlen, p, len))
74483+ goto log;
74484+
74485+ /* rewrite unprintable characters */
74486+ for (x = 0; x < len; x++) {
74487+ c = *(grarg + execlen + x);
74488+ if (c < 32 || c > 126)
74489+ *(grarg + execlen + x) = ' ';
74490+ }
74491+
74492+ execlen += len;
74493+ *(grarg + execlen) = ' ';
74494+ *(grarg + execlen + 1) = '\0';
74495+ execlen++;
74496+ }
74497+
74498+ log:
74499+ gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
74500+ bprm->file->f_path.mnt, grarg);
74501+ mutex_unlock(&gr_exec_arg_mutex);
74502+#endif
74503+ return;
74504+}
74505+
74506+#ifdef CONFIG_GRKERNSEC
74507+extern int gr_acl_is_capable(const int cap);
74508+extern int gr_acl_is_capable_nolog(const int cap);
74509+extern int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
74510+extern int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap);
74511+extern int gr_chroot_is_capable(const int cap);
74512+extern int gr_chroot_is_capable_nolog(const int cap);
74513+extern int gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
74514+extern int gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap);
74515+#endif
74516+
74517+const char *captab_log[] = {
74518+ "CAP_CHOWN",
74519+ "CAP_DAC_OVERRIDE",
74520+ "CAP_DAC_READ_SEARCH",
74521+ "CAP_FOWNER",
74522+ "CAP_FSETID",
74523+ "CAP_KILL",
74524+ "CAP_SETGID",
74525+ "CAP_SETUID",
74526+ "CAP_SETPCAP",
74527+ "CAP_LINUX_IMMUTABLE",
74528+ "CAP_NET_BIND_SERVICE",
74529+ "CAP_NET_BROADCAST",
74530+ "CAP_NET_ADMIN",
74531+ "CAP_NET_RAW",
74532+ "CAP_IPC_LOCK",
74533+ "CAP_IPC_OWNER",
74534+ "CAP_SYS_MODULE",
74535+ "CAP_SYS_RAWIO",
74536+ "CAP_SYS_CHROOT",
74537+ "CAP_SYS_PTRACE",
74538+ "CAP_SYS_PACCT",
74539+ "CAP_SYS_ADMIN",
74540+ "CAP_SYS_BOOT",
74541+ "CAP_SYS_NICE",
74542+ "CAP_SYS_RESOURCE",
74543+ "CAP_SYS_TIME",
74544+ "CAP_SYS_TTY_CONFIG",
74545+ "CAP_MKNOD",
74546+ "CAP_LEASE",
74547+ "CAP_AUDIT_WRITE",
74548+ "CAP_AUDIT_CONTROL",
74549+ "CAP_SETFCAP",
74550+ "CAP_MAC_OVERRIDE",
74551+ "CAP_MAC_ADMIN",
74552+ "CAP_SYSLOG",
74553+ "CAP_WAKE_ALARM"
74554+};
74555+
74556+int captab_log_entries = sizeof(captab_log)/sizeof(captab_log[0]);
74557+
74558+int gr_is_capable(const int cap)
74559+{
74560+#ifdef CONFIG_GRKERNSEC
74561+ if (gr_acl_is_capable(cap) && gr_chroot_is_capable(cap))
74562+ return 1;
74563+ return 0;
74564+#else
74565+ return 1;
74566+#endif
74567+}
74568+
74569+int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
74570+{
74571+#ifdef CONFIG_GRKERNSEC
74572+ if (gr_task_acl_is_capable(task, cred, cap) && gr_task_chroot_is_capable(task, cred, cap))
74573+ return 1;
74574+ return 0;
74575+#else
74576+ return 1;
74577+#endif
74578+}
74579+
74580+int gr_is_capable_nolog(const int cap)
74581+{
74582+#ifdef CONFIG_GRKERNSEC
74583+ if (gr_acl_is_capable_nolog(cap) && gr_chroot_is_capable_nolog(cap))
74584+ return 1;
74585+ return 0;
74586+#else
74587+ return 1;
74588+#endif
74589+}
74590+
74591+int gr_task_is_capable_nolog(const struct task_struct *task, const int cap)
74592+{
74593+#ifdef CONFIG_GRKERNSEC
74594+ if (gr_task_acl_is_capable_nolog(task, cap) && gr_task_chroot_is_capable_nolog(task, cap))
74595+ return 1;
74596+ return 0;
74597+#else
74598+ return 1;
74599+#endif
74600+}
74601+
74602+EXPORT_SYMBOL_GPL(gr_is_capable);
74603+EXPORT_SYMBOL_GPL(gr_is_capable_nolog);
74604+EXPORT_SYMBOL_GPL(gr_task_is_capable);
74605+EXPORT_SYMBOL_GPL(gr_task_is_capable_nolog);
74606diff --git a/grsecurity/grsec_fifo.c b/grsecurity/grsec_fifo.c
74607new file mode 100644
74608index 0000000..06cc6ea
74609--- /dev/null
74610+++ b/grsecurity/grsec_fifo.c
74611@@ -0,0 +1,24 @@
74612+#include <linux/kernel.h>
74613+#include <linux/sched.h>
74614+#include <linux/fs.h>
74615+#include <linux/file.h>
74616+#include <linux/grinternal.h>
74617+
74618+int
74619+gr_handle_fifo(const struct dentry *dentry, const struct vfsmount *mnt,
74620+ const struct dentry *dir, const int flag, const int acc_mode)
74621+{
74622+#ifdef CONFIG_GRKERNSEC_FIFO
74623+ const struct cred *cred = current_cred();
74624+
74625+ if (grsec_enable_fifo && S_ISFIFO(dentry->d_inode->i_mode) &&
74626+ !(flag & O_EXCL) && (dir->d_inode->i_mode & S_ISVTX) &&
74627+ !uid_eq(dentry->d_inode->i_uid, dir->d_inode->i_uid) &&
74628+ !uid_eq(cred->fsuid, dentry->d_inode->i_uid)) {
74629+ if (!inode_permission(dentry->d_inode, acc_mode))
74630+ 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));
74631+ return -EACCES;
74632+ }
74633+#endif
74634+ return 0;
74635+}
74636diff --git a/grsecurity/grsec_fork.c b/grsecurity/grsec_fork.c
74637new file mode 100644
74638index 0000000..8ca18bf
74639--- /dev/null
74640+++ b/grsecurity/grsec_fork.c
74641@@ -0,0 +1,23 @@
74642+#include <linux/kernel.h>
74643+#include <linux/sched.h>
74644+#include <linux/grsecurity.h>
74645+#include <linux/grinternal.h>
74646+#include <linux/errno.h>
74647+
74648+void
74649+gr_log_forkfail(const int retval)
74650+{
74651+#ifdef CONFIG_GRKERNSEC_FORKFAIL
74652+ if (grsec_enable_forkfail && (retval == -EAGAIN || retval == -ENOMEM)) {
74653+ switch (retval) {
74654+ case -EAGAIN:
74655+ gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "EAGAIN");
74656+ break;
74657+ case -ENOMEM:
74658+ gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "ENOMEM");
74659+ break;
74660+ }
74661+ }
74662+#endif
74663+ return;
74664+}
74665diff --git a/grsecurity/grsec_init.c b/grsecurity/grsec_init.c
74666new file mode 100644
74667index 0000000..ae6c028
74668--- /dev/null
74669+++ b/grsecurity/grsec_init.c
74670@@ -0,0 +1,272 @@
74671+#include <linux/kernel.h>
74672+#include <linux/sched.h>
74673+#include <linux/mm.h>
74674+#include <linux/gracl.h>
74675+#include <linux/slab.h>
74676+#include <linux/vmalloc.h>
74677+#include <linux/percpu.h>
74678+#include <linux/module.h>
74679+
74680+int grsec_enable_ptrace_readexec;
74681+int grsec_enable_setxid;
74682+int grsec_enable_symlinkown;
74683+kgid_t grsec_symlinkown_gid;
74684+int grsec_enable_brute;
74685+int grsec_enable_link;
74686+int grsec_enable_dmesg;
74687+int grsec_enable_harden_ptrace;
74688+int grsec_enable_harden_ipc;
74689+int grsec_enable_fifo;
74690+int grsec_enable_execlog;
74691+int grsec_enable_signal;
74692+int grsec_enable_forkfail;
74693+int grsec_enable_audit_ptrace;
74694+int grsec_enable_time;
74695+int grsec_enable_group;
74696+kgid_t grsec_audit_gid;
74697+int grsec_enable_chdir;
74698+int grsec_enable_mount;
74699+int grsec_enable_rofs;
74700+int grsec_deny_new_usb;
74701+int grsec_enable_chroot_findtask;
74702+int grsec_enable_chroot_mount;
74703+int grsec_enable_chroot_shmat;
74704+int grsec_enable_chroot_fchdir;
74705+int grsec_enable_chroot_double;
74706+int grsec_enable_chroot_pivot;
74707+int grsec_enable_chroot_chdir;
74708+int grsec_enable_chroot_chmod;
74709+int grsec_enable_chroot_mknod;
74710+int grsec_enable_chroot_nice;
74711+int grsec_enable_chroot_execlog;
74712+int grsec_enable_chroot_caps;
74713+int grsec_enable_chroot_sysctl;
74714+int grsec_enable_chroot_unix;
74715+int grsec_enable_tpe;
74716+kgid_t grsec_tpe_gid;
74717+int grsec_enable_blackhole;
74718+#ifdef CONFIG_IPV6_MODULE
74719+EXPORT_SYMBOL_GPL(grsec_enable_blackhole);
74720+#endif
74721+int grsec_lastack_retries;
74722+int grsec_enable_tpe_all;
74723+int grsec_enable_tpe_invert;
74724+int grsec_enable_socket_all;
74725+kgid_t grsec_socket_all_gid;
74726+int grsec_enable_socket_client;
74727+kgid_t grsec_socket_client_gid;
74728+int grsec_enable_socket_server;
74729+kgid_t grsec_socket_server_gid;
74730+int grsec_resource_logging;
74731+int grsec_disable_privio;
74732+int grsec_enable_log_rwxmaps;
74733+int grsec_lock;
74734+
74735+DEFINE_SPINLOCK(grsec_alert_lock);
74736+unsigned long grsec_alert_wtime = 0;
74737+unsigned long grsec_alert_fyet = 0;
74738+
74739+DEFINE_SPINLOCK(grsec_audit_lock);
74740+
74741+DEFINE_RWLOCK(grsec_exec_file_lock);
74742+
74743+char *gr_shared_page[4];
74744+
74745+char *gr_alert_log_fmt;
74746+char *gr_audit_log_fmt;
74747+char *gr_alert_log_buf;
74748+char *gr_audit_log_buf;
74749+
74750+void __init
74751+grsecurity_init(void)
74752+{
74753+ int j;
74754+ /* create the per-cpu shared pages */
74755+
74756+#ifdef CONFIG_X86
74757+ memset((char *)(0x41a + PAGE_OFFSET), 0, 36);
74758+#endif
74759+
74760+ for (j = 0; j < 4; j++) {
74761+ gr_shared_page[j] = (char *)__alloc_percpu(PAGE_SIZE, __alignof__(unsigned long long));
74762+ if (gr_shared_page[j] == NULL) {
74763+ panic("Unable to allocate grsecurity shared page");
74764+ return;
74765+ }
74766+ }
74767+
74768+ /* allocate log buffers */
74769+ gr_alert_log_fmt = kmalloc(512, GFP_KERNEL);
74770+ if (!gr_alert_log_fmt) {
74771+ panic("Unable to allocate grsecurity alert log format buffer");
74772+ return;
74773+ }
74774+ gr_audit_log_fmt = kmalloc(512, GFP_KERNEL);
74775+ if (!gr_audit_log_fmt) {
74776+ panic("Unable to allocate grsecurity audit log format buffer");
74777+ return;
74778+ }
74779+ gr_alert_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
74780+ if (!gr_alert_log_buf) {
74781+ panic("Unable to allocate grsecurity alert log buffer");
74782+ return;
74783+ }
74784+ gr_audit_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
74785+ if (!gr_audit_log_buf) {
74786+ panic("Unable to allocate grsecurity audit log buffer");
74787+ return;
74788+ }
74789+
74790+#ifdef CONFIG_GRKERNSEC_IO
74791+#if !defined(CONFIG_GRKERNSEC_SYSCTL_DISTRO)
74792+ grsec_disable_privio = 1;
74793+#elif defined(CONFIG_GRKERNSEC_SYSCTL_ON)
74794+ grsec_disable_privio = 1;
74795+#else
74796+ grsec_disable_privio = 0;
74797+#endif
74798+#endif
74799+
74800+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
74801+ /* for backward compatibility, tpe_invert always defaults to on if
74802+ enabled in the kernel
74803+ */
74804+ grsec_enable_tpe_invert = 1;
74805+#endif
74806+
74807+#if !defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_SYSCTL_ON)
74808+#ifndef CONFIG_GRKERNSEC_SYSCTL
74809+ grsec_lock = 1;
74810+#endif
74811+
74812+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
74813+ grsec_enable_log_rwxmaps = 1;
74814+#endif
74815+#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
74816+ grsec_enable_group = 1;
74817+ grsec_audit_gid = KGIDT_INIT(CONFIG_GRKERNSEC_AUDIT_GID);
74818+#endif
74819+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
74820+ grsec_enable_ptrace_readexec = 1;
74821+#endif
74822+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
74823+ grsec_enable_chdir = 1;
74824+#endif
74825+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
74826+ grsec_enable_harden_ptrace = 1;
74827+#endif
74828+#ifdef CONFIG_GRKERNSEC_HARDEN_IPC
74829+ grsec_enable_harden_ipc = 1;
74830+#endif
74831+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
74832+ grsec_enable_mount = 1;
74833+#endif
74834+#ifdef CONFIG_GRKERNSEC_LINK
74835+ grsec_enable_link = 1;
74836+#endif
74837+#ifdef CONFIG_GRKERNSEC_BRUTE
74838+ grsec_enable_brute = 1;
74839+#endif
74840+#ifdef CONFIG_GRKERNSEC_DMESG
74841+ grsec_enable_dmesg = 1;
74842+#endif
74843+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
74844+ grsec_enable_blackhole = 1;
74845+ grsec_lastack_retries = 4;
74846+#endif
74847+#ifdef CONFIG_GRKERNSEC_FIFO
74848+ grsec_enable_fifo = 1;
74849+#endif
74850+#ifdef CONFIG_GRKERNSEC_EXECLOG
74851+ grsec_enable_execlog = 1;
74852+#endif
74853+#ifdef CONFIG_GRKERNSEC_SETXID
74854+ grsec_enable_setxid = 1;
74855+#endif
74856+#ifdef CONFIG_GRKERNSEC_SIGNAL
74857+ grsec_enable_signal = 1;
74858+#endif
74859+#ifdef CONFIG_GRKERNSEC_FORKFAIL
74860+ grsec_enable_forkfail = 1;
74861+#endif
74862+#ifdef CONFIG_GRKERNSEC_TIME
74863+ grsec_enable_time = 1;
74864+#endif
74865+#ifdef CONFIG_GRKERNSEC_RESLOG
74866+ grsec_resource_logging = 1;
74867+#endif
74868+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
74869+ grsec_enable_chroot_findtask = 1;
74870+#endif
74871+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
74872+ grsec_enable_chroot_unix = 1;
74873+#endif
74874+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
74875+ grsec_enable_chroot_mount = 1;
74876+#endif
74877+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
74878+ grsec_enable_chroot_fchdir = 1;
74879+#endif
74880+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
74881+ grsec_enable_chroot_shmat = 1;
74882+#endif
74883+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
74884+ grsec_enable_audit_ptrace = 1;
74885+#endif
74886+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
74887+ grsec_enable_chroot_double = 1;
74888+#endif
74889+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
74890+ grsec_enable_chroot_pivot = 1;
74891+#endif
74892+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
74893+ grsec_enable_chroot_chdir = 1;
74894+#endif
74895+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
74896+ grsec_enable_chroot_chmod = 1;
74897+#endif
74898+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
74899+ grsec_enable_chroot_mknod = 1;
74900+#endif
74901+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
74902+ grsec_enable_chroot_nice = 1;
74903+#endif
74904+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
74905+ grsec_enable_chroot_execlog = 1;
74906+#endif
74907+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
74908+ grsec_enable_chroot_caps = 1;
74909+#endif
74910+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
74911+ grsec_enable_chroot_sysctl = 1;
74912+#endif
74913+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
74914+ grsec_enable_symlinkown = 1;
74915+ grsec_symlinkown_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SYMLINKOWN_GID);
74916+#endif
74917+#ifdef CONFIG_GRKERNSEC_TPE
74918+ grsec_enable_tpe = 1;
74919+ grsec_tpe_gid = KGIDT_INIT(CONFIG_GRKERNSEC_TPE_GID);
74920+#ifdef CONFIG_GRKERNSEC_TPE_ALL
74921+ grsec_enable_tpe_all = 1;
74922+#endif
74923+#endif
74924+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
74925+ grsec_enable_socket_all = 1;
74926+ grsec_socket_all_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_ALL_GID);
74927+#endif
74928+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
74929+ grsec_enable_socket_client = 1;
74930+ grsec_socket_client_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_CLIENT_GID);
74931+#endif
74932+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
74933+ grsec_enable_socket_server = 1;
74934+ grsec_socket_server_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_SERVER_GID);
74935+#endif
74936+#endif
74937+#ifdef CONFIG_GRKERNSEC_DENYUSB_FORCE
74938+ grsec_deny_new_usb = 1;
74939+#endif
74940+
74941+ return;
74942+}
74943diff --git a/grsecurity/grsec_ipc.c b/grsecurity/grsec_ipc.c
74944new file mode 100644
74945index 0000000..1773300
74946--- /dev/null
74947+++ b/grsecurity/grsec_ipc.c
74948@@ -0,0 +1,48 @@
74949+#include <linux/kernel.h>
74950+#include <linux/mm.h>
74951+#include <linux/sched.h>
74952+#include <linux/file.h>
74953+#include <linux/ipc.h>
74954+#include <linux/ipc_namespace.h>
74955+#include <linux/grsecurity.h>
74956+#include <linux/grinternal.h>
74957+
74958+int
74959+gr_ipc_permitted(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp, int requested_mode, int granted_mode)
74960+{
74961+#ifdef CONFIG_GRKERNSEC_HARDEN_IPC
74962+ int write;
74963+ int orig_granted_mode;
74964+ kuid_t euid;
74965+ kgid_t egid;
74966+
74967+ if (!grsec_enable_harden_ipc)
74968+ return 1;
74969+
74970+ euid = current_euid();
74971+ egid = current_egid();
74972+
74973+ write = requested_mode & 00002;
74974+ orig_granted_mode = ipcp->mode;
74975+
74976+ if (uid_eq(euid, ipcp->cuid) || uid_eq(euid, ipcp->uid))
74977+ orig_granted_mode >>= 6;
74978+ else {
74979+ /* if likely wrong permissions, lock to user */
74980+ if (orig_granted_mode & 0007)
74981+ orig_granted_mode = 0;
74982+ /* otherwise do a egid-only check */
74983+ else if (gid_eq(egid, ipcp->cgid) || gid_eq(egid, ipcp->gid))
74984+ orig_granted_mode >>= 3;
74985+ /* otherwise, no access */
74986+ else
74987+ orig_granted_mode = 0;
74988+ }
74989+ if (!(requested_mode & ~granted_mode & 0007) && (requested_mode & ~orig_granted_mode & 0007) &&
74990+ !ns_capable_nolog(ns->user_ns, CAP_IPC_OWNER)) {
74991+ gr_log_str_int(GR_DONT_AUDIT, GR_IPC_DENIED_MSG, write ? "write" : "read", GR_GLOBAL_UID(ipcp->cuid));
74992+ return 0;
74993+ }
74994+#endif
74995+ return 1;
74996+}
74997diff --git a/grsecurity/grsec_link.c b/grsecurity/grsec_link.c
74998new file mode 100644
74999index 0000000..5e05e20
75000--- /dev/null
75001+++ b/grsecurity/grsec_link.c
75002@@ -0,0 +1,58 @@
75003+#include <linux/kernel.h>
75004+#include <linux/sched.h>
75005+#include <linux/fs.h>
75006+#include <linux/file.h>
75007+#include <linux/grinternal.h>
75008+
75009+int gr_handle_symlink_owner(const struct path *link, const struct inode *target)
75010+{
75011+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
75012+ const struct inode *link_inode = link->dentry->d_inode;
75013+
75014+ if (grsec_enable_symlinkown && in_group_p(grsec_symlinkown_gid) &&
75015+ /* ignore root-owned links, e.g. /proc/self */
75016+ gr_is_global_nonroot(link_inode->i_uid) && target &&
75017+ !uid_eq(link_inode->i_uid, target->i_uid)) {
75018+ gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINKOWNER_MSG, link->dentry, link->mnt, link_inode->i_uid, target->i_uid);
75019+ return 1;
75020+ }
75021+#endif
75022+ return 0;
75023+}
75024+
75025+int
75026+gr_handle_follow_link(const struct inode *parent,
75027+ const struct inode *inode,
75028+ const struct dentry *dentry, const struct vfsmount *mnt)
75029+{
75030+#ifdef CONFIG_GRKERNSEC_LINK
75031+ const struct cred *cred = current_cred();
75032+
75033+ if (grsec_enable_link && S_ISLNK(inode->i_mode) &&
75034+ (parent->i_mode & S_ISVTX) && !uid_eq(parent->i_uid, inode->i_uid) &&
75035+ (parent->i_mode & S_IWOTH) && !uid_eq(cred->fsuid, inode->i_uid)) {
75036+ gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid);
75037+ return -EACCES;
75038+ }
75039+#endif
75040+ return 0;
75041+}
75042+
75043+int
75044+gr_handle_hardlink(const struct dentry *dentry,
75045+ const struct vfsmount *mnt,
75046+ struct inode *inode, const int mode, const struct filename *to)
75047+{
75048+#ifdef CONFIG_GRKERNSEC_LINK
75049+ const struct cred *cred = current_cred();
75050+
75051+ if (grsec_enable_link && !uid_eq(cred->fsuid, inode->i_uid) &&
75052+ (!S_ISREG(mode) || is_privileged_binary(dentry) ||
75053+ (inode_permission(inode, MAY_READ | MAY_WRITE))) &&
75054+ !capable(CAP_FOWNER) && gr_is_global_nonroot(cred->uid)) {
75055+ gr_log_fs_int2_str(GR_DONT_AUDIT, GR_HARDLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid, to->name);
75056+ return -EPERM;
75057+ }
75058+#endif
75059+ return 0;
75060+}
75061diff --git a/grsecurity/grsec_log.c b/grsecurity/grsec_log.c
75062new file mode 100644
75063index 0000000..dbe0a6b
75064--- /dev/null
75065+++ b/grsecurity/grsec_log.c
75066@@ -0,0 +1,341 @@
75067+#include <linux/kernel.h>
75068+#include <linux/sched.h>
75069+#include <linux/file.h>
75070+#include <linux/tty.h>
75071+#include <linux/fs.h>
75072+#include <linux/mm.h>
75073+#include <linux/grinternal.h>
75074+
75075+#ifdef CONFIG_TREE_PREEMPT_RCU
75076+#define DISABLE_PREEMPT() preempt_disable()
75077+#define ENABLE_PREEMPT() preempt_enable()
75078+#else
75079+#define DISABLE_PREEMPT()
75080+#define ENABLE_PREEMPT()
75081+#endif
75082+
75083+#define BEGIN_LOCKS(x) \
75084+ DISABLE_PREEMPT(); \
75085+ rcu_read_lock(); \
75086+ read_lock(&tasklist_lock); \
75087+ read_lock(&grsec_exec_file_lock); \
75088+ if (x != GR_DO_AUDIT) \
75089+ spin_lock(&grsec_alert_lock); \
75090+ else \
75091+ spin_lock(&grsec_audit_lock)
75092+
75093+#define END_LOCKS(x) \
75094+ if (x != GR_DO_AUDIT) \
75095+ spin_unlock(&grsec_alert_lock); \
75096+ else \
75097+ spin_unlock(&grsec_audit_lock); \
75098+ read_unlock(&grsec_exec_file_lock); \
75099+ read_unlock(&tasklist_lock); \
75100+ rcu_read_unlock(); \
75101+ ENABLE_PREEMPT(); \
75102+ if (x == GR_DONT_AUDIT) \
75103+ gr_handle_alertkill(current)
75104+
75105+enum {
75106+ FLOODING,
75107+ NO_FLOODING
75108+};
75109+
75110+extern char *gr_alert_log_fmt;
75111+extern char *gr_audit_log_fmt;
75112+extern char *gr_alert_log_buf;
75113+extern char *gr_audit_log_buf;
75114+
75115+static int gr_log_start(int audit)
75116+{
75117+ char *loglevel = (audit == GR_DO_AUDIT) ? KERN_INFO : KERN_ALERT;
75118+ char *fmt = (audit == GR_DO_AUDIT) ? gr_audit_log_fmt : gr_alert_log_fmt;
75119+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
75120+#if (CONFIG_GRKERNSEC_FLOODTIME > 0 && CONFIG_GRKERNSEC_FLOODBURST > 0)
75121+ unsigned long curr_secs = get_seconds();
75122+
75123+ if (audit == GR_DO_AUDIT)
75124+ goto set_fmt;
75125+
75126+ if (!grsec_alert_wtime || time_after(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)) {
75127+ grsec_alert_wtime = curr_secs;
75128+ grsec_alert_fyet = 0;
75129+ } else if (time_before_eq(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)
75130+ && (grsec_alert_fyet < CONFIG_GRKERNSEC_FLOODBURST)) {
75131+ grsec_alert_fyet++;
75132+ } else if (grsec_alert_fyet == CONFIG_GRKERNSEC_FLOODBURST) {
75133+ grsec_alert_wtime = curr_secs;
75134+ grsec_alert_fyet++;
75135+ printk(KERN_ALERT "grsec: more alerts, logging disabled for %d seconds\n", CONFIG_GRKERNSEC_FLOODTIME);
75136+ return FLOODING;
75137+ }
75138+ else return FLOODING;
75139+
75140+set_fmt:
75141+#endif
75142+ memset(buf, 0, PAGE_SIZE);
75143+ if (current->signal->curr_ip && gr_acl_is_enabled()) {
75144+ sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: (%.64s:%c:%.950s) ");
75145+ snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
75146+ } else if (current->signal->curr_ip) {
75147+ sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: ");
75148+ snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip);
75149+ } else if (gr_acl_is_enabled()) {
75150+ sprintf(fmt, "%s%s", loglevel, "grsec: (%.64s:%c:%.950s) ");
75151+ snprintf(buf, PAGE_SIZE - 1, fmt, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
75152+ } else {
75153+ sprintf(fmt, "%s%s", loglevel, "grsec: ");
75154+ strcpy(buf, fmt);
75155+ }
75156+
75157+ return NO_FLOODING;
75158+}
75159+
75160+static void gr_log_middle(int audit, const char *msg, va_list ap)
75161+ __attribute__ ((format (printf, 2, 0)));
75162+
75163+static void gr_log_middle(int audit, const char *msg, va_list ap)
75164+{
75165+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
75166+ unsigned int len = strlen(buf);
75167+
75168+ vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
75169+
75170+ return;
75171+}
75172+
75173+static void gr_log_middle_varargs(int audit, const char *msg, ...)
75174+ __attribute__ ((format (printf, 2, 3)));
75175+
75176+static void gr_log_middle_varargs(int audit, const char *msg, ...)
75177+{
75178+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
75179+ unsigned int len = strlen(buf);
75180+ va_list ap;
75181+
75182+ va_start(ap, msg);
75183+ vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
75184+ va_end(ap);
75185+
75186+ return;
75187+}
75188+
75189+static void gr_log_end(int audit, int append_default)
75190+{
75191+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
75192+ if (append_default) {
75193+ struct task_struct *task = current;
75194+ struct task_struct *parent = task->real_parent;
75195+ const struct cred *cred = __task_cred(task);
75196+ const struct cred *pcred = __task_cred(parent);
75197+ unsigned int len = strlen(buf);
75198+
75199+ 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));
75200+ }
75201+
75202+ printk("%s\n", buf);
75203+
75204+ return;
75205+}
75206+
75207+void gr_log_varargs(int audit, const char *msg, int argtypes, ...)
75208+{
75209+ int logtype;
75210+ char *result = (audit == GR_DO_AUDIT) ? "successful" : "denied";
75211+ char *str1 = NULL, *str2 = NULL, *str3 = NULL;
75212+ void *voidptr = NULL;
75213+ int num1 = 0, num2 = 0;
75214+ unsigned long ulong1 = 0, ulong2 = 0;
75215+ struct dentry *dentry = NULL;
75216+ struct vfsmount *mnt = NULL;
75217+ struct file *file = NULL;
75218+ struct task_struct *task = NULL;
75219+ struct vm_area_struct *vma = NULL;
75220+ const struct cred *cred, *pcred;
75221+ va_list ap;
75222+
75223+ BEGIN_LOCKS(audit);
75224+ logtype = gr_log_start(audit);
75225+ if (logtype == FLOODING) {
75226+ END_LOCKS(audit);
75227+ return;
75228+ }
75229+ va_start(ap, argtypes);
75230+ switch (argtypes) {
75231+ case GR_TTYSNIFF:
75232+ task = va_arg(ap, struct task_struct *);
75233+ 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));
75234+ break;
75235+ case GR_SYSCTL_HIDDEN:
75236+ str1 = va_arg(ap, char *);
75237+ gr_log_middle_varargs(audit, msg, result, str1);
75238+ break;
75239+ case GR_RBAC:
75240+ dentry = va_arg(ap, struct dentry *);
75241+ mnt = va_arg(ap, struct vfsmount *);
75242+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt));
75243+ break;
75244+ case GR_RBAC_STR:
75245+ dentry = va_arg(ap, struct dentry *);
75246+ mnt = va_arg(ap, struct vfsmount *);
75247+ str1 = va_arg(ap, char *);
75248+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1);
75249+ break;
75250+ case GR_STR_RBAC:
75251+ str1 = va_arg(ap, char *);
75252+ dentry = va_arg(ap, struct dentry *);
75253+ mnt = va_arg(ap, struct vfsmount *);
75254+ gr_log_middle_varargs(audit, msg, result, str1, gr_to_filename(dentry, mnt));
75255+ break;
75256+ case GR_RBAC_MODE2:
75257+ dentry = va_arg(ap, struct dentry *);
75258+ mnt = va_arg(ap, struct vfsmount *);
75259+ str1 = va_arg(ap, char *);
75260+ str2 = va_arg(ap, char *);
75261+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2);
75262+ break;
75263+ case GR_RBAC_MODE3:
75264+ dentry = va_arg(ap, struct dentry *);
75265+ mnt = va_arg(ap, struct vfsmount *);
75266+ str1 = va_arg(ap, char *);
75267+ str2 = va_arg(ap, char *);
75268+ str3 = va_arg(ap, char *);
75269+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2, str3);
75270+ break;
75271+ case GR_FILENAME:
75272+ dentry = va_arg(ap, struct dentry *);
75273+ mnt = va_arg(ap, struct vfsmount *);
75274+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt));
75275+ break;
75276+ case GR_STR_FILENAME:
75277+ str1 = va_arg(ap, char *);
75278+ dentry = va_arg(ap, struct dentry *);
75279+ mnt = va_arg(ap, struct vfsmount *);
75280+ gr_log_middle_varargs(audit, msg, str1, gr_to_filename(dentry, mnt));
75281+ break;
75282+ case GR_FILENAME_STR:
75283+ dentry = va_arg(ap, struct dentry *);
75284+ mnt = va_arg(ap, struct vfsmount *);
75285+ str1 = va_arg(ap, char *);
75286+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), str1);
75287+ break;
75288+ case GR_FILENAME_TWO_INT:
75289+ dentry = va_arg(ap, struct dentry *);
75290+ mnt = va_arg(ap, struct vfsmount *);
75291+ num1 = va_arg(ap, int);
75292+ num2 = va_arg(ap, int);
75293+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2);
75294+ break;
75295+ case GR_FILENAME_TWO_INT_STR:
75296+ dentry = va_arg(ap, struct dentry *);
75297+ mnt = va_arg(ap, struct vfsmount *);
75298+ num1 = va_arg(ap, int);
75299+ num2 = va_arg(ap, int);
75300+ str1 = va_arg(ap, char *);
75301+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2, str1);
75302+ break;
75303+ case GR_TEXTREL:
75304+ file = va_arg(ap, struct file *);
75305+ ulong1 = va_arg(ap, unsigned long);
75306+ ulong2 = va_arg(ap, unsigned long);
75307+ gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>", ulong1, ulong2);
75308+ break;
75309+ case GR_PTRACE:
75310+ task = va_arg(ap, struct task_struct *);
75311+ 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));
75312+ break;
75313+ case GR_RESOURCE:
75314+ task = va_arg(ap, struct task_struct *);
75315+ cred = __task_cred(task);
75316+ pcred = __task_cred(task->real_parent);
75317+ ulong1 = va_arg(ap, unsigned long);
75318+ str1 = va_arg(ap, char *);
75319+ ulong2 = va_arg(ap, unsigned long);
75320+ 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));
75321+ break;
75322+ case GR_CAP:
75323+ task = va_arg(ap, struct task_struct *);
75324+ cred = __task_cred(task);
75325+ pcred = __task_cred(task->real_parent);
75326+ str1 = va_arg(ap, char *);
75327+ 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));
75328+ break;
75329+ case GR_SIG:
75330+ str1 = va_arg(ap, char *);
75331+ voidptr = va_arg(ap, void *);
75332+ gr_log_middle_varargs(audit, msg, str1, voidptr);
75333+ break;
75334+ case GR_SIG2:
75335+ task = va_arg(ap, struct task_struct *);
75336+ cred = __task_cred(task);
75337+ pcred = __task_cred(task->real_parent);
75338+ num1 = va_arg(ap, int);
75339+ 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));
75340+ break;
75341+ case GR_CRASH1:
75342+ task = va_arg(ap, struct task_struct *);
75343+ cred = __task_cred(task);
75344+ pcred = __task_cred(task->real_parent);
75345+ ulong1 = va_arg(ap, unsigned long);
75346+ 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);
75347+ break;
75348+ case GR_CRASH2:
75349+ task = va_arg(ap, struct task_struct *);
75350+ cred = __task_cred(task);
75351+ pcred = __task_cred(task->real_parent);
75352+ ulong1 = va_arg(ap, unsigned long);
75353+ 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);
75354+ break;
75355+ case GR_RWXMAP:
75356+ file = va_arg(ap, struct file *);
75357+ gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>");
75358+ break;
75359+ case GR_RWXMAPVMA:
75360+ vma = va_arg(ap, struct vm_area_struct *);
75361+ if (vma->vm_file)
75362+ str1 = gr_to_filename(vma->vm_file->f_path.dentry, vma->vm_file->f_path.mnt);
75363+ else if (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP))
75364+ str1 = "<stack>";
75365+ else if (vma->vm_start <= current->mm->brk &&
75366+ vma->vm_end >= current->mm->start_brk)
75367+ str1 = "<heap>";
75368+ else
75369+ str1 = "<anonymous mapping>";
75370+ gr_log_middle_varargs(audit, msg, str1);
75371+ break;
75372+ case GR_PSACCT:
75373+ {
75374+ unsigned int wday, cday;
75375+ __u8 whr, chr;
75376+ __u8 wmin, cmin;
75377+ __u8 wsec, csec;
75378+ char cur_tty[64] = { 0 };
75379+ char parent_tty[64] = { 0 };
75380+
75381+ task = va_arg(ap, struct task_struct *);
75382+ wday = va_arg(ap, unsigned int);
75383+ cday = va_arg(ap, unsigned int);
75384+ whr = va_arg(ap, int);
75385+ chr = va_arg(ap, int);
75386+ wmin = va_arg(ap, int);
75387+ cmin = va_arg(ap, int);
75388+ wsec = va_arg(ap, int);
75389+ csec = va_arg(ap, int);
75390+ ulong1 = va_arg(ap, unsigned long);
75391+ cred = __task_cred(task);
75392+ pcred = __task_cred(task->real_parent);
75393+
75394+ 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));
75395+ }
75396+ break;
75397+ default:
75398+ gr_log_middle(audit, msg, ap);
75399+ }
75400+ va_end(ap);
75401+ // these don't need DEFAULTSECARGS printed on the end
75402+ if (argtypes == GR_CRASH1 || argtypes == GR_CRASH2)
75403+ gr_log_end(audit, 0);
75404+ else
75405+ gr_log_end(audit, 1);
75406+ END_LOCKS(audit);
75407+}
75408diff --git a/grsecurity/grsec_mem.c b/grsecurity/grsec_mem.c
75409new file mode 100644
75410index 0000000..0e39d8c
75411--- /dev/null
75412+++ b/grsecurity/grsec_mem.c
75413@@ -0,0 +1,48 @@
75414+#include <linux/kernel.h>
75415+#include <linux/sched.h>
75416+#include <linux/mm.h>
75417+#include <linux/mman.h>
75418+#include <linux/module.h>
75419+#include <linux/grinternal.h>
75420+
75421+void gr_handle_msr_write(void)
75422+{
75423+ gr_log_noargs(GR_DONT_AUDIT, GR_MSRWRITE_MSG);
75424+ return;
75425+}
75426+EXPORT_SYMBOL_GPL(gr_handle_msr_write);
75427+
75428+void
75429+gr_handle_ioperm(void)
75430+{
75431+ gr_log_noargs(GR_DONT_AUDIT, GR_IOPERM_MSG);
75432+ return;
75433+}
75434+
75435+void
75436+gr_handle_iopl(void)
75437+{
75438+ gr_log_noargs(GR_DONT_AUDIT, GR_IOPL_MSG);
75439+ return;
75440+}
75441+
75442+void
75443+gr_handle_mem_readwrite(u64 from, u64 to)
75444+{
75445+ gr_log_two_u64(GR_DONT_AUDIT, GR_MEM_READWRITE_MSG, from, to);
75446+ return;
75447+}
75448+
75449+void
75450+gr_handle_vm86(void)
75451+{
75452+ gr_log_noargs(GR_DONT_AUDIT, GR_VM86_MSG);
75453+ return;
75454+}
75455+
75456+void
75457+gr_log_badprocpid(const char *entry)
75458+{
75459+ gr_log_str(GR_DONT_AUDIT, GR_BADPROCPID_MSG, entry);
75460+ return;
75461+}
75462diff --git a/grsecurity/grsec_mount.c b/grsecurity/grsec_mount.c
75463new file mode 100644
75464index 0000000..cd9e124
75465--- /dev/null
75466+++ b/grsecurity/grsec_mount.c
75467@@ -0,0 +1,65 @@
75468+#include <linux/kernel.h>
75469+#include <linux/sched.h>
75470+#include <linux/mount.h>
75471+#include <linux/major.h>
75472+#include <linux/grsecurity.h>
75473+#include <linux/grinternal.h>
75474+
75475+void
75476+gr_log_remount(const char *devname, const int retval)
75477+{
75478+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
75479+ if (grsec_enable_mount && (retval >= 0))
75480+ gr_log_str(GR_DO_AUDIT, GR_REMOUNT_AUDIT_MSG, devname ? devname : "none");
75481+#endif
75482+ return;
75483+}
75484+
75485+void
75486+gr_log_unmount(const char *devname, const int retval)
75487+{
75488+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
75489+ if (grsec_enable_mount && (retval >= 0))
75490+ gr_log_str(GR_DO_AUDIT, GR_UNMOUNT_AUDIT_MSG, devname ? devname : "none");
75491+#endif
75492+ return;
75493+}
75494+
75495+void
75496+gr_log_mount(const char *from, const char *to, const int retval)
75497+{
75498+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
75499+ if (grsec_enable_mount && (retval >= 0))
75500+ gr_log_str_str(GR_DO_AUDIT, GR_MOUNT_AUDIT_MSG, from ? from : "none", to);
75501+#endif
75502+ return;
75503+}
75504+
75505+int
75506+gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags)
75507+{
75508+#ifdef CONFIG_GRKERNSEC_ROFS
75509+ if (grsec_enable_rofs && !(mnt_flags & MNT_READONLY)) {
75510+ gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_MOUNT_MSG, dentry, mnt);
75511+ return -EPERM;
75512+ } else
75513+ return 0;
75514+#endif
75515+ return 0;
75516+}
75517+
75518+int
75519+gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode)
75520+{
75521+#ifdef CONFIG_GRKERNSEC_ROFS
75522+ struct inode *inode = dentry->d_inode;
75523+
75524+ if (grsec_enable_rofs && (acc_mode & MAY_WRITE) &&
75525+ inode && (S_ISBLK(inode->i_mode) || (S_ISCHR(inode->i_mode) && imajor(inode) == RAW_MAJOR))) {
75526+ gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_BLOCKWRITE_MSG, dentry, mnt);
75527+ return -EPERM;
75528+ } else
75529+ return 0;
75530+#endif
75531+ return 0;
75532+}
75533diff --git a/grsecurity/grsec_pax.c b/grsecurity/grsec_pax.c
75534new file mode 100644
75535index 0000000..6ee9d50
75536--- /dev/null
75537+++ b/grsecurity/grsec_pax.c
75538@@ -0,0 +1,45 @@
75539+#include <linux/kernel.h>
75540+#include <linux/sched.h>
75541+#include <linux/mm.h>
75542+#include <linux/file.h>
75543+#include <linux/grinternal.h>
75544+#include <linux/grsecurity.h>
75545+
75546+void
75547+gr_log_textrel(struct vm_area_struct * vma)
75548+{
75549+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
75550+ if (grsec_enable_log_rwxmaps)
75551+ gr_log_textrel_ulong_ulong(GR_DONT_AUDIT, GR_TEXTREL_AUDIT_MSG, vma->vm_file, vma->vm_start, vma->vm_pgoff);
75552+#endif
75553+ return;
75554+}
75555+
75556+void gr_log_ptgnustack(struct file *file)
75557+{
75558+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
75559+ if (grsec_enable_log_rwxmaps)
75560+ gr_log_rwxmap(GR_DONT_AUDIT, GR_PTGNUSTACK_MSG, file);
75561+#endif
75562+ return;
75563+}
75564+
75565+void
75566+gr_log_rwxmmap(struct file *file)
75567+{
75568+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
75569+ if (grsec_enable_log_rwxmaps)
75570+ gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMMAP_MSG, file);
75571+#endif
75572+ return;
75573+}
75574+
75575+void
75576+gr_log_rwxmprotect(struct vm_area_struct *vma)
75577+{
75578+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
75579+ if (grsec_enable_log_rwxmaps)
75580+ gr_log_rwxmap_vma(GR_DONT_AUDIT, GR_RWXMPROTECT_MSG, vma);
75581+#endif
75582+ return;
75583+}
75584diff --git a/grsecurity/grsec_proc.c b/grsecurity/grsec_proc.c
75585new file mode 100644
75586index 0000000..2005a3a
75587--- /dev/null
75588+++ b/grsecurity/grsec_proc.c
75589@@ -0,0 +1,20 @@
75590+#include <linux/kernel.h>
75591+#include <linux/sched.h>
75592+#include <linux/grsecurity.h>
75593+#include <linux/grinternal.h>
75594+
75595+int gr_proc_is_restricted(void)
75596+{
75597+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
75598+ const struct cred *cred = current_cred();
75599+#endif
75600+
75601+#ifdef CONFIG_GRKERNSEC_PROC_USER
75602+ if (!uid_eq(cred->fsuid, GLOBAL_ROOT_UID))
75603+ return -EACCES;
75604+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
75605+ if (!uid_eq(cred->fsuid, GLOBAL_ROOT_UID) && !in_group_p(grsec_proc_gid))
75606+ return -EACCES;
75607+#endif
75608+ return 0;
75609+}
75610diff --git a/grsecurity/grsec_ptrace.c b/grsecurity/grsec_ptrace.c
75611new file mode 100644
75612index 0000000..f7f29aa
75613--- /dev/null
75614+++ b/grsecurity/grsec_ptrace.c
75615@@ -0,0 +1,30 @@
75616+#include <linux/kernel.h>
75617+#include <linux/sched.h>
75618+#include <linux/grinternal.h>
75619+#include <linux/security.h>
75620+
75621+void
75622+gr_audit_ptrace(struct task_struct *task)
75623+{
75624+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
75625+ if (grsec_enable_audit_ptrace)
75626+ gr_log_ptrace(GR_DO_AUDIT, GR_PTRACE_AUDIT_MSG, task);
75627+#endif
75628+ return;
75629+}
75630+
75631+int
75632+gr_ptrace_readexec(struct file *file, int unsafe_flags)
75633+{
75634+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
75635+ const struct dentry *dentry = file->f_path.dentry;
75636+ const struct vfsmount *mnt = file->f_path.mnt;
75637+
75638+ if (grsec_enable_ptrace_readexec && (unsafe_flags & LSM_UNSAFE_PTRACE) &&
75639+ (inode_permission(dentry->d_inode, MAY_READ) || !gr_acl_handle_open(dentry, mnt, MAY_READ))) {
75640+ gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_READEXEC_MSG, dentry, mnt);
75641+ return -EACCES;
75642+ }
75643+#endif
75644+ return 0;
75645+}
75646diff --git a/grsecurity/grsec_sig.c b/grsecurity/grsec_sig.c
75647new file mode 100644
75648index 0000000..3860c7e
75649--- /dev/null
75650+++ b/grsecurity/grsec_sig.c
75651@@ -0,0 +1,236 @@
75652+#include <linux/kernel.h>
75653+#include <linux/sched.h>
75654+#include <linux/fs.h>
75655+#include <linux/delay.h>
75656+#include <linux/grsecurity.h>
75657+#include <linux/grinternal.h>
75658+#include <linux/hardirq.h>
75659+
75660+char *signames[] = {
75661+ [SIGSEGV] = "Segmentation fault",
75662+ [SIGILL] = "Illegal instruction",
75663+ [SIGABRT] = "Abort",
75664+ [SIGBUS] = "Invalid alignment/Bus error"
75665+};
75666+
75667+void
75668+gr_log_signal(const int sig, const void *addr, const struct task_struct *t)
75669+{
75670+#ifdef CONFIG_GRKERNSEC_SIGNAL
75671+ if (grsec_enable_signal && ((sig == SIGSEGV) || (sig == SIGILL) ||
75672+ (sig == SIGABRT) || (sig == SIGBUS))) {
75673+ if (task_pid_nr(t) == task_pid_nr(current)) {
75674+ gr_log_sig_addr(GR_DONT_AUDIT_GOOD, GR_UNISIGLOG_MSG, signames[sig], addr);
75675+ } else {
75676+ gr_log_sig_task(GR_DONT_AUDIT_GOOD, GR_DUALSIGLOG_MSG, t, sig);
75677+ }
75678+ }
75679+#endif
75680+ return;
75681+}
75682+
75683+int
75684+gr_handle_signal(const struct task_struct *p, const int sig)
75685+{
75686+#ifdef CONFIG_GRKERNSEC
75687+ /* ignore the 0 signal for protected task checks */
75688+ if (task_pid_nr(current) > 1 && sig && gr_check_protected_task(p)) {
75689+ gr_log_sig_task(GR_DONT_AUDIT, GR_SIG_ACL_MSG, p, sig);
75690+ return -EPERM;
75691+ } else if (gr_pid_is_chrooted((struct task_struct *)p)) {
75692+ return -EPERM;
75693+ }
75694+#endif
75695+ return 0;
75696+}
75697+
75698+#ifdef CONFIG_GRKERNSEC
75699+extern int specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t);
75700+
75701+int gr_fake_force_sig(int sig, struct task_struct *t)
75702+{
75703+ unsigned long int flags;
75704+ int ret, blocked, ignored;
75705+ struct k_sigaction *action;
75706+
75707+ spin_lock_irqsave(&t->sighand->siglock, flags);
75708+ action = &t->sighand->action[sig-1];
75709+ ignored = action->sa.sa_handler == SIG_IGN;
75710+ blocked = sigismember(&t->blocked, sig);
75711+ if (blocked || ignored) {
75712+ action->sa.sa_handler = SIG_DFL;
75713+ if (blocked) {
75714+ sigdelset(&t->blocked, sig);
75715+ recalc_sigpending_and_wake(t);
75716+ }
75717+ }
75718+ if (action->sa.sa_handler == SIG_DFL)
75719+ t->signal->flags &= ~SIGNAL_UNKILLABLE;
75720+ ret = specific_send_sig_info(sig, SEND_SIG_PRIV, t);
75721+
75722+ spin_unlock_irqrestore(&t->sighand->siglock, flags);
75723+
75724+ return ret;
75725+}
75726+#endif
75727+
75728+#define GR_USER_BAN_TIME (15 * 60)
75729+#define GR_DAEMON_BRUTE_TIME (30 * 60)
75730+
75731+void gr_handle_brute_attach(int dumpable)
75732+{
75733+#ifdef CONFIG_GRKERNSEC_BRUTE
75734+ struct task_struct *p = current;
75735+ kuid_t uid = GLOBAL_ROOT_UID;
75736+ int daemon = 0;
75737+
75738+ if (!grsec_enable_brute)
75739+ return;
75740+
75741+ rcu_read_lock();
75742+ read_lock(&tasklist_lock);
75743+ read_lock(&grsec_exec_file_lock);
75744+ if (p->real_parent && gr_is_same_file(p->real_parent->exec_file, p->exec_file)) {
75745+ p->real_parent->brute_expires = get_seconds() + GR_DAEMON_BRUTE_TIME;
75746+ p->real_parent->brute = 1;
75747+ daemon = 1;
75748+ } else {
75749+ const struct cred *cred = __task_cred(p), *cred2;
75750+ struct task_struct *tsk, *tsk2;
75751+
75752+ if (dumpable != SUID_DUMP_USER && gr_is_global_nonroot(cred->uid)) {
75753+ struct user_struct *user;
75754+
75755+ uid = cred->uid;
75756+
75757+ /* this is put upon execution past expiration */
75758+ user = find_user(uid);
75759+ if (user == NULL)
75760+ goto unlock;
75761+ user->suid_banned = 1;
75762+ user->suid_ban_expires = get_seconds() + GR_USER_BAN_TIME;
75763+ if (user->suid_ban_expires == ~0UL)
75764+ user->suid_ban_expires--;
75765+
75766+ /* only kill other threads of the same binary, from the same user */
75767+ do_each_thread(tsk2, tsk) {
75768+ cred2 = __task_cred(tsk);
75769+ if (tsk != p && uid_eq(cred2->uid, uid) && gr_is_same_file(tsk->exec_file, p->exec_file))
75770+ gr_fake_force_sig(SIGKILL, tsk);
75771+ } while_each_thread(tsk2, tsk);
75772+ }
75773+ }
75774+unlock:
75775+ read_unlock(&grsec_exec_file_lock);
75776+ read_unlock(&tasklist_lock);
75777+ rcu_read_unlock();
75778+
75779+ if (gr_is_global_nonroot(uid))
75780+ 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);
75781+ else if (daemon)
75782+ gr_log_noargs(GR_DONT_AUDIT, GR_BRUTE_DAEMON_MSG);
75783+
75784+#endif
75785+ return;
75786+}
75787+
75788+void gr_handle_brute_check(void)
75789+{
75790+#ifdef CONFIG_GRKERNSEC_BRUTE
75791+ struct task_struct *p = current;
75792+
75793+ if (unlikely(p->brute)) {
75794+ if (!grsec_enable_brute)
75795+ p->brute = 0;
75796+ else if (time_before(get_seconds(), p->brute_expires))
75797+ msleep(30 * 1000);
75798+ }
75799+#endif
75800+ return;
75801+}
75802+
75803+void gr_handle_kernel_exploit(void)
75804+{
75805+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
75806+ const struct cred *cred;
75807+ struct task_struct *tsk, *tsk2;
75808+ struct user_struct *user;
75809+ kuid_t uid;
75810+
75811+ if (in_irq() || in_serving_softirq() || in_nmi())
75812+ panic("grsec: halting the system due to suspicious kernel crash caused in interrupt context");
75813+
75814+ uid = current_uid();
75815+
75816+ if (gr_is_global_root(uid))
75817+ panic("grsec: halting the system due to suspicious kernel crash caused by root");
75818+ else {
75819+ /* kill all the processes of this user, hold a reference
75820+ to their creds struct, and prevent them from creating
75821+ another process until system reset
75822+ */
75823+ printk(KERN_ALERT "grsec: banning user with uid %u until system restart for suspicious kernel crash\n",
75824+ GR_GLOBAL_UID(uid));
75825+ /* we intentionally leak this ref */
75826+ user = get_uid(current->cred->user);
75827+ if (user)
75828+ user->kernel_banned = 1;
75829+
75830+ /* kill all processes of this user */
75831+ read_lock(&tasklist_lock);
75832+ do_each_thread(tsk2, tsk) {
75833+ cred = __task_cred(tsk);
75834+ if (uid_eq(cred->uid, uid))
75835+ gr_fake_force_sig(SIGKILL, tsk);
75836+ } while_each_thread(tsk2, tsk);
75837+ read_unlock(&tasklist_lock);
75838+ }
75839+#endif
75840+}
75841+
75842+#ifdef CONFIG_GRKERNSEC_BRUTE
75843+static bool suid_ban_expired(struct user_struct *user)
75844+{
75845+ if (user->suid_ban_expires != ~0UL && time_after_eq(get_seconds(), user->suid_ban_expires)) {
75846+ user->suid_banned = 0;
75847+ user->suid_ban_expires = 0;
75848+ free_uid(user);
75849+ return true;
75850+ }
75851+
75852+ return false;
75853+}
75854+#endif
75855+
75856+int gr_process_kernel_exec_ban(void)
75857+{
75858+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
75859+ if (unlikely(current->cred->user->kernel_banned))
75860+ return -EPERM;
75861+#endif
75862+ return 0;
75863+}
75864+
75865+int gr_process_kernel_setuid_ban(struct user_struct *user)
75866+{
75867+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
75868+ if (unlikely(user->kernel_banned))
75869+ gr_fake_force_sig(SIGKILL, current);
75870+#endif
75871+ return 0;
75872+}
75873+
75874+int gr_process_suid_exec_ban(const struct linux_binprm *bprm)
75875+{
75876+#ifdef CONFIG_GRKERNSEC_BRUTE
75877+ struct user_struct *user = current->cred->user;
75878+ if (unlikely(user->suid_banned)) {
75879+ if (suid_ban_expired(user))
75880+ return 0;
75881+ /* disallow execution of suid binaries only */
75882+ else if (!uid_eq(bprm->cred->euid, current->cred->uid))
75883+ return -EPERM;
75884+ }
75885+#endif
75886+ return 0;
75887+}
75888diff --git a/grsecurity/grsec_sock.c b/grsecurity/grsec_sock.c
75889new file mode 100644
75890index 0000000..c0aef3a
75891--- /dev/null
75892+++ b/grsecurity/grsec_sock.c
75893@@ -0,0 +1,244 @@
75894+#include <linux/kernel.h>
75895+#include <linux/module.h>
75896+#include <linux/sched.h>
75897+#include <linux/file.h>
75898+#include <linux/net.h>
75899+#include <linux/in.h>
75900+#include <linux/ip.h>
75901+#include <net/sock.h>
75902+#include <net/inet_sock.h>
75903+#include <linux/grsecurity.h>
75904+#include <linux/grinternal.h>
75905+#include <linux/gracl.h>
75906+
75907+extern int gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb);
75908+extern int gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr);
75909+
75910+EXPORT_SYMBOL_GPL(gr_search_udp_recvmsg);
75911+EXPORT_SYMBOL_GPL(gr_search_udp_sendmsg);
75912+
75913+#ifdef CONFIG_UNIX_MODULE
75914+EXPORT_SYMBOL_GPL(gr_acl_handle_unix);
75915+EXPORT_SYMBOL_GPL(gr_acl_handle_mknod);
75916+EXPORT_SYMBOL_GPL(gr_handle_chroot_unix);
75917+EXPORT_SYMBOL_GPL(gr_handle_create);
75918+#endif
75919+
75920+#ifdef CONFIG_GRKERNSEC
75921+#define gr_conn_table_size 32749
75922+struct conn_table_entry {
75923+ struct conn_table_entry *next;
75924+ struct signal_struct *sig;
75925+};
75926+
75927+struct conn_table_entry *gr_conn_table[gr_conn_table_size];
75928+DEFINE_SPINLOCK(gr_conn_table_lock);
75929+
75930+extern const char * gr_socktype_to_name(unsigned char type);
75931+extern const char * gr_proto_to_name(unsigned char proto);
75932+extern const char * gr_sockfamily_to_name(unsigned char family);
75933+
75934+static __inline__ int
75935+conn_hash(__u32 saddr, __u32 daddr, __u16 sport, __u16 dport, unsigned int size)
75936+{
75937+ return ((daddr + saddr + (sport << 8) + (dport << 16)) % size);
75938+}
75939+
75940+static __inline__ int
75941+conn_match(const struct signal_struct *sig, __u32 saddr, __u32 daddr,
75942+ __u16 sport, __u16 dport)
75943+{
75944+ if (unlikely(sig->gr_saddr == saddr && sig->gr_daddr == daddr &&
75945+ sig->gr_sport == sport && sig->gr_dport == dport))
75946+ return 1;
75947+ else
75948+ return 0;
75949+}
75950+
75951+static void gr_add_to_task_ip_table_nolock(struct signal_struct *sig, struct conn_table_entry *newent)
75952+{
75953+ struct conn_table_entry **match;
75954+ unsigned int index;
75955+
75956+ index = conn_hash(sig->gr_saddr, sig->gr_daddr,
75957+ sig->gr_sport, sig->gr_dport,
75958+ gr_conn_table_size);
75959+
75960+ newent->sig = sig;
75961+
75962+ match = &gr_conn_table[index];
75963+ newent->next = *match;
75964+ *match = newent;
75965+
75966+ return;
75967+}
75968+
75969+static void gr_del_task_from_ip_table_nolock(struct signal_struct *sig)
75970+{
75971+ struct conn_table_entry *match, *last = NULL;
75972+ unsigned int index;
75973+
75974+ index = conn_hash(sig->gr_saddr, sig->gr_daddr,
75975+ sig->gr_sport, sig->gr_dport,
75976+ gr_conn_table_size);
75977+
75978+ match = gr_conn_table[index];
75979+ while (match && !conn_match(match->sig,
75980+ sig->gr_saddr, sig->gr_daddr, sig->gr_sport,
75981+ sig->gr_dport)) {
75982+ last = match;
75983+ match = match->next;
75984+ }
75985+
75986+ if (match) {
75987+ if (last)
75988+ last->next = match->next;
75989+ else
75990+ gr_conn_table[index] = NULL;
75991+ kfree(match);
75992+ }
75993+
75994+ return;
75995+}
75996+
75997+static struct signal_struct * gr_lookup_task_ip_table(__u32 saddr, __u32 daddr,
75998+ __u16 sport, __u16 dport)
75999+{
76000+ struct conn_table_entry *match;
76001+ unsigned int index;
76002+
76003+ index = conn_hash(saddr, daddr, sport, dport, gr_conn_table_size);
76004+
76005+ match = gr_conn_table[index];
76006+ while (match && !conn_match(match->sig, saddr, daddr, sport, dport))
76007+ match = match->next;
76008+
76009+ if (match)
76010+ return match->sig;
76011+ else
76012+ return NULL;
76013+}
76014+
76015+#endif
76016+
76017+void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet)
76018+{
76019+#ifdef CONFIG_GRKERNSEC
76020+ struct signal_struct *sig = task->signal;
76021+ struct conn_table_entry *newent;
76022+
76023+ newent = kmalloc(sizeof(struct conn_table_entry), GFP_ATOMIC);
76024+ if (newent == NULL)
76025+ return;
76026+ /* no bh lock needed since we are called with bh disabled */
76027+ spin_lock(&gr_conn_table_lock);
76028+ gr_del_task_from_ip_table_nolock(sig);
76029+ sig->gr_saddr = inet->inet_rcv_saddr;
76030+ sig->gr_daddr = inet->inet_daddr;
76031+ sig->gr_sport = inet->inet_sport;
76032+ sig->gr_dport = inet->inet_dport;
76033+ gr_add_to_task_ip_table_nolock(sig, newent);
76034+ spin_unlock(&gr_conn_table_lock);
76035+#endif
76036+ return;
76037+}
76038+
76039+void gr_del_task_from_ip_table(struct task_struct *task)
76040+{
76041+#ifdef CONFIG_GRKERNSEC
76042+ spin_lock_bh(&gr_conn_table_lock);
76043+ gr_del_task_from_ip_table_nolock(task->signal);
76044+ spin_unlock_bh(&gr_conn_table_lock);
76045+#endif
76046+ return;
76047+}
76048+
76049+void
76050+gr_attach_curr_ip(const struct sock *sk)
76051+{
76052+#ifdef CONFIG_GRKERNSEC
76053+ struct signal_struct *p, *set;
76054+ const struct inet_sock *inet = inet_sk(sk);
76055+
76056+ if (unlikely(sk->sk_protocol != IPPROTO_TCP))
76057+ return;
76058+
76059+ set = current->signal;
76060+
76061+ spin_lock_bh(&gr_conn_table_lock);
76062+ p = gr_lookup_task_ip_table(inet->inet_daddr, inet->inet_rcv_saddr,
76063+ inet->inet_dport, inet->inet_sport);
76064+ if (unlikely(p != NULL)) {
76065+ set->curr_ip = p->curr_ip;
76066+ set->used_accept = 1;
76067+ gr_del_task_from_ip_table_nolock(p);
76068+ spin_unlock_bh(&gr_conn_table_lock);
76069+ return;
76070+ }
76071+ spin_unlock_bh(&gr_conn_table_lock);
76072+
76073+ set->curr_ip = inet->inet_daddr;
76074+ set->used_accept = 1;
76075+#endif
76076+ return;
76077+}
76078+
76079+int
76080+gr_handle_sock_all(const int family, const int type, const int protocol)
76081+{
76082+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
76083+ if (grsec_enable_socket_all && in_group_p(grsec_socket_all_gid) &&
76084+ (family != AF_UNIX)) {
76085+ if (family == AF_INET)
76086+ gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), gr_proto_to_name(protocol));
76087+ else
76088+ gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), protocol);
76089+ return -EACCES;
76090+ }
76091+#endif
76092+ return 0;
76093+}
76094+
76095+int
76096+gr_handle_sock_server(const struct sockaddr *sck)
76097+{
76098+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
76099+ if (grsec_enable_socket_server &&
76100+ in_group_p(grsec_socket_server_gid) &&
76101+ sck && (sck->sa_family != AF_UNIX) &&
76102+ (sck->sa_family != AF_LOCAL)) {
76103+ gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
76104+ return -EACCES;
76105+ }
76106+#endif
76107+ return 0;
76108+}
76109+
76110+int
76111+gr_handle_sock_server_other(const struct sock *sck)
76112+{
76113+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
76114+ if (grsec_enable_socket_server &&
76115+ in_group_p(grsec_socket_server_gid) &&
76116+ sck && (sck->sk_family != AF_UNIX) &&
76117+ (sck->sk_family != AF_LOCAL)) {
76118+ gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
76119+ return -EACCES;
76120+ }
76121+#endif
76122+ return 0;
76123+}
76124+
76125+int
76126+gr_handle_sock_client(const struct sockaddr *sck)
76127+{
76128+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
76129+ if (grsec_enable_socket_client && in_group_p(grsec_socket_client_gid) &&
76130+ sck && (sck->sa_family != AF_UNIX) &&
76131+ (sck->sa_family != AF_LOCAL)) {
76132+ gr_log_noargs(GR_DONT_AUDIT, GR_CONNECT_MSG);
76133+ return -EACCES;
76134+ }
76135+#endif
76136+ return 0;
76137+}
76138diff --git a/grsecurity/grsec_sysctl.c b/grsecurity/grsec_sysctl.c
76139new file mode 100644
76140index 0000000..8159888
76141--- /dev/null
76142+++ b/grsecurity/grsec_sysctl.c
76143@@ -0,0 +1,479 @@
76144+#include <linux/kernel.h>
76145+#include <linux/sched.h>
76146+#include <linux/sysctl.h>
76147+#include <linux/grsecurity.h>
76148+#include <linux/grinternal.h>
76149+
76150+int
76151+gr_handle_sysctl_mod(const char *dirname, const char *name, const int op)
76152+{
76153+#ifdef CONFIG_GRKERNSEC_SYSCTL
76154+ if (dirname == NULL || name == NULL)
76155+ return 0;
76156+ if (!strcmp(dirname, "grsecurity") && grsec_lock && (op & MAY_WRITE)) {
76157+ gr_log_str(GR_DONT_AUDIT, GR_SYSCTL_MSG, name);
76158+ return -EACCES;
76159+ }
76160+#endif
76161+ return 0;
76162+}
76163+
76164+#if defined(CONFIG_GRKERNSEC_ROFS) || defined(CONFIG_GRKERNSEC_DENYUSB)
76165+static int __maybe_unused __read_only one = 1;
76166+#endif
76167+
76168+#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS) || \
76169+ defined(CONFIG_GRKERNSEC_DENYUSB)
76170+struct ctl_table grsecurity_table[] = {
76171+#ifdef CONFIG_GRKERNSEC_SYSCTL
76172+#ifdef CONFIG_GRKERNSEC_SYSCTL_DISTRO
76173+#ifdef CONFIG_GRKERNSEC_IO
76174+ {
76175+ .procname = "disable_priv_io",
76176+ .data = &grsec_disable_privio,
76177+ .maxlen = sizeof(int),
76178+ .mode = 0600,
76179+ .proc_handler = &proc_dointvec,
76180+ },
76181+#endif
76182+#endif
76183+#ifdef CONFIG_GRKERNSEC_LINK
76184+ {
76185+ .procname = "linking_restrictions",
76186+ .data = &grsec_enable_link,
76187+ .maxlen = sizeof(int),
76188+ .mode = 0600,
76189+ .proc_handler = &proc_dointvec,
76190+ },
76191+#endif
76192+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
76193+ {
76194+ .procname = "enforce_symlinksifowner",
76195+ .data = &grsec_enable_symlinkown,
76196+ .maxlen = sizeof(int),
76197+ .mode = 0600,
76198+ .proc_handler = &proc_dointvec,
76199+ },
76200+ {
76201+ .procname = "symlinkown_gid",
76202+ .data = &grsec_symlinkown_gid,
76203+ .maxlen = sizeof(int),
76204+ .mode = 0600,
76205+ .proc_handler = &proc_dointvec,
76206+ },
76207+#endif
76208+#ifdef CONFIG_GRKERNSEC_BRUTE
76209+ {
76210+ .procname = "deter_bruteforce",
76211+ .data = &grsec_enable_brute,
76212+ .maxlen = sizeof(int),
76213+ .mode = 0600,
76214+ .proc_handler = &proc_dointvec,
76215+ },
76216+#endif
76217+#ifdef CONFIG_GRKERNSEC_FIFO
76218+ {
76219+ .procname = "fifo_restrictions",
76220+ .data = &grsec_enable_fifo,
76221+ .maxlen = sizeof(int),
76222+ .mode = 0600,
76223+ .proc_handler = &proc_dointvec,
76224+ },
76225+#endif
76226+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
76227+ {
76228+ .procname = "ptrace_readexec",
76229+ .data = &grsec_enable_ptrace_readexec,
76230+ .maxlen = sizeof(int),
76231+ .mode = 0600,
76232+ .proc_handler = &proc_dointvec,
76233+ },
76234+#endif
76235+#ifdef CONFIG_GRKERNSEC_SETXID
76236+ {
76237+ .procname = "consistent_setxid",
76238+ .data = &grsec_enable_setxid,
76239+ .maxlen = sizeof(int),
76240+ .mode = 0600,
76241+ .proc_handler = &proc_dointvec,
76242+ },
76243+#endif
76244+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76245+ {
76246+ .procname = "ip_blackhole",
76247+ .data = &grsec_enable_blackhole,
76248+ .maxlen = sizeof(int),
76249+ .mode = 0600,
76250+ .proc_handler = &proc_dointvec,
76251+ },
76252+ {
76253+ .procname = "lastack_retries",
76254+ .data = &grsec_lastack_retries,
76255+ .maxlen = sizeof(int),
76256+ .mode = 0600,
76257+ .proc_handler = &proc_dointvec,
76258+ },
76259+#endif
76260+#ifdef CONFIG_GRKERNSEC_EXECLOG
76261+ {
76262+ .procname = "exec_logging",
76263+ .data = &grsec_enable_execlog,
76264+ .maxlen = sizeof(int),
76265+ .mode = 0600,
76266+ .proc_handler = &proc_dointvec,
76267+ },
76268+#endif
76269+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
76270+ {
76271+ .procname = "rwxmap_logging",
76272+ .data = &grsec_enable_log_rwxmaps,
76273+ .maxlen = sizeof(int),
76274+ .mode = 0600,
76275+ .proc_handler = &proc_dointvec,
76276+ },
76277+#endif
76278+#ifdef CONFIG_GRKERNSEC_SIGNAL
76279+ {
76280+ .procname = "signal_logging",
76281+ .data = &grsec_enable_signal,
76282+ .maxlen = sizeof(int),
76283+ .mode = 0600,
76284+ .proc_handler = &proc_dointvec,
76285+ },
76286+#endif
76287+#ifdef CONFIG_GRKERNSEC_FORKFAIL
76288+ {
76289+ .procname = "forkfail_logging",
76290+ .data = &grsec_enable_forkfail,
76291+ .maxlen = sizeof(int),
76292+ .mode = 0600,
76293+ .proc_handler = &proc_dointvec,
76294+ },
76295+#endif
76296+#ifdef CONFIG_GRKERNSEC_TIME
76297+ {
76298+ .procname = "timechange_logging",
76299+ .data = &grsec_enable_time,
76300+ .maxlen = sizeof(int),
76301+ .mode = 0600,
76302+ .proc_handler = &proc_dointvec,
76303+ },
76304+#endif
76305+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
76306+ {
76307+ .procname = "chroot_deny_shmat",
76308+ .data = &grsec_enable_chroot_shmat,
76309+ .maxlen = sizeof(int),
76310+ .mode = 0600,
76311+ .proc_handler = &proc_dointvec,
76312+ },
76313+#endif
76314+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
76315+ {
76316+ .procname = "chroot_deny_unix",
76317+ .data = &grsec_enable_chroot_unix,
76318+ .maxlen = sizeof(int),
76319+ .mode = 0600,
76320+ .proc_handler = &proc_dointvec,
76321+ },
76322+#endif
76323+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
76324+ {
76325+ .procname = "chroot_deny_mount",
76326+ .data = &grsec_enable_chroot_mount,
76327+ .maxlen = sizeof(int),
76328+ .mode = 0600,
76329+ .proc_handler = &proc_dointvec,
76330+ },
76331+#endif
76332+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
76333+ {
76334+ .procname = "chroot_deny_fchdir",
76335+ .data = &grsec_enable_chroot_fchdir,
76336+ .maxlen = sizeof(int),
76337+ .mode = 0600,
76338+ .proc_handler = &proc_dointvec,
76339+ },
76340+#endif
76341+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
76342+ {
76343+ .procname = "chroot_deny_chroot",
76344+ .data = &grsec_enable_chroot_double,
76345+ .maxlen = sizeof(int),
76346+ .mode = 0600,
76347+ .proc_handler = &proc_dointvec,
76348+ },
76349+#endif
76350+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
76351+ {
76352+ .procname = "chroot_deny_pivot",
76353+ .data = &grsec_enable_chroot_pivot,
76354+ .maxlen = sizeof(int),
76355+ .mode = 0600,
76356+ .proc_handler = &proc_dointvec,
76357+ },
76358+#endif
76359+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
76360+ {
76361+ .procname = "chroot_enforce_chdir",
76362+ .data = &grsec_enable_chroot_chdir,
76363+ .maxlen = sizeof(int),
76364+ .mode = 0600,
76365+ .proc_handler = &proc_dointvec,
76366+ },
76367+#endif
76368+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
76369+ {
76370+ .procname = "chroot_deny_chmod",
76371+ .data = &grsec_enable_chroot_chmod,
76372+ .maxlen = sizeof(int),
76373+ .mode = 0600,
76374+ .proc_handler = &proc_dointvec,
76375+ },
76376+#endif
76377+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
76378+ {
76379+ .procname = "chroot_deny_mknod",
76380+ .data = &grsec_enable_chroot_mknod,
76381+ .maxlen = sizeof(int),
76382+ .mode = 0600,
76383+ .proc_handler = &proc_dointvec,
76384+ },
76385+#endif
76386+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
76387+ {
76388+ .procname = "chroot_restrict_nice",
76389+ .data = &grsec_enable_chroot_nice,
76390+ .maxlen = sizeof(int),
76391+ .mode = 0600,
76392+ .proc_handler = &proc_dointvec,
76393+ },
76394+#endif
76395+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
76396+ {
76397+ .procname = "chroot_execlog",
76398+ .data = &grsec_enable_chroot_execlog,
76399+ .maxlen = sizeof(int),
76400+ .mode = 0600,
76401+ .proc_handler = &proc_dointvec,
76402+ },
76403+#endif
76404+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
76405+ {
76406+ .procname = "chroot_caps",
76407+ .data = &grsec_enable_chroot_caps,
76408+ .maxlen = sizeof(int),
76409+ .mode = 0600,
76410+ .proc_handler = &proc_dointvec,
76411+ },
76412+#endif
76413+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
76414+ {
76415+ .procname = "chroot_deny_sysctl",
76416+ .data = &grsec_enable_chroot_sysctl,
76417+ .maxlen = sizeof(int),
76418+ .mode = 0600,
76419+ .proc_handler = &proc_dointvec,
76420+ },
76421+#endif
76422+#ifdef CONFIG_GRKERNSEC_TPE
76423+ {
76424+ .procname = "tpe",
76425+ .data = &grsec_enable_tpe,
76426+ .maxlen = sizeof(int),
76427+ .mode = 0600,
76428+ .proc_handler = &proc_dointvec,
76429+ },
76430+ {
76431+ .procname = "tpe_gid",
76432+ .data = &grsec_tpe_gid,
76433+ .maxlen = sizeof(int),
76434+ .mode = 0600,
76435+ .proc_handler = &proc_dointvec,
76436+ },
76437+#endif
76438+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
76439+ {
76440+ .procname = "tpe_invert",
76441+ .data = &grsec_enable_tpe_invert,
76442+ .maxlen = sizeof(int),
76443+ .mode = 0600,
76444+ .proc_handler = &proc_dointvec,
76445+ },
76446+#endif
76447+#ifdef CONFIG_GRKERNSEC_TPE_ALL
76448+ {
76449+ .procname = "tpe_restrict_all",
76450+ .data = &grsec_enable_tpe_all,
76451+ .maxlen = sizeof(int),
76452+ .mode = 0600,
76453+ .proc_handler = &proc_dointvec,
76454+ },
76455+#endif
76456+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
76457+ {
76458+ .procname = "socket_all",
76459+ .data = &grsec_enable_socket_all,
76460+ .maxlen = sizeof(int),
76461+ .mode = 0600,
76462+ .proc_handler = &proc_dointvec,
76463+ },
76464+ {
76465+ .procname = "socket_all_gid",
76466+ .data = &grsec_socket_all_gid,
76467+ .maxlen = sizeof(int),
76468+ .mode = 0600,
76469+ .proc_handler = &proc_dointvec,
76470+ },
76471+#endif
76472+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
76473+ {
76474+ .procname = "socket_client",
76475+ .data = &grsec_enable_socket_client,
76476+ .maxlen = sizeof(int),
76477+ .mode = 0600,
76478+ .proc_handler = &proc_dointvec,
76479+ },
76480+ {
76481+ .procname = "socket_client_gid",
76482+ .data = &grsec_socket_client_gid,
76483+ .maxlen = sizeof(int),
76484+ .mode = 0600,
76485+ .proc_handler = &proc_dointvec,
76486+ },
76487+#endif
76488+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
76489+ {
76490+ .procname = "socket_server",
76491+ .data = &grsec_enable_socket_server,
76492+ .maxlen = sizeof(int),
76493+ .mode = 0600,
76494+ .proc_handler = &proc_dointvec,
76495+ },
76496+ {
76497+ .procname = "socket_server_gid",
76498+ .data = &grsec_socket_server_gid,
76499+ .maxlen = sizeof(int),
76500+ .mode = 0600,
76501+ .proc_handler = &proc_dointvec,
76502+ },
76503+#endif
76504+#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
76505+ {
76506+ .procname = "audit_group",
76507+ .data = &grsec_enable_group,
76508+ .maxlen = sizeof(int),
76509+ .mode = 0600,
76510+ .proc_handler = &proc_dointvec,
76511+ },
76512+ {
76513+ .procname = "audit_gid",
76514+ .data = &grsec_audit_gid,
76515+ .maxlen = sizeof(int),
76516+ .mode = 0600,
76517+ .proc_handler = &proc_dointvec,
76518+ },
76519+#endif
76520+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
76521+ {
76522+ .procname = "audit_chdir",
76523+ .data = &grsec_enable_chdir,
76524+ .maxlen = sizeof(int),
76525+ .mode = 0600,
76526+ .proc_handler = &proc_dointvec,
76527+ },
76528+#endif
76529+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
76530+ {
76531+ .procname = "audit_mount",
76532+ .data = &grsec_enable_mount,
76533+ .maxlen = sizeof(int),
76534+ .mode = 0600,
76535+ .proc_handler = &proc_dointvec,
76536+ },
76537+#endif
76538+#ifdef CONFIG_GRKERNSEC_DMESG
76539+ {
76540+ .procname = "dmesg",
76541+ .data = &grsec_enable_dmesg,
76542+ .maxlen = sizeof(int),
76543+ .mode = 0600,
76544+ .proc_handler = &proc_dointvec,
76545+ },
76546+#endif
76547+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
76548+ {
76549+ .procname = "chroot_findtask",
76550+ .data = &grsec_enable_chroot_findtask,
76551+ .maxlen = sizeof(int),
76552+ .mode = 0600,
76553+ .proc_handler = &proc_dointvec,
76554+ },
76555+#endif
76556+#ifdef CONFIG_GRKERNSEC_RESLOG
76557+ {
76558+ .procname = "resource_logging",
76559+ .data = &grsec_resource_logging,
76560+ .maxlen = sizeof(int),
76561+ .mode = 0600,
76562+ .proc_handler = &proc_dointvec,
76563+ },
76564+#endif
76565+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
76566+ {
76567+ .procname = "audit_ptrace",
76568+ .data = &grsec_enable_audit_ptrace,
76569+ .maxlen = sizeof(int),
76570+ .mode = 0600,
76571+ .proc_handler = &proc_dointvec,
76572+ },
76573+#endif
76574+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
76575+ {
76576+ .procname = "harden_ptrace",
76577+ .data = &grsec_enable_harden_ptrace,
76578+ .maxlen = sizeof(int),
76579+ .mode = 0600,
76580+ .proc_handler = &proc_dointvec,
76581+ },
76582+#endif
76583+#ifdef CONFIG_GRKERNSEC_HARDEN_IPC
76584+ {
76585+ .procname = "harden_ipc",
76586+ .data = &grsec_enable_harden_ipc,
76587+ .maxlen = sizeof(int),
76588+ .mode = 0600,
76589+ .proc_handler = &proc_dointvec,
76590+ },
76591+#endif
76592+ {
76593+ .procname = "grsec_lock",
76594+ .data = &grsec_lock,
76595+ .maxlen = sizeof(int),
76596+ .mode = 0600,
76597+ .proc_handler = &proc_dointvec,
76598+ },
76599+#endif
76600+#ifdef CONFIG_GRKERNSEC_ROFS
76601+ {
76602+ .procname = "romount_protect",
76603+ .data = &grsec_enable_rofs,
76604+ .maxlen = sizeof(int),
76605+ .mode = 0600,
76606+ .proc_handler = &proc_dointvec_minmax,
76607+ .extra1 = &one,
76608+ .extra2 = &one,
76609+ },
76610+#endif
76611+#if defined(CONFIG_GRKERNSEC_DENYUSB) && !defined(CONFIG_GRKERNSEC_DENYUSB_FORCE)
76612+ {
76613+ .procname = "deny_new_usb",
76614+ .data = &grsec_deny_new_usb,
76615+ .maxlen = sizeof(int),
76616+ .mode = 0600,
76617+ .proc_handler = &proc_dointvec,
76618+ },
76619+#endif
76620+ { }
76621+};
76622+#endif
76623diff --git a/grsecurity/grsec_time.c b/grsecurity/grsec_time.c
76624new file mode 100644
76625index 0000000..61b514e
76626--- /dev/null
76627+++ b/grsecurity/grsec_time.c
76628@@ -0,0 +1,16 @@
76629+#include <linux/kernel.h>
76630+#include <linux/sched.h>
76631+#include <linux/grinternal.h>
76632+#include <linux/module.h>
76633+
76634+void
76635+gr_log_timechange(void)
76636+{
76637+#ifdef CONFIG_GRKERNSEC_TIME
76638+ if (grsec_enable_time)
76639+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_TIME_MSG);
76640+#endif
76641+ return;
76642+}
76643+
76644+EXPORT_SYMBOL_GPL(gr_log_timechange);
76645diff --git a/grsecurity/grsec_tpe.c b/grsecurity/grsec_tpe.c
76646new file mode 100644
76647index 0000000..ee57dcf
76648--- /dev/null
76649+++ b/grsecurity/grsec_tpe.c
76650@@ -0,0 +1,73 @@
76651+#include <linux/kernel.h>
76652+#include <linux/sched.h>
76653+#include <linux/file.h>
76654+#include <linux/fs.h>
76655+#include <linux/grinternal.h>
76656+
76657+extern int gr_acl_tpe_check(void);
76658+
76659+int
76660+gr_tpe_allow(const struct file *file)
76661+{
76662+#ifdef CONFIG_GRKERNSEC
76663+ struct inode *inode = file->f_path.dentry->d_parent->d_inode;
76664+ const struct cred *cred = current_cred();
76665+ char *msg = NULL;
76666+ char *msg2 = NULL;
76667+
76668+ // never restrict root
76669+ if (gr_is_global_root(cred->uid))
76670+ return 1;
76671+
76672+ if (grsec_enable_tpe) {
76673+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
76674+ if (grsec_enable_tpe_invert && !in_group_p(grsec_tpe_gid))
76675+ msg = "not being in trusted group";
76676+ else if (!grsec_enable_tpe_invert && in_group_p(grsec_tpe_gid))
76677+ msg = "being in untrusted group";
76678+#else
76679+ if (in_group_p(grsec_tpe_gid))
76680+ msg = "being in untrusted group";
76681+#endif
76682+ }
76683+ if (!msg && gr_acl_tpe_check())
76684+ msg = "being in untrusted role";
76685+
76686+ // not in any affected group/role
76687+ if (!msg)
76688+ goto next_check;
76689+
76690+ if (gr_is_global_nonroot(inode->i_uid))
76691+ msg2 = "file in non-root-owned directory";
76692+ else if (inode->i_mode & S_IWOTH)
76693+ msg2 = "file in world-writable directory";
76694+ else if (inode->i_mode & S_IWGRP)
76695+ msg2 = "file in group-writable directory";
76696+
76697+ if (msg && msg2) {
76698+ char fullmsg[70] = {0};
76699+ snprintf(fullmsg, sizeof(fullmsg)-1, "%s and %s", msg, msg2);
76700+ gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, fullmsg, file->f_path.dentry, file->f_path.mnt);
76701+ return 0;
76702+ }
76703+ msg = NULL;
76704+next_check:
76705+#ifdef CONFIG_GRKERNSEC_TPE_ALL
76706+ if (!grsec_enable_tpe || !grsec_enable_tpe_all)
76707+ return 1;
76708+
76709+ if (gr_is_global_nonroot(inode->i_uid) && !uid_eq(inode->i_uid, cred->uid))
76710+ msg = "directory not owned by user";
76711+ else if (inode->i_mode & S_IWOTH)
76712+ msg = "file in world-writable directory";
76713+ else if (inode->i_mode & S_IWGRP)
76714+ msg = "file in group-writable directory";
76715+
76716+ if (msg) {
76717+ gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, msg, file->f_path.dentry, file->f_path.mnt);
76718+ return 0;
76719+ }
76720+#endif
76721+#endif
76722+ return 1;
76723+}
76724diff --git a/grsecurity/grsec_usb.c b/grsecurity/grsec_usb.c
76725new file mode 100644
76726index 0000000..ae02d8e
76727--- /dev/null
76728+++ b/grsecurity/grsec_usb.c
76729@@ -0,0 +1,15 @@
76730+#include <linux/kernel.h>
76731+#include <linux/grinternal.h>
76732+#include <linux/module.h>
76733+
76734+int gr_handle_new_usb(void)
76735+{
76736+#ifdef CONFIG_GRKERNSEC_DENYUSB
76737+ if (grsec_deny_new_usb) {
76738+ printk(KERN_ALERT "grsec: denied insert of new USB device\n");
76739+ return 1;
76740+ }
76741+#endif
76742+ return 0;
76743+}
76744+EXPORT_SYMBOL_GPL(gr_handle_new_usb);
76745diff --git a/grsecurity/grsum.c b/grsecurity/grsum.c
76746new file mode 100644
76747index 0000000..9f7b1ac
76748--- /dev/null
76749+++ b/grsecurity/grsum.c
76750@@ -0,0 +1,61 @@
76751+#include <linux/err.h>
76752+#include <linux/kernel.h>
76753+#include <linux/sched.h>
76754+#include <linux/mm.h>
76755+#include <linux/scatterlist.h>
76756+#include <linux/crypto.h>
76757+#include <linux/gracl.h>
76758+
76759+
76760+#if !defined(CONFIG_CRYPTO) || defined(CONFIG_CRYPTO_MODULE) || !defined(CONFIG_CRYPTO_SHA256) || defined(CONFIG_CRYPTO_SHA256_MODULE)
76761+#error "crypto and sha256 must be built into the kernel"
76762+#endif
76763+
76764+int
76765+chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum)
76766+{
76767+ char *p;
76768+ struct crypto_hash *tfm;
76769+ struct hash_desc desc;
76770+ struct scatterlist sg;
76771+ unsigned char temp_sum[GR_SHA_LEN];
76772+ volatile int retval = 0;
76773+ volatile int dummy = 0;
76774+ unsigned int i;
76775+
76776+ sg_init_table(&sg, 1);
76777+
76778+ tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
76779+ if (IS_ERR(tfm)) {
76780+ /* should never happen, since sha256 should be built in */
76781+ return 1;
76782+ }
76783+
76784+ desc.tfm = tfm;
76785+ desc.flags = 0;
76786+
76787+ crypto_hash_init(&desc);
76788+
76789+ p = salt;
76790+ sg_set_buf(&sg, p, GR_SALT_LEN);
76791+ crypto_hash_update(&desc, &sg, sg.length);
76792+
76793+ p = entry->pw;
76794+ sg_set_buf(&sg, p, strlen(p));
76795+
76796+ crypto_hash_update(&desc, &sg, sg.length);
76797+
76798+ crypto_hash_final(&desc, temp_sum);
76799+
76800+ memset(entry->pw, 0, GR_PW_LEN);
76801+
76802+ for (i = 0; i < GR_SHA_LEN; i++)
76803+ if (sum[i] != temp_sum[i])
76804+ retval = 1;
76805+ else
76806+ dummy = 1; // waste a cycle
76807+
76808+ crypto_free_hash(tfm);
76809+
76810+ return retval;
76811+}
76812diff --git a/include/asm-generic/4level-fixup.h b/include/asm-generic/4level-fixup.h
76813index 77ff547..181834f 100644
76814--- a/include/asm-generic/4level-fixup.h
76815+++ b/include/asm-generic/4level-fixup.h
76816@@ -13,8 +13,10 @@
76817 #define pmd_alloc(mm, pud, address) \
76818 ((unlikely(pgd_none(*(pud))) && __pmd_alloc(mm, pud, address))? \
76819 NULL: pmd_offset(pud, address))
76820+#define pmd_alloc_kernel(mm, pud, address) pmd_alloc((mm), (pud), (address))
76821
76822 #define pud_alloc(mm, pgd, address) (pgd)
76823+#define pud_alloc_kernel(mm, pgd, address) pud_alloc((mm), (pgd), (address))
76824 #define pud_offset(pgd, start) (pgd)
76825 #define pud_none(pud) 0
76826 #define pud_bad(pud) 0
76827diff --git a/include/asm-generic/atomic-long.h b/include/asm-generic/atomic-long.h
76828index b7babf0..97f4c4f 100644
76829--- a/include/asm-generic/atomic-long.h
76830+++ b/include/asm-generic/atomic-long.h
76831@@ -22,6 +22,12 @@
76832
76833 typedef atomic64_t atomic_long_t;
76834
76835+#ifdef CONFIG_PAX_REFCOUNT
76836+typedef atomic64_unchecked_t atomic_long_unchecked_t;
76837+#else
76838+typedef atomic64_t atomic_long_unchecked_t;
76839+#endif
76840+
76841 #define ATOMIC_LONG_INIT(i) ATOMIC64_INIT(i)
76842
76843 static inline long atomic_long_read(atomic_long_t *l)
76844@@ -31,6 +37,15 @@ static inline long atomic_long_read(atomic_long_t *l)
76845 return (long)atomic64_read(v);
76846 }
76847
76848+#ifdef CONFIG_PAX_REFCOUNT
76849+static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
76850+{
76851+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
76852+
76853+ return (long)atomic64_read_unchecked(v);
76854+}
76855+#endif
76856+
76857 static inline void atomic_long_set(atomic_long_t *l, long i)
76858 {
76859 atomic64_t *v = (atomic64_t *)l;
76860@@ -38,6 +53,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
76861 atomic64_set(v, i);
76862 }
76863
76864+#ifdef CONFIG_PAX_REFCOUNT
76865+static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
76866+{
76867+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
76868+
76869+ atomic64_set_unchecked(v, i);
76870+}
76871+#endif
76872+
76873 static inline void atomic_long_inc(atomic_long_t *l)
76874 {
76875 atomic64_t *v = (atomic64_t *)l;
76876@@ -45,6 +69,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
76877 atomic64_inc(v);
76878 }
76879
76880+#ifdef CONFIG_PAX_REFCOUNT
76881+static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
76882+{
76883+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
76884+
76885+ atomic64_inc_unchecked(v);
76886+}
76887+#endif
76888+
76889 static inline void atomic_long_dec(atomic_long_t *l)
76890 {
76891 atomic64_t *v = (atomic64_t *)l;
76892@@ -52,6 +85,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
76893 atomic64_dec(v);
76894 }
76895
76896+#ifdef CONFIG_PAX_REFCOUNT
76897+static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
76898+{
76899+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
76900+
76901+ atomic64_dec_unchecked(v);
76902+}
76903+#endif
76904+
76905 static inline void atomic_long_add(long i, atomic_long_t *l)
76906 {
76907 atomic64_t *v = (atomic64_t *)l;
76908@@ -59,6 +101,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
76909 atomic64_add(i, v);
76910 }
76911
76912+#ifdef CONFIG_PAX_REFCOUNT
76913+static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
76914+{
76915+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
76916+
76917+ atomic64_add_unchecked(i, v);
76918+}
76919+#endif
76920+
76921 static inline void atomic_long_sub(long i, atomic_long_t *l)
76922 {
76923 atomic64_t *v = (atomic64_t *)l;
76924@@ -66,6 +117,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
76925 atomic64_sub(i, v);
76926 }
76927
76928+#ifdef CONFIG_PAX_REFCOUNT
76929+static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
76930+{
76931+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
76932+
76933+ atomic64_sub_unchecked(i, v);
76934+}
76935+#endif
76936+
76937 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
76938 {
76939 atomic64_t *v = (atomic64_t *)l;
76940@@ -94,13 +154,22 @@ static inline int atomic_long_add_negative(long i, atomic_long_t *l)
76941 return atomic64_add_negative(i, v);
76942 }
76943
76944-static inline long atomic_long_add_return(long i, atomic_long_t *l)
76945+static inline long __intentional_overflow(-1) atomic_long_add_return(long i, atomic_long_t *l)
76946 {
76947 atomic64_t *v = (atomic64_t *)l;
76948
76949 return (long)atomic64_add_return(i, v);
76950 }
76951
76952+#ifdef CONFIG_PAX_REFCOUNT
76953+static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
76954+{
76955+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
76956+
76957+ return (long)atomic64_add_return_unchecked(i, v);
76958+}
76959+#endif
76960+
76961 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
76962 {
76963 atomic64_t *v = (atomic64_t *)l;
76964@@ -115,6 +184,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
76965 return (long)atomic64_inc_return(v);
76966 }
76967
76968+#ifdef CONFIG_PAX_REFCOUNT
76969+static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
76970+{
76971+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
76972+
76973+ return (long)atomic64_inc_return_unchecked(v);
76974+}
76975+#endif
76976+
76977 static inline long atomic_long_dec_return(atomic_long_t *l)
76978 {
76979 atomic64_t *v = (atomic64_t *)l;
76980@@ -140,6 +218,12 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
76981
76982 typedef atomic_t atomic_long_t;
76983
76984+#ifdef CONFIG_PAX_REFCOUNT
76985+typedef atomic_unchecked_t atomic_long_unchecked_t;
76986+#else
76987+typedef atomic_t atomic_long_unchecked_t;
76988+#endif
76989+
76990 #define ATOMIC_LONG_INIT(i) ATOMIC_INIT(i)
76991 static inline long atomic_long_read(atomic_long_t *l)
76992 {
76993@@ -148,6 +232,15 @@ static inline long atomic_long_read(atomic_long_t *l)
76994 return (long)atomic_read(v);
76995 }
76996
76997+#ifdef CONFIG_PAX_REFCOUNT
76998+static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
76999+{
77000+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
77001+
77002+ return (long)atomic_read_unchecked(v);
77003+}
77004+#endif
77005+
77006 static inline void atomic_long_set(atomic_long_t *l, long i)
77007 {
77008 atomic_t *v = (atomic_t *)l;
77009@@ -155,6 +248,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
77010 atomic_set(v, i);
77011 }
77012
77013+#ifdef CONFIG_PAX_REFCOUNT
77014+static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
77015+{
77016+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
77017+
77018+ atomic_set_unchecked(v, i);
77019+}
77020+#endif
77021+
77022 static inline void atomic_long_inc(atomic_long_t *l)
77023 {
77024 atomic_t *v = (atomic_t *)l;
77025@@ -162,6 +264,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
77026 atomic_inc(v);
77027 }
77028
77029+#ifdef CONFIG_PAX_REFCOUNT
77030+static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
77031+{
77032+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
77033+
77034+ atomic_inc_unchecked(v);
77035+}
77036+#endif
77037+
77038 static inline void atomic_long_dec(atomic_long_t *l)
77039 {
77040 atomic_t *v = (atomic_t *)l;
77041@@ -169,6 +280,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
77042 atomic_dec(v);
77043 }
77044
77045+#ifdef CONFIG_PAX_REFCOUNT
77046+static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
77047+{
77048+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
77049+
77050+ atomic_dec_unchecked(v);
77051+}
77052+#endif
77053+
77054 static inline void atomic_long_add(long i, atomic_long_t *l)
77055 {
77056 atomic_t *v = (atomic_t *)l;
77057@@ -176,6 +296,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
77058 atomic_add(i, v);
77059 }
77060
77061+#ifdef CONFIG_PAX_REFCOUNT
77062+static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
77063+{
77064+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
77065+
77066+ atomic_add_unchecked(i, v);
77067+}
77068+#endif
77069+
77070 static inline void atomic_long_sub(long i, atomic_long_t *l)
77071 {
77072 atomic_t *v = (atomic_t *)l;
77073@@ -183,6 +312,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
77074 atomic_sub(i, v);
77075 }
77076
77077+#ifdef CONFIG_PAX_REFCOUNT
77078+static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
77079+{
77080+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
77081+
77082+ atomic_sub_unchecked(i, v);
77083+}
77084+#endif
77085+
77086 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
77087 {
77088 atomic_t *v = (atomic_t *)l;
77089@@ -218,6 +356,16 @@ static inline long atomic_long_add_return(long i, atomic_long_t *l)
77090 return (long)atomic_add_return(i, v);
77091 }
77092
77093+#ifdef CONFIG_PAX_REFCOUNT
77094+static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
77095+{
77096+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
77097+
77098+ return (long)atomic_add_return_unchecked(i, v);
77099+}
77100+
77101+#endif
77102+
77103 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
77104 {
77105 atomic_t *v = (atomic_t *)l;
77106@@ -232,6 +380,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
77107 return (long)atomic_inc_return(v);
77108 }
77109
77110+#ifdef CONFIG_PAX_REFCOUNT
77111+static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
77112+{
77113+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
77114+
77115+ return (long)atomic_inc_return_unchecked(v);
77116+}
77117+#endif
77118+
77119 static inline long atomic_long_dec_return(atomic_long_t *l)
77120 {
77121 atomic_t *v = (atomic_t *)l;
77122@@ -255,4 +412,57 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
77123
77124 #endif /* BITS_PER_LONG == 64 */
77125
77126+#ifdef CONFIG_PAX_REFCOUNT
77127+static inline void pax_refcount_needs_these_functions(void)
77128+{
77129+ atomic_read_unchecked((atomic_unchecked_t *)NULL);
77130+ atomic_set_unchecked((atomic_unchecked_t *)NULL, 0);
77131+ atomic_add_unchecked(0, (atomic_unchecked_t *)NULL);
77132+ atomic_sub_unchecked(0, (atomic_unchecked_t *)NULL);
77133+ atomic_inc_unchecked((atomic_unchecked_t *)NULL);
77134+ (void)atomic_inc_and_test_unchecked((atomic_unchecked_t *)NULL);
77135+ atomic_inc_return_unchecked((atomic_unchecked_t *)NULL);
77136+ atomic_add_return_unchecked(0, (atomic_unchecked_t *)NULL);
77137+ atomic_dec_unchecked((atomic_unchecked_t *)NULL);
77138+ atomic_cmpxchg_unchecked((atomic_unchecked_t *)NULL, 0, 0);
77139+ (void)atomic_xchg_unchecked((atomic_unchecked_t *)NULL, 0);
77140+#ifdef CONFIG_X86
77141+ atomic_clear_mask_unchecked(0, NULL);
77142+ atomic_set_mask_unchecked(0, NULL);
77143+#endif
77144+
77145+ atomic_long_read_unchecked((atomic_long_unchecked_t *)NULL);
77146+ atomic_long_set_unchecked((atomic_long_unchecked_t *)NULL, 0);
77147+ atomic_long_add_unchecked(0, (atomic_long_unchecked_t *)NULL);
77148+ atomic_long_sub_unchecked(0, (atomic_long_unchecked_t *)NULL);
77149+ atomic_long_inc_unchecked((atomic_long_unchecked_t *)NULL);
77150+ atomic_long_add_return_unchecked(0, (atomic_long_unchecked_t *)NULL);
77151+ atomic_long_inc_return_unchecked((atomic_long_unchecked_t *)NULL);
77152+ atomic_long_dec_unchecked((atomic_long_unchecked_t *)NULL);
77153+}
77154+#else
77155+#define atomic_read_unchecked(v) atomic_read(v)
77156+#define atomic_set_unchecked(v, i) atomic_set((v), (i))
77157+#define atomic_add_unchecked(i, v) atomic_add((i), (v))
77158+#define atomic_sub_unchecked(i, v) atomic_sub((i), (v))
77159+#define atomic_inc_unchecked(v) atomic_inc(v)
77160+#define atomic_inc_and_test_unchecked(v) atomic_inc_and_test(v)
77161+#define atomic_inc_return_unchecked(v) atomic_inc_return(v)
77162+#define atomic_add_return_unchecked(i, v) atomic_add_return((i), (v))
77163+#define atomic_dec_unchecked(v) atomic_dec(v)
77164+#define atomic_cmpxchg_unchecked(v, o, n) atomic_cmpxchg((v), (o), (n))
77165+#define atomic_xchg_unchecked(v, i) atomic_xchg((v), (i))
77166+#define atomic_clear_mask_unchecked(mask, v) atomic_clear_mask((mask), (v))
77167+#define atomic_set_mask_unchecked(mask, v) atomic_set_mask((mask), (v))
77168+
77169+#define atomic_long_read_unchecked(v) atomic_long_read(v)
77170+#define atomic_long_set_unchecked(v, i) atomic_long_set((v), (i))
77171+#define atomic_long_add_unchecked(i, v) atomic_long_add((i), (v))
77172+#define atomic_long_sub_unchecked(i, v) atomic_long_sub((i), (v))
77173+#define atomic_long_inc_unchecked(v) atomic_long_inc(v)
77174+#define atomic_long_add_return_unchecked(i, v) atomic_long_add_return((i), (v))
77175+#define atomic_long_inc_return_unchecked(v) atomic_long_inc_return(v)
77176+#define atomic_long_dec_unchecked(v) atomic_long_dec(v)
77177+#endif
77178+
77179 #endif /* _ASM_GENERIC_ATOMIC_LONG_H */
77180diff --git a/include/asm-generic/atomic.h b/include/asm-generic/atomic.h
77181index 33bd2de..f31bff97 100644
77182--- a/include/asm-generic/atomic.h
77183+++ b/include/asm-generic/atomic.h
77184@@ -153,7 +153,7 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
77185 * Atomically clears the bits set in @mask from @v
77186 */
77187 #ifndef atomic_clear_mask
77188-static inline void atomic_clear_mask(unsigned long mask, atomic_t *v)
77189+static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
77190 {
77191 unsigned long flags;
77192
77193diff --git a/include/asm-generic/atomic64.h b/include/asm-generic/atomic64.h
77194index b18ce4f..2ee2843 100644
77195--- a/include/asm-generic/atomic64.h
77196+++ b/include/asm-generic/atomic64.h
77197@@ -16,6 +16,8 @@ typedef struct {
77198 long long counter;
77199 } atomic64_t;
77200
77201+typedef atomic64_t atomic64_unchecked_t;
77202+
77203 #define ATOMIC64_INIT(i) { (i) }
77204
77205 extern long long atomic64_read(const atomic64_t *v);
77206@@ -39,4 +41,14 @@ extern int atomic64_add_unless(atomic64_t *v, long long a, long long u);
77207 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
77208 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
77209
77210+#define atomic64_read_unchecked(v) atomic64_read(v)
77211+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
77212+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
77213+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
77214+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
77215+#define atomic64_inc_unchecked(v) atomic64_inc(v)
77216+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
77217+#define atomic64_dec_unchecked(v) atomic64_dec(v)
77218+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
77219+
77220 #endif /* _ASM_GENERIC_ATOMIC64_H */
77221diff --git a/include/asm-generic/bitops/__fls.h b/include/asm-generic/bitops/__fls.h
77222index a60a7cc..0fe12f2 100644
77223--- a/include/asm-generic/bitops/__fls.h
77224+++ b/include/asm-generic/bitops/__fls.h
77225@@ -9,7 +9,7 @@
77226 *
77227 * Undefined if no set bit exists, so code should check against 0 first.
77228 */
77229-static __always_inline unsigned long __fls(unsigned long word)
77230+static __always_inline unsigned long __intentional_overflow(-1) __fls(unsigned long word)
77231 {
77232 int num = BITS_PER_LONG - 1;
77233
77234diff --git a/include/asm-generic/bitops/fls.h b/include/asm-generic/bitops/fls.h
77235index 0576d1f..dad6c71 100644
77236--- a/include/asm-generic/bitops/fls.h
77237+++ b/include/asm-generic/bitops/fls.h
77238@@ -9,7 +9,7 @@
77239 * Note fls(0) = 0, fls(1) = 1, fls(0x80000000) = 32.
77240 */
77241
77242-static __always_inline int fls(int x)
77243+static __always_inline int __intentional_overflow(-1) fls(int x)
77244 {
77245 int r = 32;
77246
77247diff --git a/include/asm-generic/bitops/fls64.h b/include/asm-generic/bitops/fls64.h
77248index b097cf8..3d40e14 100644
77249--- a/include/asm-generic/bitops/fls64.h
77250+++ b/include/asm-generic/bitops/fls64.h
77251@@ -15,7 +15,7 @@
77252 * at position 64.
77253 */
77254 #if BITS_PER_LONG == 32
77255-static __always_inline int fls64(__u64 x)
77256+static __always_inline int __intentional_overflow(-1) fls64(__u64 x)
77257 {
77258 __u32 h = x >> 32;
77259 if (h)
77260@@ -23,7 +23,7 @@ static __always_inline int fls64(__u64 x)
77261 return fls(x);
77262 }
77263 #elif BITS_PER_LONG == 64
77264-static __always_inline int fls64(__u64 x)
77265+static __always_inline int __intentional_overflow(-1) fls64(__u64 x)
77266 {
77267 if (x == 0)
77268 return 0;
77269diff --git a/include/asm-generic/cache.h b/include/asm-generic/cache.h
77270index 1bfcfe5..e04c5c9 100644
77271--- a/include/asm-generic/cache.h
77272+++ b/include/asm-generic/cache.h
77273@@ -6,7 +6,7 @@
77274 * cache lines need to provide their own cache.h.
77275 */
77276
77277-#define L1_CACHE_SHIFT 5
77278-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
77279+#define L1_CACHE_SHIFT 5UL
77280+#define L1_CACHE_BYTES (1UL << L1_CACHE_SHIFT)
77281
77282 #endif /* __ASM_GENERIC_CACHE_H */
77283diff --git a/include/asm-generic/emergency-restart.h b/include/asm-generic/emergency-restart.h
77284index 0d68a1e..b74a761 100644
77285--- a/include/asm-generic/emergency-restart.h
77286+++ b/include/asm-generic/emergency-restart.h
77287@@ -1,7 +1,7 @@
77288 #ifndef _ASM_GENERIC_EMERGENCY_RESTART_H
77289 #define _ASM_GENERIC_EMERGENCY_RESTART_H
77290
77291-static inline void machine_emergency_restart(void)
77292+static inline __noreturn void machine_emergency_restart(void)
77293 {
77294 machine_restart(NULL);
77295 }
77296diff --git a/include/asm-generic/kmap_types.h b/include/asm-generic/kmap_types.h
77297index 90f99c7..00ce236 100644
77298--- a/include/asm-generic/kmap_types.h
77299+++ b/include/asm-generic/kmap_types.h
77300@@ -2,9 +2,9 @@
77301 #define _ASM_GENERIC_KMAP_TYPES_H
77302
77303 #ifdef __WITH_KM_FENCE
77304-# define KM_TYPE_NR 41
77305+# define KM_TYPE_NR 42
77306 #else
77307-# define KM_TYPE_NR 20
77308+# define KM_TYPE_NR 21
77309 #endif
77310
77311 #endif
77312diff --git a/include/asm-generic/local.h b/include/asm-generic/local.h
77313index 9ceb03b..62b0b8f 100644
77314--- a/include/asm-generic/local.h
77315+++ b/include/asm-generic/local.h
77316@@ -23,24 +23,37 @@ typedef struct
77317 atomic_long_t a;
77318 } local_t;
77319
77320+typedef struct {
77321+ atomic_long_unchecked_t a;
77322+} local_unchecked_t;
77323+
77324 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
77325
77326 #define local_read(l) atomic_long_read(&(l)->a)
77327+#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
77328 #define local_set(l,i) atomic_long_set((&(l)->a),(i))
77329+#define local_set_unchecked(l,i) atomic_long_set_unchecked((&(l)->a),(i))
77330 #define local_inc(l) atomic_long_inc(&(l)->a)
77331+#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
77332 #define local_dec(l) atomic_long_dec(&(l)->a)
77333+#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
77334 #define local_add(i,l) atomic_long_add((i),(&(l)->a))
77335+#define local_add_unchecked(i,l) atomic_long_add_unchecked((i),(&(l)->a))
77336 #define local_sub(i,l) atomic_long_sub((i),(&(l)->a))
77337+#define local_sub_unchecked(i,l) atomic_long_sub_unchecked((i),(&(l)->a))
77338
77339 #define local_sub_and_test(i, l) atomic_long_sub_and_test((i), (&(l)->a))
77340 #define local_dec_and_test(l) atomic_long_dec_and_test(&(l)->a)
77341 #define local_inc_and_test(l) atomic_long_inc_and_test(&(l)->a)
77342 #define local_add_negative(i, l) atomic_long_add_negative((i), (&(l)->a))
77343 #define local_add_return(i, l) atomic_long_add_return((i), (&(l)->a))
77344+#define local_add_return_unchecked(i, l) atomic_long_add_return_unchecked((i), (&(l)->a))
77345 #define local_sub_return(i, l) atomic_long_sub_return((i), (&(l)->a))
77346 #define local_inc_return(l) atomic_long_inc_return(&(l)->a)
77347+#define local_dec_return(l) atomic_long_dec_return(&(l)->a)
77348
77349 #define local_cmpxchg(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
77350+#define local_cmpxchg_unchecked(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
77351 #define local_xchg(l, n) atomic_long_xchg((&(l)->a), (n))
77352 #define local_add_unless(l, _a, u) atomic_long_add_unless((&(l)->a), (_a), (u))
77353 #define local_inc_not_zero(l) atomic_long_inc_not_zero(&(l)->a)
77354diff --git a/include/asm-generic/pgtable-nopmd.h b/include/asm-generic/pgtable-nopmd.h
77355index 725612b..9cc513a 100644
77356--- a/include/asm-generic/pgtable-nopmd.h
77357+++ b/include/asm-generic/pgtable-nopmd.h
77358@@ -1,14 +1,19 @@
77359 #ifndef _PGTABLE_NOPMD_H
77360 #define _PGTABLE_NOPMD_H
77361
77362-#ifndef __ASSEMBLY__
77363-
77364 #include <asm-generic/pgtable-nopud.h>
77365
77366-struct mm_struct;
77367-
77368 #define __PAGETABLE_PMD_FOLDED
77369
77370+#define PMD_SHIFT PUD_SHIFT
77371+#define PTRS_PER_PMD 1
77372+#define PMD_SIZE (_AC(1,UL) << PMD_SHIFT)
77373+#define PMD_MASK (~(PMD_SIZE-1))
77374+
77375+#ifndef __ASSEMBLY__
77376+
77377+struct mm_struct;
77378+
77379 /*
77380 * Having the pmd type consist of a pud gets the size right, and allows
77381 * us to conceptually access the pud entry that this pmd is folded into
77382@@ -16,11 +21,6 @@ struct mm_struct;
77383 */
77384 typedef struct { pud_t pud; } pmd_t;
77385
77386-#define PMD_SHIFT PUD_SHIFT
77387-#define PTRS_PER_PMD 1
77388-#define PMD_SIZE (1UL << PMD_SHIFT)
77389-#define PMD_MASK (~(PMD_SIZE-1))
77390-
77391 /*
77392 * The "pud_xxx()" functions here are trivial for a folded two-level
77393 * setup: the pmd is never bad, and a pmd always exists (as it's folded
77394diff --git a/include/asm-generic/pgtable-nopud.h b/include/asm-generic/pgtable-nopud.h
77395index 810431d..0ec4804f 100644
77396--- a/include/asm-generic/pgtable-nopud.h
77397+++ b/include/asm-generic/pgtable-nopud.h
77398@@ -1,10 +1,15 @@
77399 #ifndef _PGTABLE_NOPUD_H
77400 #define _PGTABLE_NOPUD_H
77401
77402-#ifndef __ASSEMBLY__
77403-
77404 #define __PAGETABLE_PUD_FOLDED
77405
77406+#define PUD_SHIFT PGDIR_SHIFT
77407+#define PTRS_PER_PUD 1
77408+#define PUD_SIZE (_AC(1,UL) << PUD_SHIFT)
77409+#define PUD_MASK (~(PUD_SIZE-1))
77410+
77411+#ifndef __ASSEMBLY__
77412+
77413 /*
77414 * Having the pud type consist of a pgd gets the size right, and allows
77415 * us to conceptually access the pgd entry that this pud is folded into
77416@@ -12,11 +17,6 @@
77417 */
77418 typedef struct { pgd_t pgd; } pud_t;
77419
77420-#define PUD_SHIFT PGDIR_SHIFT
77421-#define PTRS_PER_PUD 1
77422-#define PUD_SIZE (1UL << PUD_SHIFT)
77423-#define PUD_MASK (~(PUD_SIZE-1))
77424-
77425 /*
77426 * The "pgd_xxx()" functions here are trivial for a folded two-level
77427 * setup: the pud is never bad, and a pud always exists (as it's folded
77428@@ -29,6 +29,7 @@ static inline void pgd_clear(pgd_t *pgd) { }
77429 #define pud_ERROR(pud) (pgd_ERROR((pud).pgd))
77430
77431 #define pgd_populate(mm, pgd, pud) do { } while (0)
77432+#define pgd_populate_kernel(mm, pgd, pud) do { } while (0)
77433 /*
77434 * (puds are folded into pgds so this doesn't get actually called,
77435 * but the define is needed for a generic inline function.)
77436diff --git a/include/asm-generic/pgtable.h b/include/asm-generic/pgtable.h
77437index 34c7bdc..38d4f3b 100644
77438--- a/include/asm-generic/pgtable.h
77439+++ b/include/asm-generic/pgtable.h
77440@@ -787,6 +787,22 @@ static inline void pmdp_set_numa(struct mm_struct *mm, unsigned long addr,
77441 }
77442 #endif /* CONFIG_NUMA_BALANCING */
77443
77444+#ifndef __HAVE_ARCH_PAX_OPEN_KERNEL
77445+#ifdef CONFIG_PAX_KERNEXEC
77446+#error KERNEXEC requires pax_open_kernel
77447+#else
77448+static inline unsigned long pax_open_kernel(void) { return 0; }
77449+#endif
77450+#endif
77451+
77452+#ifndef __HAVE_ARCH_PAX_CLOSE_KERNEL
77453+#ifdef CONFIG_PAX_KERNEXEC
77454+#error KERNEXEC requires pax_close_kernel
77455+#else
77456+static inline unsigned long pax_close_kernel(void) { return 0; }
77457+#endif
77458+#endif
77459+
77460 #endif /* CONFIG_MMU */
77461
77462 #endif /* !__ASSEMBLY__ */
77463diff --git a/include/asm-generic/uaccess.h b/include/asm-generic/uaccess.h
77464index 72d8803..cb9749c 100644
77465--- a/include/asm-generic/uaccess.h
77466+++ b/include/asm-generic/uaccess.h
77467@@ -343,4 +343,20 @@ clear_user(void __user *to, unsigned long n)
77468 return __clear_user(to, n);
77469 }
77470
77471+#ifndef __HAVE_ARCH_PAX_OPEN_USERLAND
77472+#ifdef CONFIG_PAX_MEMORY_UDEREF
77473+#error UDEREF requires pax_open_userland
77474+#else
77475+static inline unsigned long pax_open_userland(void) { return 0; }
77476+#endif
77477+#endif
77478+
77479+#ifndef __HAVE_ARCH_PAX_CLOSE_USERLAND
77480+#ifdef CONFIG_PAX_MEMORY_UDEREF
77481+#error UDEREF requires pax_close_userland
77482+#else
77483+static inline unsigned long pax_close_userland(void) { return 0; }
77484+#endif
77485+#endif
77486+
77487 #endif /* __ASM_GENERIC_UACCESS_H */
77488diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
77489index bc2121f..2f41f9a 100644
77490--- a/include/asm-generic/vmlinux.lds.h
77491+++ b/include/asm-generic/vmlinux.lds.h
77492@@ -232,6 +232,7 @@
77493 .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
77494 VMLINUX_SYMBOL(__start_rodata) = .; \
77495 *(.rodata) *(.rodata.*) \
77496+ *(.data..read_only) \
77497 *(__vermagic) /* Kernel version magic */ \
77498 . = ALIGN(8); \
77499 VMLINUX_SYMBOL(__start___tracepoints_ptrs) = .; \
77500@@ -716,17 +717,18 @@
77501 * section in the linker script will go there too. @phdr should have
77502 * a leading colon.
77503 *
77504- * Note that this macros defines __per_cpu_load as an absolute symbol.
77505+ * Note that this macros defines per_cpu_load as an absolute symbol.
77506 * If there is no need to put the percpu section at a predetermined
77507 * address, use PERCPU_SECTION.
77508 */
77509 #define PERCPU_VADDR(cacheline, vaddr, phdr) \
77510- VMLINUX_SYMBOL(__per_cpu_load) = .; \
77511- .data..percpu vaddr : AT(VMLINUX_SYMBOL(__per_cpu_load) \
77512+ per_cpu_load = .; \
77513+ .data..percpu vaddr : AT(VMLINUX_SYMBOL(per_cpu_load) \
77514 - LOAD_OFFSET) { \
77515+ VMLINUX_SYMBOL(__per_cpu_load) = . + per_cpu_load; \
77516 PERCPU_INPUT(cacheline) \
77517 } phdr \
77518- . = VMLINUX_SYMBOL(__per_cpu_load) + SIZEOF(.data..percpu);
77519+ . = VMLINUX_SYMBOL(per_cpu_load) + SIZEOF(.data..percpu);
77520
77521 /**
77522 * PERCPU_SECTION - define output section for percpu area, simple version
77523diff --git a/include/crypto/algapi.h b/include/crypto/algapi.h
77524index e73c19e..5b89e00 100644
77525--- a/include/crypto/algapi.h
77526+++ b/include/crypto/algapi.h
77527@@ -34,7 +34,7 @@ struct crypto_type {
77528 unsigned int maskclear;
77529 unsigned int maskset;
77530 unsigned int tfmsize;
77531-};
77532+} __do_const;
77533
77534 struct crypto_instance {
77535 struct crypto_alg alg;
77536diff --git a/include/drm/drmP.h b/include/drm/drmP.h
77537index 04a7f31..668d424 100644
77538--- a/include/drm/drmP.h
77539+++ b/include/drm/drmP.h
77540@@ -67,6 +67,7 @@
77541 #include <linux/workqueue.h>
77542 #include <linux/poll.h>
77543 #include <asm/pgalloc.h>
77544+#include <asm/local.h>
77545 #include <drm/drm.h>
77546 #include <drm/drm_sarea.h>
77547 #include <drm/drm_vma_manager.h>
77548@@ -297,10 +298,12 @@ do { \
77549 * \param cmd command.
77550 * \param arg argument.
77551 */
77552-typedef int drm_ioctl_t(struct drm_device *dev, void *data,
77553+typedef int (* const drm_ioctl_t)(struct drm_device *dev, void *data,
77554+ struct drm_file *file_priv);
77555+typedef int (* drm_ioctl_no_const_t)(struct drm_device *dev, void *data,
77556 struct drm_file *file_priv);
77557
77558-typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
77559+typedef int (* const drm_ioctl_compat_t)(struct file *filp, unsigned int cmd,
77560 unsigned long arg);
77561
77562 #define DRM_IOCTL_NR(n) _IOC_NR(n)
77563@@ -316,10 +319,10 @@ typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
77564 struct drm_ioctl_desc {
77565 unsigned int cmd;
77566 int flags;
77567- drm_ioctl_t *func;
77568+ drm_ioctl_t func;
77569 unsigned int cmd_drv;
77570 const char *name;
77571-};
77572+} __do_const;
77573
77574 /**
77575 * Creates a driver or general drm_ioctl_desc array entry for the given
77576@@ -1022,7 +1025,8 @@ struct drm_info_list {
77577 int (*show)(struct seq_file*, void*); /** show callback */
77578 u32 driver_features; /**< Required driver features for this entry */
77579 void *data;
77580-};
77581+} __do_const;
77582+typedef struct drm_info_list __no_const drm_info_list_no_const;
77583
77584 /**
77585 * debugfs node structure. This structure represents a debugfs file.
77586@@ -1106,7 +1110,7 @@ struct drm_device {
77587
77588 /** \name Usage Counters */
77589 /*@{ */
77590- int open_count; /**< Outstanding files open */
77591+ local_t open_count; /**< Outstanding files open */
77592 int buf_use; /**< Buffers in use -- cannot alloc */
77593 atomic_t buf_alloc; /**< Buffer allocation in progress */
77594 /*@} */
77595diff --git a/include/drm/drm_crtc_helper.h b/include/drm/drm_crtc_helper.h
77596index b1388b5..e1d1163 100644
77597--- a/include/drm/drm_crtc_helper.h
77598+++ b/include/drm/drm_crtc_helper.h
77599@@ -109,7 +109,7 @@ struct drm_encoder_helper_funcs {
77600 struct drm_connector *connector);
77601 /* disable encoder when not in use - more explicit than dpms off */
77602 void (*disable)(struct drm_encoder *encoder);
77603-};
77604+} __no_const;
77605
77606 /**
77607 * drm_connector_helper_funcs - helper operations for connectors
77608diff --git a/include/drm/i915_pciids.h b/include/drm/i915_pciids.h
77609index 940ece4..8cb727f 100644
77610--- a/include/drm/i915_pciids.h
77611+++ b/include/drm/i915_pciids.h
77612@@ -37,7 +37,7 @@
77613 */
77614 #define INTEL_VGA_DEVICE(id, info) { \
77615 0x8086, id, \
77616- ~0, ~0, \
77617+ PCI_ANY_ID, PCI_ANY_ID, \
77618 0x030000, 0xff0000, \
77619 (unsigned long) info }
77620
77621diff --git a/include/drm/ttm/ttm_memory.h b/include/drm/ttm/ttm_memory.h
77622index 72dcbe8..8db58d7 100644
77623--- a/include/drm/ttm/ttm_memory.h
77624+++ b/include/drm/ttm/ttm_memory.h
77625@@ -48,7 +48,7 @@
77626
77627 struct ttm_mem_shrink {
77628 int (*do_shrink) (struct ttm_mem_shrink *);
77629-};
77630+} __no_const;
77631
77632 /**
77633 * struct ttm_mem_global - Global memory accounting structure.
77634diff --git a/include/drm/ttm/ttm_page_alloc.h b/include/drm/ttm/ttm_page_alloc.h
77635index 49a8284..9643967 100644
77636--- a/include/drm/ttm/ttm_page_alloc.h
77637+++ b/include/drm/ttm/ttm_page_alloc.h
77638@@ -80,6 +80,7 @@ void ttm_dma_page_alloc_fini(void);
77639 */
77640 extern int ttm_dma_page_alloc_debugfs(struct seq_file *m, void *data);
77641
77642+struct device;
77643 extern int ttm_dma_populate(struct ttm_dma_tt *ttm_dma, struct device *dev);
77644 extern void ttm_dma_unpopulate(struct ttm_dma_tt *ttm_dma, struct device *dev);
77645
77646diff --git a/include/keys/asymmetric-subtype.h b/include/keys/asymmetric-subtype.h
77647index 4b840e8..155d235 100644
77648--- a/include/keys/asymmetric-subtype.h
77649+++ b/include/keys/asymmetric-subtype.h
77650@@ -37,7 +37,7 @@ struct asymmetric_key_subtype {
77651 /* Verify the signature on a key of this subtype (optional) */
77652 int (*verify_signature)(const struct key *key,
77653 const struct public_key_signature *sig);
77654-};
77655+} __do_const;
77656
77657 /**
77658 * asymmetric_key_subtype - Get the subtype from an asymmetric key
77659diff --git a/include/linux/atmdev.h b/include/linux/atmdev.h
77660index c1da539..1dcec55 100644
77661--- a/include/linux/atmdev.h
77662+++ b/include/linux/atmdev.h
77663@@ -28,7 +28,7 @@ struct compat_atm_iobuf {
77664 #endif
77665
77666 struct k_atm_aal_stats {
77667-#define __HANDLE_ITEM(i) atomic_t i
77668+#define __HANDLE_ITEM(i) atomic_unchecked_t i
77669 __AAL_STAT_ITEMS
77670 #undef __HANDLE_ITEM
77671 };
77672@@ -200,7 +200,7 @@ struct atmdev_ops { /* only send is required */
77673 int (*change_qos)(struct atm_vcc *vcc,struct atm_qos *qos,int flags);
77674 int (*proc_read)(struct atm_dev *dev,loff_t *pos,char *page);
77675 struct module *owner;
77676-};
77677+} __do_const ;
77678
77679 struct atmphy_ops {
77680 int (*start)(struct atm_dev *dev);
77681diff --git a/include/linux/audit.h b/include/linux/audit.h
77682index ec1464d..833274b 100644
77683--- a/include/linux/audit.h
77684+++ b/include/linux/audit.h
77685@@ -196,7 +196,7 @@ static inline void audit_ptrace(struct task_struct *t)
77686 extern unsigned int audit_serial(void);
77687 extern int auditsc_get_stamp(struct audit_context *ctx,
77688 struct timespec *t, unsigned int *serial);
77689-extern int audit_set_loginuid(kuid_t loginuid);
77690+extern int __intentional_overflow(-1) audit_set_loginuid(kuid_t loginuid);
77691
77692 static inline kuid_t audit_get_loginuid(struct task_struct *tsk)
77693 {
77694diff --git a/include/linux/binfmts.h b/include/linux/binfmts.h
77695index b4a745d..e3c0942 100644
77696--- a/include/linux/binfmts.h
77697+++ b/include/linux/binfmts.h
77698@@ -45,7 +45,7 @@ struct linux_binprm {
77699 unsigned interp_data;
77700 unsigned long loader, exec;
77701 char tcomm[TASK_COMM_LEN];
77702-};
77703+} __randomize_layout;
77704
77705 #define BINPRM_FLAGS_ENFORCE_NONDUMP_BIT 0
77706 #define BINPRM_FLAGS_ENFORCE_NONDUMP (1 << BINPRM_FLAGS_ENFORCE_NONDUMP_BIT)
77707@@ -74,8 +74,10 @@ struct linux_binfmt {
77708 int (*load_binary)(struct linux_binprm *);
77709 int (*load_shlib)(struct file *);
77710 int (*core_dump)(struct coredump_params *cprm);
77711+ void (*handle_mprotect)(struct vm_area_struct *vma, unsigned long newflags);
77712+ void (*handle_mmap)(struct file *);
77713 unsigned long min_coredump; /* minimal dump size */
77714-};
77715+} __do_const __randomize_layout;
77716
77717 extern void __register_binfmt(struct linux_binfmt *fmt, int insert);
77718
77719diff --git a/include/linux/bitops.h b/include/linux/bitops.h
77720index be5fd38..d71192a 100644
77721--- a/include/linux/bitops.h
77722+++ b/include/linux/bitops.h
77723@@ -102,7 +102,7 @@ static inline __u64 ror64(__u64 word, unsigned int shift)
77724 * @word: value to rotate
77725 * @shift: bits to roll
77726 */
77727-static inline __u32 rol32(__u32 word, unsigned int shift)
77728+static inline __u32 __intentional_overflow(-1) rol32(__u32 word, unsigned int shift)
77729 {
77730 return (word << shift) | (word >> (32 - shift));
77731 }
77732@@ -112,7 +112,7 @@ static inline __u32 rol32(__u32 word, unsigned int shift)
77733 * @word: value to rotate
77734 * @shift: bits to roll
77735 */
77736-static inline __u32 ror32(__u32 word, unsigned int shift)
77737+static inline __u32 __intentional_overflow(-1) ror32(__u32 word, unsigned int shift)
77738 {
77739 return (word >> shift) | (word << (32 - shift));
77740 }
77741@@ -168,7 +168,7 @@ static inline __s32 sign_extend32(__u32 value, int index)
77742 return (__s32)(value << shift) >> shift;
77743 }
77744
77745-static inline unsigned fls_long(unsigned long l)
77746+static inline unsigned __intentional_overflow(-1) fls_long(unsigned long l)
77747 {
77748 if (sizeof(l) == 4)
77749 return fls(l);
77750diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
77751index 4afa4f8..1ed7824 100644
77752--- a/include/linux/blkdev.h
77753+++ b/include/linux/blkdev.h
77754@@ -1572,7 +1572,7 @@ struct block_device_operations {
77755 /* this callback is with swap_lock and sometimes page table lock held */
77756 void (*swap_slot_free_notify) (struct block_device *, unsigned long);
77757 struct module *owner;
77758-};
77759+} __do_const;
77760
77761 extern int __blkdev_driver_ioctl(struct block_device *, fmode_t, unsigned int,
77762 unsigned long);
77763diff --git a/include/linux/blktrace_api.h b/include/linux/blktrace_api.h
77764index afc1343..9735539 100644
77765--- a/include/linux/blktrace_api.h
77766+++ b/include/linux/blktrace_api.h
77767@@ -25,7 +25,7 @@ struct blk_trace {
77768 struct dentry *dropped_file;
77769 struct dentry *msg_file;
77770 struct list_head running_list;
77771- atomic_t dropped;
77772+ atomic_unchecked_t dropped;
77773 };
77774
77775 extern int blk_trace_ioctl(struct block_device *, unsigned, char __user *);
77776diff --git a/include/linux/cache.h b/include/linux/cache.h
77777index 17e7e82..1d7da26 100644
77778--- a/include/linux/cache.h
77779+++ b/include/linux/cache.h
77780@@ -16,6 +16,14 @@
77781 #define __read_mostly
77782 #endif
77783
77784+#ifndef __read_only
77785+#ifdef CONFIG_PAX_KERNEXEC
77786+#error KERNEXEC requires __read_only
77787+#else
77788+#define __read_only __read_mostly
77789+#endif
77790+#endif
77791+
77792 #ifndef ____cacheline_aligned
77793 #define ____cacheline_aligned __attribute__((__aligned__(SMP_CACHE_BYTES)))
77794 #endif
77795diff --git a/include/linux/capability.h b/include/linux/capability.h
77796index a6ee1f9..e1ca49d 100644
77797--- a/include/linux/capability.h
77798+++ b/include/linux/capability.h
77799@@ -212,8 +212,13 @@ extern bool capable(int cap);
77800 extern bool ns_capable(struct user_namespace *ns, int cap);
77801 extern bool inode_capable(const struct inode *inode, int cap);
77802 extern bool file_ns_capable(const struct file *file, struct user_namespace *ns, int cap);
77803+extern bool capable_nolog(int cap);
77804+extern bool ns_capable_nolog(struct user_namespace *ns, int cap);
77805+extern bool inode_capable_nolog(const struct inode *inode, int cap);
77806
77807 /* audit system wants to get cap info from files as well */
77808 extern int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data *cpu_caps);
77809
77810+extern int is_privileged_binary(const struct dentry *dentry);
77811+
77812 #endif /* !_LINUX_CAPABILITY_H */
77813diff --git a/include/linux/cdrom.h b/include/linux/cdrom.h
77814index 8609d57..86e4d79 100644
77815--- a/include/linux/cdrom.h
77816+++ b/include/linux/cdrom.h
77817@@ -87,7 +87,6 @@ struct cdrom_device_ops {
77818
77819 /* driver specifications */
77820 const int capability; /* capability flags */
77821- int n_minors; /* number of active minor devices */
77822 /* handle uniform packets for scsi type devices (scsi,atapi) */
77823 int (*generic_packet) (struct cdrom_device_info *,
77824 struct packet_command *);
77825diff --git a/include/linux/cleancache.h b/include/linux/cleancache.h
77826index 4ce9056..86caac6 100644
77827--- a/include/linux/cleancache.h
77828+++ b/include/linux/cleancache.h
77829@@ -31,7 +31,7 @@ struct cleancache_ops {
77830 void (*invalidate_page)(int, struct cleancache_filekey, pgoff_t);
77831 void (*invalidate_inode)(int, struct cleancache_filekey);
77832 void (*invalidate_fs)(int);
77833-};
77834+} __no_const;
77835
77836 extern struct cleancache_ops *
77837 cleancache_register_ops(struct cleancache_ops *ops);
77838diff --git a/include/linux/clk-provider.h b/include/linux/clk-provider.h
77839index 939533d..cf0a57c 100644
77840--- a/include/linux/clk-provider.h
77841+++ b/include/linux/clk-provider.h
77842@@ -166,6 +166,7 @@ struct clk_ops {
77843 unsigned long parent_accuracy);
77844 void (*init)(struct clk_hw *hw);
77845 };
77846+typedef struct clk_ops __no_const clk_ops_no_const;
77847
77848 /**
77849 * struct clk_init_data - holds init data that's common to all clocks and is
77850diff --git a/include/linux/compat.h b/include/linux/compat.h
77851index 3f448c6..df3ce1d 100644
77852--- a/include/linux/compat.h
77853+++ b/include/linux/compat.h
77854@@ -313,7 +313,7 @@ compat_sys_get_robust_list(int pid, compat_uptr_t __user *head_ptr,
77855 compat_size_t __user *len_ptr);
77856
77857 asmlinkage long compat_sys_ipc(u32, int, int, u32, compat_uptr_t, u32);
77858-asmlinkage long compat_sys_shmat(int shmid, compat_uptr_t shmaddr, int shmflg);
77859+asmlinkage long compat_sys_shmat(int shmid, compat_uptr_t shmaddr, int shmflg) __intentional_overflow(0);
77860 asmlinkage long compat_sys_semctl(int semid, int semnum, int cmd, int arg);
77861 asmlinkage long compat_sys_msgsnd(int msqid, compat_uptr_t msgp,
77862 compat_ssize_t msgsz, int msgflg);
77863@@ -420,7 +420,7 @@ extern int compat_ptrace_request(struct task_struct *child,
77864 extern long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
77865 compat_ulong_t addr, compat_ulong_t data);
77866 asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
77867- compat_long_t addr, compat_long_t data);
77868+ compat_ulong_t addr, compat_ulong_t data);
77869
77870 asmlinkage long compat_sys_lookup_dcookie(u32, u32, char __user *, compat_size_t);
77871 /*
77872diff --git a/include/linux/compiler-gcc4.h b/include/linux/compiler-gcc4.h
77873index 2507fd2..55203f8 100644
77874--- a/include/linux/compiler-gcc4.h
77875+++ b/include/linux/compiler-gcc4.h
77876@@ -39,9 +39,34 @@
77877 # define __compiletime_warning(message) __attribute__((warning(message)))
77878 # define __compiletime_error(message) __attribute__((error(message)))
77879 #endif /* __CHECKER__ */
77880+
77881+#define __alloc_size(...) __attribute((alloc_size(__VA_ARGS__)))
77882+#define __bos(ptr, arg) __builtin_object_size((ptr), (arg))
77883+#define __bos0(ptr) __bos((ptr), 0)
77884+#define __bos1(ptr) __bos((ptr), 1)
77885 #endif /* GCC_VERSION >= 40300 */
77886
77887 #if GCC_VERSION >= 40500
77888+
77889+#ifdef RANDSTRUCT_PLUGIN
77890+#define __randomize_layout __attribute__((randomize_layout))
77891+#define __no_randomize_layout __attribute__((no_randomize_layout))
77892+#endif
77893+
77894+#ifdef CONSTIFY_PLUGIN
77895+#define __no_const __attribute__((no_const))
77896+#define __do_const __attribute__((do_const))
77897+#endif
77898+
77899+#ifdef SIZE_OVERFLOW_PLUGIN
77900+#define __size_overflow(...) __attribute__((size_overflow(__VA_ARGS__)))
77901+#define __intentional_overflow(...) __attribute__((intentional_overflow(__VA_ARGS__)))
77902+#endif
77903+
77904+#ifdef LATENT_ENTROPY_PLUGIN
77905+#define __latent_entropy __attribute__((latent_entropy))
77906+#endif
77907+
77908 /*
77909 * Mark a position in code as unreachable. This can be used to
77910 * suppress control flow warnings after asm blocks that transfer
77911diff --git a/include/linux/compiler.h b/include/linux/compiler.h
77912index 2472740..4857634 100644
77913--- a/include/linux/compiler.h
77914+++ b/include/linux/compiler.h
77915@@ -5,11 +5,14 @@
77916
77917 #ifdef __CHECKER__
77918 # define __user __attribute__((noderef, address_space(1)))
77919+# define __force_user __force __user
77920 # define __kernel __attribute__((address_space(0)))
77921+# define __force_kernel __force __kernel
77922 # define __safe __attribute__((safe))
77923 # define __force __attribute__((force))
77924 # define __nocast __attribute__((nocast))
77925 # define __iomem __attribute__((noderef, address_space(2)))
77926+# define __force_iomem __force __iomem
77927 # define __must_hold(x) __attribute__((context(x,1,1)))
77928 # define __acquires(x) __attribute__((context(x,0,1)))
77929 # define __releases(x) __attribute__((context(x,1,0)))
77930@@ -17,20 +20,37 @@
77931 # define __release(x) __context__(x,-1)
77932 # define __cond_lock(x,c) ((c) ? ({ __acquire(x); 1; }) : 0)
77933 # define __percpu __attribute__((noderef, address_space(3)))
77934+# define __force_percpu __force __percpu
77935 #ifdef CONFIG_SPARSE_RCU_POINTER
77936 # define __rcu __attribute__((noderef, address_space(4)))
77937+# define __force_rcu __force __rcu
77938 #else
77939 # define __rcu
77940+# define __force_rcu
77941 #endif
77942 extern void __chk_user_ptr(const volatile void __user *);
77943 extern void __chk_io_ptr(const volatile void __iomem *);
77944 #else
77945-# define __user
77946-# define __kernel
77947+# ifdef CHECKER_PLUGIN
77948+//# define __user
77949+//# define __force_user
77950+//# define __kernel
77951+//# define __force_kernel
77952+# else
77953+# ifdef STRUCTLEAK_PLUGIN
77954+# define __user __attribute__((user))
77955+# else
77956+# define __user
77957+# endif
77958+# define __force_user
77959+# define __kernel
77960+# define __force_kernel
77961+# endif
77962 # define __safe
77963 # define __force
77964 # define __nocast
77965 # define __iomem
77966+# define __force_iomem
77967 # define __chk_user_ptr(x) (void)0
77968 # define __chk_io_ptr(x) (void)0
77969 # define __builtin_warning(x, y...) (1)
77970@@ -41,7 +61,9 @@ extern void __chk_io_ptr(const volatile void __iomem *);
77971 # define __release(x) (void)0
77972 # define __cond_lock(x,c) (c)
77973 # define __percpu
77974+# define __force_percpu
77975 # define __rcu
77976+# define __force_rcu
77977 #endif
77978
77979 /* Indirect macros required for expanded argument pasting, eg. __LINE__. */
77980@@ -279,6 +301,34 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
77981 # define __attribute_const__ /* unimplemented */
77982 #endif
77983
77984+#ifndef __randomize_layout
77985+# define __randomize_layout
77986+#endif
77987+
77988+#ifndef __no_randomize_layout
77989+# define __no_randomize_layout
77990+#endif
77991+
77992+#ifndef __no_const
77993+# define __no_const
77994+#endif
77995+
77996+#ifndef __do_const
77997+# define __do_const
77998+#endif
77999+
78000+#ifndef __size_overflow
78001+# define __size_overflow(...)
78002+#endif
78003+
78004+#ifndef __intentional_overflow
78005+# define __intentional_overflow(...)
78006+#endif
78007+
78008+#ifndef __latent_entropy
78009+# define __latent_entropy
78010+#endif
78011+
78012 /*
78013 * Tell gcc if a function is cold. The compiler will assume any path
78014 * directly leading to the call is unlikely.
78015@@ -288,6 +338,22 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
78016 #define __cold
78017 #endif
78018
78019+#ifndef __alloc_size
78020+#define __alloc_size(...)
78021+#endif
78022+
78023+#ifndef __bos
78024+#define __bos(ptr, arg)
78025+#endif
78026+
78027+#ifndef __bos0
78028+#define __bos0(ptr)
78029+#endif
78030+
78031+#ifndef __bos1
78032+#define __bos1(ptr)
78033+#endif
78034+
78035 /* Simple shorthand for a section definition */
78036 #ifndef __section
78037 # define __section(S) __attribute__ ((__section__(#S)))
78038@@ -362,7 +428,8 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
78039 * use is to mediate communication between process-level code and irq/NMI
78040 * handlers, all running on the same CPU.
78041 */
78042-#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
78043+#define ACCESS_ONCE(x) (*(volatile const typeof(x) *)&(x))
78044+#define ACCESS_ONCE_RW(x) (*(volatile typeof(x) *)&(x))
78045
78046 /* Ignore/forbid kprobes attach on very low level functions marked by this attribute: */
78047 #ifdef CONFIG_KPROBES
78048diff --git a/include/linux/completion.h b/include/linux/completion.h
78049index 5d5aaae..0ea9b84 100644
78050--- a/include/linux/completion.h
78051+++ b/include/linux/completion.h
78052@@ -90,16 +90,16 @@ static inline void reinit_completion(struct completion *x)
78053
78054 extern void wait_for_completion(struct completion *);
78055 extern void wait_for_completion_io(struct completion *);
78056-extern int wait_for_completion_interruptible(struct completion *x);
78057-extern int wait_for_completion_killable(struct completion *x);
78058+extern int wait_for_completion_interruptible(struct completion *x) __intentional_overflow(-1);
78059+extern int wait_for_completion_killable(struct completion *x) __intentional_overflow(-1);
78060 extern unsigned long wait_for_completion_timeout(struct completion *x,
78061- unsigned long timeout);
78062+ unsigned long timeout) __intentional_overflow(-1);
78063 extern unsigned long wait_for_completion_io_timeout(struct completion *x,
78064- unsigned long timeout);
78065+ unsigned long timeout) __intentional_overflow(-1);
78066 extern long wait_for_completion_interruptible_timeout(
78067- struct completion *x, unsigned long timeout);
78068+ struct completion *x, unsigned long timeout) __intentional_overflow(-1);
78069 extern long wait_for_completion_killable_timeout(
78070- struct completion *x, unsigned long timeout);
78071+ struct completion *x, unsigned long timeout) __intentional_overflow(-1);
78072 extern bool try_wait_for_completion(struct completion *x);
78073 extern bool completion_done(struct completion *x);
78074
78075diff --git a/include/linux/configfs.h b/include/linux/configfs.h
78076index 34025df..d94bbbc 100644
78077--- a/include/linux/configfs.h
78078+++ b/include/linux/configfs.h
78079@@ -125,7 +125,7 @@ struct configfs_attribute {
78080 const char *ca_name;
78081 struct module *ca_owner;
78082 umode_t ca_mode;
78083-};
78084+} __do_const;
78085
78086 /*
78087 * Users often need to create attribute structures for their configurable
78088diff --git a/include/linux/cpufreq.h b/include/linux/cpufreq.h
78089index 4d89e0e..5281847 100644
78090--- a/include/linux/cpufreq.h
78091+++ b/include/linux/cpufreq.h
78092@@ -191,6 +191,7 @@ struct global_attr {
78093 ssize_t (*store)(struct kobject *a, struct attribute *b,
78094 const char *c, size_t count);
78095 };
78096+typedef struct global_attr __no_const global_attr_no_const;
78097
78098 #define define_one_global_ro(_name) \
78099 static struct global_attr _name = \
78100@@ -232,7 +233,7 @@ struct cpufreq_driver {
78101 bool boost_supported;
78102 bool boost_enabled;
78103 int (*set_boost) (int state);
78104-};
78105+} __do_const;
78106
78107 /* flags */
78108 #define CPUFREQ_STICKY (1 << 0) /* driver isn't removed even if
78109diff --git a/include/linux/cpuidle.h b/include/linux/cpuidle.h
78110index 50fcbb0..9d2dbd9 100644
78111--- a/include/linux/cpuidle.h
78112+++ b/include/linux/cpuidle.h
78113@@ -50,7 +50,8 @@ struct cpuidle_state {
78114 int index);
78115
78116 int (*enter_dead) (struct cpuidle_device *dev, int index);
78117-};
78118+} __do_const;
78119+typedef struct cpuidle_state __no_const cpuidle_state_no_const;
78120
78121 /* Idle State Flags */
78122 #define CPUIDLE_FLAG_TIME_VALID (0x01) /* is residency time measurable? */
78123@@ -192,7 +193,7 @@ struct cpuidle_governor {
78124 void (*reflect) (struct cpuidle_device *dev, int index);
78125
78126 struct module *owner;
78127-};
78128+} __do_const;
78129
78130 #ifdef CONFIG_CPU_IDLE
78131 extern int cpuidle_register_governor(struct cpuidle_governor *gov);
78132diff --git a/include/linux/cpumask.h b/include/linux/cpumask.h
78133index d08e4d2..95fad61 100644
78134--- a/include/linux/cpumask.h
78135+++ b/include/linux/cpumask.h
78136@@ -118,17 +118,17 @@ static inline unsigned int cpumask_first(const struct cpumask *srcp)
78137 }
78138
78139 /* Valid inputs for n are -1 and 0. */
78140-static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
78141+static inline unsigned int __intentional_overflow(-1) cpumask_next(int n, const struct cpumask *srcp)
78142 {
78143 return n+1;
78144 }
78145
78146-static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
78147+static inline unsigned int __intentional_overflow(-1) cpumask_next_zero(int n, const struct cpumask *srcp)
78148 {
78149 return n+1;
78150 }
78151
78152-static inline unsigned int cpumask_next_and(int n,
78153+static inline unsigned int __intentional_overflow(-1) cpumask_next_and(int n,
78154 const struct cpumask *srcp,
78155 const struct cpumask *andp)
78156 {
78157@@ -167,7 +167,7 @@ static inline unsigned int cpumask_first(const struct cpumask *srcp)
78158 *
78159 * Returns >= nr_cpu_ids if no further cpus set.
78160 */
78161-static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
78162+static inline unsigned int __intentional_overflow(-1) cpumask_next(int n, const struct cpumask *srcp)
78163 {
78164 /* -1 is a legal arg here. */
78165 if (n != -1)
78166@@ -182,7 +182,7 @@ static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
78167 *
78168 * Returns >= nr_cpu_ids if no further cpus unset.
78169 */
78170-static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
78171+static inline unsigned int __intentional_overflow(-1) cpumask_next_zero(int n, const struct cpumask *srcp)
78172 {
78173 /* -1 is a legal arg here. */
78174 if (n != -1)
78175@@ -190,7 +190,7 @@ static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
78176 return find_next_zero_bit(cpumask_bits(srcp), nr_cpumask_bits, n+1);
78177 }
78178
78179-int cpumask_next_and(int n, const struct cpumask *, const struct cpumask *);
78180+int cpumask_next_and(int n, const struct cpumask *, const struct cpumask *) __intentional_overflow(-1);
78181 int cpumask_any_but(const struct cpumask *mask, unsigned int cpu);
78182
78183 /**
78184diff --git a/include/linux/cred.h b/include/linux/cred.h
78185index 04421e8..117e17a 100644
78186--- a/include/linux/cred.h
78187+++ b/include/linux/cred.h
78188@@ -35,7 +35,7 @@ struct group_info {
78189 int nblocks;
78190 kgid_t small_block[NGROUPS_SMALL];
78191 kgid_t *blocks[0];
78192-};
78193+} __randomize_layout;
78194
78195 /**
78196 * get_group_info - Get a reference to a group info structure
78197@@ -136,7 +136,7 @@ struct cred {
78198 struct user_namespace *user_ns; /* user_ns the caps and keyrings are relative to. */
78199 struct group_info *group_info; /* supplementary groups for euid/fsgid */
78200 struct rcu_head rcu; /* RCU deletion hook */
78201-};
78202+} __randomize_layout;
78203
78204 extern void __put_cred(struct cred *);
78205 extern void exit_creds(struct task_struct *);
78206@@ -194,6 +194,9 @@ static inline void validate_creds_for_do_exit(struct task_struct *tsk)
78207 static inline void validate_process_creds(void)
78208 {
78209 }
78210+static inline void validate_task_creds(struct task_struct *task)
78211+{
78212+}
78213 #endif
78214
78215 /**
78216diff --git a/include/linux/crypto.h b/include/linux/crypto.h
78217index b92eadf..b4ecdc1 100644
78218--- a/include/linux/crypto.h
78219+++ b/include/linux/crypto.h
78220@@ -373,7 +373,7 @@ struct cipher_tfm {
78221 const u8 *key, unsigned int keylen);
78222 void (*cit_encrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
78223 void (*cit_decrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
78224-};
78225+} __no_const;
78226
78227 struct hash_tfm {
78228 int (*init)(struct hash_desc *desc);
78229@@ -394,13 +394,13 @@ struct compress_tfm {
78230 int (*cot_decompress)(struct crypto_tfm *tfm,
78231 const u8 *src, unsigned int slen,
78232 u8 *dst, unsigned int *dlen);
78233-};
78234+} __no_const;
78235
78236 struct rng_tfm {
78237 int (*rng_gen_random)(struct crypto_rng *tfm, u8 *rdata,
78238 unsigned int dlen);
78239 int (*rng_reset)(struct crypto_rng *tfm, u8 *seed, unsigned int slen);
78240-};
78241+} __no_const;
78242
78243 #define crt_ablkcipher crt_u.ablkcipher
78244 #define crt_aead crt_u.aead
78245diff --git a/include/linux/ctype.h b/include/linux/ctype.h
78246index 653589e..4ef254a 100644
78247--- a/include/linux/ctype.h
78248+++ b/include/linux/ctype.h
78249@@ -56,7 +56,7 @@ static inline unsigned char __toupper(unsigned char c)
78250 * Fast implementation of tolower() for internal usage. Do not use in your
78251 * code.
78252 */
78253-static inline char _tolower(const char c)
78254+static inline unsigned char _tolower(const unsigned char c)
78255 {
78256 return c | 0x20;
78257 }
78258diff --git a/include/linux/dcache.h b/include/linux/dcache.h
78259index bf72e9a..4ca7927 100644
78260--- a/include/linux/dcache.h
78261+++ b/include/linux/dcache.h
78262@@ -133,7 +133,7 @@ struct dentry {
78263 } d_u;
78264 struct list_head d_subdirs; /* our children */
78265 struct hlist_node d_alias; /* inode alias list */
78266-};
78267+} __randomize_layout;
78268
78269 /*
78270 * dentry->d_lock spinlock nesting subclasses:
78271diff --git a/include/linux/decompress/mm.h b/include/linux/decompress/mm.h
78272index 7925bf0..d5143d2 100644
78273--- a/include/linux/decompress/mm.h
78274+++ b/include/linux/decompress/mm.h
78275@@ -77,7 +77,7 @@ static void free(void *where)
78276 * warnings when not needed (indeed large_malloc / large_free are not
78277 * needed by inflate */
78278
78279-#define malloc(a) kmalloc(a, GFP_KERNEL)
78280+#define malloc(a) kmalloc((a), GFP_KERNEL)
78281 #define free(a) kfree(a)
78282
78283 #define large_malloc(a) vmalloc(a)
78284diff --git a/include/linux/devfreq.h b/include/linux/devfreq.h
78285index d48dc00..211ee54 100644
78286--- a/include/linux/devfreq.h
78287+++ b/include/linux/devfreq.h
78288@@ -114,7 +114,7 @@ struct devfreq_governor {
78289 int (*get_target_freq)(struct devfreq *this, unsigned long *freq);
78290 int (*event_handler)(struct devfreq *devfreq,
78291 unsigned int event, void *data);
78292-};
78293+} __do_const;
78294
78295 /**
78296 * struct devfreq - Device devfreq structure
78297diff --git a/include/linux/device.h b/include/linux/device.h
78298index 952b010..d5b7691 100644
78299--- a/include/linux/device.h
78300+++ b/include/linux/device.h
78301@@ -310,7 +310,7 @@ struct subsys_interface {
78302 struct list_head node;
78303 int (*add_dev)(struct device *dev, struct subsys_interface *sif);
78304 int (*remove_dev)(struct device *dev, struct subsys_interface *sif);
78305-};
78306+} __do_const;
78307
78308 int subsys_interface_register(struct subsys_interface *sif);
78309 void subsys_interface_unregister(struct subsys_interface *sif);
78310@@ -506,7 +506,7 @@ struct device_type {
78311 void (*release)(struct device *dev);
78312
78313 const struct dev_pm_ops *pm;
78314-};
78315+} __do_const;
78316
78317 /* interface for exporting device attributes */
78318 struct device_attribute {
78319@@ -516,11 +516,12 @@ struct device_attribute {
78320 ssize_t (*store)(struct device *dev, struct device_attribute *attr,
78321 const char *buf, size_t count);
78322 };
78323+typedef struct device_attribute __no_const device_attribute_no_const;
78324
78325 struct dev_ext_attribute {
78326 struct device_attribute attr;
78327 void *var;
78328-};
78329+} __do_const;
78330
78331 ssize_t device_show_ulong(struct device *dev, struct device_attribute *attr,
78332 char *buf);
78333diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h
78334index fd4aee2..1f28db9 100644
78335--- a/include/linux/dma-mapping.h
78336+++ b/include/linux/dma-mapping.h
78337@@ -54,7 +54,7 @@ struct dma_map_ops {
78338 u64 (*get_required_mask)(struct device *dev);
78339 #endif
78340 int is_phys;
78341-};
78342+} __do_const;
78343
78344 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
78345
78346diff --git a/include/linux/dmaengine.h b/include/linux/dmaengine.h
78347index c5c92d5..6a5c2b2 100644
78348--- a/include/linux/dmaengine.h
78349+++ b/include/linux/dmaengine.h
78350@@ -1150,9 +1150,9 @@ struct dma_pinned_list {
78351 struct dma_pinned_list *dma_pin_iovec_pages(struct iovec *iov, size_t len);
78352 void dma_unpin_iovec_pages(struct dma_pinned_list* pinned_list);
78353
78354-dma_cookie_t dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
78355+dma_cookie_t __intentional_overflow(0) dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
78356 struct dma_pinned_list *pinned_list, unsigned char *kdata, size_t len);
78357-dma_cookie_t dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
78358+dma_cookie_t __intentional_overflow(0) dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
78359 struct dma_pinned_list *pinned_list, struct page *page,
78360 unsigned int offset, size_t len);
78361
78362diff --git a/include/linux/efi.h b/include/linux/efi.h
78363index 0a819e7..8ed47f1 100644
78364--- a/include/linux/efi.h
78365+++ b/include/linux/efi.h
78366@@ -768,6 +768,7 @@ struct efivar_operations {
78367 efi_set_variable_t *set_variable;
78368 efi_query_variable_store_t *query_variable_store;
78369 };
78370+typedef struct efivar_operations __no_const efivar_operations_no_const;
78371
78372 struct efivars {
78373 /*
78374diff --git a/include/linux/elf.h b/include/linux/elf.h
78375index 67a5fa7..b817372 100644
78376--- a/include/linux/elf.h
78377+++ b/include/linux/elf.h
78378@@ -24,6 +24,7 @@ extern Elf32_Dyn _DYNAMIC [];
78379 #define elf_note elf32_note
78380 #define elf_addr_t Elf32_Off
78381 #define Elf_Half Elf32_Half
78382+#define elf_dyn Elf32_Dyn
78383
78384 #else
78385
78386@@ -34,6 +35,7 @@ extern Elf64_Dyn _DYNAMIC [];
78387 #define elf_note elf64_note
78388 #define elf_addr_t Elf64_Off
78389 #define Elf_Half Elf64_Half
78390+#define elf_dyn Elf64_Dyn
78391
78392 #endif
78393
78394diff --git a/include/linux/err.h b/include/linux/err.h
78395index 15f92e0..e825a8e 100644
78396--- a/include/linux/err.h
78397+++ b/include/linux/err.h
78398@@ -19,12 +19,12 @@
78399
78400 #define IS_ERR_VALUE(x) unlikely((x) >= (unsigned long)-MAX_ERRNO)
78401
78402-static inline void * __must_check ERR_PTR(long error)
78403+static inline void * __must_check __intentional_overflow(-1) ERR_PTR(long error)
78404 {
78405 return (void *) error;
78406 }
78407
78408-static inline long __must_check PTR_ERR(__force const void *ptr)
78409+static inline long __must_check __intentional_overflow(-1) PTR_ERR(__force const void *ptr)
78410 {
78411 return (long) ptr;
78412 }
78413diff --git a/include/linux/extcon.h b/include/linux/extcon.h
78414index 21c59af..6057a03 100644
78415--- a/include/linux/extcon.h
78416+++ b/include/linux/extcon.h
78417@@ -135,7 +135,7 @@ struct extcon_dev {
78418 /* /sys/class/extcon/.../mutually_exclusive/... */
78419 struct attribute_group attr_g_muex;
78420 struct attribute **attrs_muex;
78421- struct device_attribute *d_attrs_muex;
78422+ device_attribute_no_const *d_attrs_muex;
78423 };
78424
78425 /**
78426diff --git a/include/linux/fb.h b/include/linux/fb.h
78427index fe6ac95..898d41d 100644
78428--- a/include/linux/fb.h
78429+++ b/include/linux/fb.h
78430@@ -304,7 +304,7 @@ struct fb_ops {
78431 /* called at KDB enter and leave time to prepare the console */
78432 int (*fb_debug_enter)(struct fb_info *info);
78433 int (*fb_debug_leave)(struct fb_info *info);
78434-};
78435+} __do_const;
78436
78437 #ifdef CONFIG_FB_TILEBLITTING
78438 #define FB_TILE_CURSOR_NONE 0
78439diff --git a/include/linux/fdtable.h b/include/linux/fdtable.h
78440index 70e8e21..1939916 100644
78441--- a/include/linux/fdtable.h
78442+++ b/include/linux/fdtable.h
78443@@ -102,7 +102,7 @@ struct files_struct *get_files_struct(struct task_struct *);
78444 void put_files_struct(struct files_struct *fs);
78445 void reset_files_struct(struct files_struct *);
78446 int unshare_files(struct files_struct **);
78447-struct files_struct *dup_fd(struct files_struct *, int *);
78448+struct files_struct *dup_fd(struct files_struct *, int *) __latent_entropy;
78449 void do_close_on_exec(struct files_struct *);
78450 int iterate_fd(struct files_struct *, unsigned,
78451 int (*)(const void *, struct file *, unsigned),
78452diff --git a/include/linux/frontswap.h b/include/linux/frontswap.h
78453index 8293262..2b3b8bd 100644
78454--- a/include/linux/frontswap.h
78455+++ b/include/linux/frontswap.h
78456@@ -11,7 +11,7 @@ struct frontswap_ops {
78457 int (*load)(unsigned, pgoff_t, struct page *);
78458 void (*invalidate_page)(unsigned, pgoff_t);
78459 void (*invalidate_area)(unsigned);
78460-};
78461+} __no_const;
78462
78463 extern bool frontswap_enabled;
78464 extern struct frontswap_ops *
78465diff --git a/include/linux/fs.h b/include/linux/fs.h
78466index 23b2a35..8764ab7 100644
78467--- a/include/linux/fs.h
78468+++ b/include/linux/fs.h
78469@@ -426,7 +426,7 @@ struct address_space {
78470 spinlock_t private_lock; /* for use by the address_space */
78471 struct list_head private_list; /* ditto */
78472 void *private_data; /* ditto */
78473-} __attribute__((aligned(sizeof(long))));
78474+} __attribute__((aligned(sizeof(long)))) __randomize_layout;
78475 /*
78476 * On most architectures that alignment is already the case; but
78477 * must be enforced here for CRIS, to let the least significant bit
78478@@ -469,7 +469,7 @@ struct block_device {
78479 int bd_fsfreeze_count;
78480 /* Mutex for freeze */
78481 struct mutex bd_fsfreeze_mutex;
78482-};
78483+} __randomize_layout;
78484
78485 /*
78486 * Radix-tree tags, for tagging dirty and writeback pages within the pagecache
78487@@ -613,7 +613,7 @@ struct inode {
78488 atomic_t i_readcount; /* struct files open RO */
78489 #endif
78490 void *i_private; /* fs or device private pointer */
78491-};
78492+} __randomize_layout;
78493
78494 static inline int inode_unhashed(struct inode *inode)
78495 {
78496@@ -812,7 +812,7 @@ struct file {
78497 #ifdef CONFIG_DEBUG_WRITECOUNT
78498 unsigned long f_mnt_write_state;
78499 #endif
78500-} __attribute__((aligned(4))); /* lest something weird decides that 2 is OK */
78501+} __attribute__((aligned(4))) __randomize_layout; /* lest something weird decides that 2 is OK */
78502
78503 struct file_handle {
78504 __u32 handle_bytes;
78505@@ -982,7 +982,7 @@ struct file_lock {
78506 int state; /* state of grant or error if -ve */
78507 } afs;
78508 } fl_u;
78509-};
78510+} __randomize_layout;
78511
78512 /* The following constant reflects the upper bound of the file/locking space */
78513 #ifndef OFFSET_MAX
78514@@ -1329,7 +1329,7 @@ struct super_block {
78515 struct list_lru s_dentry_lru ____cacheline_aligned_in_smp;
78516 struct list_lru s_inode_lru ____cacheline_aligned_in_smp;
78517 struct rcu_head rcu;
78518-};
78519+} __randomize_layout;
78520
78521 extern struct timespec current_fs_time(struct super_block *sb);
78522
78523@@ -1551,7 +1551,8 @@ struct file_operations {
78524 long (*fallocate)(struct file *file, int mode, loff_t offset,
78525 loff_t len);
78526 int (*show_fdinfo)(struct seq_file *m, struct file *f);
78527-};
78528+} __do_const __randomize_layout;
78529+typedef struct file_operations __no_const file_operations_no_const;
78530
78531 struct inode_operations {
78532 struct dentry * (*lookup) (struct inode *,struct dentry *, unsigned int);
78533@@ -2820,4 +2821,14 @@ static inline bool dir_relax(struct inode *inode)
78534 return !IS_DEADDIR(inode);
78535 }
78536
78537+static inline bool is_sidechannel_device(const struct inode *inode)
78538+{
78539+#ifdef CONFIG_GRKERNSEC_DEVICE_SIDECHANNEL
78540+ umode_t mode = inode->i_mode;
78541+ return ((S_ISCHR(mode) || S_ISBLK(mode)) && (mode & (S_IROTH | S_IWOTH)));
78542+#else
78543+ return false;
78544+#endif
78545+}
78546+
78547 #endif /* _LINUX_FS_H */
78548diff --git a/include/linux/fs_struct.h b/include/linux/fs_struct.h
78549index 0efc3e6..fd23610 100644
78550--- a/include/linux/fs_struct.h
78551+++ b/include/linux/fs_struct.h
78552@@ -6,13 +6,13 @@
78553 #include <linux/seqlock.h>
78554
78555 struct fs_struct {
78556- int users;
78557+ atomic_t users;
78558 spinlock_t lock;
78559 seqcount_t seq;
78560 int umask;
78561 int in_exec;
78562 struct path root, pwd;
78563-};
78564+} __randomize_layout;
78565
78566 extern struct kmem_cache *fs_cachep;
78567
78568diff --git a/include/linux/fscache-cache.h b/include/linux/fscache-cache.h
78569index 7714849..a4a5c7a 100644
78570--- a/include/linux/fscache-cache.h
78571+++ b/include/linux/fscache-cache.h
78572@@ -113,7 +113,7 @@ struct fscache_operation {
78573 fscache_operation_release_t release;
78574 };
78575
78576-extern atomic_t fscache_op_debug_id;
78577+extern atomic_unchecked_t fscache_op_debug_id;
78578 extern void fscache_op_work_func(struct work_struct *work);
78579
78580 extern void fscache_enqueue_operation(struct fscache_operation *);
78581@@ -135,7 +135,7 @@ static inline void fscache_operation_init(struct fscache_operation *op,
78582 INIT_WORK(&op->work, fscache_op_work_func);
78583 atomic_set(&op->usage, 1);
78584 op->state = FSCACHE_OP_ST_INITIALISED;
78585- op->debug_id = atomic_inc_return(&fscache_op_debug_id);
78586+ op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
78587 op->processor = processor;
78588 op->release = release;
78589 INIT_LIST_HEAD(&op->pend_link);
78590diff --git a/include/linux/fscache.h b/include/linux/fscache.h
78591index 115bb81..e7b812b 100644
78592--- a/include/linux/fscache.h
78593+++ b/include/linux/fscache.h
78594@@ -152,7 +152,7 @@ struct fscache_cookie_def {
78595 * - this is mandatory for any object that may have data
78596 */
78597 void (*now_uncached)(void *cookie_netfs_data);
78598-};
78599+} __do_const;
78600
78601 /*
78602 * fscache cached network filesystem type
78603diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h
78604index 1c804b0..1432c2b 100644
78605--- a/include/linux/fsnotify.h
78606+++ b/include/linux/fsnotify.h
78607@@ -195,6 +195,9 @@ static inline void fsnotify_access(struct file *file)
78608 struct inode *inode = file_inode(file);
78609 __u32 mask = FS_ACCESS;
78610
78611+ if (is_sidechannel_device(inode))
78612+ return;
78613+
78614 if (S_ISDIR(inode->i_mode))
78615 mask |= FS_ISDIR;
78616
78617@@ -213,6 +216,9 @@ static inline void fsnotify_modify(struct file *file)
78618 struct inode *inode = file_inode(file);
78619 __u32 mask = FS_MODIFY;
78620
78621+ if (is_sidechannel_device(inode))
78622+ return;
78623+
78624 if (S_ISDIR(inode->i_mode))
78625 mask |= FS_ISDIR;
78626
78627@@ -315,7 +321,7 @@ static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid)
78628 */
78629 static inline const unsigned char *fsnotify_oldname_init(const unsigned char *name)
78630 {
78631- return kstrdup(name, GFP_KERNEL);
78632+ return (const unsigned char *)kstrdup((const char *)name, GFP_KERNEL);
78633 }
78634
78635 /*
78636diff --git a/include/linux/genhd.h b/include/linux/genhd.h
78637index 9f3c275..8bdff5d 100644
78638--- a/include/linux/genhd.h
78639+++ b/include/linux/genhd.h
78640@@ -194,7 +194,7 @@ struct gendisk {
78641 struct kobject *slave_dir;
78642
78643 struct timer_rand_state *random;
78644- atomic_t sync_io; /* RAID */
78645+ atomic_unchecked_t sync_io; /* RAID */
78646 struct disk_events *ev;
78647 #ifdef CONFIG_BLK_DEV_INTEGRITY
78648 struct blk_integrity *integrity;
78649@@ -435,7 +435,7 @@ extern void disk_flush_events(struct gendisk *disk, unsigned int mask);
78650 extern unsigned int disk_clear_events(struct gendisk *disk, unsigned int mask);
78651
78652 /* drivers/char/random.c */
78653-extern void add_disk_randomness(struct gendisk *disk);
78654+extern void add_disk_randomness(struct gendisk *disk) __latent_entropy;
78655 extern void rand_initialize_disk(struct gendisk *disk);
78656
78657 static inline sector_t get_start_sect(struct block_device *bdev)
78658diff --git a/include/linux/genl_magic_func.h b/include/linux/genl_magic_func.h
78659index c0894dd..2fbf10c 100644
78660--- a/include/linux/genl_magic_func.h
78661+++ b/include/linux/genl_magic_func.h
78662@@ -246,7 +246,7 @@ const char *CONCAT_(GENL_MAGIC_FAMILY, _genl_cmd_to_str)(__u8 cmd)
78663 },
78664
78665 #define ZZZ_genl_ops CONCAT_(GENL_MAGIC_FAMILY, _genl_ops)
78666-static struct genl_ops ZZZ_genl_ops[] __read_mostly = {
78667+static struct genl_ops ZZZ_genl_ops[] = {
78668 #include GENL_MAGIC_INCLUDE_FILE
78669 };
78670
78671diff --git a/include/linux/gfp.h b/include/linux/gfp.h
78672index 39b81dc..819dc51 100644
78673--- a/include/linux/gfp.h
78674+++ b/include/linux/gfp.h
78675@@ -36,6 +36,13 @@ struct vm_area_struct;
78676 #define ___GFP_NO_KSWAPD 0x400000u
78677 #define ___GFP_OTHER_NODE 0x800000u
78678 #define ___GFP_WRITE 0x1000000u
78679+
78680+#ifdef CONFIG_PAX_USERCOPY_SLABS
78681+#define ___GFP_USERCOPY 0x2000000u
78682+#else
78683+#define ___GFP_USERCOPY 0
78684+#endif
78685+
78686 /* If the above are modified, __GFP_BITS_SHIFT may need updating */
78687
78688 /*
78689@@ -93,6 +100,7 @@ struct vm_area_struct;
78690 #define __GFP_OTHER_NODE ((__force gfp_t)___GFP_OTHER_NODE) /* On behalf of other node */
78691 #define __GFP_KMEMCG ((__force gfp_t)___GFP_KMEMCG) /* Allocation comes from a memcg-accounted resource */
78692 #define __GFP_WRITE ((__force gfp_t)___GFP_WRITE) /* Allocator intends to dirty page */
78693+#define __GFP_USERCOPY ((__force gfp_t)___GFP_USERCOPY)/* Allocator intends to copy page to/from userland */
78694
78695 /*
78696 * This may seem redundant, but it's a way of annotating false positives vs.
78697@@ -100,7 +108,7 @@ struct vm_area_struct;
78698 */
78699 #define __GFP_NOTRACK_FALSE_POSITIVE (__GFP_NOTRACK)
78700
78701-#define __GFP_BITS_SHIFT 25 /* Room for N __GFP_FOO bits */
78702+#define __GFP_BITS_SHIFT 26 /* Room for N __GFP_FOO bits */
78703 #define __GFP_BITS_MASK ((__force gfp_t)((1 << __GFP_BITS_SHIFT) - 1))
78704
78705 /* This equals 0, but use constants in case they ever change */
78706@@ -158,6 +166,8 @@ struct vm_area_struct;
78707 /* 4GB DMA on some platforms */
78708 #define GFP_DMA32 __GFP_DMA32
78709
78710+#define GFP_USERCOPY __GFP_USERCOPY
78711+
78712 /* Convert GFP flags to their corresponding migrate type */
78713 static inline int allocflags_to_migratetype(gfp_t gfp_flags)
78714 {
78715diff --git a/include/linux/gracl.h b/include/linux/gracl.h
78716new file mode 100644
78717index 0000000..edb2cb6
78718--- /dev/null
78719+++ b/include/linux/gracl.h
78720@@ -0,0 +1,340 @@
78721+#ifndef GR_ACL_H
78722+#define GR_ACL_H
78723+
78724+#include <linux/grdefs.h>
78725+#include <linux/resource.h>
78726+#include <linux/capability.h>
78727+#include <linux/dcache.h>
78728+#include <asm/resource.h>
78729+
78730+/* Major status information */
78731+
78732+#define GR_VERSION "grsecurity 3.0"
78733+#define GRSECURITY_VERSION 0x3000
78734+
78735+enum {
78736+ GR_SHUTDOWN = 0,
78737+ GR_ENABLE = 1,
78738+ GR_SPROLE = 2,
78739+ GR_OLDRELOAD = 3,
78740+ GR_SEGVMOD = 4,
78741+ GR_STATUS = 5,
78742+ GR_UNSPROLE = 6,
78743+ GR_PASSSET = 7,
78744+ GR_SPROLEPAM = 8,
78745+ GR_RELOAD = 9,
78746+};
78747+
78748+/* Password setup definitions
78749+ * kernel/grhash.c */
78750+enum {
78751+ GR_PW_LEN = 128,
78752+ GR_SALT_LEN = 16,
78753+ GR_SHA_LEN = 32,
78754+};
78755+
78756+enum {
78757+ GR_SPROLE_LEN = 64,
78758+};
78759+
78760+enum {
78761+ GR_NO_GLOB = 0,
78762+ GR_REG_GLOB,
78763+ GR_CREATE_GLOB
78764+};
78765+
78766+#define GR_NLIMITS 32
78767+
78768+/* Begin Data Structures */
78769+
78770+struct sprole_pw {
78771+ unsigned char *rolename;
78772+ unsigned char salt[GR_SALT_LEN];
78773+ unsigned char sum[GR_SHA_LEN]; /* 256-bit SHA hash of the password */
78774+};
78775+
78776+struct name_entry {
78777+ __u32 key;
78778+ ino_t inode;
78779+ dev_t device;
78780+ char *name;
78781+ __u16 len;
78782+ __u8 deleted;
78783+ struct name_entry *prev;
78784+ struct name_entry *next;
78785+};
78786+
78787+struct inodev_entry {
78788+ struct name_entry *nentry;
78789+ struct inodev_entry *prev;
78790+ struct inodev_entry *next;
78791+};
78792+
78793+struct acl_role_db {
78794+ struct acl_role_label **r_hash;
78795+ __u32 r_size;
78796+};
78797+
78798+struct inodev_db {
78799+ struct inodev_entry **i_hash;
78800+ __u32 i_size;
78801+};
78802+
78803+struct name_db {
78804+ struct name_entry **n_hash;
78805+ __u32 n_size;
78806+};
78807+
78808+struct crash_uid {
78809+ uid_t uid;
78810+ unsigned long expires;
78811+};
78812+
78813+struct gr_hash_struct {
78814+ void **table;
78815+ void **nametable;
78816+ void *first;
78817+ __u32 table_size;
78818+ __u32 used_size;
78819+ int type;
78820+};
78821+
78822+/* Userspace Grsecurity ACL data structures */
78823+
78824+struct acl_subject_label {
78825+ char *filename;
78826+ ino_t inode;
78827+ dev_t device;
78828+ __u32 mode;
78829+ kernel_cap_t cap_mask;
78830+ kernel_cap_t cap_lower;
78831+ kernel_cap_t cap_invert_audit;
78832+
78833+ struct rlimit res[GR_NLIMITS];
78834+ __u32 resmask;
78835+
78836+ __u8 user_trans_type;
78837+ __u8 group_trans_type;
78838+ uid_t *user_transitions;
78839+ gid_t *group_transitions;
78840+ __u16 user_trans_num;
78841+ __u16 group_trans_num;
78842+
78843+ __u32 sock_families[2];
78844+ __u32 ip_proto[8];
78845+ __u32 ip_type;
78846+ struct acl_ip_label **ips;
78847+ __u32 ip_num;
78848+ __u32 inaddr_any_override;
78849+
78850+ __u32 crashes;
78851+ unsigned long expires;
78852+
78853+ struct acl_subject_label *parent_subject;
78854+ struct gr_hash_struct *hash;
78855+ struct acl_subject_label *prev;
78856+ struct acl_subject_label *next;
78857+
78858+ struct acl_object_label **obj_hash;
78859+ __u32 obj_hash_size;
78860+ __u16 pax_flags;
78861+};
78862+
78863+struct role_allowed_ip {
78864+ __u32 addr;
78865+ __u32 netmask;
78866+
78867+ struct role_allowed_ip *prev;
78868+ struct role_allowed_ip *next;
78869+};
78870+
78871+struct role_transition {
78872+ char *rolename;
78873+
78874+ struct role_transition *prev;
78875+ struct role_transition *next;
78876+};
78877+
78878+struct acl_role_label {
78879+ char *rolename;
78880+ uid_t uidgid;
78881+ __u16 roletype;
78882+
78883+ __u16 auth_attempts;
78884+ unsigned long expires;
78885+
78886+ struct acl_subject_label *root_label;
78887+ struct gr_hash_struct *hash;
78888+
78889+ struct acl_role_label *prev;
78890+ struct acl_role_label *next;
78891+
78892+ struct role_transition *transitions;
78893+ struct role_allowed_ip *allowed_ips;
78894+ uid_t *domain_children;
78895+ __u16 domain_child_num;
78896+
78897+ umode_t umask;
78898+
78899+ struct acl_subject_label **subj_hash;
78900+ __u32 subj_hash_size;
78901+};
78902+
78903+struct user_acl_role_db {
78904+ struct acl_role_label **r_table;
78905+ __u32 num_pointers; /* Number of allocations to track */
78906+ __u32 num_roles; /* Number of roles */
78907+ __u32 num_domain_children; /* Number of domain children */
78908+ __u32 num_subjects; /* Number of subjects */
78909+ __u32 num_objects; /* Number of objects */
78910+};
78911+
78912+struct acl_object_label {
78913+ char *filename;
78914+ ino_t inode;
78915+ dev_t device;
78916+ __u32 mode;
78917+
78918+ struct acl_subject_label *nested;
78919+ struct acl_object_label *globbed;
78920+
78921+ /* next two structures not used */
78922+
78923+ struct acl_object_label *prev;
78924+ struct acl_object_label *next;
78925+};
78926+
78927+struct acl_ip_label {
78928+ char *iface;
78929+ __u32 addr;
78930+ __u32 netmask;
78931+ __u16 low, high;
78932+ __u8 mode;
78933+ __u32 type;
78934+ __u32 proto[8];
78935+
78936+ /* next two structures not used */
78937+
78938+ struct acl_ip_label *prev;
78939+ struct acl_ip_label *next;
78940+};
78941+
78942+struct gr_arg {
78943+ struct user_acl_role_db role_db;
78944+ unsigned char pw[GR_PW_LEN];
78945+ unsigned char salt[GR_SALT_LEN];
78946+ unsigned char sum[GR_SHA_LEN];
78947+ unsigned char sp_role[GR_SPROLE_LEN];
78948+ struct sprole_pw *sprole_pws;
78949+ dev_t segv_device;
78950+ ino_t segv_inode;
78951+ uid_t segv_uid;
78952+ __u16 num_sprole_pws;
78953+ __u16 mode;
78954+};
78955+
78956+struct gr_arg_wrapper {
78957+ struct gr_arg *arg;
78958+ __u32 version;
78959+ __u32 size;
78960+};
78961+
78962+struct subject_map {
78963+ struct acl_subject_label *user;
78964+ struct acl_subject_label *kernel;
78965+ struct subject_map *prev;
78966+ struct subject_map *next;
78967+};
78968+
78969+struct acl_subj_map_db {
78970+ struct subject_map **s_hash;
78971+ __u32 s_size;
78972+};
78973+
78974+struct gr_policy_state {
78975+ struct sprole_pw **acl_special_roles;
78976+ __u16 num_sprole_pws;
78977+ struct acl_role_label *kernel_role;
78978+ struct acl_role_label *role_list;
78979+ struct acl_role_label *default_role;
78980+ struct acl_role_db acl_role_set;
78981+ struct acl_subj_map_db subj_map_set;
78982+ struct name_db name_set;
78983+ struct inodev_db inodev_set;
78984+};
78985+
78986+struct gr_alloc_state {
78987+ unsigned long alloc_stack_next;
78988+ unsigned long alloc_stack_size;
78989+ void **alloc_stack;
78990+};
78991+
78992+struct gr_reload_state {
78993+ struct gr_policy_state oldpolicy;
78994+ struct gr_alloc_state oldalloc;
78995+ struct gr_policy_state newpolicy;
78996+ struct gr_alloc_state newalloc;
78997+ struct gr_policy_state *oldpolicy_ptr;
78998+ struct gr_alloc_state *oldalloc_ptr;
78999+ unsigned char oldmode;
79000+};
79001+
79002+/* End Data Structures Section */
79003+
79004+/* Hash functions generated by empirical testing by Brad Spengler
79005+ Makes good use of the low bits of the inode. Generally 0-1 times
79006+ in loop for successful match. 0-3 for unsuccessful match.
79007+ Shift/add algorithm with modulus of table size and an XOR*/
79008+
79009+static __inline__ unsigned int
79010+gr_rhash(const uid_t uid, const __u16 type, const unsigned int sz)
79011+{
79012+ return ((((uid + type) << (16 + type)) ^ uid) % sz);
79013+}
79014+
79015+ static __inline__ unsigned int
79016+gr_shash(const struct acl_subject_label *userp, const unsigned int sz)
79017+{
79018+ return ((const unsigned long)userp % sz);
79019+}
79020+
79021+static __inline__ unsigned int
79022+gr_fhash(const ino_t ino, const dev_t dev, const unsigned int sz)
79023+{
79024+ return (((ino + dev) ^ ((ino << 13) + (ino << 23) + (dev << 9))) % sz);
79025+}
79026+
79027+static __inline__ unsigned int
79028+gr_nhash(const char *name, const __u16 len, const unsigned int sz)
79029+{
79030+ return full_name_hash((const unsigned char *)name, len) % sz;
79031+}
79032+
79033+#define FOR_EACH_SUBJECT_START(role,subj,iter) \
79034+ subj = NULL; \
79035+ iter = 0; \
79036+ while (iter < role->subj_hash_size) { \
79037+ if (subj == NULL) \
79038+ subj = role->subj_hash[iter]; \
79039+ if (subj == NULL) { \
79040+ iter++; \
79041+ continue; \
79042+ }
79043+
79044+#define FOR_EACH_SUBJECT_END(subj,iter) \
79045+ subj = subj->next; \
79046+ if (subj == NULL) \
79047+ iter++; \
79048+ }
79049+
79050+
79051+#define FOR_EACH_NESTED_SUBJECT_START(role,subj) \
79052+ subj = role->hash->first; \
79053+ while (subj != NULL) {
79054+
79055+#define FOR_EACH_NESTED_SUBJECT_END(subj) \
79056+ subj = subj->next; \
79057+ }
79058+
79059+#endif
79060+
79061diff --git a/include/linux/gracl_compat.h b/include/linux/gracl_compat.h
79062new file mode 100644
79063index 0000000..33ebd1f
79064--- /dev/null
79065+++ b/include/linux/gracl_compat.h
79066@@ -0,0 +1,156 @@
79067+#ifndef GR_ACL_COMPAT_H
79068+#define GR_ACL_COMPAT_H
79069+
79070+#include <linux/resource.h>
79071+#include <asm/resource.h>
79072+
79073+struct sprole_pw_compat {
79074+ compat_uptr_t rolename;
79075+ unsigned char salt[GR_SALT_LEN];
79076+ unsigned char sum[GR_SHA_LEN];
79077+};
79078+
79079+struct gr_hash_struct_compat {
79080+ compat_uptr_t table;
79081+ compat_uptr_t nametable;
79082+ compat_uptr_t first;
79083+ __u32 table_size;
79084+ __u32 used_size;
79085+ int type;
79086+};
79087+
79088+struct acl_subject_label_compat {
79089+ compat_uptr_t filename;
79090+ compat_ino_t inode;
79091+ __u32 device;
79092+ __u32 mode;
79093+ kernel_cap_t cap_mask;
79094+ kernel_cap_t cap_lower;
79095+ kernel_cap_t cap_invert_audit;
79096+
79097+ struct compat_rlimit res[GR_NLIMITS];
79098+ __u32 resmask;
79099+
79100+ __u8 user_trans_type;
79101+ __u8 group_trans_type;
79102+ compat_uptr_t user_transitions;
79103+ compat_uptr_t group_transitions;
79104+ __u16 user_trans_num;
79105+ __u16 group_trans_num;
79106+
79107+ __u32 sock_families[2];
79108+ __u32 ip_proto[8];
79109+ __u32 ip_type;
79110+ compat_uptr_t ips;
79111+ __u32 ip_num;
79112+ __u32 inaddr_any_override;
79113+
79114+ __u32 crashes;
79115+ compat_ulong_t expires;
79116+
79117+ compat_uptr_t parent_subject;
79118+ compat_uptr_t hash;
79119+ compat_uptr_t prev;
79120+ compat_uptr_t next;
79121+
79122+ compat_uptr_t obj_hash;
79123+ __u32 obj_hash_size;
79124+ __u16 pax_flags;
79125+};
79126+
79127+struct role_allowed_ip_compat {
79128+ __u32 addr;
79129+ __u32 netmask;
79130+
79131+ compat_uptr_t prev;
79132+ compat_uptr_t next;
79133+};
79134+
79135+struct role_transition_compat {
79136+ compat_uptr_t rolename;
79137+
79138+ compat_uptr_t prev;
79139+ compat_uptr_t next;
79140+};
79141+
79142+struct acl_role_label_compat {
79143+ compat_uptr_t rolename;
79144+ uid_t uidgid;
79145+ __u16 roletype;
79146+
79147+ __u16 auth_attempts;
79148+ compat_ulong_t expires;
79149+
79150+ compat_uptr_t root_label;
79151+ compat_uptr_t hash;
79152+
79153+ compat_uptr_t prev;
79154+ compat_uptr_t next;
79155+
79156+ compat_uptr_t transitions;
79157+ compat_uptr_t allowed_ips;
79158+ compat_uptr_t domain_children;
79159+ __u16 domain_child_num;
79160+
79161+ umode_t umask;
79162+
79163+ compat_uptr_t subj_hash;
79164+ __u32 subj_hash_size;
79165+};
79166+
79167+struct user_acl_role_db_compat {
79168+ compat_uptr_t r_table;
79169+ __u32 num_pointers;
79170+ __u32 num_roles;
79171+ __u32 num_domain_children;
79172+ __u32 num_subjects;
79173+ __u32 num_objects;
79174+};
79175+
79176+struct acl_object_label_compat {
79177+ compat_uptr_t filename;
79178+ compat_ino_t inode;
79179+ __u32 device;
79180+ __u32 mode;
79181+
79182+ compat_uptr_t nested;
79183+ compat_uptr_t globbed;
79184+
79185+ compat_uptr_t prev;
79186+ compat_uptr_t next;
79187+};
79188+
79189+struct acl_ip_label_compat {
79190+ compat_uptr_t iface;
79191+ __u32 addr;
79192+ __u32 netmask;
79193+ __u16 low, high;
79194+ __u8 mode;
79195+ __u32 type;
79196+ __u32 proto[8];
79197+
79198+ compat_uptr_t prev;
79199+ compat_uptr_t next;
79200+};
79201+
79202+struct gr_arg_compat {
79203+ struct user_acl_role_db_compat role_db;
79204+ unsigned char pw[GR_PW_LEN];
79205+ unsigned char salt[GR_SALT_LEN];
79206+ unsigned char sum[GR_SHA_LEN];
79207+ unsigned char sp_role[GR_SPROLE_LEN];
79208+ compat_uptr_t sprole_pws;
79209+ __u32 segv_device;
79210+ compat_ino_t segv_inode;
79211+ uid_t segv_uid;
79212+ __u16 num_sprole_pws;
79213+ __u16 mode;
79214+};
79215+
79216+struct gr_arg_wrapper_compat {
79217+ compat_uptr_t arg;
79218+ __u32 version;
79219+ __u32 size;
79220+};
79221+
79222+#endif
79223diff --git a/include/linux/gralloc.h b/include/linux/gralloc.h
79224new file mode 100644
79225index 0000000..323ecf2
79226--- /dev/null
79227+++ b/include/linux/gralloc.h
79228@@ -0,0 +1,9 @@
79229+#ifndef __GRALLOC_H
79230+#define __GRALLOC_H
79231+
79232+void acl_free_all(void);
79233+int acl_alloc_stack_init(unsigned long size);
79234+void *acl_alloc(unsigned long len);
79235+void *acl_alloc_num(unsigned long num, unsigned long len);
79236+
79237+#endif
79238diff --git a/include/linux/grdefs.h b/include/linux/grdefs.h
79239new file mode 100644
79240index 0000000..be66033
79241--- /dev/null
79242+++ b/include/linux/grdefs.h
79243@@ -0,0 +1,140 @@
79244+#ifndef GRDEFS_H
79245+#define GRDEFS_H
79246+
79247+/* Begin grsecurity status declarations */
79248+
79249+enum {
79250+ GR_READY = 0x01,
79251+ GR_STATUS_INIT = 0x00 // disabled state
79252+};
79253+
79254+/* Begin ACL declarations */
79255+
79256+/* Role flags */
79257+
79258+enum {
79259+ GR_ROLE_USER = 0x0001,
79260+ GR_ROLE_GROUP = 0x0002,
79261+ GR_ROLE_DEFAULT = 0x0004,
79262+ GR_ROLE_SPECIAL = 0x0008,
79263+ GR_ROLE_AUTH = 0x0010,
79264+ GR_ROLE_NOPW = 0x0020,
79265+ GR_ROLE_GOD = 0x0040,
79266+ GR_ROLE_LEARN = 0x0080,
79267+ GR_ROLE_TPE = 0x0100,
79268+ GR_ROLE_DOMAIN = 0x0200,
79269+ GR_ROLE_PAM = 0x0400,
79270+ GR_ROLE_PERSIST = 0x0800
79271+};
79272+
79273+/* ACL Subject and Object mode flags */
79274+enum {
79275+ GR_DELETED = 0x80000000
79276+};
79277+
79278+/* ACL Object-only mode flags */
79279+enum {
79280+ GR_READ = 0x00000001,
79281+ GR_APPEND = 0x00000002,
79282+ GR_WRITE = 0x00000004,
79283+ GR_EXEC = 0x00000008,
79284+ GR_FIND = 0x00000010,
79285+ GR_INHERIT = 0x00000020,
79286+ GR_SETID = 0x00000040,
79287+ GR_CREATE = 0x00000080,
79288+ GR_DELETE = 0x00000100,
79289+ GR_LINK = 0x00000200,
79290+ GR_AUDIT_READ = 0x00000400,
79291+ GR_AUDIT_APPEND = 0x00000800,
79292+ GR_AUDIT_WRITE = 0x00001000,
79293+ GR_AUDIT_EXEC = 0x00002000,
79294+ GR_AUDIT_FIND = 0x00004000,
79295+ GR_AUDIT_INHERIT= 0x00008000,
79296+ GR_AUDIT_SETID = 0x00010000,
79297+ GR_AUDIT_CREATE = 0x00020000,
79298+ GR_AUDIT_DELETE = 0x00040000,
79299+ GR_AUDIT_LINK = 0x00080000,
79300+ GR_PTRACERD = 0x00100000,
79301+ GR_NOPTRACE = 0x00200000,
79302+ GR_SUPPRESS = 0x00400000,
79303+ GR_NOLEARN = 0x00800000,
79304+ GR_INIT_TRANSFER= 0x01000000
79305+};
79306+
79307+#define GR_AUDITS (GR_AUDIT_READ | GR_AUDIT_WRITE | GR_AUDIT_APPEND | GR_AUDIT_EXEC | \
79308+ GR_AUDIT_FIND | GR_AUDIT_INHERIT | GR_AUDIT_SETID | \
79309+ GR_AUDIT_CREATE | GR_AUDIT_DELETE | GR_AUDIT_LINK)
79310+
79311+/* ACL subject-only mode flags */
79312+enum {
79313+ GR_KILL = 0x00000001,
79314+ GR_VIEW = 0x00000002,
79315+ GR_PROTECTED = 0x00000004,
79316+ GR_LEARN = 0x00000008,
79317+ GR_OVERRIDE = 0x00000010,
79318+ /* just a placeholder, this mode is only used in userspace */
79319+ GR_DUMMY = 0x00000020,
79320+ GR_PROTSHM = 0x00000040,
79321+ GR_KILLPROC = 0x00000080,
79322+ GR_KILLIPPROC = 0x00000100,
79323+ /* just a placeholder, this mode is only used in userspace */
79324+ GR_NOTROJAN = 0x00000200,
79325+ GR_PROTPROCFD = 0x00000400,
79326+ GR_PROCACCT = 0x00000800,
79327+ GR_RELAXPTRACE = 0x00001000,
79328+ //GR_NESTED = 0x00002000,
79329+ GR_INHERITLEARN = 0x00004000,
79330+ GR_PROCFIND = 0x00008000,
79331+ GR_POVERRIDE = 0x00010000,
79332+ GR_KERNELAUTH = 0x00020000,
79333+ GR_ATSECURE = 0x00040000,
79334+ GR_SHMEXEC = 0x00080000
79335+};
79336+
79337+enum {
79338+ GR_PAX_ENABLE_SEGMEXEC = 0x0001,
79339+ GR_PAX_ENABLE_PAGEEXEC = 0x0002,
79340+ GR_PAX_ENABLE_MPROTECT = 0x0004,
79341+ GR_PAX_ENABLE_RANDMMAP = 0x0008,
79342+ GR_PAX_ENABLE_EMUTRAMP = 0x0010,
79343+ GR_PAX_DISABLE_SEGMEXEC = 0x0100,
79344+ GR_PAX_DISABLE_PAGEEXEC = 0x0200,
79345+ GR_PAX_DISABLE_MPROTECT = 0x0400,
79346+ GR_PAX_DISABLE_RANDMMAP = 0x0800,
79347+ GR_PAX_DISABLE_EMUTRAMP = 0x1000,
79348+};
79349+
79350+enum {
79351+ GR_ID_USER = 0x01,
79352+ GR_ID_GROUP = 0x02,
79353+};
79354+
79355+enum {
79356+ GR_ID_ALLOW = 0x01,
79357+ GR_ID_DENY = 0x02,
79358+};
79359+
79360+#define GR_CRASH_RES 31
79361+#define GR_UIDTABLE_MAX 500
79362+
79363+/* begin resource learning section */
79364+enum {
79365+ GR_RLIM_CPU_BUMP = 60,
79366+ GR_RLIM_FSIZE_BUMP = 50000,
79367+ GR_RLIM_DATA_BUMP = 10000,
79368+ GR_RLIM_STACK_BUMP = 1000,
79369+ GR_RLIM_CORE_BUMP = 10000,
79370+ GR_RLIM_RSS_BUMP = 500000,
79371+ GR_RLIM_NPROC_BUMP = 1,
79372+ GR_RLIM_NOFILE_BUMP = 5,
79373+ GR_RLIM_MEMLOCK_BUMP = 50000,
79374+ GR_RLIM_AS_BUMP = 500000,
79375+ GR_RLIM_LOCKS_BUMP = 2,
79376+ GR_RLIM_SIGPENDING_BUMP = 5,
79377+ GR_RLIM_MSGQUEUE_BUMP = 10000,
79378+ GR_RLIM_NICE_BUMP = 1,
79379+ GR_RLIM_RTPRIO_BUMP = 1,
79380+ GR_RLIM_RTTIME_BUMP = 1000000
79381+};
79382+
79383+#endif
79384diff --git a/include/linux/grinternal.h b/include/linux/grinternal.h
79385new file mode 100644
79386index 0000000..d25522e
79387--- /dev/null
79388+++ b/include/linux/grinternal.h
79389@@ -0,0 +1,229 @@
79390+#ifndef __GRINTERNAL_H
79391+#define __GRINTERNAL_H
79392+
79393+#ifdef CONFIG_GRKERNSEC
79394+
79395+#include <linux/fs.h>
79396+#include <linux/mnt_namespace.h>
79397+#include <linux/nsproxy.h>
79398+#include <linux/gracl.h>
79399+#include <linux/grdefs.h>
79400+#include <linux/grmsg.h>
79401+
79402+void gr_add_learn_entry(const char *fmt, ...)
79403+ __attribute__ ((format (printf, 1, 2)));
79404+__u32 gr_search_file(const struct dentry *dentry, const __u32 mode,
79405+ const struct vfsmount *mnt);
79406+__u32 gr_check_create(const struct dentry *new_dentry,
79407+ const struct dentry *parent,
79408+ const struct vfsmount *mnt, const __u32 mode);
79409+int gr_check_protected_task(const struct task_struct *task);
79410+__u32 to_gr_audit(const __u32 reqmode);
79411+int gr_set_acls(const int type);
79412+int gr_acl_is_enabled(void);
79413+char gr_roletype_to_char(void);
79414+
79415+void gr_handle_alertkill(struct task_struct *task);
79416+char *gr_to_filename(const struct dentry *dentry,
79417+ const struct vfsmount *mnt);
79418+char *gr_to_filename1(const struct dentry *dentry,
79419+ const struct vfsmount *mnt);
79420+char *gr_to_filename2(const struct dentry *dentry,
79421+ const struct vfsmount *mnt);
79422+char *gr_to_filename3(const struct dentry *dentry,
79423+ const struct vfsmount *mnt);
79424+
79425+extern int grsec_enable_ptrace_readexec;
79426+extern int grsec_enable_harden_ptrace;
79427+extern int grsec_enable_link;
79428+extern int grsec_enable_fifo;
79429+extern int grsec_enable_execve;
79430+extern int grsec_enable_shm;
79431+extern int grsec_enable_execlog;
79432+extern int grsec_enable_signal;
79433+extern int grsec_enable_audit_ptrace;
79434+extern int grsec_enable_forkfail;
79435+extern int grsec_enable_time;
79436+extern int grsec_enable_rofs;
79437+extern int grsec_deny_new_usb;
79438+extern int grsec_enable_chroot_shmat;
79439+extern int grsec_enable_chroot_mount;
79440+extern int grsec_enable_chroot_double;
79441+extern int grsec_enable_chroot_pivot;
79442+extern int grsec_enable_chroot_chdir;
79443+extern int grsec_enable_chroot_chmod;
79444+extern int grsec_enable_chroot_mknod;
79445+extern int grsec_enable_chroot_fchdir;
79446+extern int grsec_enable_chroot_nice;
79447+extern int grsec_enable_chroot_execlog;
79448+extern int grsec_enable_chroot_caps;
79449+extern int grsec_enable_chroot_sysctl;
79450+extern int grsec_enable_chroot_unix;
79451+extern int grsec_enable_symlinkown;
79452+extern kgid_t grsec_symlinkown_gid;
79453+extern int grsec_enable_tpe;
79454+extern kgid_t grsec_tpe_gid;
79455+extern int grsec_enable_tpe_all;
79456+extern int grsec_enable_tpe_invert;
79457+extern int grsec_enable_socket_all;
79458+extern kgid_t grsec_socket_all_gid;
79459+extern int grsec_enable_socket_client;
79460+extern kgid_t grsec_socket_client_gid;
79461+extern int grsec_enable_socket_server;
79462+extern kgid_t grsec_socket_server_gid;
79463+extern kgid_t grsec_audit_gid;
79464+extern int grsec_enable_group;
79465+extern int grsec_enable_log_rwxmaps;
79466+extern int grsec_enable_mount;
79467+extern int grsec_enable_chdir;
79468+extern int grsec_resource_logging;
79469+extern int grsec_enable_blackhole;
79470+extern int grsec_lastack_retries;
79471+extern int grsec_enable_brute;
79472+extern int grsec_enable_harden_ipc;
79473+extern int grsec_lock;
79474+
79475+extern spinlock_t grsec_alert_lock;
79476+extern unsigned long grsec_alert_wtime;
79477+extern unsigned long grsec_alert_fyet;
79478+
79479+extern spinlock_t grsec_audit_lock;
79480+
79481+extern rwlock_t grsec_exec_file_lock;
79482+
79483+#define gr_task_fullpath(tsk) ((tsk)->exec_file ? \
79484+ gr_to_filename2((tsk)->exec_file->f_path.dentry, \
79485+ (tsk)->exec_file->f_path.mnt) : "/")
79486+
79487+#define gr_parent_task_fullpath(tsk) ((tsk)->real_parent->exec_file ? \
79488+ gr_to_filename3((tsk)->real_parent->exec_file->f_path.dentry, \
79489+ (tsk)->real_parent->exec_file->f_path.mnt) : "/")
79490+
79491+#define gr_task_fullpath0(tsk) ((tsk)->exec_file ? \
79492+ gr_to_filename((tsk)->exec_file->f_path.dentry, \
79493+ (tsk)->exec_file->f_path.mnt) : "/")
79494+
79495+#define gr_parent_task_fullpath0(tsk) ((tsk)->real_parent->exec_file ? \
79496+ gr_to_filename1((tsk)->real_parent->exec_file->f_path.dentry, \
79497+ (tsk)->real_parent->exec_file->f_path.mnt) : "/")
79498+
79499+#define proc_is_chrooted(tsk_a) ((tsk_a)->gr_is_chrooted)
79500+
79501+#define have_same_root(tsk_a,tsk_b) ((tsk_a)->gr_chroot_dentry == (tsk_b)->gr_chroot_dentry)
79502+
79503+static inline bool gr_is_same_file(const struct file *file1, const struct file *file2)
79504+{
79505+ if (file1 && file2) {
79506+ const struct inode *inode1 = file1->f_path.dentry->d_inode;
79507+ const struct inode *inode2 = file2->f_path.dentry->d_inode;
79508+ if (inode1->i_ino == inode2->i_ino && inode1->i_sb->s_dev == inode2->i_sb->s_dev)
79509+ return true;
79510+ }
79511+
79512+ return false;
79513+}
79514+
79515+#define GR_CHROOT_CAPS {{ \
79516+ CAP_TO_MASK(CAP_LINUX_IMMUTABLE) | CAP_TO_MASK(CAP_NET_ADMIN) | \
79517+ CAP_TO_MASK(CAP_SYS_MODULE) | CAP_TO_MASK(CAP_SYS_RAWIO) | \
79518+ CAP_TO_MASK(CAP_SYS_PACCT) | CAP_TO_MASK(CAP_SYS_ADMIN) | \
79519+ CAP_TO_MASK(CAP_SYS_BOOT) | CAP_TO_MASK(CAP_SYS_TIME) | \
79520+ CAP_TO_MASK(CAP_NET_RAW) | CAP_TO_MASK(CAP_SYS_TTY_CONFIG) | \
79521+ CAP_TO_MASK(CAP_IPC_OWNER) | CAP_TO_MASK(CAP_SETFCAP), \
79522+ CAP_TO_MASK(CAP_SYSLOG) | CAP_TO_MASK(CAP_MAC_ADMIN) }}
79523+
79524+#define security_learn(normal_msg,args...) \
79525+({ \
79526+ read_lock(&grsec_exec_file_lock); \
79527+ gr_add_learn_entry(normal_msg "\n", ## args); \
79528+ read_unlock(&grsec_exec_file_lock); \
79529+})
79530+
79531+enum {
79532+ GR_DO_AUDIT,
79533+ GR_DONT_AUDIT,
79534+ /* used for non-audit messages that we shouldn't kill the task on */
79535+ GR_DONT_AUDIT_GOOD
79536+};
79537+
79538+enum {
79539+ GR_TTYSNIFF,
79540+ GR_RBAC,
79541+ GR_RBAC_STR,
79542+ GR_STR_RBAC,
79543+ GR_RBAC_MODE2,
79544+ GR_RBAC_MODE3,
79545+ GR_FILENAME,
79546+ GR_SYSCTL_HIDDEN,
79547+ GR_NOARGS,
79548+ GR_ONE_INT,
79549+ GR_ONE_INT_TWO_STR,
79550+ GR_ONE_STR,
79551+ GR_STR_INT,
79552+ GR_TWO_STR_INT,
79553+ GR_TWO_INT,
79554+ GR_TWO_U64,
79555+ GR_THREE_INT,
79556+ GR_FIVE_INT_TWO_STR,
79557+ GR_TWO_STR,
79558+ GR_THREE_STR,
79559+ GR_FOUR_STR,
79560+ GR_STR_FILENAME,
79561+ GR_FILENAME_STR,
79562+ GR_FILENAME_TWO_INT,
79563+ GR_FILENAME_TWO_INT_STR,
79564+ GR_TEXTREL,
79565+ GR_PTRACE,
79566+ GR_RESOURCE,
79567+ GR_CAP,
79568+ GR_SIG,
79569+ GR_SIG2,
79570+ GR_CRASH1,
79571+ GR_CRASH2,
79572+ GR_PSACCT,
79573+ GR_RWXMAP,
79574+ GR_RWXMAPVMA
79575+};
79576+
79577+#define gr_log_hidden_sysctl(audit, msg, str) gr_log_varargs(audit, msg, GR_SYSCTL_HIDDEN, str)
79578+#define gr_log_ttysniff(audit, msg, task) gr_log_varargs(audit, msg, GR_TTYSNIFF, task)
79579+#define gr_log_fs_rbac_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_RBAC, dentry, mnt)
79580+#define gr_log_fs_rbac_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_RBAC_STR, dentry, mnt, str)
79581+#define gr_log_fs_str_rbac(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_RBAC, str, dentry, mnt)
79582+#define gr_log_fs_rbac_mode2(audit, msg, dentry, mnt, str1, str2) gr_log_varargs(audit, msg, GR_RBAC_MODE2, dentry, mnt, str1, str2)
79583+#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)
79584+#define gr_log_fs_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_FILENAME, dentry, mnt)
79585+#define gr_log_noargs(audit, msg) gr_log_varargs(audit, msg, GR_NOARGS)
79586+#define gr_log_int(audit, msg, num) gr_log_varargs(audit, msg, GR_ONE_INT, num)
79587+#define gr_log_int_str2(audit, msg, num, str1, str2) gr_log_varargs(audit, msg, GR_ONE_INT_TWO_STR, num, str1, str2)
79588+#define gr_log_str(audit, msg, str) gr_log_varargs(audit, msg, GR_ONE_STR, str)
79589+#define gr_log_str_int(audit, msg, str, num) gr_log_varargs(audit, msg, GR_STR_INT, str, num)
79590+#define gr_log_int_int(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_INT, num1, num2)
79591+#define gr_log_two_u64(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_U64, num1, num2)
79592+#define gr_log_int3(audit, msg, num1, num2, num3) gr_log_varargs(audit, msg, GR_THREE_INT, num1, num2, num3)
79593+#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)
79594+#define gr_log_str_str(audit, msg, str1, str2) gr_log_varargs(audit, msg, GR_TWO_STR, str1, str2)
79595+#define gr_log_str2_int(audit, msg, str1, str2, num) gr_log_varargs(audit, msg, GR_TWO_STR_INT, str1, str2, num)
79596+#define gr_log_str3(audit, msg, str1, str2, str3) gr_log_varargs(audit, msg, GR_THREE_STR, str1, str2, str3)
79597+#define gr_log_str4(audit, msg, str1, str2, str3, str4) gr_log_varargs(audit, msg, GR_FOUR_STR, str1, str2, str3, str4)
79598+#define gr_log_str_fs(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_FILENAME, str, dentry, mnt)
79599+#define gr_log_fs_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_FILENAME_STR, dentry, mnt, str)
79600+#define gr_log_fs_int2(audit, msg, dentry, mnt, num1, num2) gr_log_varargs(audit, msg, GR_FILENAME_TWO_INT, dentry, mnt, num1, num2)
79601+#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)
79602+#define gr_log_textrel_ulong_ulong(audit, msg, file, ulong1, ulong2) gr_log_varargs(audit, msg, GR_TEXTREL, file, ulong1, ulong2)
79603+#define gr_log_ptrace(audit, msg, task) gr_log_varargs(audit, msg, GR_PTRACE, task)
79604+#define gr_log_res_ulong2_str(audit, msg, task, ulong1, str, ulong2) gr_log_varargs(audit, msg, GR_RESOURCE, task, ulong1, str, ulong2)
79605+#define gr_log_cap(audit, msg, task, str) gr_log_varargs(audit, msg, GR_CAP, task, str)
79606+#define gr_log_sig_addr(audit, msg, str, addr) gr_log_varargs(audit, msg, GR_SIG, str, addr)
79607+#define gr_log_sig_task(audit, msg, task, num) gr_log_varargs(audit, msg, GR_SIG2, task, num)
79608+#define gr_log_crash1(audit, msg, task, ulong) gr_log_varargs(audit, msg, GR_CRASH1, task, ulong)
79609+#define gr_log_crash2(audit, msg, task, ulong1) gr_log_varargs(audit, msg, GR_CRASH2, task, ulong1)
79610+#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)
79611+#define gr_log_rwxmap(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAP, str)
79612+#define gr_log_rwxmap_vma(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAPVMA, str)
79613+
79614+void gr_log_varargs(int audit, const char *msg, int argtypes, ...);
79615+
79616+#endif
79617+
79618+#endif
79619diff --git a/include/linux/grmsg.h b/include/linux/grmsg.h
79620new file mode 100644
79621index 0000000..ba93581
79622--- /dev/null
79623+++ b/include/linux/grmsg.h
79624@@ -0,0 +1,116 @@
79625+#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"
79626+#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"
79627+#define GR_PTRACE_ACL_MSG "denied ptrace of %.950s(%.16s:%d) by "
79628+#define GR_STOPMOD_MSG "denied modification of module state by "
79629+#define GR_ROFS_BLOCKWRITE_MSG "denied write to block device %.950s by "
79630+#define GR_ROFS_MOUNT_MSG "denied writable mount of %.950s by "
79631+#define GR_IOPERM_MSG "denied use of ioperm() by "
79632+#define GR_IOPL_MSG "denied use of iopl() by "
79633+#define GR_SHMAT_ACL_MSG "denied attach of shared memory of UID %u, PID %d, ID %u by "
79634+#define GR_UNIX_CHROOT_MSG "denied connect() to abstract AF_UNIX socket outside of chroot by "
79635+#define GR_SHMAT_CHROOT_MSG "denied attach of shared memory outside of chroot by "
79636+#define GR_MEM_READWRITE_MSG "denied access of range %Lx -> %Lx in /dev/mem by "
79637+#define GR_SYMLINK_MSG "not following symlink %.950s owned by %d.%d by "
79638+#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"
79639+#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"
79640+#define GR_HIDDEN_ACL_MSG "%s access to hidden file %.950s by "
79641+#define GR_OPEN_ACL_MSG "%s open of %.950s for%s%s by "
79642+#define GR_CREATE_ACL_MSG "%s create of %.950s for%s%s by "
79643+#define GR_FIFO_MSG "denied writing FIFO %.950s of %d.%d by "
79644+#define GR_MKNOD_CHROOT_MSG "denied mknod of %.950s from chroot by "
79645+#define GR_MKNOD_ACL_MSG "%s mknod of %.950s by "
79646+#define GR_UNIXCONNECT_ACL_MSG "%s connect() to the unix domain socket %.950s by "
79647+#define GR_TTYSNIFF_ACL_MSG "terminal being sniffed by IP:%pI4 %.480s[%.16s:%d], parent %.480s[%.16s:%d] against "
79648+#define GR_MKDIR_ACL_MSG "%s mkdir of %.950s by "
79649+#define GR_RMDIR_ACL_MSG "%s rmdir of %.950s by "
79650+#define GR_UNLINK_ACL_MSG "%s unlink of %.950s by "
79651+#define GR_SYMLINK_ACL_MSG "%s symlink from %.480s to %.480s by "
79652+#define GR_HARDLINK_MSG "denied hardlink of %.930s (owned by %d.%d) to %.30s for "
79653+#define GR_LINK_ACL_MSG "%s link of %.480s to %.480s by "
79654+#define GR_INHERIT_ACL_MSG "successful inherit of %.480s's ACL for %.480s by "
79655+#define GR_RENAME_ACL_MSG "%s rename of %.480s to %.480s by "
79656+#define GR_UNSAFESHARE_EXEC_ACL_MSG "denied exec with cloned fs of %.950s by "
79657+#define GR_PTRACE_EXEC_ACL_MSG "denied ptrace of %.950s by "
79658+#define GR_EXEC_ACL_MSG "%s execution of %.950s by "
79659+#define GR_EXEC_TPE_MSG "denied untrusted exec (due to %.70s) of %.950s by "
79660+#define GR_SEGVSTART_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning uid %u from login for %lu seconds"
79661+#define GR_SEGVNOSUID_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning execution for %lu seconds"
79662+#define GR_MOUNT_CHROOT_MSG "denied mount of %.256s as %.930s from chroot by "
79663+#define GR_PIVOT_CHROOT_MSG "denied pivot_root from chroot by "
79664+#define GR_TRUNCATE_ACL_MSG "%s truncate of %.950s by "
79665+#define GR_ATIME_ACL_MSG "%s access time change of %.950s by "
79666+#define GR_ACCESS_ACL_MSG "%s access of %.950s for%s%s%s by "
79667+#define GR_CHROOT_CHROOT_MSG "denied double chroot to %.950s by "
79668+#define GR_CHMOD_CHROOT_MSG "denied chmod +s of %.950s by "
79669+#define GR_CHMOD_ACL_MSG "%s chmod of %.950s by "
79670+#define GR_CHROOT_FCHDIR_MSG "denied fchdir outside of chroot to %.950s by "
79671+#define GR_CHOWN_ACL_MSG "%s chown of %.950s by "
79672+#define GR_SETXATTR_ACL_MSG "%s setting extended attribute of %.950s by "
79673+#define GR_REMOVEXATTR_ACL_MSG "%s removing extended attribute of %.950s by "
79674+#define GR_WRITLIB_ACL_MSG "denied load of writable library %.950s by "
79675+#define GR_INITF_ACL_MSG "init_variables() failed %s by "
79676+#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"
79677+#define GR_DEV_ACL_MSG "/dev/grsec: %d bytes sent %d required, being fed garbage by "
79678+#define GR_SHUTS_ACL_MSG "shutdown auth success for "
79679+#define GR_SHUTF_ACL_MSG "shutdown auth failure for "
79680+#define GR_SHUTI_ACL_MSG "ignoring shutdown for disabled RBAC system for "
79681+#define GR_SEGVMODS_ACL_MSG "segvmod auth success for "
79682+#define GR_SEGVMODF_ACL_MSG "segvmod auth failure for "
79683+#define GR_SEGVMODI_ACL_MSG "ignoring segvmod for disabled RBAC system for "
79684+#define GR_ENABLE_ACL_MSG "%s RBAC system loaded by "
79685+#define GR_ENABLEF_ACL_MSG "unable to load %s for "
79686+#define GR_RELOADI_ACL_MSG "ignoring reload request for disabled RBAC system"
79687+#define GR_RELOAD_ACL_MSG "%s RBAC system reloaded by "
79688+#define GR_RELOADF_ACL_MSG "failed reload of %s for "
79689+#define GR_SPROLEI_ACL_MSG "ignoring change to special role for disabled RBAC system for "
79690+#define GR_SPROLES_ACL_MSG "successful change to special role %s (id %d) by "
79691+#define GR_SPROLEL_ACL_MSG "special role %s (id %d) exited by "
79692+#define GR_SPROLEF_ACL_MSG "special role %s failure for "
79693+#define GR_UNSPROLEI_ACL_MSG "ignoring unauth of special role for disabled RBAC system for "
79694+#define GR_UNSPROLES_ACL_MSG "successful unauth of special role %s (id %d) by "
79695+#define GR_INVMODE_ACL_MSG "invalid mode %d by "
79696+#define GR_PRIORITY_CHROOT_MSG "denied priority change of process (%.16s:%d) by "
79697+#define GR_FAILFORK_MSG "failed fork with errno %s by "
79698+#define GR_NICE_CHROOT_MSG "denied priority change by "
79699+#define GR_UNISIGLOG_MSG "%.32s occurred at %p in "
79700+#define GR_DUALSIGLOG_MSG "signal %d sent to " DEFAULTSECMSG " by "
79701+#define GR_SIG_ACL_MSG "denied send of signal %d to protected task " DEFAULTSECMSG " by "
79702+#define GR_SYSCTL_MSG "denied modification of grsecurity sysctl value : %.32s by "
79703+#define GR_SYSCTL_ACL_MSG "%s sysctl of %.950s for%s%s by "
79704+#define GR_TIME_MSG "time set by "
79705+#define GR_DEFACL_MSG "fatal: unable to find subject for (%.16s:%d), loaded by "
79706+#define GR_MMAP_ACL_MSG "%s executable mmap of %.950s by "
79707+#define GR_MPROTECT_ACL_MSG "%s executable mprotect of %.950s by "
79708+#define GR_SOCK_MSG "denied socket(%.16s,%.16s,%.16s) by "
79709+#define GR_SOCK_NOINET_MSG "denied socket(%.16s,%.16s,%d) by "
79710+#define GR_BIND_MSG "denied bind() by "
79711+#define GR_CONNECT_MSG "denied connect() by "
79712+#define GR_BIND_ACL_MSG "denied bind() to %pI4 port %u sock type %.16s protocol %.16s by "
79713+#define GR_CONNECT_ACL_MSG "denied connect() to %pI4 port %u sock type %.16s protocol %.16s by "
79714+#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"
79715+#define GR_EXEC_CHROOT_MSG "exec of %.980s within chroot by process "
79716+#define GR_CAP_ACL_MSG "use of %s denied for "
79717+#define GR_CAP_CHROOT_MSG "use of %s in chroot denied for "
79718+#define GR_CAP_ACL_MSG2 "use of %s permitted for "
79719+#define GR_USRCHANGE_ACL_MSG "change to uid %u denied for "
79720+#define GR_GRPCHANGE_ACL_MSG "change to gid %u denied for "
79721+#define GR_REMOUNT_AUDIT_MSG "remount of %.256s by "
79722+#define GR_UNMOUNT_AUDIT_MSG "unmount of %.256s by "
79723+#define GR_MOUNT_AUDIT_MSG "mount of %.256s to %.256s by "
79724+#define GR_CHDIR_AUDIT_MSG "chdir to %.980s by "
79725+#define GR_EXEC_AUDIT_MSG "exec of %.930s (%.128s) by "
79726+#define GR_RESOURCE_MSG "denied resource overstep by requesting %lu for %.16s against limit %lu for "
79727+#define GR_RWXMMAP_MSG "denied RWX mmap of %.950s by "
79728+#define GR_RWXMPROTECT_MSG "denied RWX mprotect of %.950s by "
79729+#define GR_TEXTREL_AUDIT_MSG "denied text relocation in %.950s, VMA:0x%08lx 0x%08lx by "
79730+#define GR_PTGNUSTACK_MSG "denied marking stack executable as requested by PT_GNU_STACK marking in %.950s by "
79731+#define GR_VM86_MSG "denied use of vm86 by "
79732+#define GR_PTRACE_AUDIT_MSG "process %.950s(%.16s:%d) attached to via ptrace by "
79733+#define GR_PTRACE_READEXEC_MSG "denied ptrace of unreadable binary %.950s by "
79734+#define GR_INIT_TRANSFER_MSG "persistent special role transferred privilege to init by "
79735+#define GR_BADPROCPID_MSG "denied read of sensitive /proc/pid/%s entry via fd passed across exec by "
79736+#define GR_SYMLINKOWNER_MSG "denied following symlink %.950s since symlink owner %u does not match target owner %u, by "
79737+#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 "
79738+#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 "
79739+#define GR_IPC_DENIED_MSG "denied %s of overly-permissive IPC object with creator uid %u by "
79740+#define GR_MSRWRITE_MSG "denied write to CPU MSR by "
79741diff --git a/include/linux/grsecurity.h b/include/linux/grsecurity.h
79742new file mode 100644
79743index 0000000..f2d8c6c
79744--- /dev/null
79745+++ b/include/linux/grsecurity.h
79746@@ -0,0 +1,248 @@
79747+#ifndef GR_SECURITY_H
79748+#define GR_SECURITY_H
79749+#include <linux/fs.h>
79750+#include <linux/fs_struct.h>
79751+#include <linux/binfmts.h>
79752+#include <linux/gracl.h>
79753+
79754+/* notify of brain-dead configs */
79755+#if defined(CONFIG_GRKERNSEC_PROC_USER) && defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
79756+#error "CONFIG_GRKERNSEC_PROC_USER and CONFIG_GRKERNSEC_PROC_USERGROUP cannot both be enabled."
79757+#endif
79758+#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_PAGEEXEC) && !defined(CONFIG_PAX_SEGMEXEC) && !defined(CONFIG_PAX_KERNEXEC)
79759+#error "CONFIG_PAX_NOEXEC enabled, but PAGEEXEC, SEGMEXEC, and KERNEXEC are disabled."
79760+#endif
79761+#if defined(CONFIG_PAX_ASLR) && !defined(CONFIG_PAX_RANDKSTACK) && !defined(CONFIG_PAX_RANDUSTACK) && !defined(CONFIG_PAX_RANDMMAP)
79762+#error "CONFIG_PAX_ASLR enabled, but RANDKSTACK, RANDUSTACK, and RANDMMAP are disabled."
79763+#endif
79764+#if defined(CONFIG_PAX) && !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_ASLR)
79765+#error "CONFIG_PAX enabled, but no PaX options are enabled."
79766+#endif
79767+
79768+int gr_handle_new_usb(void);
79769+
79770+void gr_handle_brute_attach(int dumpable);
79771+void gr_handle_brute_check(void);
79772+void gr_handle_kernel_exploit(void);
79773+
79774+char gr_roletype_to_char(void);
79775+
79776+int gr_proc_is_restricted(void);
79777+
79778+int gr_acl_enable_at_secure(void);
79779+
79780+int gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs);
79781+int gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs);
79782+
79783+void gr_del_task_from_ip_table(struct task_struct *p);
79784+
79785+int gr_pid_is_chrooted(struct task_struct *p);
79786+int gr_handle_chroot_fowner(struct pid *pid, enum pid_type type);
79787+int gr_handle_chroot_nice(void);
79788+int gr_handle_chroot_sysctl(const int op);
79789+int gr_handle_chroot_setpriority(struct task_struct *p,
79790+ const int niceval);
79791+int gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt);
79792+int gr_handle_chroot_chroot(const struct dentry *dentry,
79793+ const struct vfsmount *mnt);
79794+void gr_handle_chroot_chdir(const struct path *path);
79795+int gr_handle_chroot_chmod(const struct dentry *dentry,
79796+ const struct vfsmount *mnt, const int mode);
79797+int gr_handle_chroot_mknod(const struct dentry *dentry,
79798+ const struct vfsmount *mnt, const int mode);
79799+int gr_handle_chroot_mount(const struct dentry *dentry,
79800+ const struct vfsmount *mnt,
79801+ const char *dev_name);
79802+int gr_handle_chroot_pivot(void);
79803+int gr_handle_chroot_unix(const pid_t pid);
79804+
79805+int gr_handle_rawio(const struct inode *inode);
79806+
79807+void gr_handle_ioperm(void);
79808+void gr_handle_iopl(void);
79809+void gr_handle_msr_write(void);
79810+
79811+umode_t gr_acl_umask(void);
79812+
79813+int gr_tpe_allow(const struct file *file);
79814+
79815+void gr_set_chroot_entries(struct task_struct *task, const struct path *path);
79816+void gr_clear_chroot_entries(struct task_struct *task);
79817+
79818+void gr_log_forkfail(const int retval);
79819+void gr_log_timechange(void);
79820+void gr_log_signal(const int sig, const void *addr, const struct task_struct *t);
79821+void gr_log_chdir(const struct dentry *dentry,
79822+ const struct vfsmount *mnt);
79823+void gr_log_chroot_exec(const struct dentry *dentry,
79824+ const struct vfsmount *mnt);
79825+void gr_log_remount(const char *devname, const int retval);
79826+void gr_log_unmount(const char *devname, const int retval);
79827+void gr_log_mount(const char *from, const char *to, const int retval);
79828+void gr_log_textrel(struct vm_area_struct *vma);
79829+void gr_log_ptgnustack(struct file *file);
79830+void gr_log_rwxmmap(struct file *file);
79831+void gr_log_rwxmprotect(struct vm_area_struct *vma);
79832+
79833+int gr_handle_follow_link(const struct inode *parent,
79834+ const struct inode *inode,
79835+ const struct dentry *dentry,
79836+ const struct vfsmount *mnt);
79837+int gr_handle_fifo(const struct dentry *dentry,
79838+ const struct vfsmount *mnt,
79839+ const struct dentry *dir, const int flag,
79840+ const int acc_mode);
79841+int gr_handle_hardlink(const struct dentry *dentry,
79842+ const struct vfsmount *mnt,
79843+ struct inode *inode,
79844+ const int mode, const struct filename *to);
79845+
79846+int gr_is_capable(const int cap);
79847+int gr_is_capable_nolog(const int cap);
79848+int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
79849+int gr_task_is_capable_nolog(const struct task_struct *task, const int cap);
79850+
79851+void gr_copy_label(struct task_struct *tsk);
79852+void gr_handle_crash(struct task_struct *task, const int sig);
79853+int gr_handle_signal(const struct task_struct *p, const int sig);
79854+int gr_check_crash_uid(const kuid_t uid);
79855+int gr_check_protected_task(const struct task_struct *task);
79856+int gr_check_protected_task_fowner(struct pid *pid, enum pid_type type);
79857+int gr_acl_handle_mmap(const struct file *file,
79858+ const unsigned long prot);
79859+int gr_acl_handle_mprotect(const struct file *file,
79860+ const unsigned long prot);
79861+int gr_check_hidden_task(const struct task_struct *tsk);
79862+__u32 gr_acl_handle_truncate(const struct dentry *dentry,
79863+ const struct vfsmount *mnt);
79864+__u32 gr_acl_handle_utime(const struct dentry *dentry,
79865+ const struct vfsmount *mnt);
79866+__u32 gr_acl_handle_access(const struct dentry *dentry,
79867+ const struct vfsmount *mnt, const int fmode);
79868+__u32 gr_acl_handle_chmod(const struct dentry *dentry,
79869+ const struct vfsmount *mnt, umode_t *mode);
79870+__u32 gr_acl_handle_chown(const struct dentry *dentry,
79871+ const struct vfsmount *mnt);
79872+__u32 gr_acl_handle_setxattr(const struct dentry *dentry,
79873+ const struct vfsmount *mnt);
79874+__u32 gr_acl_handle_removexattr(const struct dentry *dentry,
79875+ const struct vfsmount *mnt);
79876+int gr_handle_ptrace(struct task_struct *task, const long request);
79877+int gr_handle_proc_ptrace(struct task_struct *task);
79878+__u32 gr_acl_handle_execve(const struct dentry *dentry,
79879+ const struct vfsmount *mnt);
79880+int gr_check_crash_exec(const struct file *filp);
79881+int gr_acl_is_enabled(void);
79882+void gr_set_role_label(struct task_struct *task, const kuid_t uid,
79883+ const kgid_t gid);
79884+int gr_set_proc_label(const struct dentry *dentry,
79885+ const struct vfsmount *mnt,
79886+ const int unsafe_flags);
79887+__u32 gr_acl_handle_hidden_file(const struct dentry *dentry,
79888+ const struct vfsmount *mnt);
79889+__u32 gr_acl_handle_open(const struct dentry *dentry,
79890+ const struct vfsmount *mnt, int acc_mode);
79891+__u32 gr_acl_handle_creat(const struct dentry *dentry,
79892+ const struct dentry *p_dentry,
79893+ const struct vfsmount *p_mnt,
79894+ int open_flags, int acc_mode, const int imode);
79895+void gr_handle_create(const struct dentry *dentry,
79896+ const struct vfsmount *mnt);
79897+void gr_handle_proc_create(const struct dentry *dentry,
79898+ const struct inode *inode);
79899+__u32 gr_acl_handle_mknod(const struct dentry *new_dentry,
79900+ const struct dentry *parent_dentry,
79901+ const struct vfsmount *parent_mnt,
79902+ const int mode);
79903+__u32 gr_acl_handle_mkdir(const struct dentry *new_dentry,
79904+ const struct dentry *parent_dentry,
79905+ const struct vfsmount *parent_mnt);
79906+__u32 gr_acl_handle_rmdir(const struct dentry *dentry,
79907+ const struct vfsmount *mnt);
79908+void gr_handle_delete(const ino_t ino, const dev_t dev);
79909+__u32 gr_acl_handle_unlink(const struct dentry *dentry,
79910+ const struct vfsmount *mnt);
79911+__u32 gr_acl_handle_symlink(const struct dentry *new_dentry,
79912+ const struct dentry *parent_dentry,
79913+ const struct vfsmount *parent_mnt,
79914+ const struct filename *from);
79915+__u32 gr_acl_handle_link(const struct dentry *new_dentry,
79916+ const struct dentry *parent_dentry,
79917+ const struct vfsmount *parent_mnt,
79918+ const struct dentry *old_dentry,
79919+ const struct vfsmount *old_mnt, const struct filename *to);
79920+int gr_handle_symlink_owner(const struct path *link, const struct inode *target);
79921+int gr_acl_handle_rename(struct dentry *new_dentry,
79922+ struct dentry *parent_dentry,
79923+ const struct vfsmount *parent_mnt,
79924+ struct dentry *old_dentry,
79925+ struct inode *old_parent_inode,
79926+ struct vfsmount *old_mnt, const struct filename *newname);
79927+void gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
79928+ struct dentry *old_dentry,
79929+ struct dentry *new_dentry,
79930+ struct vfsmount *mnt, const __u8 replace);
79931+__u32 gr_check_link(const struct dentry *new_dentry,
79932+ const struct dentry *parent_dentry,
79933+ const struct vfsmount *parent_mnt,
79934+ const struct dentry *old_dentry,
79935+ const struct vfsmount *old_mnt);
79936+int gr_acl_handle_filldir(const struct file *file, const char *name,
79937+ const unsigned int namelen, const ino_t ino);
79938+
79939+__u32 gr_acl_handle_unix(const struct dentry *dentry,
79940+ const struct vfsmount *mnt);
79941+void gr_acl_handle_exit(void);
79942+void gr_acl_handle_psacct(struct task_struct *task, const long code);
79943+int gr_acl_handle_procpidmem(const struct task_struct *task);
79944+int gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags);
79945+int gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode);
79946+void gr_audit_ptrace(struct task_struct *task);
79947+dev_t gr_get_dev_from_dentry(struct dentry *dentry);
79948+void gr_put_exec_file(struct task_struct *task);
79949+
79950+int gr_ptrace_readexec(struct file *file, int unsafe_flags);
79951+
79952+#if defined(CONFIG_GRKERNSEC) && (defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC))
79953+extern void gr_learn_resource(const struct task_struct *task, const int res,
79954+ const unsigned long wanted, const int gt);
79955+#else
79956+static inline void gr_learn_resource(const struct task_struct *task, const int res,
79957+ const unsigned long wanted, const int gt)
79958+{
79959+}
79960+#endif
79961+
79962+#ifdef CONFIG_GRKERNSEC_RESLOG
79963+extern void gr_log_resource(const struct task_struct *task, const int res,
79964+ const unsigned long wanted, const int gt);
79965+#else
79966+static inline void gr_log_resource(const struct task_struct *task, const int res,
79967+ const unsigned long wanted, const int gt)
79968+{
79969+}
79970+#endif
79971+
79972+#ifdef CONFIG_GRKERNSEC
79973+void task_grsec_rbac(struct seq_file *m, struct task_struct *p);
79974+void gr_handle_vm86(void);
79975+void gr_handle_mem_readwrite(u64 from, u64 to);
79976+
79977+void gr_log_badprocpid(const char *entry);
79978+
79979+extern int grsec_enable_dmesg;
79980+extern int grsec_disable_privio;
79981+
79982+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
79983+extern kgid_t grsec_proc_gid;
79984+#endif
79985+
79986+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
79987+extern int grsec_enable_chroot_findtask;
79988+#endif
79989+#ifdef CONFIG_GRKERNSEC_SETXID
79990+extern int grsec_enable_setxid;
79991+#endif
79992+#endif
79993+
79994+#endif
79995diff --git a/include/linux/grsock.h b/include/linux/grsock.h
79996new file mode 100644
79997index 0000000..e7ffaaf
79998--- /dev/null
79999+++ b/include/linux/grsock.h
80000@@ -0,0 +1,19 @@
80001+#ifndef __GRSOCK_H
80002+#define __GRSOCK_H
80003+
80004+extern void gr_attach_curr_ip(const struct sock *sk);
80005+extern int gr_handle_sock_all(const int family, const int type,
80006+ const int protocol);
80007+extern int gr_handle_sock_server(const struct sockaddr *sck);
80008+extern int gr_handle_sock_server_other(const struct sock *sck);
80009+extern int gr_handle_sock_client(const struct sockaddr *sck);
80010+extern int gr_search_connect(struct socket * sock,
80011+ struct sockaddr_in * addr);
80012+extern int gr_search_bind(struct socket * sock,
80013+ struct sockaddr_in * addr);
80014+extern int gr_search_listen(struct socket * sock);
80015+extern int gr_search_accept(struct socket * sock);
80016+extern int gr_search_socket(const int domain, const int type,
80017+ const int protocol);
80018+
80019+#endif
80020diff --git a/include/linux/hash.h b/include/linux/hash.h
80021index bd1754c..8240892 100644
80022--- a/include/linux/hash.h
80023+++ b/include/linux/hash.h
80024@@ -83,7 +83,7 @@ static inline u32 hash32_ptr(const void *ptr)
80025 struct fast_hash_ops {
80026 u32 (*hash)(const void *data, u32 len, u32 seed);
80027 u32 (*hash2)(const u32 *data, u32 len, u32 seed);
80028-};
80029+} __no_const;
80030
80031 /**
80032 * arch_fast_hash - Caclulates a hash over a given buffer that can have
80033diff --git a/include/linux/highmem.h b/include/linux/highmem.h
80034index 7fb31da..08b5114 100644
80035--- a/include/linux/highmem.h
80036+++ b/include/linux/highmem.h
80037@@ -189,6 +189,18 @@ static inline void clear_highpage(struct page *page)
80038 kunmap_atomic(kaddr);
80039 }
80040
80041+static inline void sanitize_highpage(struct page *page)
80042+{
80043+ void *kaddr;
80044+ unsigned long flags;
80045+
80046+ local_irq_save(flags);
80047+ kaddr = kmap_atomic(page);
80048+ clear_page(kaddr);
80049+ kunmap_atomic(kaddr);
80050+ local_irq_restore(flags);
80051+}
80052+
80053 static inline void zero_user_segments(struct page *page,
80054 unsigned start1, unsigned end1,
80055 unsigned start2, unsigned end2)
80056diff --git a/include/linux/hwmon-sysfs.h b/include/linux/hwmon-sysfs.h
80057index 1c7b89a..7dda400 100644
80058--- a/include/linux/hwmon-sysfs.h
80059+++ b/include/linux/hwmon-sysfs.h
80060@@ -25,7 +25,8 @@
80061 struct sensor_device_attribute{
80062 struct device_attribute dev_attr;
80063 int index;
80064-};
80065+} __do_const;
80066+typedef struct sensor_device_attribute __no_const sensor_device_attribute_no_const;
80067 #define to_sensor_dev_attr(_dev_attr) \
80068 container_of(_dev_attr, struct sensor_device_attribute, dev_attr)
80069
80070@@ -41,7 +42,8 @@ struct sensor_device_attribute_2 {
80071 struct device_attribute dev_attr;
80072 u8 index;
80073 u8 nr;
80074-};
80075+} __do_const;
80076+typedef struct sensor_device_attribute_2 __no_const sensor_device_attribute_2_no_const;
80077 #define to_sensor_dev_attr_2(_dev_attr) \
80078 container_of(_dev_attr, struct sensor_device_attribute_2, dev_attr)
80079
80080diff --git a/include/linux/i2c.h b/include/linux/i2c.h
80081index deddeb8..bcaf62d 100644
80082--- a/include/linux/i2c.h
80083+++ b/include/linux/i2c.h
80084@@ -378,6 +378,7 @@ struct i2c_algorithm {
80085 /* To determine what the adapter supports */
80086 u32 (*functionality) (struct i2c_adapter *);
80087 };
80088+typedef struct i2c_algorithm __no_const i2c_algorithm_no_const;
80089
80090 /**
80091 * struct i2c_bus_recovery_info - I2C bus recovery information
80092diff --git a/include/linux/i2o.h b/include/linux/i2o.h
80093index d23c3c2..eb63c81 100644
80094--- a/include/linux/i2o.h
80095+++ b/include/linux/i2o.h
80096@@ -565,7 +565,7 @@ struct i2o_controller {
80097 struct i2o_device *exec; /* Executive */
80098 #if BITS_PER_LONG == 64
80099 spinlock_t context_list_lock; /* lock for context_list */
80100- atomic_t context_list_counter; /* needed for unique contexts */
80101+ atomic_unchecked_t context_list_counter; /* needed for unique contexts */
80102 struct list_head context_list; /* list of context id's
80103 and pointers */
80104 #endif
80105diff --git a/include/linux/if_pppox.h b/include/linux/if_pppox.h
80106index aff7ad8..3942bbd 100644
80107--- a/include/linux/if_pppox.h
80108+++ b/include/linux/if_pppox.h
80109@@ -76,7 +76,7 @@ struct pppox_proto {
80110 int (*ioctl)(struct socket *sock, unsigned int cmd,
80111 unsigned long arg);
80112 struct module *owner;
80113-};
80114+} __do_const;
80115
80116 extern int register_pppox_proto(int proto_num, const struct pppox_proto *pp);
80117 extern void unregister_pppox_proto(int proto_num);
80118diff --git a/include/linux/init.h b/include/linux/init.h
80119index e168880..d9b489d 100644
80120--- a/include/linux/init.h
80121+++ b/include/linux/init.h
80122@@ -37,9 +37,17 @@
80123 * section.
80124 */
80125
80126+#define add_init_latent_entropy __latent_entropy
80127+
80128+#ifdef CONFIG_MEMORY_HOTPLUG
80129+#define add_meminit_latent_entropy
80130+#else
80131+#define add_meminit_latent_entropy __latent_entropy
80132+#endif
80133+
80134 /* These are for everybody (although not all archs will actually
80135 discard it in modules) */
80136-#define __init __section(.init.text) __cold notrace
80137+#define __init __section(.init.text) __cold notrace add_init_latent_entropy
80138 #define __initdata __section(.init.data)
80139 #define __initconst __constsection(.init.rodata)
80140 #define __exitdata __section(.exit.data)
80141@@ -100,7 +108,7 @@
80142 #define __cpuexitconst
80143
80144 /* Used for MEMORY_HOTPLUG */
80145-#define __meminit __section(.meminit.text) __cold notrace
80146+#define __meminit __section(.meminit.text) __cold notrace add_meminit_latent_entropy
80147 #define __meminitdata __section(.meminit.data)
80148 #define __meminitconst __constsection(.meminit.rodata)
80149 #define __memexit __section(.memexit.text) __exitused __cold notrace
80150diff --git a/include/linux/init_task.h b/include/linux/init_task.h
80151index 6df7f9f..d0bf699 100644
80152--- a/include/linux/init_task.h
80153+++ b/include/linux/init_task.h
80154@@ -156,6 +156,12 @@ extern struct task_group root_task_group;
80155
80156 #define INIT_TASK_COMM "swapper"
80157
80158+#ifdef CONFIG_X86
80159+#define INIT_TASK_THREAD_INFO .tinfo = INIT_THREAD_INFO,
80160+#else
80161+#define INIT_TASK_THREAD_INFO
80162+#endif
80163+
80164 #ifdef CONFIG_RT_MUTEXES
80165 # define INIT_RT_MUTEXES(tsk) \
80166 .pi_waiters = RB_ROOT, \
80167@@ -203,6 +209,7 @@ extern struct task_group root_task_group;
80168 RCU_POINTER_INITIALIZER(cred, &init_cred), \
80169 .comm = INIT_TASK_COMM, \
80170 .thread = INIT_THREAD, \
80171+ INIT_TASK_THREAD_INFO \
80172 .fs = &init_fs, \
80173 .files = &init_files, \
80174 .signal = &init_signals, \
80175diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h
80176index a2678d3..e411b1b 100644
80177--- a/include/linux/interrupt.h
80178+++ b/include/linux/interrupt.h
80179@@ -373,8 +373,8 @@ extern const char * const softirq_to_name[NR_SOFTIRQS];
80180
80181 struct softirq_action
80182 {
80183- void (*action)(struct softirq_action *);
80184-};
80185+ void (*action)(void);
80186+} __no_const;
80187
80188 asmlinkage void do_softirq(void);
80189 asmlinkage void __do_softirq(void);
80190@@ -388,7 +388,7 @@ static inline void do_softirq_own_stack(void)
80191 }
80192 #endif
80193
80194-extern void open_softirq(int nr, void (*action)(struct softirq_action *));
80195+extern void open_softirq(int nr, void (*action)(void));
80196 extern void softirq_init(void);
80197 extern void __raise_softirq_irqoff(unsigned int nr);
80198
80199diff --git a/include/linux/iommu.h b/include/linux/iommu.h
80200index b96a5b2..2732d1c 100644
80201--- a/include/linux/iommu.h
80202+++ b/include/linux/iommu.h
80203@@ -131,7 +131,7 @@ struct iommu_ops {
80204 u32 (*domain_get_windows)(struct iommu_domain *domain);
80205
80206 unsigned long pgsize_bitmap;
80207-};
80208+} __do_const;
80209
80210 #define IOMMU_GROUP_NOTIFY_ADD_DEVICE 1 /* Device added */
80211 #define IOMMU_GROUP_NOTIFY_DEL_DEVICE 2 /* Pre Device removed */
80212diff --git a/include/linux/ioport.h b/include/linux/ioport.h
80213index 89b7c24..382af74 100644
80214--- a/include/linux/ioport.h
80215+++ b/include/linux/ioport.h
80216@@ -161,7 +161,7 @@ struct resource *lookup_resource(struct resource *root, resource_size_t start);
80217 int adjust_resource(struct resource *res, resource_size_t start,
80218 resource_size_t size);
80219 resource_size_t resource_alignment(struct resource *res);
80220-static inline resource_size_t resource_size(const struct resource *res)
80221+static inline resource_size_t __intentional_overflow(-1) resource_size(const struct resource *res)
80222 {
80223 return res->end - res->start + 1;
80224 }
80225diff --git a/include/linux/ipc_namespace.h b/include/linux/ipc_namespace.h
80226index 35e7eca..6afb7ad 100644
80227--- a/include/linux/ipc_namespace.h
80228+++ b/include/linux/ipc_namespace.h
80229@@ -69,7 +69,7 @@ struct ipc_namespace {
80230 struct user_namespace *user_ns;
80231
80232 unsigned int proc_inum;
80233-};
80234+} __randomize_layout;
80235
80236 extern struct ipc_namespace init_ipc_ns;
80237 extern atomic_t nr_ipc_ns;
80238diff --git a/include/linux/irq.h b/include/linux/irq.h
80239index 7dc1003..407327b 100644
80240--- a/include/linux/irq.h
80241+++ b/include/linux/irq.h
80242@@ -338,7 +338,8 @@ struct irq_chip {
80243 void (*irq_print_chip)(struct irq_data *data, struct seq_file *p);
80244
80245 unsigned long flags;
80246-};
80247+} __do_const;
80248+typedef struct irq_chip __no_const irq_chip_no_const;
80249
80250 /*
80251 * irq_chip specific flags
80252diff --git a/include/linux/irqchip/arm-gic.h b/include/linux/irqchip/arm-gic.h
80253index 0ceb389..eed3fb8 100644
80254--- a/include/linux/irqchip/arm-gic.h
80255+++ b/include/linux/irqchip/arm-gic.h
80256@@ -73,9 +73,11 @@
80257
80258 #ifndef __ASSEMBLY__
80259
80260+#include <linux/irq.h>
80261+
80262 struct device_node;
80263
80264-extern struct irq_chip gic_arch_extn;
80265+extern irq_chip_no_const gic_arch_extn;
80266
80267 void gic_init_bases(unsigned int, int, void __iomem *, void __iomem *,
80268 u32 offset, struct device_node *);
80269diff --git a/include/linux/jiffies.h b/include/linux/jiffies.h
80270index 1f44466..b481806 100644
80271--- a/include/linux/jiffies.h
80272+++ b/include/linux/jiffies.h
80273@@ -292,20 +292,20 @@ extern unsigned long preset_lpj;
80274 /*
80275 * Convert various time units to each other:
80276 */
80277-extern unsigned int jiffies_to_msecs(const unsigned long j);
80278-extern unsigned int jiffies_to_usecs(const unsigned long j);
80279+extern unsigned int jiffies_to_msecs(const unsigned long j) __intentional_overflow(-1);
80280+extern unsigned int jiffies_to_usecs(const unsigned long j) __intentional_overflow(-1);
80281
80282-static inline u64 jiffies_to_nsecs(const unsigned long j)
80283+static inline u64 __intentional_overflow(-1) jiffies_to_nsecs(const unsigned long j)
80284 {
80285 return (u64)jiffies_to_usecs(j) * NSEC_PER_USEC;
80286 }
80287
80288-extern unsigned long msecs_to_jiffies(const unsigned int m);
80289-extern unsigned long usecs_to_jiffies(const unsigned int u);
80290+extern unsigned long msecs_to_jiffies(const unsigned int m) __intentional_overflow(-1);
80291+extern unsigned long usecs_to_jiffies(const unsigned int u) __intentional_overflow(-1);
80292 extern unsigned long timespec_to_jiffies(const struct timespec *value);
80293 extern void jiffies_to_timespec(const unsigned long jiffies,
80294- struct timespec *value);
80295-extern unsigned long timeval_to_jiffies(const struct timeval *value);
80296+ struct timespec *value) __intentional_overflow(-1);
80297+extern unsigned long timeval_to_jiffies(const struct timeval *value) __intentional_overflow(-1);
80298 extern void jiffies_to_timeval(const unsigned long jiffies,
80299 struct timeval *value);
80300
80301diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h
80302index 6883e19..e854fcb 100644
80303--- a/include/linux/kallsyms.h
80304+++ b/include/linux/kallsyms.h
80305@@ -15,7 +15,8 @@
80306
80307 struct module;
80308
80309-#ifdef CONFIG_KALLSYMS
80310+#if !defined(__INCLUDED_BY_HIDESYM) || !defined(CONFIG_KALLSYMS)
80311+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
80312 /* Lookup the address for a symbol. Returns 0 if not found. */
80313 unsigned long kallsyms_lookup_name(const char *name);
80314
80315@@ -106,6 +107,21 @@ static inline int lookup_symbol_attrs(unsigned long addr, unsigned long *size, u
80316 /* Stupid that this does nothing, but I didn't create this mess. */
80317 #define __print_symbol(fmt, addr)
80318 #endif /*CONFIG_KALLSYMS*/
80319+#else /* when included by kallsyms.c, vsnprintf.c, kprobes.c, or
80320+ arch/x86/kernel/dumpstack.c, with HIDESYM enabled */
80321+extern unsigned long kallsyms_lookup_name(const char *name);
80322+extern void __print_symbol(const char *fmt, unsigned long address);
80323+extern int sprint_backtrace(char *buffer, unsigned long address);
80324+extern int sprint_symbol(char *buffer, unsigned long address);
80325+extern int sprint_symbol_no_offset(char *buffer, unsigned long address);
80326+const char *kallsyms_lookup(unsigned long addr,
80327+ unsigned long *symbolsize,
80328+ unsigned long *offset,
80329+ char **modname, char *namebuf);
80330+extern int kallsyms_lookup_size_offset(unsigned long addr,
80331+ unsigned long *symbolsize,
80332+ unsigned long *offset);
80333+#endif
80334
80335 /* This macro allows us to keep printk typechecking */
80336 static __printf(1, 2)
80337diff --git a/include/linux/key-type.h b/include/linux/key-type.h
80338index a74c3a8..28d3f21 100644
80339--- a/include/linux/key-type.h
80340+++ b/include/linux/key-type.h
80341@@ -131,7 +131,7 @@ struct key_type {
80342 /* internal fields */
80343 struct list_head link; /* link in types list */
80344 struct lock_class_key lock_class; /* key->sem lock class */
80345-};
80346+} __do_const;
80347
80348 extern struct key_type key_type_keyring;
80349
80350diff --git a/include/linux/kgdb.h b/include/linux/kgdb.h
80351index 6b06d37..c134867 100644
80352--- a/include/linux/kgdb.h
80353+++ b/include/linux/kgdb.h
80354@@ -52,7 +52,7 @@ extern int kgdb_connected;
80355 extern int kgdb_io_module_registered;
80356
80357 extern atomic_t kgdb_setting_breakpoint;
80358-extern atomic_t kgdb_cpu_doing_single_step;
80359+extern atomic_unchecked_t kgdb_cpu_doing_single_step;
80360
80361 extern struct task_struct *kgdb_usethread;
80362 extern struct task_struct *kgdb_contthread;
80363@@ -254,7 +254,7 @@ struct kgdb_arch {
80364 void (*correct_hw_break)(void);
80365
80366 void (*enable_nmi)(bool on);
80367-};
80368+} __do_const;
80369
80370 /**
80371 * struct kgdb_io - Describe the interface for an I/O driver to talk with KGDB.
80372@@ -279,7 +279,7 @@ struct kgdb_io {
80373 void (*pre_exception) (void);
80374 void (*post_exception) (void);
80375 int is_console;
80376-};
80377+} __do_const;
80378
80379 extern struct kgdb_arch arch_kgdb_ops;
80380
80381diff --git a/include/linux/kmod.h b/include/linux/kmod.h
80382index 0555cc6..40116ce 100644
80383--- a/include/linux/kmod.h
80384+++ b/include/linux/kmod.h
80385@@ -34,6 +34,8 @@ extern char modprobe_path[]; /* for sysctl */
80386 * usually useless though. */
80387 extern __printf(2, 3)
80388 int __request_module(bool wait, const char *name, ...);
80389+extern __printf(3, 4)
80390+int ___request_module(bool wait, char *param_name, const char *name, ...);
80391 #define request_module(mod...) __request_module(true, mod)
80392 #define request_module_nowait(mod...) __request_module(false, mod)
80393 #define try_then_request_module(x, mod...) \
80394@@ -57,6 +59,9 @@ struct subprocess_info {
80395 struct work_struct work;
80396 struct completion *complete;
80397 char *path;
80398+#ifdef CONFIG_GRKERNSEC
80399+ char *origpath;
80400+#endif
80401 char **argv;
80402 char **envp;
80403 int wait;
80404diff --git a/include/linux/kobject.h b/include/linux/kobject.h
80405index 926afb6..58dd6e5 100644
80406--- a/include/linux/kobject.h
80407+++ b/include/linux/kobject.h
80408@@ -116,7 +116,7 @@ struct kobj_type {
80409 struct attribute **default_attrs;
80410 const struct kobj_ns_type_operations *(*child_ns_type)(struct kobject *kobj);
80411 const void *(*namespace)(struct kobject *kobj);
80412-};
80413+} __do_const;
80414
80415 struct kobj_uevent_env {
80416 char *envp[UEVENT_NUM_ENVP];
80417@@ -139,6 +139,7 @@ struct kobj_attribute {
80418 ssize_t (*store)(struct kobject *kobj, struct kobj_attribute *attr,
80419 const char *buf, size_t count);
80420 };
80421+typedef struct kobj_attribute __no_const kobj_attribute_no_const;
80422
80423 extern const struct sysfs_ops kobj_sysfs_ops;
80424
80425@@ -166,7 +167,7 @@ struct kset {
80426 spinlock_t list_lock;
80427 struct kobject kobj;
80428 const struct kset_uevent_ops *uevent_ops;
80429-};
80430+} __randomize_layout;
80431
80432 extern void kset_init(struct kset *kset);
80433 extern int __must_check kset_register(struct kset *kset);
80434diff --git a/include/linux/kobject_ns.h b/include/linux/kobject_ns.h
80435index df32d25..fb52e27 100644
80436--- a/include/linux/kobject_ns.h
80437+++ b/include/linux/kobject_ns.h
80438@@ -44,7 +44,7 @@ struct kobj_ns_type_operations {
80439 const void *(*netlink_ns)(struct sock *sk);
80440 const void *(*initial_ns)(void);
80441 void (*drop_ns)(void *);
80442-};
80443+} __do_const;
80444
80445 int kobj_ns_type_register(const struct kobj_ns_type_operations *ops);
80446 int kobj_ns_type_registered(enum kobj_ns_type type);
80447diff --git a/include/linux/kref.h b/include/linux/kref.h
80448index 484604d..0f6c5b6 100644
80449--- a/include/linux/kref.h
80450+++ b/include/linux/kref.h
80451@@ -68,7 +68,7 @@ static inline void kref_get(struct kref *kref)
80452 static inline int kref_sub(struct kref *kref, unsigned int count,
80453 void (*release)(struct kref *kref))
80454 {
80455- WARN_ON(release == NULL);
80456+ BUG_ON(release == NULL);
80457
80458 if (atomic_sub_and_test((int) count, &kref->refcount)) {
80459 release(kref);
80460diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
80461index b8e9a43..632678d 100644
80462--- a/include/linux/kvm_host.h
80463+++ b/include/linux/kvm_host.h
80464@@ -455,7 +455,7 @@ static inline void kvm_irqfd_exit(void)
80465 {
80466 }
80467 #endif
80468-int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
80469+int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
80470 struct module *module);
80471 void kvm_exit(void);
80472
80473@@ -621,7 +621,7 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
80474 struct kvm_guest_debug *dbg);
80475 int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run);
80476
80477-int kvm_arch_init(void *opaque);
80478+int kvm_arch_init(const void *opaque);
80479 void kvm_arch_exit(void);
80480
80481 int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu);
80482diff --git a/include/linux/libata.h b/include/linux/libata.h
80483index 3fee55e..42565b7 100644
80484--- a/include/linux/libata.h
80485+++ b/include/linux/libata.h
80486@@ -976,7 +976,7 @@ struct ata_port_operations {
80487 * fields must be pointers.
80488 */
80489 const struct ata_port_operations *inherits;
80490-};
80491+} __do_const;
80492
80493 struct ata_port_info {
80494 unsigned long flags;
80495diff --git a/include/linux/linkage.h b/include/linux/linkage.h
80496index a6a42dd..6c5ebce 100644
80497--- a/include/linux/linkage.h
80498+++ b/include/linux/linkage.h
80499@@ -36,6 +36,7 @@
80500 #endif
80501
80502 #define __page_aligned_data __section(.data..page_aligned) __aligned(PAGE_SIZE)
80503+#define __page_aligned_rodata __read_only __aligned(PAGE_SIZE)
80504 #define __page_aligned_bss __section(.bss..page_aligned) __aligned(PAGE_SIZE)
80505
80506 /*
80507diff --git a/include/linux/list.h b/include/linux/list.h
80508index ef95941..82db65a 100644
80509--- a/include/linux/list.h
80510+++ b/include/linux/list.h
80511@@ -112,6 +112,19 @@ extern void __list_del_entry(struct list_head *entry);
80512 extern void list_del(struct list_head *entry);
80513 #endif
80514
80515+extern void __pax_list_add(struct list_head *new,
80516+ struct list_head *prev,
80517+ struct list_head *next);
80518+static inline void pax_list_add(struct list_head *new, struct list_head *head)
80519+{
80520+ __pax_list_add(new, head, head->next);
80521+}
80522+static inline void pax_list_add_tail(struct list_head *new, struct list_head *head)
80523+{
80524+ __pax_list_add(new, head->prev, head);
80525+}
80526+extern void pax_list_del(struct list_head *entry);
80527+
80528 /**
80529 * list_replace - replace old entry by new one
80530 * @old : the element to be replaced
80531@@ -145,6 +158,8 @@ static inline void list_del_init(struct list_head *entry)
80532 INIT_LIST_HEAD(entry);
80533 }
80534
80535+extern void pax_list_del_init(struct list_head *entry);
80536+
80537 /**
80538 * list_move - delete from one list and add as another's head
80539 * @list: the entry to move
80540diff --git a/include/linux/math64.h b/include/linux/math64.h
80541index c45c089..298841c 100644
80542--- a/include/linux/math64.h
80543+++ b/include/linux/math64.h
80544@@ -15,7 +15,7 @@
80545 * This is commonly provided by 32bit archs to provide an optimized 64bit
80546 * divide.
80547 */
80548-static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
80549+static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
80550 {
80551 *remainder = dividend % divisor;
80552 return dividend / divisor;
80553@@ -42,7 +42,7 @@ static inline u64 div64_u64_rem(u64 dividend, u64 divisor, u64 *remainder)
80554 /**
80555 * div64_u64 - unsigned 64bit divide with 64bit divisor
80556 */
80557-static inline u64 div64_u64(u64 dividend, u64 divisor)
80558+static inline u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor)
80559 {
80560 return dividend / divisor;
80561 }
80562@@ -61,7 +61,7 @@ static inline s64 div64_s64(s64 dividend, s64 divisor)
80563 #define div64_ul(x, y) div_u64((x), (y))
80564
80565 #ifndef div_u64_rem
80566-static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
80567+static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
80568 {
80569 *remainder = do_div(dividend, divisor);
80570 return dividend;
80571@@ -77,7 +77,7 @@ extern u64 div64_u64_rem(u64 dividend, u64 divisor, u64 *remainder);
80572 #endif
80573
80574 #ifndef div64_u64
80575-extern u64 div64_u64(u64 dividend, u64 divisor);
80576+extern u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor);
80577 #endif
80578
80579 #ifndef div64_s64
80580@@ -94,7 +94,7 @@ extern s64 div64_s64(s64 dividend, s64 divisor);
80581 * divide.
80582 */
80583 #ifndef div_u64
80584-static inline u64 div_u64(u64 dividend, u32 divisor)
80585+static inline u64 __intentional_overflow(-1) div_u64(u64 dividend, u32 divisor)
80586 {
80587 u32 remainder;
80588 return div_u64_rem(dividend, divisor, &remainder);
80589diff --git a/include/linux/mempolicy.h b/include/linux/mempolicy.h
80590index 5f1ea75..5125ac5 100644
80591--- a/include/linux/mempolicy.h
80592+++ b/include/linux/mempolicy.h
80593@@ -91,6 +91,10 @@ static inline struct mempolicy *mpol_dup(struct mempolicy *pol)
80594 }
80595
80596 #define vma_policy(vma) ((vma)->vm_policy)
80597+static inline void set_vma_policy(struct vm_area_struct *vma, struct mempolicy *pol)
80598+{
80599+ vma->vm_policy = pol;
80600+}
80601
80602 static inline void mpol_get(struct mempolicy *pol)
80603 {
80604@@ -223,6 +227,9 @@ static inline void mpol_free_shared_policy(struct shared_policy *p)
80605 }
80606
80607 #define vma_policy(vma) NULL
80608+static inline void set_vma_policy(struct vm_area_struct *vma, struct mempolicy *pol)
80609+{
80610+}
80611
80612 static inline int
80613 vma_dup_policy(struct vm_area_struct *src, struct vm_area_struct *dst)
80614diff --git a/include/linux/mm.h b/include/linux/mm.h
80615index c1b7414..5ea2ad8 100644
80616--- a/include/linux/mm.h
80617+++ b/include/linux/mm.h
80618@@ -127,6 +127,11 @@ extern unsigned int kobjsize(const void *objp);
80619 #define VM_HUGETLB 0x00400000 /* Huge TLB Page VM */
80620 #define VM_NONLINEAR 0x00800000 /* Is non-linear (remap_file_pages) */
80621 #define VM_ARCH_1 0x01000000 /* Architecture-specific flag */
80622+
80623+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
80624+#define VM_PAGEEXEC 0x02000000 /* vma->vm_page_prot needs special handling */
80625+#endif
80626+
80627 #define VM_DONTDUMP 0x04000000 /* Do not include in the core dump */
80628
80629 #ifdef CONFIG_MEM_SOFT_DIRTY
80630@@ -229,8 +234,8 @@ struct vm_operations_struct {
80631 /* called by access_process_vm when get_user_pages() fails, typically
80632 * for use by special VMAs that can switch between memory and hardware
80633 */
80634- int (*access)(struct vm_area_struct *vma, unsigned long addr,
80635- void *buf, int len, int write);
80636+ ssize_t (*access)(struct vm_area_struct *vma, unsigned long addr,
80637+ void *buf, size_t len, int write);
80638 #ifdef CONFIG_NUMA
80639 /*
80640 * set_policy() op must add a reference to any non-NULL @new mempolicy
80641@@ -260,6 +265,7 @@ struct vm_operations_struct {
80642 int (*remap_pages)(struct vm_area_struct *vma, unsigned long addr,
80643 unsigned long size, pgoff_t pgoff);
80644 };
80645+typedef struct vm_operations_struct __no_const vm_operations_struct_no_const;
80646
80647 struct mmu_gather;
80648 struct inode;
80649@@ -1112,8 +1118,8 @@ int follow_pfn(struct vm_area_struct *vma, unsigned long address,
80650 unsigned long *pfn);
80651 int follow_phys(struct vm_area_struct *vma, unsigned long address,
80652 unsigned int flags, unsigned long *prot, resource_size_t *phys);
80653-int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
80654- void *buf, int len, int write);
80655+ssize_t generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
80656+ void *buf, size_t len, int write);
80657
80658 static inline void unmap_shared_mapping_range(struct address_space *mapping,
80659 loff_t const holebegin, loff_t const holelen)
80660@@ -1152,9 +1158,9 @@ static inline int fixup_user_fault(struct task_struct *tsk,
80661 }
80662 #endif
80663
80664-extern int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write);
80665-extern int access_remote_vm(struct mm_struct *mm, unsigned long addr,
80666- void *buf, int len, int write);
80667+extern ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, size_t len, int write);
80668+extern ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
80669+ void *buf, size_t len, int write);
80670
80671 long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
80672 unsigned long start, unsigned long nr_pages,
80673@@ -1186,34 +1192,6 @@ int set_page_dirty(struct page *page);
80674 int set_page_dirty_lock(struct page *page);
80675 int clear_page_dirty_for_io(struct page *page);
80676
80677-/* Is the vma a continuation of the stack vma above it? */
80678-static inline int vma_growsdown(struct vm_area_struct *vma, unsigned long addr)
80679-{
80680- return vma && (vma->vm_end == addr) && (vma->vm_flags & VM_GROWSDOWN);
80681-}
80682-
80683-static inline int stack_guard_page_start(struct vm_area_struct *vma,
80684- unsigned long addr)
80685-{
80686- return (vma->vm_flags & VM_GROWSDOWN) &&
80687- (vma->vm_start == addr) &&
80688- !vma_growsdown(vma->vm_prev, addr);
80689-}
80690-
80691-/* Is the vma a continuation of the stack vma below it? */
80692-static inline int vma_growsup(struct vm_area_struct *vma, unsigned long addr)
80693-{
80694- return vma && (vma->vm_start == addr) && (vma->vm_flags & VM_GROWSUP);
80695-}
80696-
80697-static inline int stack_guard_page_end(struct vm_area_struct *vma,
80698- unsigned long addr)
80699-{
80700- return (vma->vm_flags & VM_GROWSUP) &&
80701- (vma->vm_end == addr) &&
80702- !vma_growsup(vma->vm_next, addr);
80703-}
80704-
80705 extern pid_t
80706 vm_is_stack(struct task_struct *task, struct vm_area_struct *vma, int in_group);
80707
80708@@ -1313,6 +1291,15 @@ static inline void sync_mm_rss(struct mm_struct *mm)
80709 }
80710 #endif
80711
80712+#ifdef CONFIG_MMU
80713+pgprot_t vm_get_page_prot(vm_flags_t vm_flags);
80714+#else
80715+static inline pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
80716+{
80717+ return __pgprot(0);
80718+}
80719+#endif
80720+
80721 int vma_wants_writenotify(struct vm_area_struct *vma);
80722
80723 extern pte_t *__get_locked_pte(struct mm_struct *mm, unsigned long addr,
80724@@ -1331,8 +1318,15 @@ static inline int __pud_alloc(struct mm_struct *mm, pgd_t *pgd,
80725 {
80726 return 0;
80727 }
80728+
80729+static inline int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd,
80730+ unsigned long address)
80731+{
80732+ return 0;
80733+}
80734 #else
80735 int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
80736+int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
80737 #endif
80738
80739 #ifdef __PAGETABLE_PMD_FOLDED
80740@@ -1341,8 +1335,15 @@ static inline int __pmd_alloc(struct mm_struct *mm, pud_t *pud,
80741 {
80742 return 0;
80743 }
80744+
80745+static inline int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud,
80746+ unsigned long address)
80747+{
80748+ return 0;
80749+}
80750 #else
80751 int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address);
80752+int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address);
80753 #endif
80754
80755 int __pte_alloc(struct mm_struct *mm, struct vm_area_struct *vma,
80756@@ -1360,11 +1361,23 @@ static inline pud_t *pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long a
80757 NULL: pud_offset(pgd, address);
80758 }
80759
80760+static inline pud_t *pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
80761+{
80762+ return (unlikely(pgd_none(*pgd)) && __pud_alloc_kernel(mm, pgd, address))?
80763+ NULL: pud_offset(pgd, address);
80764+}
80765+
80766 static inline pmd_t *pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
80767 {
80768 return (unlikely(pud_none(*pud)) && __pmd_alloc(mm, pud, address))?
80769 NULL: pmd_offset(pud, address);
80770 }
80771+
80772+static inline pmd_t *pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
80773+{
80774+ return (unlikely(pud_none(*pud)) && __pmd_alloc_kernel(mm, pud, address))?
80775+ NULL: pmd_offset(pud, address);
80776+}
80777 #endif /* CONFIG_MMU && !__ARCH_HAS_4LEVEL_HACK */
80778
80779 #if USE_SPLIT_PTE_PTLOCKS
80780@@ -1754,7 +1767,7 @@ extern int install_special_mapping(struct mm_struct *mm,
80781 unsigned long addr, unsigned long len,
80782 unsigned long flags, struct page **pages);
80783
80784-extern unsigned long get_unmapped_area(struct file *, unsigned long, unsigned long, unsigned long, unsigned long);
80785+extern unsigned long get_unmapped_area(struct file *, unsigned long, unsigned long, unsigned long, unsigned long) __intentional_overflow(-1);
80786
80787 extern unsigned long mmap_region(struct file *file, unsigned long addr,
80788 unsigned long len, vm_flags_t vm_flags, unsigned long pgoff);
80789@@ -1762,6 +1775,7 @@ extern unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
80790 unsigned long len, unsigned long prot, unsigned long flags,
80791 unsigned long pgoff, unsigned long *populate);
80792 extern int do_munmap(struct mm_struct *, unsigned long, size_t);
80793+extern int __do_munmap(struct mm_struct *, unsigned long, size_t);
80794
80795 #ifdef CONFIG_MMU
80796 extern int __mm_populate(unsigned long addr, unsigned long len,
80797@@ -1790,10 +1804,11 @@ struct vm_unmapped_area_info {
80798 unsigned long high_limit;
80799 unsigned long align_mask;
80800 unsigned long align_offset;
80801+ unsigned long threadstack_offset;
80802 };
80803
80804-extern unsigned long unmapped_area(struct vm_unmapped_area_info *info);
80805-extern unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info);
80806+extern unsigned long unmapped_area(const struct vm_unmapped_area_info *info);
80807+extern unsigned long unmapped_area_topdown(const struct vm_unmapped_area_info *info);
80808
80809 /*
80810 * Search for an unmapped address range.
80811@@ -1805,7 +1820,7 @@ extern unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info);
80812 * - satisfies (begin_addr & align_mask) == (align_offset & align_mask)
80813 */
80814 static inline unsigned long
80815-vm_unmapped_area(struct vm_unmapped_area_info *info)
80816+vm_unmapped_area(const struct vm_unmapped_area_info *info)
80817 {
80818 if (!(info->flags & VM_UNMAPPED_AREA_TOPDOWN))
80819 return unmapped_area(info);
80820@@ -1868,6 +1883,10 @@ extern struct vm_area_struct * find_vma(struct mm_struct * mm, unsigned long add
80821 extern struct vm_area_struct * find_vma_prev(struct mm_struct * mm, unsigned long addr,
80822 struct vm_area_struct **pprev);
80823
80824+extern struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma);
80825+extern __must_check long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma);
80826+extern void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl);
80827+
80828 /* Look up the first VMA which intersects the interval start_addr..end_addr-1,
80829 NULL if none. Assume start_addr < end_addr. */
80830 static inline struct vm_area_struct * find_vma_intersection(struct mm_struct * mm, unsigned long start_addr, unsigned long end_addr)
80831@@ -1896,15 +1915,6 @@ static inline struct vm_area_struct *find_exact_vma(struct mm_struct *mm,
80832 return vma;
80833 }
80834
80835-#ifdef CONFIG_MMU
80836-pgprot_t vm_get_page_prot(unsigned long vm_flags);
80837-#else
80838-static inline pgprot_t vm_get_page_prot(unsigned long vm_flags)
80839-{
80840- return __pgprot(0);
80841-}
80842-#endif
80843-
80844 #ifdef CONFIG_NUMA_BALANCING
80845 unsigned long change_prot_numa(struct vm_area_struct *vma,
80846 unsigned long start, unsigned long end);
80847@@ -1956,6 +1966,11 @@ void vm_stat_account(struct mm_struct *, unsigned long, struct file *, long);
80848 static inline void vm_stat_account(struct mm_struct *mm,
80849 unsigned long flags, struct file *file, long pages)
80850 {
80851+
80852+#ifdef CONFIG_PAX_RANDMMAP
80853+ if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
80854+#endif
80855+
80856 mm->total_vm += pages;
80857 }
80858 #endif /* CONFIG_PROC_FS */
80859@@ -2037,7 +2052,7 @@ extern int unpoison_memory(unsigned long pfn);
80860 extern int sysctl_memory_failure_early_kill;
80861 extern int sysctl_memory_failure_recovery;
80862 extern void shake_page(struct page *p, int access);
80863-extern atomic_long_t num_poisoned_pages;
80864+extern atomic_long_unchecked_t num_poisoned_pages;
80865 extern int soft_offline_page(struct page *page, int flags);
80866
80867 #if defined(CONFIG_TRANSPARENT_HUGEPAGE) || defined(CONFIG_HUGETLBFS)
80868@@ -2072,5 +2087,11 @@ void __init setup_nr_node_ids(void);
80869 static inline void setup_nr_node_ids(void) {}
80870 #endif
80871
80872+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
80873+extern void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot);
80874+#else
80875+static inline void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot) {}
80876+#endif
80877+
80878 #endif /* __KERNEL__ */
80879 #endif /* _LINUX_MM_H */
80880diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
80881index 290901a..e99b01c 100644
80882--- a/include/linux/mm_types.h
80883+++ b/include/linux/mm_types.h
80884@@ -307,7 +307,9 @@ struct vm_area_struct {
80885 #ifdef CONFIG_NUMA
80886 struct mempolicy *vm_policy; /* NUMA policy for the VMA */
80887 #endif
80888-};
80889+
80890+ struct vm_area_struct *vm_mirror;/* PaX: mirror vma or NULL */
80891+} __randomize_layout;
80892
80893 struct core_thread {
80894 struct task_struct *task;
80895@@ -453,7 +455,25 @@ struct mm_struct {
80896 bool tlb_flush_pending;
80897 #endif
80898 struct uprobes_state uprobes_state;
80899-};
80900+
80901+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
80902+ unsigned long pax_flags;
80903+#endif
80904+
80905+#ifdef CONFIG_PAX_DLRESOLVE
80906+ unsigned long call_dl_resolve;
80907+#endif
80908+
80909+#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
80910+ unsigned long call_syscall;
80911+#endif
80912+
80913+#ifdef CONFIG_PAX_ASLR
80914+ unsigned long delta_mmap; /* randomized offset */
80915+ unsigned long delta_stack; /* randomized offset */
80916+#endif
80917+
80918+} __randomize_layout;
80919
80920 static inline void mm_init_cpumask(struct mm_struct *mm)
80921 {
80922diff --git a/include/linux/mmiotrace.h b/include/linux/mmiotrace.h
80923index c5d5278..f0b68c8 100644
80924--- a/include/linux/mmiotrace.h
80925+++ b/include/linux/mmiotrace.h
80926@@ -46,7 +46,7 @@ extern int kmmio_handler(struct pt_regs *regs, unsigned long addr);
80927 /* Called from ioremap.c */
80928 extern void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
80929 void __iomem *addr);
80930-extern void mmiotrace_iounmap(volatile void __iomem *addr);
80931+extern void mmiotrace_iounmap(const volatile void __iomem *addr);
80932
80933 /* For anyone to insert markers. Remember trailing newline. */
80934 extern __printf(1, 2) int mmiotrace_printk(const char *fmt, ...);
80935@@ -66,7 +66,7 @@ static inline void mmiotrace_ioremap(resource_size_t offset,
80936 {
80937 }
80938
80939-static inline void mmiotrace_iounmap(volatile void __iomem *addr)
80940+static inline void mmiotrace_iounmap(const volatile void __iomem *addr)
80941 {
80942 }
80943
80944diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
80945index 9b61b9b..52147d6b 100644
80946--- a/include/linux/mmzone.h
80947+++ b/include/linux/mmzone.h
80948@@ -396,7 +396,7 @@ struct zone {
80949 unsigned long flags; /* zone flags, see below */
80950
80951 /* Zone statistics */
80952- atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
80953+ atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
80954
80955 /*
80956 * The target ratio of ACTIVE_ANON to INACTIVE_ANON pages on
80957diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h
80958index 45e9214..a7227d6 100644
80959--- a/include/linux/mod_devicetable.h
80960+++ b/include/linux/mod_devicetable.h
80961@@ -13,7 +13,7 @@
80962 typedef unsigned long kernel_ulong_t;
80963 #endif
80964
80965-#define PCI_ANY_ID (~0)
80966+#define PCI_ANY_ID ((__u16)~0)
80967
80968 struct pci_device_id {
80969 __u32 vendor, device; /* Vendor and device ID or PCI_ANY_ID*/
80970@@ -139,7 +139,7 @@ struct usb_device_id {
80971 #define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x0200
80972 #define USB_DEVICE_ID_MATCH_INT_NUMBER 0x0400
80973
80974-#define HID_ANY_ID (~0)
80975+#define HID_ANY_ID (~0U)
80976 #define HID_BUS_ANY 0xffff
80977 #define HID_GROUP_ANY 0x0000
80978
80979@@ -467,7 +467,7 @@ struct dmi_system_id {
80980 const char *ident;
80981 struct dmi_strmatch matches[4];
80982 void *driver_data;
80983-};
80984+} __do_const;
80985 /*
80986 * struct dmi_device_id appears during expansion of
80987 * "MODULE_DEVICE_TABLE(dmi, x)". Compiler doesn't look inside it
80988diff --git a/include/linux/module.h b/include/linux/module.h
80989index eaf60ff..641979a 100644
80990--- a/include/linux/module.h
80991+++ b/include/linux/module.h
80992@@ -17,9 +17,11 @@
80993 #include <linux/moduleparam.h>
80994 #include <linux/tracepoint.h>
80995 #include <linux/export.h>
80996+#include <linux/fs.h>
80997
80998 #include <linux/percpu.h>
80999 #include <asm/module.h>
81000+#include <asm/pgtable.h>
81001
81002 /* In stripped ARM and x86-64 modules, ~ is surprisingly rare. */
81003 #define MODULE_SIG_STRING "~Module signature appended~\n"
81004@@ -42,7 +44,7 @@ struct module_kobject {
81005 struct kobject *drivers_dir;
81006 struct module_param_attrs *mp;
81007 struct completion *kobj_completion;
81008-};
81009+} __randomize_layout;
81010
81011 struct module_attribute {
81012 struct attribute attr;
81013@@ -54,12 +56,13 @@ struct module_attribute {
81014 int (*test)(struct module *);
81015 void (*free)(struct module *);
81016 };
81017+typedef struct module_attribute __no_const module_attribute_no_const;
81018
81019 struct module_version_attribute {
81020 struct module_attribute mattr;
81021 const char *module_name;
81022 const char *version;
81023-} __attribute__ ((__aligned__(sizeof(void *))));
81024+} __do_const __attribute__ ((__aligned__(sizeof(void *))));
81025
81026 extern ssize_t __modver_version_show(struct module_attribute *,
81027 struct module_kobject *, char *);
81028@@ -238,7 +241,7 @@ struct module {
81029
81030 /* Sysfs stuff. */
81031 struct module_kobject mkobj;
81032- struct module_attribute *modinfo_attrs;
81033+ module_attribute_no_const *modinfo_attrs;
81034 const char *version;
81035 const char *srcversion;
81036 struct kobject *holders_dir;
81037@@ -287,19 +290,16 @@ struct module {
81038 int (*init)(void);
81039
81040 /* If this is non-NULL, vfree after init() returns */
81041- void *module_init;
81042+ void *module_init_rx, *module_init_rw;
81043
81044 /* Here is the actual code + data, vfree'd on unload. */
81045- void *module_core;
81046+ void *module_core_rx, *module_core_rw;
81047
81048 /* Here are the sizes of the init and core sections */
81049- unsigned int init_size, core_size;
81050+ unsigned int init_size_rw, core_size_rw;
81051
81052 /* The size of the executable code in each section. */
81053- unsigned int init_text_size, core_text_size;
81054-
81055- /* Size of RO sections of the module (text+rodata) */
81056- unsigned int init_ro_size, core_ro_size;
81057+ unsigned int init_size_rx, core_size_rx;
81058
81059 /* Arch-specific module values */
81060 struct mod_arch_specific arch;
81061@@ -355,6 +355,10 @@ struct module {
81062 #ifdef CONFIG_EVENT_TRACING
81063 struct ftrace_event_call **trace_events;
81064 unsigned int num_trace_events;
81065+ struct file_operations trace_id;
81066+ struct file_operations trace_enable;
81067+ struct file_operations trace_format;
81068+ struct file_operations trace_filter;
81069 #endif
81070 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
81071 unsigned int num_ftrace_callsites;
81072@@ -378,7 +382,7 @@ struct module {
81073 ctor_fn_t *ctors;
81074 unsigned int num_ctors;
81075 #endif
81076-};
81077+} __randomize_layout;
81078 #ifndef MODULE_ARCH_INIT
81079 #define MODULE_ARCH_INIT {}
81080 #endif
81081@@ -399,16 +403,46 @@ bool is_module_address(unsigned long addr);
81082 bool is_module_percpu_address(unsigned long addr);
81083 bool is_module_text_address(unsigned long addr);
81084
81085+static inline int within_module_range(unsigned long addr, void *start, unsigned long size)
81086+{
81087+
81088+#ifdef CONFIG_PAX_KERNEXEC
81089+ if (ktla_ktva(addr) >= (unsigned long)start &&
81090+ ktla_ktva(addr) < (unsigned long)start + size)
81091+ return 1;
81092+#endif
81093+
81094+ return ((void *)addr >= start && (void *)addr < start + size);
81095+}
81096+
81097+static inline int within_module_core_rx(unsigned long addr, const struct module *mod)
81098+{
81099+ return within_module_range(addr, mod->module_core_rx, mod->core_size_rx);
81100+}
81101+
81102+static inline int within_module_core_rw(unsigned long addr, const struct module *mod)
81103+{
81104+ return within_module_range(addr, mod->module_core_rw, mod->core_size_rw);
81105+}
81106+
81107+static inline int within_module_init_rx(unsigned long addr, const struct module *mod)
81108+{
81109+ return within_module_range(addr, mod->module_init_rx, mod->init_size_rx);
81110+}
81111+
81112+static inline int within_module_init_rw(unsigned long addr, const struct module *mod)
81113+{
81114+ return within_module_range(addr, mod->module_init_rw, mod->init_size_rw);
81115+}
81116+
81117 static inline int within_module_core(unsigned long addr, const struct module *mod)
81118 {
81119- return (unsigned long)mod->module_core <= addr &&
81120- addr < (unsigned long)mod->module_core + mod->core_size;
81121+ return within_module_core_rx(addr, mod) || within_module_core_rw(addr, mod);
81122 }
81123
81124 static inline int within_module_init(unsigned long addr, const struct module *mod)
81125 {
81126- return (unsigned long)mod->module_init <= addr &&
81127- addr < (unsigned long)mod->module_init + mod->init_size;
81128+ return within_module_init_rx(addr, mod) || within_module_init_rw(addr, mod);
81129 }
81130
81131 /* Search for module by name: must hold module_mutex. */
81132diff --git a/include/linux/moduleloader.h b/include/linux/moduleloader.h
81133index 560ca53..ef621ef 100644
81134--- a/include/linux/moduleloader.h
81135+++ b/include/linux/moduleloader.h
81136@@ -25,9 +25,21 @@ unsigned int arch_mod_section_prepend(struct module *mod, unsigned int section);
81137 sections. Returns NULL on failure. */
81138 void *module_alloc(unsigned long size);
81139
81140+#ifdef CONFIG_PAX_KERNEXEC
81141+void *module_alloc_exec(unsigned long size);
81142+#else
81143+#define module_alloc_exec(x) module_alloc(x)
81144+#endif
81145+
81146 /* Free memory returned from module_alloc. */
81147 void module_free(struct module *mod, void *module_region);
81148
81149+#ifdef CONFIG_PAX_KERNEXEC
81150+void module_free_exec(struct module *mod, void *module_region);
81151+#else
81152+#define module_free_exec(x, y) module_free((x), (y))
81153+#endif
81154+
81155 /*
81156 * Apply the given relocation to the (simplified) ELF. Return -error
81157 * or 0.
81158@@ -45,7 +57,9 @@ static inline int apply_relocate(Elf_Shdr *sechdrs,
81159 unsigned int relsec,
81160 struct module *me)
81161 {
81162+#ifdef CONFIG_MODULES
81163 printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name);
81164+#endif
81165 return -ENOEXEC;
81166 }
81167 #endif
81168@@ -67,7 +81,9 @@ static inline int apply_relocate_add(Elf_Shdr *sechdrs,
81169 unsigned int relsec,
81170 struct module *me)
81171 {
81172+#ifdef CONFIG_MODULES
81173 printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name);
81174+#endif
81175 return -ENOEXEC;
81176 }
81177 #endif
81178diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h
81179index c3eb102..073c4a6 100644
81180--- a/include/linux/moduleparam.h
81181+++ b/include/linux/moduleparam.h
81182@@ -295,7 +295,7 @@ static inline void __kernel_param_unlock(void)
81183 * @len is usually just sizeof(string).
81184 */
81185 #define module_param_string(name, string, len, perm) \
81186- static const struct kparam_string __param_string_##name \
81187+ static const struct kparam_string __param_string_##name __used \
81188 = { len, string }; \
81189 __module_param_call(MODULE_PARAM_PREFIX, name, \
81190 &param_ops_string, \
81191@@ -434,7 +434,7 @@ extern int param_set_bint(const char *val, const struct kernel_param *kp);
81192 */
81193 #define module_param_array_named(name, array, type, nump, perm) \
81194 param_check_##type(name, &(array)[0]); \
81195- static const struct kparam_array __param_arr_##name \
81196+ static const struct kparam_array __param_arr_##name __used \
81197 = { .max = ARRAY_SIZE(array), .num = nump, \
81198 .ops = &param_ops_##type, \
81199 .elemsize = sizeof(array[0]), .elem = array }; \
81200diff --git a/include/linux/mount.h b/include/linux/mount.h
81201index 839bac2..a96b37c 100644
81202--- a/include/linux/mount.h
81203+++ b/include/linux/mount.h
81204@@ -59,7 +59,7 @@ struct vfsmount {
81205 struct dentry *mnt_root; /* root of the mounted tree */
81206 struct super_block *mnt_sb; /* pointer to superblock */
81207 int mnt_flags;
81208-};
81209+} __randomize_layout;
81210
81211 struct file; /* forward dec */
81212
81213diff --git a/include/linux/namei.h b/include/linux/namei.h
81214index 492de72..1bddcd4 100644
81215--- a/include/linux/namei.h
81216+++ b/include/linux/namei.h
81217@@ -19,7 +19,7 @@ struct nameidata {
81218 unsigned seq, m_seq;
81219 int last_type;
81220 unsigned depth;
81221- char *saved_names[MAX_NESTED_LINKS + 1];
81222+ const char *saved_names[MAX_NESTED_LINKS + 1];
81223 };
81224
81225 /*
81226@@ -83,12 +83,12 @@ extern void unlock_rename(struct dentry *, struct dentry *);
81227
81228 extern void nd_jump_link(struct nameidata *nd, struct path *path);
81229
81230-static inline void nd_set_link(struct nameidata *nd, char *path)
81231+static inline void nd_set_link(struct nameidata *nd, const char *path)
81232 {
81233 nd->saved_names[nd->depth] = path;
81234 }
81235
81236-static inline char *nd_get_link(struct nameidata *nd)
81237+static inline const char *nd_get_link(const struct nameidata *nd)
81238 {
81239 return nd->saved_names[nd->depth];
81240 }
81241diff --git a/include/linux/net.h b/include/linux/net.h
81242index 94734a6..d8d6931 100644
81243--- a/include/linux/net.h
81244+++ b/include/linux/net.h
81245@@ -192,7 +192,7 @@ struct net_proto_family {
81246 int (*create)(struct net *net, struct socket *sock,
81247 int protocol, int kern);
81248 struct module *owner;
81249-};
81250+} __do_const;
81251
81252 struct iovec;
81253 struct kvec;
81254diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
81255index daafd95..74c5d1e 100644
81256--- a/include/linux/netdevice.h
81257+++ b/include/linux/netdevice.h
81258@@ -1146,6 +1146,7 @@ struct net_device_ops {
81259 struct net_device *dev,
81260 void *priv);
81261 };
81262+typedef struct net_device_ops __no_const net_device_ops_no_const;
81263
81264 /*
81265 * The DEVICE structure.
81266@@ -1228,7 +1229,7 @@ struct net_device {
81267 int iflink;
81268
81269 struct net_device_stats stats;
81270- atomic_long_t rx_dropped; /* dropped packets by core network
81271+ atomic_long_unchecked_t rx_dropped; /* dropped packets by core network
81272 * Do not use this in drivers.
81273 */
81274
81275diff --git a/include/linux/netfilter.h b/include/linux/netfilter.h
81276index 2077489..a15e561 100644
81277--- a/include/linux/netfilter.h
81278+++ b/include/linux/netfilter.h
81279@@ -84,7 +84,7 @@ struct nf_sockopt_ops {
81280 #endif
81281 /* Use the module struct to lock set/get code in place */
81282 struct module *owner;
81283-};
81284+} __do_const;
81285
81286 /* Function to register/unregister hook points. */
81287 int nf_register_hook(struct nf_hook_ops *reg);
81288diff --git a/include/linux/netfilter/nfnetlink.h b/include/linux/netfilter/nfnetlink.h
81289index 28c7436..2d6156a 100644
81290--- a/include/linux/netfilter/nfnetlink.h
81291+++ b/include/linux/netfilter/nfnetlink.h
81292@@ -19,7 +19,7 @@ struct nfnl_callback {
81293 const struct nlattr * const cda[]);
81294 const struct nla_policy *policy; /* netlink attribute policy */
81295 const u_int16_t attr_count; /* number of nlattr's */
81296-};
81297+} __do_const;
81298
81299 struct nfnetlink_subsystem {
81300 const char *name;
81301diff --git a/include/linux/netfilter/xt_gradm.h b/include/linux/netfilter/xt_gradm.h
81302new file mode 100644
81303index 0000000..33f4af8
81304--- /dev/null
81305+++ b/include/linux/netfilter/xt_gradm.h
81306@@ -0,0 +1,9 @@
81307+#ifndef _LINUX_NETFILTER_XT_GRADM_H
81308+#define _LINUX_NETFILTER_XT_GRADM_H 1
81309+
81310+struct xt_gradm_mtinfo {
81311+ __u16 flags;
81312+ __u16 invflags;
81313+};
81314+
81315+#endif
81316diff --git a/include/linux/nls.h b/include/linux/nls.h
81317index 520681b..1d67ed2 100644
81318--- a/include/linux/nls.h
81319+++ b/include/linux/nls.h
81320@@ -31,7 +31,7 @@ struct nls_table {
81321 const unsigned char *charset2upper;
81322 struct module *owner;
81323 struct nls_table *next;
81324-};
81325+} __do_const;
81326
81327 /* this value hold the maximum octet of charset */
81328 #define NLS_MAX_CHARSET_SIZE 6 /* for UTF-8 */
81329diff --git a/include/linux/notifier.h b/include/linux/notifier.h
81330index d14a4c3..a078786 100644
81331--- a/include/linux/notifier.h
81332+++ b/include/linux/notifier.h
81333@@ -54,7 +54,8 @@ struct notifier_block {
81334 notifier_fn_t notifier_call;
81335 struct notifier_block __rcu *next;
81336 int priority;
81337-};
81338+} __do_const;
81339+typedef struct notifier_block __no_const notifier_block_no_const;
81340
81341 struct atomic_notifier_head {
81342 spinlock_t lock;
81343diff --git a/include/linux/oprofile.h b/include/linux/oprofile.h
81344index b2a0f15..4d7da32 100644
81345--- a/include/linux/oprofile.h
81346+++ b/include/linux/oprofile.h
81347@@ -138,9 +138,9 @@ int oprofilefs_create_ulong(struct dentry * root,
81348 int oprofilefs_create_ro_ulong(struct dentry * root,
81349 char const * name, ulong * val);
81350
81351-/** Create a file for read-only access to an atomic_t. */
81352+/** Create a file for read-only access to an atomic_unchecked_t. */
81353 int oprofilefs_create_ro_atomic(struct dentry * root,
81354- char const * name, atomic_t * val);
81355+ char const * name, atomic_unchecked_t * val);
81356
81357 /** create a directory */
81358 struct dentry *oprofilefs_mkdir(struct dentry *parent, char const *name);
81359diff --git a/include/linux/padata.h b/include/linux/padata.h
81360index 4386946..f50c615 100644
81361--- a/include/linux/padata.h
81362+++ b/include/linux/padata.h
81363@@ -129,7 +129,7 @@ struct parallel_data {
81364 struct padata_serial_queue __percpu *squeue;
81365 atomic_t reorder_objects;
81366 atomic_t refcnt;
81367- atomic_t seq_nr;
81368+ atomic_unchecked_t seq_nr;
81369 struct padata_cpumask cpumask;
81370 spinlock_t lock ____cacheline_aligned;
81371 unsigned int processed;
81372diff --git a/include/linux/path.h b/include/linux/path.h
81373index d137218..be0c176 100644
81374--- a/include/linux/path.h
81375+++ b/include/linux/path.h
81376@@ -1,13 +1,15 @@
81377 #ifndef _LINUX_PATH_H
81378 #define _LINUX_PATH_H
81379
81380+#include <linux/compiler.h>
81381+
81382 struct dentry;
81383 struct vfsmount;
81384
81385 struct path {
81386 struct vfsmount *mnt;
81387 struct dentry *dentry;
81388-};
81389+} __randomize_layout;
81390
81391 extern void path_get(const struct path *);
81392 extern void path_put(const struct path *);
81393diff --git a/include/linux/pci_hotplug.h b/include/linux/pci_hotplug.h
81394index 5f2e559..7d59314 100644
81395--- a/include/linux/pci_hotplug.h
81396+++ b/include/linux/pci_hotplug.h
81397@@ -71,7 +71,8 @@ struct hotplug_slot_ops {
81398 int (*get_latch_status) (struct hotplug_slot *slot, u8 *value);
81399 int (*get_adapter_status) (struct hotplug_slot *slot, u8 *value);
81400 int (*reset_slot) (struct hotplug_slot *slot, int probe);
81401-};
81402+} __do_const;
81403+typedef struct hotplug_slot_ops __no_const hotplug_slot_ops_no_const;
81404
81405 /**
81406 * struct hotplug_slot_info - used to notify the hotplug pci core of the state of the slot
81407diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
81408index e56b07f..aef789b 100644
81409--- a/include/linux/perf_event.h
81410+++ b/include/linux/perf_event.h
81411@@ -328,8 +328,8 @@ struct perf_event {
81412
81413 enum perf_event_active_state state;
81414 unsigned int attach_state;
81415- local64_t count;
81416- atomic64_t child_count;
81417+ local64_t count; /* PaX: fix it one day */
81418+ atomic64_unchecked_t child_count;
81419
81420 /*
81421 * These are the total time in nanoseconds that the event
81422@@ -380,8 +380,8 @@ struct perf_event {
81423 * These accumulate total time (in nanoseconds) that children
81424 * events have been enabled and running, respectively.
81425 */
81426- atomic64_t child_total_time_enabled;
81427- atomic64_t child_total_time_running;
81428+ atomic64_unchecked_t child_total_time_enabled;
81429+ atomic64_unchecked_t child_total_time_running;
81430
81431 /*
81432 * Protect attach/detach and child_list:
81433@@ -708,7 +708,7 @@ static inline void perf_callchain_store(struct perf_callchain_entry *entry, u64
81434 entry->ip[entry->nr++] = ip;
81435 }
81436
81437-extern int sysctl_perf_event_paranoid;
81438+extern int sysctl_perf_event_legitimately_concerned;
81439 extern int sysctl_perf_event_mlock;
81440 extern int sysctl_perf_event_sample_rate;
81441 extern int sysctl_perf_cpu_time_max_percent;
81442@@ -723,19 +723,24 @@ extern int perf_cpu_time_max_percent_handler(struct ctl_table *table, int write,
81443 loff_t *ppos);
81444
81445
81446+static inline bool perf_paranoid_any(void)
81447+{
81448+ return sysctl_perf_event_legitimately_concerned > 2;
81449+}
81450+
81451 static inline bool perf_paranoid_tracepoint_raw(void)
81452 {
81453- return sysctl_perf_event_paranoid > -1;
81454+ return sysctl_perf_event_legitimately_concerned > -1;
81455 }
81456
81457 static inline bool perf_paranoid_cpu(void)
81458 {
81459- return sysctl_perf_event_paranoid > 0;
81460+ return sysctl_perf_event_legitimately_concerned > 0;
81461 }
81462
81463 static inline bool perf_paranoid_kernel(void)
81464 {
81465- return sysctl_perf_event_paranoid > 1;
81466+ return sysctl_perf_event_legitimately_concerned > 1;
81467 }
81468
81469 extern void perf_event_init(void);
81470@@ -851,7 +856,7 @@ struct perf_pmu_events_attr {
81471 struct device_attribute attr;
81472 u64 id;
81473 const char *event_str;
81474-};
81475+} __do_const;
81476
81477 #define PMU_EVENT_ATTR(_name, _var, _id, _show) \
81478 static struct perf_pmu_events_attr _var = { \
81479diff --git a/include/linux/pid_namespace.h b/include/linux/pid_namespace.h
81480index 7246ef3..1539ea4 100644
81481--- a/include/linux/pid_namespace.h
81482+++ b/include/linux/pid_namespace.h
81483@@ -43,7 +43,7 @@ struct pid_namespace {
81484 int hide_pid;
81485 int reboot; /* group exit code if this pidns was rebooted */
81486 unsigned int proc_inum;
81487-};
81488+} __randomize_layout;
81489
81490 extern struct pid_namespace init_pid_ns;
81491
81492diff --git a/include/linux/pipe_fs_i.h b/include/linux/pipe_fs_i.h
81493index ab57526..94598804 100644
81494--- a/include/linux/pipe_fs_i.h
81495+++ b/include/linux/pipe_fs_i.h
81496@@ -47,10 +47,10 @@ struct pipe_inode_info {
81497 struct mutex mutex;
81498 wait_queue_head_t wait;
81499 unsigned int nrbufs, curbuf, buffers;
81500- unsigned int readers;
81501- unsigned int writers;
81502- unsigned int files;
81503- unsigned int waiting_writers;
81504+ atomic_t readers;
81505+ atomic_t writers;
81506+ atomic_t files;
81507+ atomic_t waiting_writers;
81508 unsigned int r_counter;
81509 unsigned int w_counter;
81510 struct page *tmp_page;
81511diff --git a/include/linux/pm.h b/include/linux/pm.h
81512index 8c6583a..febb84c 100644
81513--- a/include/linux/pm.h
81514+++ b/include/linux/pm.h
81515@@ -597,6 +597,7 @@ extern int dev_pm_put_subsys_data(struct device *dev);
81516 struct dev_pm_domain {
81517 struct dev_pm_ops ops;
81518 };
81519+typedef struct dev_pm_domain __no_const dev_pm_domain_no_const;
81520
81521 /*
81522 * The PM_EVENT_ messages are also used by drivers implementing the legacy
81523diff --git a/include/linux/pm_domain.h b/include/linux/pm_domain.h
81524index 7c1d252..0e7061d 100644
81525--- a/include/linux/pm_domain.h
81526+++ b/include/linux/pm_domain.h
81527@@ -44,11 +44,11 @@ struct gpd_dev_ops {
81528 int (*thaw_early)(struct device *dev);
81529 int (*thaw)(struct device *dev);
81530 bool (*active_wakeup)(struct device *dev);
81531-};
81532+} __no_const;
81533
81534 struct gpd_cpu_data {
81535 unsigned int saved_exit_latency;
81536- struct cpuidle_state *idle_state;
81537+ cpuidle_state_no_const *idle_state;
81538 };
81539
81540 struct generic_pm_domain {
81541diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h
81542index 16c9a62..f9f0838 100644
81543--- a/include/linux/pm_runtime.h
81544+++ b/include/linux/pm_runtime.h
81545@@ -109,7 +109,7 @@ static inline bool pm_runtime_callbacks_present(struct device *dev)
81546
81547 static inline void pm_runtime_mark_last_busy(struct device *dev)
81548 {
81549- ACCESS_ONCE(dev->power.last_busy) = jiffies;
81550+ ACCESS_ONCE_RW(dev->power.last_busy) = jiffies;
81551 }
81552
81553 #else /* !CONFIG_PM_RUNTIME */
81554diff --git a/include/linux/pnp.h b/include/linux/pnp.h
81555index 195aafc..49a7bc2 100644
81556--- a/include/linux/pnp.h
81557+++ b/include/linux/pnp.h
81558@@ -297,7 +297,7 @@ static inline void pnp_set_drvdata(struct pnp_dev *pdev, void *data)
81559 struct pnp_fixup {
81560 char id[7];
81561 void (*quirk_function) (struct pnp_dev * dev); /* fixup function */
81562-};
81563+} __do_const;
81564
81565 /* config parameters */
81566 #define PNP_CONFIG_NORMAL 0x0001
81567diff --git a/include/linux/poison.h b/include/linux/poison.h
81568index 2110a81..13a11bb 100644
81569--- a/include/linux/poison.h
81570+++ b/include/linux/poison.h
81571@@ -19,8 +19,8 @@
81572 * under normal circumstances, used to verify that nobody uses
81573 * non-initialized list entries.
81574 */
81575-#define LIST_POISON1 ((void *) 0x00100100 + POISON_POINTER_DELTA)
81576-#define LIST_POISON2 ((void *) 0x00200200 + POISON_POINTER_DELTA)
81577+#define LIST_POISON1 ((void *) (long)0xFFFFFF01)
81578+#define LIST_POISON2 ((void *) (long)0xFFFFFF02)
81579
81580 /********** include/linux/timer.h **********/
81581 /*
81582diff --git a/include/linux/power/smartreflex.h b/include/linux/power/smartreflex.h
81583index d8b187c3..9a9257a 100644
81584--- a/include/linux/power/smartreflex.h
81585+++ b/include/linux/power/smartreflex.h
81586@@ -238,7 +238,7 @@ struct omap_sr_class_data {
81587 int (*notify)(struct omap_sr *sr, u32 status);
81588 u8 notify_flags;
81589 u8 class_type;
81590-};
81591+} __do_const;
81592
81593 /**
81594 * struct omap_sr_nvalue_table - Smartreflex n-target value info
81595diff --git a/include/linux/ppp-comp.h b/include/linux/ppp-comp.h
81596index 4ea1d37..80f4b33 100644
81597--- a/include/linux/ppp-comp.h
81598+++ b/include/linux/ppp-comp.h
81599@@ -84,7 +84,7 @@ struct compressor {
81600 struct module *owner;
81601 /* Extra skb space needed by the compressor algorithm */
81602 unsigned int comp_extra;
81603-};
81604+} __do_const;
81605
81606 /*
81607 * The return value from decompress routine is the length of the
81608diff --git a/include/linux/preempt.h b/include/linux/preempt.h
81609index de83b4e..c4b997d 100644
81610--- a/include/linux/preempt.h
81611+++ b/include/linux/preempt.h
81612@@ -27,11 +27,16 @@ extern void preempt_count_sub(int val);
81613 #define preempt_count_dec_and_test() __preempt_count_dec_and_test()
81614 #endif
81615
81616+#define raw_preempt_count_add(val) __preempt_count_add(val)
81617+#define raw_preempt_count_sub(val) __preempt_count_sub(val)
81618+
81619 #define __preempt_count_inc() __preempt_count_add(1)
81620 #define __preempt_count_dec() __preempt_count_sub(1)
81621
81622 #define preempt_count_inc() preempt_count_add(1)
81623+#define raw_preempt_count_inc() raw_preempt_count_add(1)
81624 #define preempt_count_dec() preempt_count_sub(1)
81625+#define raw_preempt_count_dec() raw_preempt_count_sub(1)
81626
81627 #ifdef CONFIG_PREEMPT_COUNT
81628
81629@@ -41,6 +46,12 @@ do { \
81630 barrier(); \
81631 } while (0)
81632
81633+#define raw_preempt_disable() \
81634+do { \
81635+ raw_preempt_count_inc(); \
81636+ barrier(); \
81637+} while (0)
81638+
81639 #define sched_preempt_enable_no_resched() \
81640 do { \
81641 barrier(); \
81642@@ -49,6 +60,12 @@ do { \
81643
81644 #define preempt_enable_no_resched() sched_preempt_enable_no_resched()
81645
81646+#define raw_preempt_enable_no_resched() \
81647+do { \
81648+ barrier(); \
81649+ raw_preempt_count_dec(); \
81650+} while (0)
81651+
81652 #ifdef CONFIG_PREEMPT
81653 #define preempt_enable() \
81654 do { \
81655@@ -113,8 +130,10 @@ do { \
81656 * region.
81657 */
81658 #define preempt_disable() barrier()
81659+#define raw_preempt_disable() barrier()
81660 #define sched_preempt_enable_no_resched() barrier()
81661 #define preempt_enable_no_resched() barrier()
81662+#define raw_preempt_enable_no_resched() barrier()
81663 #define preempt_enable() barrier()
81664 #define preempt_check_resched() do { } while (0)
81665
81666@@ -128,11 +147,13 @@ do { \
81667 /*
81668 * Modules have no business playing preemption tricks.
81669 */
81670+#ifndef CONFIG_PAX_KERNEXEC
81671 #undef sched_preempt_enable_no_resched
81672 #undef preempt_enable_no_resched
81673 #undef preempt_enable_no_resched_notrace
81674 #undef preempt_check_resched
81675 #endif
81676+#endif
81677
81678 #define preempt_set_need_resched() \
81679 do { \
81680diff --git a/include/linux/printk.h b/include/linux/printk.h
81681index fa47e27..c08e034 100644
81682--- a/include/linux/printk.h
81683+++ b/include/linux/printk.h
81684@@ -114,6 +114,8 @@ static inline __printf(1, 2) __cold
81685 void early_printk(const char *s, ...) { }
81686 #endif
81687
81688+extern int kptr_restrict;
81689+
81690 #ifdef CONFIG_PRINTK
81691 asmlinkage __printf(5, 0)
81692 int vprintk_emit(int facility, int level,
81693@@ -148,7 +150,6 @@ extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
81694
81695 extern int printk_delay_msec;
81696 extern int dmesg_restrict;
81697-extern int kptr_restrict;
81698
81699 extern void wake_up_klogd(void);
81700
81701diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
81702index 608e60a..bbcb1a0 100644
81703--- a/include/linux/proc_fs.h
81704+++ b/include/linux/proc_fs.h
81705@@ -17,8 +17,11 @@ extern void proc_flush_task(struct task_struct *);
81706 extern struct proc_dir_entry *proc_symlink(const char *,
81707 struct proc_dir_entry *, const char *);
81708 extern struct proc_dir_entry *proc_mkdir(const char *, struct proc_dir_entry *);
81709+extern struct proc_dir_entry *proc_mkdir_restrict(const char *, struct proc_dir_entry *);
81710 extern struct proc_dir_entry *proc_mkdir_data(const char *, umode_t,
81711 struct proc_dir_entry *, void *);
81712+extern struct proc_dir_entry *proc_mkdir_data_restrict(const char *, umode_t,
81713+ struct proc_dir_entry *, void *);
81714 extern struct proc_dir_entry *proc_mkdir_mode(const char *, umode_t,
81715 struct proc_dir_entry *);
81716
81717@@ -34,6 +37,19 @@ static inline struct proc_dir_entry *proc_create(
81718 return proc_create_data(name, mode, parent, proc_fops, NULL);
81719 }
81720
81721+static inline struct proc_dir_entry *proc_create_grsec(const char *name, umode_t mode,
81722+ struct proc_dir_entry *parent, const struct file_operations *proc_fops)
81723+{
81724+#ifdef CONFIG_GRKERNSEC_PROC_USER
81725+ return proc_create_data(name, S_IRUSR, parent, proc_fops, NULL);
81726+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
81727+ return proc_create_data(name, S_IRUSR | S_IRGRP, parent, proc_fops, NULL);
81728+#else
81729+ return proc_create_data(name, mode, parent, proc_fops, NULL);
81730+#endif
81731+}
81732+
81733+
81734 extern void proc_set_size(struct proc_dir_entry *, loff_t);
81735 extern void proc_set_user(struct proc_dir_entry *, kuid_t, kgid_t);
81736 extern void *PDE_DATA(const struct inode *);
81737@@ -73,7 +89,7 @@ static inline int remove_proc_subtree(const char *name, struct proc_dir_entry *p
81738 static inline struct proc_dir_entry *proc_net_mkdir(
81739 struct net *net, const char *name, struct proc_dir_entry *parent)
81740 {
81741- return proc_mkdir_data(name, 0, parent, net);
81742+ return proc_mkdir_data_restrict(name, 0, parent, net);
81743 }
81744
81745 #endif /* _LINUX_PROC_FS_H */
81746diff --git a/include/linux/proc_ns.h b/include/linux/proc_ns.h
81747index 34a1e10..70f6bde 100644
81748--- a/include/linux/proc_ns.h
81749+++ b/include/linux/proc_ns.h
81750@@ -14,7 +14,7 @@ struct proc_ns_operations {
81751 void (*put)(void *ns);
81752 int (*install)(struct nsproxy *nsproxy, void *ns);
81753 unsigned int (*inum)(void *ns);
81754-};
81755+} __do_const __randomize_layout;
81756
81757 struct proc_ns {
81758 void *ns;
81759diff --git a/include/linux/quota.h b/include/linux/quota.h
81760index cc7494a..1e27036 100644
81761--- a/include/linux/quota.h
81762+++ b/include/linux/quota.h
81763@@ -70,7 +70,7 @@ struct kqid { /* Type in which we store the quota identifier */
81764
81765 extern bool qid_eq(struct kqid left, struct kqid right);
81766 extern bool qid_lt(struct kqid left, struct kqid right);
81767-extern qid_t from_kqid(struct user_namespace *to, struct kqid qid);
81768+extern qid_t from_kqid(struct user_namespace *to, struct kqid qid) __intentional_overflow(-1);
81769 extern qid_t from_kqid_munged(struct user_namespace *to, struct kqid qid);
81770 extern bool qid_valid(struct kqid qid);
81771
81772diff --git a/include/linux/random.h b/include/linux/random.h
81773index 1cfce0e..b0b9235 100644
81774--- a/include/linux/random.h
81775+++ b/include/linux/random.h
81776@@ -9,9 +9,19 @@
81777 #include <uapi/linux/random.h>
81778
81779 extern void add_device_randomness(const void *, unsigned int);
81780+
81781+static inline void add_latent_entropy(void)
81782+{
81783+
81784+#ifdef LATENT_ENTROPY_PLUGIN
81785+ add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
81786+#endif
81787+
81788+}
81789+
81790 extern void add_input_randomness(unsigned int type, unsigned int code,
81791- unsigned int value);
81792-extern void add_interrupt_randomness(int irq, int irq_flags);
81793+ unsigned int value) __latent_entropy;
81794+extern void add_interrupt_randomness(int irq, int irq_flags) __latent_entropy;
81795
81796 extern void get_random_bytes(void *buf, int nbytes);
81797 extern void get_random_bytes_arch(void *buf, int nbytes);
81798@@ -22,10 +32,10 @@ extern int random_int_secret_init(void);
81799 extern const struct file_operations random_fops, urandom_fops;
81800 #endif
81801
81802-unsigned int get_random_int(void);
81803+unsigned int __intentional_overflow(-1) get_random_int(void);
81804 unsigned long randomize_range(unsigned long start, unsigned long end, unsigned long len);
81805
81806-u32 prandom_u32(void);
81807+u32 prandom_u32(void) __intentional_overflow(-1);
81808 void prandom_bytes(void *buf, int nbytes);
81809 void prandom_seed(u32 seed);
81810 void prandom_reseed_late(void);
81811@@ -37,6 +47,11 @@ struct rnd_state {
81812 u32 prandom_u32_state(struct rnd_state *state);
81813 void prandom_bytes_state(struct rnd_state *state, void *buf, int nbytes);
81814
81815+static inline unsigned long __intentional_overflow(-1) pax_get_random_long(void)
81816+{
81817+ return prandom_u32() + (sizeof(long) > 4 ? (unsigned long)prandom_u32() << 32 : 0);
81818+}
81819+
81820 /**
81821 * prandom_u32_max - returns a pseudo-random number in interval [0, ep_ro)
81822 * @ep_ro: right open interval endpoint
81823diff --git a/include/linux/rbtree_augmented.h b/include/linux/rbtree_augmented.h
81824index fea49b5..2ac22bb 100644
81825--- a/include/linux/rbtree_augmented.h
81826+++ b/include/linux/rbtree_augmented.h
81827@@ -80,7 +80,9 @@ rbname ## _rotate(struct rb_node *rb_old, struct rb_node *rb_new) \
81828 old->rbaugmented = rbcompute(old); \
81829 } \
81830 rbstatic const struct rb_augment_callbacks rbname = { \
81831- rbname ## _propagate, rbname ## _copy, rbname ## _rotate \
81832+ .propagate = rbname ## _propagate, \
81833+ .copy = rbname ## _copy, \
81834+ .rotate = rbname ## _rotate \
81835 };
81836
81837
81838diff --git a/include/linux/rculist.h b/include/linux/rculist.h
81839index dbaf990..52e07b8 100644
81840--- a/include/linux/rculist.h
81841+++ b/include/linux/rculist.h
81842@@ -29,8 +29,8 @@
81843 */
81844 static inline void INIT_LIST_HEAD_RCU(struct list_head *list)
81845 {
81846- ACCESS_ONCE(list->next) = list;
81847- ACCESS_ONCE(list->prev) = list;
81848+ ACCESS_ONCE_RW(list->next) = list;
81849+ ACCESS_ONCE_RW(list->prev) = list;
81850 }
81851
81852 /*
81853@@ -59,6 +59,9 @@ void __list_add_rcu(struct list_head *new,
81854 struct list_head *prev, struct list_head *next);
81855 #endif
81856
81857+void __pax_list_add_rcu(struct list_head *new,
81858+ struct list_head *prev, struct list_head *next);
81859+
81860 /**
81861 * list_add_rcu - add a new entry to rcu-protected list
81862 * @new: new entry to be added
81863@@ -80,6 +83,11 @@ static inline void list_add_rcu(struct list_head *new, struct list_head *head)
81864 __list_add_rcu(new, head, head->next);
81865 }
81866
81867+static inline void pax_list_add_rcu(struct list_head *new, struct list_head *head)
81868+{
81869+ __pax_list_add_rcu(new, head, head->next);
81870+}
81871+
81872 /**
81873 * list_add_tail_rcu - add a new entry to rcu-protected list
81874 * @new: new entry to be added
81875@@ -102,6 +110,12 @@ static inline void list_add_tail_rcu(struct list_head *new,
81876 __list_add_rcu(new, head->prev, head);
81877 }
81878
81879+static inline void pax_list_add_tail_rcu(struct list_head *new,
81880+ struct list_head *head)
81881+{
81882+ __pax_list_add_rcu(new, head->prev, head);
81883+}
81884+
81885 /**
81886 * list_del_rcu - deletes entry from list without re-initialization
81887 * @entry: the element to delete from the list.
81888@@ -132,6 +146,8 @@ static inline void list_del_rcu(struct list_head *entry)
81889 entry->prev = LIST_POISON2;
81890 }
81891
81892+extern void pax_list_del_rcu(struct list_head *entry);
81893+
81894 /**
81895 * hlist_del_init_rcu - deletes entry from hash list with re-initialization
81896 * @n: the element to delete from the hash list.
81897diff --git a/include/linux/rcupdate.h b/include/linux/rcupdate.h
81898index 72bf3a0..853347f 100644
81899--- a/include/linux/rcupdate.h
81900+++ b/include/linux/rcupdate.h
81901@@ -588,7 +588,7 @@ static inline void rcu_preempt_sleep_check(void)
81902 #define rcu_assign_pointer(p, v) \
81903 do { \
81904 smp_wmb(); \
81905- ACCESS_ONCE(p) = RCU_INITIALIZER(v); \
81906+ ACCESS_ONCE_RW(p) = RCU_INITIALIZER(v); \
81907 } while (0)
81908
81909
81910diff --git a/include/linux/reboot.h b/include/linux/reboot.h
81911index 9e7db9e..7d4fd72 100644
81912--- a/include/linux/reboot.h
81913+++ b/include/linux/reboot.h
81914@@ -44,9 +44,9 @@ extern int unregister_reboot_notifier(struct notifier_block *);
81915 */
81916
81917 extern void migrate_to_reboot_cpu(void);
81918-extern void machine_restart(char *cmd);
81919-extern void machine_halt(void);
81920-extern void machine_power_off(void);
81921+extern void machine_restart(char *cmd) __noreturn;
81922+extern void machine_halt(void) __noreturn;
81923+extern void machine_power_off(void) __noreturn;
81924
81925 extern void machine_shutdown(void);
81926 struct pt_regs;
81927@@ -57,9 +57,9 @@ extern void machine_crash_shutdown(struct pt_regs *);
81928 */
81929
81930 extern void kernel_restart_prepare(char *cmd);
81931-extern void kernel_restart(char *cmd);
81932-extern void kernel_halt(void);
81933-extern void kernel_power_off(void);
81934+extern void kernel_restart(char *cmd) __noreturn;
81935+extern void kernel_halt(void) __noreturn;
81936+extern void kernel_power_off(void) __noreturn;
81937
81938 extern int C_A_D; /* for sysctl */
81939 void ctrl_alt_del(void);
81940@@ -73,7 +73,7 @@ extern int orderly_poweroff(bool force);
81941 * Emergency restart, callable from an interrupt handler.
81942 */
81943
81944-extern void emergency_restart(void);
81945+extern void emergency_restart(void) __noreturn;
81946 #include <asm/emergency-restart.h>
81947
81948 #endif /* _LINUX_REBOOT_H */
81949diff --git a/include/linux/regset.h b/include/linux/regset.h
81950index 8e0c9fe..ac4d221 100644
81951--- a/include/linux/regset.h
81952+++ b/include/linux/regset.h
81953@@ -161,7 +161,8 @@ struct user_regset {
81954 unsigned int align;
81955 unsigned int bias;
81956 unsigned int core_note_type;
81957-};
81958+} __do_const;
81959+typedef struct user_regset __no_const user_regset_no_const;
81960
81961 /**
81962 * struct user_regset_view - available regsets
81963diff --git a/include/linux/relay.h b/include/linux/relay.h
81964index d7c8359..818daf5 100644
81965--- a/include/linux/relay.h
81966+++ b/include/linux/relay.h
81967@@ -157,7 +157,7 @@ struct rchan_callbacks
81968 * The callback should return 0 if successful, negative if not.
81969 */
81970 int (*remove_buf_file)(struct dentry *dentry);
81971-};
81972+} __no_const;
81973
81974 /*
81975 * CONFIG_RELAY kernel API, kernel/relay.c
81976diff --git a/include/linux/rio.h b/include/linux/rio.h
81977index b71d573..2f940bd 100644
81978--- a/include/linux/rio.h
81979+++ b/include/linux/rio.h
81980@@ -355,7 +355,7 @@ struct rio_ops {
81981 int (*map_inb)(struct rio_mport *mport, dma_addr_t lstart,
81982 u64 rstart, u32 size, u32 flags);
81983 void (*unmap_inb)(struct rio_mport *mport, dma_addr_t lstart);
81984-};
81985+} __no_const;
81986
81987 #define RIO_RESOURCE_MEM 0x00000100
81988 #define RIO_RESOURCE_DOORBELL 0x00000200
81989diff --git a/include/linux/rmap.h b/include/linux/rmap.h
81990index b66c211..13d2915 100644
81991--- a/include/linux/rmap.h
81992+++ b/include/linux/rmap.h
81993@@ -145,8 +145,8 @@ static inline void anon_vma_unlock_read(struct anon_vma *anon_vma)
81994 void anon_vma_init(void); /* create anon_vma_cachep */
81995 int anon_vma_prepare(struct vm_area_struct *);
81996 void unlink_anon_vmas(struct vm_area_struct *);
81997-int anon_vma_clone(struct vm_area_struct *, struct vm_area_struct *);
81998-int anon_vma_fork(struct vm_area_struct *, struct vm_area_struct *);
81999+int anon_vma_clone(struct vm_area_struct *, const struct vm_area_struct *);
82000+int anon_vma_fork(struct vm_area_struct *, const struct vm_area_struct *);
82001
82002 static inline void anon_vma_merge(struct vm_area_struct *vma,
82003 struct vm_area_struct *next)
82004diff --git a/include/linux/sched.h b/include/linux/sched.h
82005index a781dec..be1d2a3 100644
82006--- a/include/linux/sched.h
82007+++ b/include/linux/sched.h
82008@@ -129,6 +129,7 @@ struct fs_struct;
82009 struct perf_event_context;
82010 struct blk_plug;
82011 struct filename;
82012+struct linux_binprm;
82013
82014 /*
82015 * List of flags we want to share for kernel threads,
82016@@ -369,7 +370,7 @@ extern char __sched_text_start[], __sched_text_end[];
82017 extern int in_sched_functions(unsigned long addr);
82018
82019 #define MAX_SCHEDULE_TIMEOUT LONG_MAX
82020-extern signed long schedule_timeout(signed long timeout);
82021+extern signed long schedule_timeout(signed long timeout) __intentional_overflow(-1);
82022 extern signed long schedule_timeout_interruptible(signed long timeout);
82023 extern signed long schedule_timeout_killable(signed long timeout);
82024 extern signed long schedule_timeout_uninterruptible(signed long timeout);
82025@@ -380,6 +381,19 @@ struct nsproxy;
82026 struct user_namespace;
82027
82028 #ifdef CONFIG_MMU
82029+
82030+#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
82031+extern unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags);
82032+#else
82033+static inline unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
82034+{
82035+ return 0;
82036+}
82037+#endif
82038+
82039+extern bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset);
82040+extern unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset);
82041+
82042 extern void arch_pick_mmap_layout(struct mm_struct *mm);
82043 extern unsigned long
82044 arch_get_unmapped_area(struct file *, unsigned long, unsigned long,
82045@@ -677,6 +691,17 @@ struct signal_struct {
82046 #ifdef CONFIG_TASKSTATS
82047 struct taskstats *stats;
82048 #endif
82049+
82050+#ifdef CONFIG_GRKERNSEC
82051+ u32 curr_ip;
82052+ u32 saved_ip;
82053+ u32 gr_saddr;
82054+ u32 gr_daddr;
82055+ u16 gr_sport;
82056+ u16 gr_dport;
82057+ u8 used_accept:1;
82058+#endif
82059+
82060 #ifdef CONFIG_AUDIT
82061 unsigned audit_tty;
82062 unsigned audit_tty_log_passwd;
82063@@ -703,7 +728,7 @@ struct signal_struct {
82064 struct mutex cred_guard_mutex; /* guard against foreign influences on
82065 * credential calculations
82066 * (notably. ptrace) */
82067-};
82068+} __randomize_layout;
82069
82070 /*
82071 * Bits in flags field of signal_struct.
82072@@ -757,6 +782,14 @@ struct user_struct {
82073 struct key *session_keyring; /* UID's default session keyring */
82074 #endif
82075
82076+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
82077+ unsigned char kernel_banned;
82078+#endif
82079+#ifdef CONFIG_GRKERNSEC_BRUTE
82080+ unsigned char suid_banned;
82081+ unsigned long suid_ban_expires;
82082+#endif
82083+
82084 /* Hash table maintenance information */
82085 struct hlist_node uidhash_node;
82086 kuid_t uid;
82087@@ -764,7 +797,7 @@ struct user_struct {
82088 #ifdef CONFIG_PERF_EVENTS
82089 atomic_long_t locked_vm;
82090 #endif
82091-};
82092+} __randomize_layout;
82093
82094 extern int uids_sysfs_init(void);
82095
82096@@ -1286,8 +1319,8 @@ struct task_struct {
82097 struct list_head thread_node;
82098
82099 struct completion *vfork_done; /* for vfork() */
82100- int __user *set_child_tid; /* CLONE_CHILD_SETTID */
82101- int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
82102+ pid_t __user *set_child_tid; /* CLONE_CHILD_SETTID */
82103+ pid_t __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
82104
82105 cputime_t utime, stime, utimescaled, stimescaled;
82106 cputime_t gtime;
82107@@ -1312,11 +1345,6 @@ struct task_struct {
82108 struct task_cputime cputime_expires;
82109 struct list_head cpu_timers[3];
82110
82111-/* process credentials */
82112- const struct cred __rcu *real_cred; /* objective and real subjective task
82113- * credentials (COW) */
82114- const struct cred __rcu *cred; /* effective (overridable) subjective task
82115- * credentials (COW) */
82116 char comm[TASK_COMM_LEN]; /* executable name excluding path
82117 - access with [gs]et_task_comm (which lock
82118 it with task_lock())
82119@@ -1333,6 +1361,10 @@ struct task_struct {
82120 #endif
82121 /* CPU-specific state of this task */
82122 struct thread_struct thread;
82123+/* thread_info moved to task_struct */
82124+#ifdef CONFIG_X86
82125+ struct thread_info tinfo;
82126+#endif
82127 /* filesystem information */
82128 struct fs_struct *fs;
82129 /* open file information */
82130@@ -1409,6 +1441,10 @@ struct task_struct {
82131 gfp_t lockdep_reclaim_gfp;
82132 #endif
82133
82134+/* process credentials */
82135+ const struct cred __rcu *real_cred; /* objective and real subjective task
82136+ * credentials (COW) */
82137+
82138 /* journalling filesystem info */
82139 void *journal_info;
82140
82141@@ -1447,6 +1483,10 @@ struct task_struct {
82142 /* cg_list protected by css_set_lock and tsk->alloc_lock */
82143 struct list_head cg_list;
82144 #endif
82145+
82146+ const struct cred __rcu *cred; /* effective (overridable) subjective task
82147+ * credentials (COW) */
82148+
82149 #ifdef CONFIG_FUTEX
82150 struct robust_list_head __user *robust_list;
82151 #ifdef CONFIG_COMPAT
82152@@ -1581,7 +1621,78 @@ struct task_struct {
82153 unsigned int sequential_io;
82154 unsigned int sequential_io_avg;
82155 #endif
82156-};
82157+
82158+#ifdef CONFIG_GRKERNSEC
82159+ /* grsecurity */
82160+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
82161+ u64 exec_id;
82162+#endif
82163+#ifdef CONFIG_GRKERNSEC_SETXID
82164+ const struct cred *delayed_cred;
82165+#endif
82166+ struct dentry *gr_chroot_dentry;
82167+ struct acl_subject_label *acl;
82168+ struct acl_subject_label *tmpacl;
82169+ struct acl_role_label *role;
82170+ struct file *exec_file;
82171+ unsigned long brute_expires;
82172+ u16 acl_role_id;
82173+ u8 inherited;
82174+ /* is this the task that authenticated to the special role */
82175+ u8 acl_sp_role;
82176+ u8 is_writable;
82177+ u8 brute;
82178+ u8 gr_is_chrooted;
82179+#endif
82180+
82181+} __randomize_layout;
82182+
82183+#define MF_PAX_PAGEEXEC 0x01000000 /* Paging based non-executable pages */
82184+#define MF_PAX_EMUTRAMP 0x02000000 /* Emulate trampolines */
82185+#define MF_PAX_MPROTECT 0x04000000 /* Restrict mprotect() */
82186+#define MF_PAX_RANDMMAP 0x08000000 /* Randomize mmap() base */
82187+/*#define MF_PAX_RANDEXEC 0x10000000*/ /* Randomize ET_EXEC base */
82188+#define MF_PAX_SEGMEXEC 0x20000000 /* Segmentation based non-executable pages */
82189+
82190+#ifdef CONFIG_PAX_SOFTMODE
82191+extern int pax_softmode;
82192+#endif
82193+
82194+extern int pax_check_flags(unsigned long *);
82195+#define PAX_PARSE_FLAGS_FALLBACK (~0UL)
82196+
82197+/* if tsk != current then task_lock must be held on it */
82198+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
82199+static inline unsigned long pax_get_flags(struct task_struct *tsk)
82200+{
82201+ if (likely(tsk->mm))
82202+ return tsk->mm->pax_flags;
82203+ else
82204+ return 0UL;
82205+}
82206+
82207+/* if tsk != current then task_lock must be held on it */
82208+static inline long pax_set_flags(struct task_struct *tsk, unsigned long flags)
82209+{
82210+ if (likely(tsk->mm)) {
82211+ tsk->mm->pax_flags = flags;
82212+ return 0;
82213+ }
82214+ return -EINVAL;
82215+}
82216+#endif
82217+
82218+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
82219+extern void pax_set_initial_flags(struct linux_binprm *bprm);
82220+#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
82221+extern void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
82222+#endif
82223+
82224+struct path;
82225+extern char *pax_get_path(const struct path *path, char *buf, int buflen);
82226+extern void pax_report_fault(struct pt_regs *regs, void *pc, void *sp);
82227+extern void pax_report_insns(struct pt_regs *regs, void *pc, void *sp);
82228+extern void pax_report_refcount_overflow(struct pt_regs *regs);
82229
82230 /* Future-safe accessor for struct task_struct's cpus_allowed. */
82231 #define tsk_cpus_allowed(tsk) (&(tsk)->cpus_allowed)
82232@@ -1658,7 +1769,7 @@ struct pid_namespace;
82233 pid_t __task_pid_nr_ns(struct task_struct *task, enum pid_type type,
82234 struct pid_namespace *ns);
82235
82236-static inline pid_t task_pid_nr(struct task_struct *tsk)
82237+static inline pid_t task_pid_nr(const struct task_struct *tsk)
82238 {
82239 return tsk->pid;
82240 }
82241@@ -2112,7 +2223,9 @@ void yield(void);
82242 extern struct exec_domain default_exec_domain;
82243
82244 union thread_union {
82245+#ifndef CONFIG_X86
82246 struct thread_info thread_info;
82247+#endif
82248 unsigned long stack[THREAD_SIZE/sizeof(long)];
82249 };
82250
82251@@ -2145,6 +2258,7 @@ extern struct pid_namespace init_pid_ns;
82252 */
82253
82254 extern struct task_struct *find_task_by_vpid(pid_t nr);
82255+extern struct task_struct *find_task_by_vpid_unrestricted(pid_t nr);
82256 extern struct task_struct *find_task_by_pid_ns(pid_t nr,
82257 struct pid_namespace *ns);
82258
82259@@ -2307,7 +2421,7 @@ extern void __cleanup_sighand(struct sighand_struct *);
82260 extern void exit_itimers(struct signal_struct *);
82261 extern void flush_itimer_signals(void);
82262
82263-extern void do_group_exit(int);
82264+extern __noreturn void do_group_exit(int);
82265
82266 extern int allow_signal(int);
82267 extern int disallow_signal(int);
82268@@ -2508,9 +2622,9 @@ static inline unsigned long *end_of_stack(struct task_struct *p)
82269
82270 #endif
82271
82272-static inline int object_is_on_stack(void *obj)
82273+static inline int object_starts_on_stack(void *obj)
82274 {
82275- void *stack = task_stack_page(current);
82276+ const void *stack = task_stack_page(current);
82277
82278 return (obj >= stack) && (obj < (stack + THREAD_SIZE));
82279 }
82280diff --git a/include/linux/sched/sysctl.h b/include/linux/sched/sysctl.h
82281index 8045a55..c959cd5 100644
82282--- a/include/linux/sched/sysctl.h
82283+++ b/include/linux/sched/sysctl.h
82284@@ -30,6 +30,7 @@ enum { sysctl_hung_task_timeout_secs = 0 };
82285 #define DEFAULT_MAX_MAP_COUNT (USHRT_MAX - MAPCOUNT_ELF_CORE_MARGIN)
82286
82287 extern int sysctl_max_map_count;
82288+extern unsigned long sysctl_heap_stack_gap;
82289
82290 extern unsigned int sysctl_sched_latency;
82291 extern unsigned int sysctl_sched_min_granularity;
82292diff --git a/include/linux/security.h b/include/linux/security.h
82293index 2fc42d1..4d802f2 100644
82294--- a/include/linux/security.h
82295+++ b/include/linux/security.h
82296@@ -27,6 +27,7 @@
82297 #include <linux/slab.h>
82298 #include <linux/err.h>
82299 #include <linux/string.h>
82300+#include <linux/grsecurity.h>
82301
82302 struct linux_binprm;
82303 struct cred;
82304@@ -116,8 +117,6 @@ struct seq_file;
82305
82306 extern int cap_netlink_send(struct sock *sk, struct sk_buff *skb);
82307
82308-void reset_security_ops(void);
82309-
82310 #ifdef CONFIG_MMU
82311 extern unsigned long mmap_min_addr;
82312 extern unsigned long dac_mmap_min_addr;
82313@@ -1719,7 +1718,7 @@ struct security_operations {
82314 struct audit_context *actx);
82315 void (*audit_rule_free) (void *lsmrule);
82316 #endif /* CONFIG_AUDIT */
82317-};
82318+} __randomize_layout;
82319
82320 /* prototypes */
82321 extern int security_init(void);
82322diff --git a/include/linux/semaphore.h b/include/linux/semaphore.h
82323index dc368b8..e895209 100644
82324--- a/include/linux/semaphore.h
82325+++ b/include/linux/semaphore.h
82326@@ -37,7 +37,7 @@ static inline void sema_init(struct semaphore *sem, int val)
82327 }
82328
82329 extern void down(struct semaphore *sem);
82330-extern int __must_check down_interruptible(struct semaphore *sem);
82331+extern int __must_check down_interruptible(struct semaphore *sem) __intentional_overflow(-1);
82332 extern int __must_check down_killable(struct semaphore *sem);
82333 extern int __must_check down_trylock(struct semaphore *sem);
82334 extern int __must_check down_timeout(struct semaphore *sem, long jiffies);
82335diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h
82336index 52e0097..383f21d 100644
82337--- a/include/linux/seq_file.h
82338+++ b/include/linux/seq_file.h
82339@@ -27,6 +27,9 @@ struct seq_file {
82340 struct mutex lock;
82341 const struct seq_operations *op;
82342 int poll_event;
82343+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
82344+ u64 exec_id;
82345+#endif
82346 #ifdef CONFIG_USER_NS
82347 struct user_namespace *user_ns;
82348 #endif
82349@@ -39,6 +42,7 @@ struct seq_operations {
82350 void * (*next) (struct seq_file *m, void *v, loff_t *pos);
82351 int (*show) (struct seq_file *m, void *v);
82352 };
82353+typedef struct seq_operations __no_const seq_operations_no_const;
82354
82355 #define SEQ_SKIP 1
82356
82357@@ -96,6 +100,7 @@ void seq_pad(struct seq_file *m, char c);
82358
82359 char *mangle_path(char *s, const char *p, const char *esc);
82360 int seq_open(struct file *, const struct seq_operations *);
82361+int seq_open_restrict(struct file *, const struct seq_operations *);
82362 ssize_t seq_read(struct file *, char __user *, size_t, loff_t *);
82363 loff_t seq_lseek(struct file *, loff_t, int);
82364 int seq_release(struct inode *, struct file *);
82365@@ -138,6 +143,7 @@ static inline int seq_nodemask_list(struct seq_file *m, nodemask_t *mask)
82366 }
82367
82368 int single_open(struct file *, int (*)(struct seq_file *, void *), void *);
82369+int single_open_restrict(struct file *, int (*)(struct seq_file *, void *), void *);
82370 int single_open_size(struct file *, int (*)(struct seq_file *, void *), void *, size_t);
82371 int single_release(struct inode *, struct file *);
82372 void *__seq_open_private(struct file *, const struct seq_operations *, int);
82373diff --git a/include/linux/shm.h b/include/linux/shm.h
82374index 1e2cd2e..0288750 100644
82375--- a/include/linux/shm.h
82376+++ b/include/linux/shm.h
82377@@ -21,6 +21,10 @@ struct shmid_kernel /* private to the kernel */
82378
82379 /* The task created the shm object. NULL if the task is dead. */
82380 struct task_struct *shm_creator;
82381+#ifdef CONFIG_GRKERNSEC
82382+ time_t shm_createtime;
82383+ pid_t shm_lapid;
82384+#endif
82385 };
82386
82387 /* shm_mode upper byte flags */
82388diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
82389index 15ede6a..80161c3 100644
82390--- a/include/linux/skbuff.h
82391+++ b/include/linux/skbuff.h
82392@@ -662,7 +662,7 @@ bool skb_try_coalesce(struct sk_buff *to, struct sk_buff *from,
82393 struct sk_buff *__alloc_skb(unsigned int size, gfp_t priority, int flags,
82394 int node);
82395 struct sk_buff *build_skb(void *data, unsigned int frag_size);
82396-static inline struct sk_buff *alloc_skb(unsigned int size,
82397+static inline struct sk_buff * __intentional_overflow(0) alloc_skb(unsigned int size,
82398 gfp_t priority)
82399 {
82400 return __alloc_skb(size, priority, 0, NUMA_NO_NODE);
82401@@ -1768,7 +1768,7 @@ static inline u32 skb_inner_network_header_len(const struct sk_buff *skb)
82402 return skb->inner_transport_header - skb->inner_network_header;
82403 }
82404
82405-static inline int skb_network_offset(const struct sk_buff *skb)
82406+static inline int __intentional_overflow(0) skb_network_offset(const struct sk_buff *skb)
82407 {
82408 return skb_network_header(skb) - skb->data;
82409 }
82410@@ -1828,7 +1828,7 @@ static inline int pskb_network_may_pull(struct sk_buff *skb, unsigned int len)
82411 * NET_IP_ALIGN(2) + ethernet_header(14) + IP_header(20/40) + ports(8)
82412 */
82413 #ifndef NET_SKB_PAD
82414-#define NET_SKB_PAD max(32, L1_CACHE_BYTES)
82415+#define NET_SKB_PAD max(_AC(32,UL), L1_CACHE_BYTES)
82416 #endif
82417
82418 int ___pskb_trim(struct sk_buff *skb, unsigned int len);
82419@@ -2427,7 +2427,7 @@ struct sk_buff *skb_recv_datagram(struct sock *sk, unsigned flags, int noblock,
82420 int *err);
82421 unsigned int datagram_poll(struct file *file, struct socket *sock,
82422 struct poll_table_struct *wait);
82423-int skb_copy_datagram_iovec(const struct sk_buff *from, int offset,
82424+int __intentional_overflow(0) skb_copy_datagram_iovec(const struct sk_buff *from, int offset,
82425 struct iovec *to, int size);
82426 int skb_copy_and_csum_datagram_iovec(struct sk_buff *skb, int hlen,
82427 struct iovec *iov);
82428@@ -2721,6 +2721,9 @@ static inline void nf_reset(struct sk_buff *skb)
82429 nf_bridge_put(skb->nf_bridge);
82430 skb->nf_bridge = NULL;
82431 #endif
82432+#if IS_ENABLED(CONFIG_NETFILTER_XT_TARGET_TRACE)
82433+ skb->nf_trace = 0;
82434+#endif
82435 }
82436
82437 static inline void nf_reset_trace(struct sk_buff *skb)
82438diff --git a/include/linux/slab.h b/include/linux/slab.h
82439index b5b2df6..69f5734 100644
82440--- a/include/linux/slab.h
82441+++ b/include/linux/slab.h
82442@@ -14,15 +14,29 @@
82443 #include <linux/gfp.h>
82444 #include <linux/types.h>
82445 #include <linux/workqueue.h>
82446-
82447+#include <linux/err.h>
82448
82449 /*
82450 * Flags to pass to kmem_cache_create().
82451 * The ones marked DEBUG are only valid if CONFIG_SLAB_DEBUG is set.
82452 */
82453 #define SLAB_DEBUG_FREE 0x00000100UL /* DEBUG: Perform (expensive) checks on free */
82454+
82455+#ifdef CONFIG_PAX_USERCOPY_SLABS
82456+#define SLAB_USERCOPY 0x00000200UL /* PaX: Allow copying objs to/from userland */
82457+#else
82458+#define SLAB_USERCOPY 0x00000000UL
82459+#endif
82460+
82461 #define SLAB_RED_ZONE 0x00000400UL /* DEBUG: Red zone objs in a cache */
82462 #define SLAB_POISON 0x00000800UL /* DEBUG: Poison objects */
82463+
82464+#ifdef CONFIG_PAX_MEMORY_SANITIZE
82465+#define SLAB_NO_SANITIZE 0x00001000UL /* PaX: Do not sanitize objs on free */
82466+#else
82467+#define SLAB_NO_SANITIZE 0x00000000UL
82468+#endif
82469+
82470 #define SLAB_HWCACHE_ALIGN 0x00002000UL /* Align objs on cache lines */
82471 #define SLAB_CACHE_DMA 0x00004000UL /* Use GFP_DMA memory */
82472 #define SLAB_STORE_USER 0x00010000UL /* DEBUG: Store the last owner for bug hunting */
82473@@ -98,10 +112,13 @@
82474 * ZERO_SIZE_PTR can be passed to kfree though in the same way that NULL can.
82475 * Both make kfree a no-op.
82476 */
82477-#define ZERO_SIZE_PTR ((void *)16)
82478+#define ZERO_SIZE_PTR \
82479+({ \
82480+ BUILD_BUG_ON(!(MAX_ERRNO & ~PAGE_MASK));\
82481+ (void *)(-MAX_ERRNO-1L); \
82482+})
82483
82484-#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) <= \
82485- (unsigned long)ZERO_SIZE_PTR)
82486+#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) - 1 >= (unsigned long)ZERO_SIZE_PTR - 1)
82487
82488 #include <linux/kmemleak.h>
82489
82490@@ -142,6 +159,8 @@ void * __must_check krealloc(const void *, size_t, gfp_t);
82491 void kfree(const void *);
82492 void kzfree(const void *);
82493 size_t ksize(const void *);
82494+const char *check_heap_object(const void *ptr, unsigned long n);
82495+bool is_usercopy_object(const void *ptr);
82496
82497 /*
82498 * Some archs want to perform DMA into kmalloc caches and need a guaranteed
82499@@ -174,7 +193,7 @@ struct kmem_cache {
82500 unsigned int align; /* Alignment as calculated */
82501 unsigned long flags; /* Active flags on the slab */
82502 const char *name; /* Slab name for sysfs */
82503- int refcount; /* Use counter */
82504+ atomic_t refcount; /* Use counter */
82505 void (*ctor)(void *); /* Called on object slot creation */
82506 struct list_head list; /* List of all slab caches on the system */
82507 };
82508@@ -248,6 +267,10 @@ extern struct kmem_cache *kmalloc_caches[KMALLOC_SHIFT_HIGH + 1];
82509 extern struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
82510 #endif
82511
82512+#ifdef CONFIG_PAX_USERCOPY_SLABS
82513+extern struct kmem_cache *kmalloc_usercopy_caches[KMALLOC_SHIFT_HIGH + 1];
82514+#endif
82515+
82516 /*
82517 * Figure out which kmalloc slab an allocation of a certain size
82518 * belongs to.
82519@@ -256,7 +279,7 @@ extern struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
82520 * 2 = 120 .. 192 bytes
82521 * n = 2^(n-1) .. 2^n -1
82522 */
82523-static __always_inline int kmalloc_index(size_t size)
82524+static __always_inline __size_overflow(1) int kmalloc_index(size_t size)
82525 {
82526 if (!size)
82527 return 0;
82528@@ -299,11 +322,11 @@ static __always_inline int kmalloc_index(size_t size)
82529 }
82530 #endif /* !CONFIG_SLOB */
82531
82532-void *__kmalloc(size_t size, gfp_t flags);
82533+void *__kmalloc(size_t size, gfp_t flags) __alloc_size(1);
82534 void *kmem_cache_alloc(struct kmem_cache *, gfp_t flags);
82535
82536 #ifdef CONFIG_NUMA
82537-void *__kmalloc_node(size_t size, gfp_t flags, int node);
82538+void *__kmalloc_node(size_t size, gfp_t flags, int node) __alloc_size(1);
82539 void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
82540 #else
82541 static __always_inline void *__kmalloc_node(size_t size, gfp_t flags, int node)
82542diff --git a/include/linux/slab_def.h b/include/linux/slab_def.h
82543index 8235dfb..47ce586 100644
82544--- a/include/linux/slab_def.h
82545+++ b/include/linux/slab_def.h
82546@@ -38,7 +38,7 @@ struct kmem_cache {
82547 /* 4) cache creation/removal */
82548 const char *name;
82549 struct list_head list;
82550- int refcount;
82551+ atomic_t refcount;
82552 int object_size;
82553 int align;
82554
82555@@ -54,10 +54,14 @@ struct kmem_cache {
82556 unsigned long node_allocs;
82557 unsigned long node_frees;
82558 unsigned long node_overflow;
82559- atomic_t allochit;
82560- atomic_t allocmiss;
82561- atomic_t freehit;
82562- atomic_t freemiss;
82563+ atomic_unchecked_t allochit;
82564+ atomic_unchecked_t allocmiss;
82565+ atomic_unchecked_t freehit;
82566+ atomic_unchecked_t freemiss;
82567+#ifdef CONFIG_PAX_MEMORY_SANITIZE
82568+ atomic_unchecked_t sanitized;
82569+ atomic_unchecked_t not_sanitized;
82570+#endif
82571
82572 /*
82573 * If debugging is enabled, then the allocator can add additional
82574diff --git a/include/linux/slub_def.h b/include/linux/slub_def.h
82575index f56bfa9..8378a26 100644
82576--- a/include/linux/slub_def.h
82577+++ b/include/linux/slub_def.h
82578@@ -74,7 +74,7 @@ struct kmem_cache {
82579 struct kmem_cache_order_objects max;
82580 struct kmem_cache_order_objects min;
82581 gfp_t allocflags; /* gfp flags to use on each alloc */
82582- int refcount; /* Refcount for slab cache destroy */
82583+ atomic_t refcount; /* Refcount for slab cache destroy */
82584 void (*ctor)(void *);
82585 int inuse; /* Offset to metadata */
82586 int align; /* Alignment */
82587diff --git a/include/linux/smp.h b/include/linux/smp.h
82588index 6ae004e..2743532 100644
82589--- a/include/linux/smp.h
82590+++ b/include/linux/smp.h
82591@@ -180,7 +180,9 @@ static inline void kick_all_cpus_sync(void) { }
82592 #endif
82593
82594 #define get_cpu() ({ preempt_disable(); smp_processor_id(); })
82595+#define raw_get_cpu() ({ raw_preempt_disable(); raw_smp_processor_id(); })
82596 #define put_cpu() preempt_enable()
82597+#define raw_put_cpu_no_resched() raw_preempt_enable_no_resched()
82598
82599 /*
82600 * Callback to arch code if there's nosmp or maxcpus=0 on the
82601diff --git a/include/linux/sock_diag.h b/include/linux/sock_diag.h
82602index 54f91d3..be2c379 100644
82603--- a/include/linux/sock_diag.h
82604+++ b/include/linux/sock_diag.h
82605@@ -11,7 +11,7 @@ struct sock;
82606 struct sock_diag_handler {
82607 __u8 family;
82608 int (*dump)(struct sk_buff *skb, struct nlmsghdr *nlh);
82609-};
82610+} __do_const;
82611
82612 int sock_diag_register(const struct sock_diag_handler *h);
82613 void sock_diag_unregister(const struct sock_diag_handler *h);
82614diff --git a/include/linux/sonet.h b/include/linux/sonet.h
82615index 680f9a3..f13aeb0 100644
82616--- a/include/linux/sonet.h
82617+++ b/include/linux/sonet.h
82618@@ -7,7 +7,7 @@
82619 #include <uapi/linux/sonet.h>
82620
82621 struct k_sonet_stats {
82622-#define __HANDLE_ITEM(i) atomic_t i
82623+#define __HANDLE_ITEM(i) atomic_unchecked_t i
82624 __SONET_ITEMS
82625 #undef __HANDLE_ITEM
82626 };
82627diff --git a/include/linux/sunrpc/addr.h b/include/linux/sunrpc/addr.h
82628index 07d8e53..dc934c9 100644
82629--- a/include/linux/sunrpc/addr.h
82630+++ b/include/linux/sunrpc/addr.h
82631@@ -23,9 +23,9 @@ static inline unsigned short rpc_get_port(const struct sockaddr *sap)
82632 {
82633 switch (sap->sa_family) {
82634 case AF_INET:
82635- return ntohs(((struct sockaddr_in *)sap)->sin_port);
82636+ return ntohs(((const struct sockaddr_in *)sap)->sin_port);
82637 case AF_INET6:
82638- return ntohs(((struct sockaddr_in6 *)sap)->sin6_port);
82639+ return ntohs(((const struct sockaddr_in6 *)sap)->sin6_port);
82640 }
82641 return 0;
82642 }
82643@@ -58,7 +58,7 @@ static inline bool __rpc_cmp_addr4(const struct sockaddr *sap1,
82644 static inline bool __rpc_copy_addr4(struct sockaddr *dst,
82645 const struct sockaddr *src)
82646 {
82647- const struct sockaddr_in *ssin = (struct sockaddr_in *) src;
82648+ const struct sockaddr_in *ssin = (const struct sockaddr_in *) src;
82649 struct sockaddr_in *dsin = (struct sockaddr_in *) dst;
82650
82651 dsin->sin_family = ssin->sin_family;
82652@@ -164,7 +164,7 @@ static inline u32 rpc_get_scope_id(const struct sockaddr *sa)
82653 if (sa->sa_family != AF_INET6)
82654 return 0;
82655
82656- return ((struct sockaddr_in6 *) sa)->sin6_scope_id;
82657+ return ((const struct sockaddr_in6 *) sa)->sin6_scope_id;
82658 }
82659
82660 #endif /* _LINUX_SUNRPC_ADDR_H */
82661diff --git a/include/linux/sunrpc/clnt.h b/include/linux/sunrpc/clnt.h
82662index 8af2804..c7414ef 100644
82663--- a/include/linux/sunrpc/clnt.h
82664+++ b/include/linux/sunrpc/clnt.h
82665@@ -97,7 +97,7 @@ struct rpc_procinfo {
82666 unsigned int p_timer; /* Which RTT timer to use */
82667 u32 p_statidx; /* Which procedure to account */
82668 const char * p_name; /* name of procedure */
82669-};
82670+} __do_const;
82671
82672 #ifdef __KERNEL__
82673
82674diff --git a/include/linux/sunrpc/svc.h b/include/linux/sunrpc/svc.h
82675index 04e7632..2e2a8a3 100644
82676--- a/include/linux/sunrpc/svc.h
82677+++ b/include/linux/sunrpc/svc.h
82678@@ -412,7 +412,7 @@ struct svc_procedure {
82679 unsigned int pc_count; /* call count */
82680 unsigned int pc_cachetype; /* cache info (NFS) */
82681 unsigned int pc_xdrressize; /* maximum size of XDR reply */
82682-};
82683+} __do_const;
82684
82685 /*
82686 * Function prototypes.
82687diff --git a/include/linux/sunrpc/svc_rdma.h b/include/linux/sunrpc/svc_rdma.h
82688index 0b8e3e6..33e0a01 100644
82689--- a/include/linux/sunrpc/svc_rdma.h
82690+++ b/include/linux/sunrpc/svc_rdma.h
82691@@ -53,15 +53,15 @@ extern unsigned int svcrdma_ord;
82692 extern unsigned int svcrdma_max_requests;
82693 extern unsigned int svcrdma_max_req_size;
82694
82695-extern atomic_t rdma_stat_recv;
82696-extern atomic_t rdma_stat_read;
82697-extern atomic_t rdma_stat_write;
82698-extern atomic_t rdma_stat_sq_starve;
82699-extern atomic_t rdma_stat_rq_starve;
82700-extern atomic_t rdma_stat_rq_poll;
82701-extern atomic_t rdma_stat_rq_prod;
82702-extern atomic_t rdma_stat_sq_poll;
82703-extern atomic_t rdma_stat_sq_prod;
82704+extern atomic_unchecked_t rdma_stat_recv;
82705+extern atomic_unchecked_t rdma_stat_read;
82706+extern atomic_unchecked_t rdma_stat_write;
82707+extern atomic_unchecked_t rdma_stat_sq_starve;
82708+extern atomic_unchecked_t rdma_stat_rq_starve;
82709+extern atomic_unchecked_t rdma_stat_rq_poll;
82710+extern atomic_unchecked_t rdma_stat_rq_prod;
82711+extern atomic_unchecked_t rdma_stat_sq_poll;
82712+extern atomic_unchecked_t rdma_stat_sq_prod;
82713
82714 #define RPCRDMA_VERSION 1
82715
82716diff --git a/include/linux/sunrpc/svcauth.h b/include/linux/sunrpc/svcauth.h
82717index 8d71d65..f79586e 100644
82718--- a/include/linux/sunrpc/svcauth.h
82719+++ b/include/linux/sunrpc/svcauth.h
82720@@ -120,7 +120,7 @@ struct auth_ops {
82721 int (*release)(struct svc_rqst *rq);
82722 void (*domain_release)(struct auth_domain *);
82723 int (*set_client)(struct svc_rqst *rq);
82724-};
82725+} __do_const;
82726
82727 #define SVC_GARBAGE 1
82728 #define SVC_SYSERR 2
82729diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h
82730index a5ffd32..0935dea 100644
82731--- a/include/linux/swiotlb.h
82732+++ b/include/linux/swiotlb.h
82733@@ -60,7 +60,8 @@ extern void
82734
82735 extern void
82736 swiotlb_free_coherent(struct device *hwdev, size_t size,
82737- void *vaddr, dma_addr_t dma_handle);
82738+ void *vaddr, dma_addr_t dma_handle,
82739+ struct dma_attrs *attrs);
82740
82741 extern dma_addr_t swiotlb_map_page(struct device *dev, struct page *page,
82742 unsigned long offset, size_t size,
82743diff --git a/include/linux/syscalls.h b/include/linux/syscalls.h
82744index a747a77..9e14df7 100644
82745--- a/include/linux/syscalls.h
82746+++ b/include/linux/syscalls.h
82747@@ -98,8 +98,14 @@ struct sigaltstack;
82748 #define __MAP(n,...) __MAP##n(__VA_ARGS__)
82749
82750 #define __SC_DECL(t, a) t a
82751+#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))
82752 #define __TYPE_IS_LL(t) (__same_type((t)0, 0LL) || __same_type((t)0, 0ULL))
82753-#define __SC_LONG(t, a) __typeof(__builtin_choose_expr(__TYPE_IS_LL(t), 0LL, 0L)) a
82754+#define __SC_LONG(t, a) __typeof( \
82755+ __builtin_choose_expr( \
82756+ sizeof(t) > sizeof(int), \
82757+ (t) 0, \
82758+ __builtin_choose_expr(__TYPE_IS_U(t), 0UL, 0L) \
82759+ )) a
82760 #define __SC_CAST(t, a) (t) a
82761 #define __SC_ARGS(t, a) a
82762 #define __SC_TEST(t, a) (void)BUILD_BUG_ON_ZERO(!__TYPE_IS_LL(t) && sizeof(t) > sizeof(long))
82763@@ -371,11 +377,11 @@ asmlinkage long sys_sync(void);
82764 asmlinkage long sys_fsync(unsigned int fd);
82765 asmlinkage long sys_fdatasync(unsigned int fd);
82766 asmlinkage long sys_bdflush(int func, long data);
82767-asmlinkage long sys_mount(char __user *dev_name, char __user *dir_name,
82768- char __user *type, unsigned long flags,
82769+asmlinkage long sys_mount(const char __user *dev_name, const char __user *dir_name,
82770+ const char __user *type, unsigned long flags,
82771 void __user *data);
82772-asmlinkage long sys_umount(char __user *name, int flags);
82773-asmlinkage long sys_oldumount(char __user *name);
82774+asmlinkage long sys_umount(const char __user *name, int flags);
82775+asmlinkage long sys_oldumount(const char __user *name);
82776 asmlinkage long sys_truncate(const char __user *path, long length);
82777 asmlinkage long sys_ftruncate(unsigned int fd, unsigned long length);
82778 asmlinkage long sys_stat(const char __user *filename,
82779@@ -587,7 +593,7 @@ asmlinkage long sys_getsockname(int, struct sockaddr __user *, int __user *);
82780 asmlinkage long sys_getpeername(int, struct sockaddr __user *, int __user *);
82781 asmlinkage long sys_send(int, void __user *, size_t, unsigned);
82782 asmlinkage long sys_sendto(int, void __user *, size_t, unsigned,
82783- struct sockaddr __user *, int);
82784+ struct sockaddr __user *, int) __intentional_overflow(0);
82785 asmlinkage long sys_sendmsg(int fd, struct msghdr __user *msg, unsigned flags);
82786 asmlinkage long sys_sendmmsg(int fd, struct mmsghdr __user *msg,
82787 unsigned int vlen, unsigned flags);
82788diff --git a/include/linux/syscore_ops.h b/include/linux/syscore_ops.h
82789index 27b3b0b..e093dd9 100644
82790--- a/include/linux/syscore_ops.h
82791+++ b/include/linux/syscore_ops.h
82792@@ -16,7 +16,7 @@ struct syscore_ops {
82793 int (*suspend)(void);
82794 void (*resume)(void);
82795 void (*shutdown)(void);
82796-};
82797+} __do_const;
82798
82799 extern void register_syscore_ops(struct syscore_ops *ops);
82800 extern void unregister_syscore_ops(struct syscore_ops *ops);
82801diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
82802index 14a8ff2..fa95f3a 100644
82803--- a/include/linux/sysctl.h
82804+++ b/include/linux/sysctl.h
82805@@ -34,13 +34,13 @@ struct ctl_table_root;
82806 struct ctl_table_header;
82807 struct ctl_dir;
82808
82809-typedef struct ctl_table ctl_table;
82810-
82811 typedef int proc_handler (struct ctl_table *ctl, int write,
82812 void __user *buffer, size_t *lenp, loff_t *ppos);
82813
82814 extern int proc_dostring(struct ctl_table *, int,
82815 void __user *, size_t *, loff_t *);
82816+extern int proc_dostring_modpriv(struct ctl_table *, int,
82817+ void __user *, size_t *, loff_t *);
82818 extern int proc_dointvec(struct ctl_table *, int,
82819 void __user *, size_t *, loff_t *);
82820 extern int proc_dointvec_minmax(struct ctl_table *, int,
82821@@ -115,7 +115,9 @@ struct ctl_table
82822 struct ctl_table_poll *poll;
82823 void *extra1;
82824 void *extra2;
82825-};
82826+} __do_const __randomize_layout;
82827+typedef struct ctl_table __no_const ctl_table_no_const;
82828+typedef struct ctl_table ctl_table;
82829
82830 struct ctl_node {
82831 struct rb_node node;
82832diff --git a/include/linux/sysfs.h b/include/linux/sysfs.h
82833index 30b2ebe..37412ef 100644
82834--- a/include/linux/sysfs.h
82835+++ b/include/linux/sysfs.h
82836@@ -34,7 +34,8 @@ struct attribute {
82837 struct lock_class_key *key;
82838 struct lock_class_key skey;
82839 #endif
82840-};
82841+} __do_const;
82842+typedef struct attribute __no_const attribute_no_const;
82843
82844 /**
82845 * sysfs_attr_init - initialize a dynamically allocated sysfs attribute
82846@@ -63,7 +64,8 @@ struct attribute_group {
82847 struct attribute *, int);
82848 struct attribute **attrs;
82849 struct bin_attribute **bin_attrs;
82850-};
82851+} __do_const;
82852+typedef struct attribute_group __no_const attribute_group_no_const;
82853
82854 /**
82855 * Use these macros to make defining attributes easier. See include/linux/device.h
82856@@ -127,7 +129,8 @@ struct bin_attribute {
82857 char *, loff_t, size_t);
82858 int (*mmap)(struct file *, struct kobject *, struct bin_attribute *attr,
82859 struct vm_area_struct *vma);
82860-};
82861+} __do_const;
82862+typedef struct bin_attribute __no_const bin_attribute_no_const;
82863
82864 /**
82865 * sysfs_bin_attr_init - initialize a dynamically allocated bin_attribute
82866diff --git a/include/linux/sysrq.h b/include/linux/sysrq.h
82867index 387fa7d..3fcde6b 100644
82868--- a/include/linux/sysrq.h
82869+++ b/include/linux/sysrq.h
82870@@ -16,6 +16,7 @@
82871
82872 #include <linux/errno.h>
82873 #include <linux/types.h>
82874+#include <linux/compiler.h>
82875
82876 /* Possible values of bitmask for enabling sysrq functions */
82877 /* 0x0001 is reserved for enable everything */
82878@@ -33,7 +34,7 @@ struct sysrq_key_op {
82879 char *help_msg;
82880 char *action_msg;
82881 int enable_mask;
82882-};
82883+} __do_const;
82884
82885 #ifdef CONFIG_MAGIC_SYSRQ
82886
82887diff --git a/include/linux/thread_info.h b/include/linux/thread_info.h
82888index fddbe20..e4cce53 100644
82889--- a/include/linux/thread_info.h
82890+++ b/include/linux/thread_info.h
82891@@ -161,6 +161,25 @@ static inline bool test_and_clear_restore_sigmask(void)
82892 #error "no set_restore_sigmask() provided and default one won't work"
82893 #endif
82894
82895+extern void __check_object_size(const void *ptr, unsigned long n, bool to_user);
82896+
82897+#if defined(CONFIG_X86) && defined(CONFIG_PAX_USERCOPY)
82898+extern void pax_check_alloca(unsigned long size);
82899+#endif
82900+
82901+static inline void check_object_size(const void *ptr, unsigned long n, bool to_user)
82902+{
82903+#if defined(CONFIG_X86) && defined(CONFIG_PAX_USERCOPY)
82904+ /* always check if we've overflowed the stack in a copy*user */
82905+ pax_check_alloca(sizeof(unsigned long));
82906+#endif
82907+
82908+#ifndef CONFIG_PAX_USERCOPY_DEBUG
82909+ if (!__builtin_constant_p(n))
82910+#endif
82911+ __check_object_size(ptr, n, to_user);
82912+}
82913+
82914 #endif /* __KERNEL__ */
82915
82916 #endif /* _LINUX_THREAD_INFO_H */
82917diff --git a/include/linux/tty.h b/include/linux/tty.h
82918index b90b5c2..e23a512 100644
82919--- a/include/linux/tty.h
82920+++ b/include/linux/tty.h
82921@@ -202,7 +202,7 @@ struct tty_port {
82922 const struct tty_port_operations *ops; /* Port operations */
82923 spinlock_t lock; /* Lock protecting tty field */
82924 int blocked_open; /* Waiting to open */
82925- int count; /* Usage count */
82926+ atomic_t count; /* Usage count */
82927 wait_queue_head_t open_wait; /* Open waiters */
82928 wait_queue_head_t close_wait; /* Close waiters */
82929 wait_queue_head_t delta_msr_wait; /* Modem status change */
82930@@ -284,7 +284,7 @@ struct tty_struct {
82931 /* If the tty has a pending do_SAK, queue it here - akpm */
82932 struct work_struct SAK_work;
82933 struct tty_port *port;
82934-};
82935+} __randomize_layout;
82936
82937 /* Each of a tty's open files has private_data pointing to tty_file_private */
82938 struct tty_file_private {
82939@@ -550,7 +550,7 @@ extern int tty_port_open(struct tty_port *port,
82940 struct tty_struct *tty, struct file *filp);
82941 static inline int tty_port_users(struct tty_port *port)
82942 {
82943- return port->count + port->blocked_open;
82944+ return atomic_read(&port->count) + port->blocked_open;
82945 }
82946
82947 extern int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc);
82948diff --git a/include/linux/tty_driver.h b/include/linux/tty_driver.h
82949index 756a609..89db85e 100644
82950--- a/include/linux/tty_driver.h
82951+++ b/include/linux/tty_driver.h
82952@@ -285,7 +285,7 @@ struct tty_operations {
82953 void (*poll_put_char)(struct tty_driver *driver, int line, char ch);
82954 #endif
82955 const struct file_operations *proc_fops;
82956-};
82957+} __do_const __randomize_layout;
82958
82959 struct tty_driver {
82960 int magic; /* magic number for this structure */
82961@@ -319,7 +319,7 @@ struct tty_driver {
82962
82963 const struct tty_operations *ops;
82964 struct list_head tty_drivers;
82965-};
82966+} __randomize_layout;
82967
82968 extern struct list_head tty_drivers;
82969
82970diff --git a/include/linux/tty_ldisc.h b/include/linux/tty_ldisc.h
82971index b8347c2..85d8b0f 100644
82972--- a/include/linux/tty_ldisc.h
82973+++ b/include/linux/tty_ldisc.h
82974@@ -213,7 +213,7 @@ struct tty_ldisc_ops {
82975
82976 struct module *owner;
82977
82978- int refcount;
82979+ atomic_t refcount;
82980 };
82981
82982 struct tty_ldisc {
82983diff --git a/include/linux/types.h b/include/linux/types.h
82984index 4d118ba..c3ee9bf 100644
82985--- a/include/linux/types.h
82986+++ b/include/linux/types.h
82987@@ -176,10 +176,26 @@ typedef struct {
82988 int counter;
82989 } atomic_t;
82990
82991+#ifdef CONFIG_PAX_REFCOUNT
82992+typedef struct {
82993+ int counter;
82994+} atomic_unchecked_t;
82995+#else
82996+typedef atomic_t atomic_unchecked_t;
82997+#endif
82998+
82999 #ifdef CONFIG_64BIT
83000 typedef struct {
83001 long counter;
83002 } atomic64_t;
83003+
83004+#ifdef CONFIG_PAX_REFCOUNT
83005+typedef struct {
83006+ long counter;
83007+} atomic64_unchecked_t;
83008+#else
83009+typedef atomic64_t atomic64_unchecked_t;
83010+#endif
83011 #endif
83012
83013 struct list_head {
83014diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h
83015index ecd3319..8a36ded 100644
83016--- a/include/linux/uaccess.h
83017+++ b/include/linux/uaccess.h
83018@@ -75,11 +75,11 @@ static inline unsigned long __copy_from_user_nocache(void *to,
83019 long ret; \
83020 mm_segment_t old_fs = get_fs(); \
83021 \
83022- set_fs(KERNEL_DS); \
83023 pagefault_disable(); \
83024- ret = __copy_from_user_inatomic(&(retval), (__force typeof(retval) __user *)(addr), sizeof(retval)); \
83025- pagefault_enable(); \
83026+ set_fs(KERNEL_DS); \
83027+ ret = __copy_from_user_inatomic(&(retval), (typeof(retval) __force_user *)(addr), sizeof(retval)); \
83028 set_fs(old_fs); \
83029+ pagefault_enable(); \
83030 ret; \
83031 })
83032
83033diff --git a/include/linux/uidgid.h b/include/linux/uidgid.h
83034index 2d1f9b6..d7a9fce 100644
83035--- a/include/linux/uidgid.h
83036+++ b/include/linux/uidgid.h
83037@@ -175,4 +175,9 @@ static inline bool kgid_has_mapping(struct user_namespace *ns, kgid_t gid)
83038
83039 #endif /* CONFIG_USER_NS */
83040
83041+#define GR_GLOBAL_UID(x) from_kuid_munged(&init_user_ns, (x))
83042+#define GR_GLOBAL_GID(x) from_kgid_munged(&init_user_ns, (x))
83043+#define gr_is_global_root(x) uid_eq((x), GLOBAL_ROOT_UID)
83044+#define gr_is_global_nonroot(x) (!uid_eq((x), GLOBAL_ROOT_UID))
83045+
83046 #endif /* _LINUX_UIDGID_H */
83047diff --git a/include/linux/unaligned/access_ok.h b/include/linux/unaligned/access_ok.h
83048index 99c1b4d..562e6f3 100644
83049--- a/include/linux/unaligned/access_ok.h
83050+++ b/include/linux/unaligned/access_ok.h
83051@@ -4,34 +4,34 @@
83052 #include <linux/kernel.h>
83053 #include <asm/byteorder.h>
83054
83055-static inline u16 get_unaligned_le16(const void *p)
83056+static inline u16 __intentional_overflow(-1) get_unaligned_le16(const void *p)
83057 {
83058- return le16_to_cpup((__le16 *)p);
83059+ return le16_to_cpup((const __le16 *)p);
83060 }
83061
83062-static inline u32 get_unaligned_le32(const void *p)
83063+static inline u32 __intentional_overflow(-1) get_unaligned_le32(const void *p)
83064 {
83065- return le32_to_cpup((__le32 *)p);
83066+ return le32_to_cpup((const __le32 *)p);
83067 }
83068
83069-static inline u64 get_unaligned_le64(const void *p)
83070+static inline u64 __intentional_overflow(-1) get_unaligned_le64(const void *p)
83071 {
83072- return le64_to_cpup((__le64 *)p);
83073+ return le64_to_cpup((const __le64 *)p);
83074 }
83075
83076-static inline u16 get_unaligned_be16(const void *p)
83077+static inline u16 __intentional_overflow(-1) get_unaligned_be16(const void *p)
83078 {
83079- return be16_to_cpup((__be16 *)p);
83080+ return be16_to_cpup((const __be16 *)p);
83081 }
83082
83083-static inline u32 get_unaligned_be32(const void *p)
83084+static inline u32 __intentional_overflow(-1) get_unaligned_be32(const void *p)
83085 {
83086- return be32_to_cpup((__be32 *)p);
83087+ return be32_to_cpup((const __be32 *)p);
83088 }
83089
83090-static inline u64 get_unaligned_be64(const void *p)
83091+static inline u64 __intentional_overflow(-1) get_unaligned_be64(const void *p)
83092 {
83093- return be64_to_cpup((__be64 *)p);
83094+ return be64_to_cpup((const __be64 *)p);
83095 }
83096
83097 static inline void put_unaligned_le16(u16 val, void *p)
83098diff --git a/include/linux/usb.h b/include/linux/usb.h
83099index 7f6eb85..656e806 100644
83100--- a/include/linux/usb.h
83101+++ b/include/linux/usb.h
83102@@ -563,7 +563,7 @@ struct usb_device {
83103 int maxchild;
83104
83105 u32 quirks;
83106- atomic_t urbnum;
83107+ atomic_unchecked_t urbnum;
83108
83109 unsigned long active_duration;
83110
83111@@ -1642,7 +1642,7 @@ void usb_buffer_unmap_sg(const struct usb_device *dev, int is_in,
83112
83113 extern int usb_control_msg(struct usb_device *dev, unsigned int pipe,
83114 __u8 request, __u8 requesttype, __u16 value, __u16 index,
83115- void *data, __u16 size, int timeout);
83116+ void *data, __u16 size, int timeout) __intentional_overflow(-1);
83117 extern int usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
83118 void *data, int len, int *actual_length, int timeout);
83119 extern int usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
83120diff --git a/include/linux/usb/renesas_usbhs.h b/include/linux/usb/renesas_usbhs.h
83121index e452ba6..78f8e80 100644
83122--- a/include/linux/usb/renesas_usbhs.h
83123+++ b/include/linux/usb/renesas_usbhs.h
83124@@ -39,7 +39,7 @@ enum {
83125 */
83126 struct renesas_usbhs_driver_callback {
83127 int (*notify_hotplug)(struct platform_device *pdev);
83128-};
83129+} __no_const;
83130
83131 /*
83132 * callback functions for platform
83133diff --git a/include/linux/user_namespace.h b/include/linux/user_namespace.h
83134index 4836ba3..603f6ee 100644
83135--- a/include/linux/user_namespace.h
83136+++ b/include/linux/user_namespace.h
83137@@ -33,7 +33,7 @@ struct user_namespace {
83138 struct key *persistent_keyring_register;
83139 struct rw_semaphore persistent_keyring_register_sem;
83140 #endif
83141-};
83142+} __randomize_layout;
83143
83144 extern struct user_namespace init_user_ns;
83145
83146diff --git a/include/linux/utsname.h b/include/linux/utsname.h
83147index 239e277..22a5cf5 100644
83148--- a/include/linux/utsname.h
83149+++ b/include/linux/utsname.h
83150@@ -24,7 +24,7 @@ struct uts_namespace {
83151 struct new_utsname name;
83152 struct user_namespace *user_ns;
83153 unsigned int proc_inum;
83154-};
83155+} __randomize_layout;
83156 extern struct uts_namespace init_uts_ns;
83157
83158 #ifdef CONFIG_UTS_NS
83159diff --git a/include/linux/vermagic.h b/include/linux/vermagic.h
83160index 6f8fbcf..4efc177 100644
83161--- a/include/linux/vermagic.h
83162+++ b/include/linux/vermagic.h
83163@@ -25,9 +25,42 @@
83164 #define MODULE_ARCH_VERMAGIC ""
83165 #endif
83166
83167+#ifdef CONFIG_PAX_REFCOUNT
83168+#define MODULE_PAX_REFCOUNT "REFCOUNT "
83169+#else
83170+#define MODULE_PAX_REFCOUNT ""
83171+#endif
83172+
83173+#ifdef CONSTIFY_PLUGIN
83174+#define MODULE_CONSTIFY_PLUGIN "CONSTIFY_PLUGIN "
83175+#else
83176+#define MODULE_CONSTIFY_PLUGIN ""
83177+#endif
83178+
83179+#ifdef STACKLEAK_PLUGIN
83180+#define MODULE_STACKLEAK_PLUGIN "STACKLEAK_PLUGIN "
83181+#else
83182+#define MODULE_STACKLEAK_PLUGIN ""
83183+#endif
83184+
83185+#ifdef RANDSTRUCT_PLUGIN
83186+#include <generated/randomize_layout_hash.h>
83187+#define MODULE_RANDSTRUCT_PLUGIN "RANDSTRUCT_PLUGIN_" RANDSTRUCT_HASHED_SEED
83188+#else
83189+#define MODULE_RANDSTRUCT_PLUGIN
83190+#endif
83191+
83192+#ifdef CONFIG_GRKERNSEC
83193+#define MODULE_GRSEC "GRSEC "
83194+#else
83195+#define MODULE_GRSEC ""
83196+#endif
83197+
83198 #define VERMAGIC_STRING \
83199 UTS_RELEASE " " \
83200 MODULE_VERMAGIC_SMP MODULE_VERMAGIC_PREEMPT \
83201 MODULE_VERMAGIC_MODULE_UNLOAD MODULE_VERMAGIC_MODVERSIONS \
83202- MODULE_ARCH_VERMAGIC
83203+ MODULE_ARCH_VERMAGIC \
83204+ MODULE_PAX_REFCOUNT MODULE_CONSTIFY_PLUGIN MODULE_STACKLEAK_PLUGIN \
83205+ MODULE_GRSEC MODULE_RANDSTRUCT_PLUGIN
83206
83207diff --git a/include/linux/vga_switcheroo.h b/include/linux/vga_switcheroo.h
83208index 502073a..a7de024 100644
83209--- a/include/linux/vga_switcheroo.h
83210+++ b/include/linux/vga_switcheroo.h
83211@@ -63,8 +63,8 @@ int vga_switcheroo_get_client_state(struct pci_dev *dev);
83212
83213 void vga_switcheroo_set_dynamic_switch(struct pci_dev *pdev, enum vga_switcheroo_state dynamic);
83214
83215-int vga_switcheroo_init_domain_pm_ops(struct device *dev, struct dev_pm_domain *domain);
83216-int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, struct dev_pm_domain *domain);
83217+int vga_switcheroo_init_domain_pm_ops(struct device *dev, dev_pm_domain_no_const *domain);
83218+int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, dev_pm_domain_no_const *domain);
83219 #else
83220
83221 static inline void vga_switcheroo_unregister_client(struct pci_dev *dev) {}
83222@@ -81,8 +81,8 @@ static inline int vga_switcheroo_get_client_state(struct pci_dev *dev) { return
83223
83224 static inline void vga_switcheroo_set_dynamic_switch(struct pci_dev *pdev, enum vga_switcheroo_state dynamic) {}
83225
83226-static inline int vga_switcheroo_init_domain_pm_ops(struct device *dev, struct dev_pm_domain *domain) { return -EINVAL; }
83227-static inline int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, struct dev_pm_domain *domain) { return -EINVAL; }
83228+static inline int vga_switcheroo_init_domain_pm_ops(struct device *dev, dev_pm_domain_no_const *domain) { return -EINVAL; }
83229+static inline int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, dev_pm_domain_no_const *domain) { return -EINVAL; }
83230
83231 #endif
83232 #endif /* _LINUX_VGA_SWITCHEROO_H_ */
83233diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
83234index 4b8a891..cb8df6e 100644
83235--- a/include/linux/vmalloc.h
83236+++ b/include/linux/vmalloc.h
83237@@ -16,6 +16,11 @@ struct vm_area_struct; /* vma defining user mapping in mm_types.h */
83238 #define VM_USERMAP 0x00000008 /* suitable for remap_vmalloc_range */
83239 #define VM_VPAGES 0x00000010 /* buffer for pages was vmalloc'ed */
83240 #define VM_UNINITIALIZED 0x00000020 /* vm_struct is not fully initialized */
83241+
83242+#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
83243+#define VM_KERNEXEC 0x00000040 /* allocate from executable kernel memory range */
83244+#endif
83245+
83246 /* bits [20..32] reserved for arch specific ioremap internals */
83247
83248 /*
83249@@ -142,7 +147,7 @@ extern void free_vm_area(struct vm_struct *area);
83250
83251 /* for /dev/kmem */
83252 extern long vread(char *buf, char *addr, unsigned long count);
83253-extern long vwrite(char *buf, char *addr, unsigned long count);
83254+extern long vwrite(char *buf, char *addr, unsigned long count) __size_overflow(3);
83255
83256 /*
83257 * Internals. Dont't use..
83258diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h
83259index 67ce70c..d540954 100644
83260--- a/include/linux/vmstat.h
83261+++ b/include/linux/vmstat.h
83262@@ -98,18 +98,18 @@ static inline void vm_events_fold_cpu(int cpu)
83263 /*
83264 * Zone based page accounting with per cpu differentials.
83265 */
83266-extern atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
83267+extern atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
83268
83269 static inline void zone_page_state_add(long x, struct zone *zone,
83270 enum zone_stat_item item)
83271 {
83272- atomic_long_add(x, &zone->vm_stat[item]);
83273- atomic_long_add(x, &vm_stat[item]);
83274+ atomic_long_add_unchecked(x, &zone->vm_stat[item]);
83275+ atomic_long_add_unchecked(x, &vm_stat[item]);
83276 }
83277
83278-static inline unsigned long global_page_state(enum zone_stat_item item)
83279+static inline unsigned long __intentional_overflow(-1) global_page_state(enum zone_stat_item item)
83280 {
83281- long x = atomic_long_read(&vm_stat[item]);
83282+ long x = atomic_long_read_unchecked(&vm_stat[item]);
83283 #ifdef CONFIG_SMP
83284 if (x < 0)
83285 x = 0;
83286@@ -117,10 +117,10 @@ static inline unsigned long global_page_state(enum zone_stat_item item)
83287 return x;
83288 }
83289
83290-static inline unsigned long zone_page_state(struct zone *zone,
83291+static inline unsigned long __intentional_overflow(-1) zone_page_state(struct zone *zone,
83292 enum zone_stat_item item)
83293 {
83294- long x = atomic_long_read(&zone->vm_stat[item]);
83295+ long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
83296 #ifdef CONFIG_SMP
83297 if (x < 0)
83298 x = 0;
83299@@ -137,7 +137,7 @@ static inline unsigned long zone_page_state(struct zone *zone,
83300 static inline unsigned long zone_page_state_snapshot(struct zone *zone,
83301 enum zone_stat_item item)
83302 {
83303- long x = atomic_long_read(&zone->vm_stat[item]);
83304+ long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
83305
83306 #ifdef CONFIG_SMP
83307 int cpu;
83308@@ -226,8 +226,8 @@ static inline void __mod_zone_page_state(struct zone *zone,
83309
83310 static inline void __inc_zone_state(struct zone *zone, enum zone_stat_item item)
83311 {
83312- atomic_long_inc(&zone->vm_stat[item]);
83313- atomic_long_inc(&vm_stat[item]);
83314+ atomic_long_inc_unchecked(&zone->vm_stat[item]);
83315+ atomic_long_inc_unchecked(&vm_stat[item]);
83316 }
83317
83318 static inline void __inc_zone_page_state(struct page *page,
83319@@ -238,8 +238,8 @@ static inline void __inc_zone_page_state(struct page *page,
83320
83321 static inline void __dec_zone_state(struct zone *zone, enum zone_stat_item item)
83322 {
83323- atomic_long_dec(&zone->vm_stat[item]);
83324- atomic_long_dec(&vm_stat[item]);
83325+ atomic_long_dec_unchecked(&zone->vm_stat[item]);
83326+ atomic_long_dec_unchecked(&vm_stat[item]);
83327 }
83328
83329 static inline void __dec_zone_page_state(struct page *page,
83330diff --git a/include/linux/xattr.h b/include/linux/xattr.h
83331index 91b0a68..0e9adf6 100644
83332--- a/include/linux/xattr.h
83333+++ b/include/linux/xattr.h
83334@@ -28,7 +28,7 @@ struct xattr_handler {
83335 size_t size, int handler_flags);
83336 int (*set)(struct dentry *dentry, const char *name, const void *buffer,
83337 size_t size, int flags, int handler_flags);
83338-};
83339+} __do_const;
83340
83341 struct xattr {
83342 const char *name;
83343@@ -37,6 +37,9 @@ struct xattr {
83344 };
83345
83346 ssize_t xattr_getsecurity(struct inode *, const char *, void *, size_t);
83347+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
83348+ssize_t pax_getxattr(struct dentry *, void *, size_t);
83349+#endif
83350 ssize_t vfs_getxattr(struct dentry *, const char *, void *, size_t);
83351 ssize_t vfs_listxattr(struct dentry *d, char *list, size_t size);
83352 int __vfs_setxattr_noperm(struct dentry *, const char *, const void *, size_t, int);
83353diff --git a/include/linux/zlib.h b/include/linux/zlib.h
83354index 9c5a6b4..09c9438 100644
83355--- a/include/linux/zlib.h
83356+++ b/include/linux/zlib.h
83357@@ -31,6 +31,7 @@
83358 #define _ZLIB_H
83359
83360 #include <linux/zconf.h>
83361+#include <linux/compiler.h>
83362
83363 /* zlib deflate based on ZLIB_VERSION "1.1.3" */
83364 /* zlib inflate based on ZLIB_VERSION "1.2.3" */
83365@@ -179,7 +180,7 @@ typedef z_stream *z_streamp;
83366
83367 /* basic functions */
83368
83369-extern int zlib_deflate_workspacesize (int windowBits, int memLevel);
83370+extern int zlib_deflate_workspacesize (int windowBits, int memLevel) __intentional_overflow(0);
83371 /*
83372 Returns the number of bytes that needs to be allocated for a per-
83373 stream workspace with the specified parameters. A pointer to this
83374diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
83375index c768c9f..bdcaa5a 100644
83376--- a/include/media/v4l2-dev.h
83377+++ b/include/media/v4l2-dev.h
83378@@ -76,7 +76,7 @@ struct v4l2_file_operations {
83379 int (*mmap) (struct file *, struct vm_area_struct *);
83380 int (*open) (struct file *);
83381 int (*release) (struct file *);
83382-};
83383+} __do_const;
83384
83385 /*
83386 * Newer version of video_device, handled by videodev2.c
83387diff --git a/include/media/v4l2-device.h b/include/media/v4l2-device.h
83388index c9b1593..a572459 100644
83389--- a/include/media/v4l2-device.h
83390+++ b/include/media/v4l2-device.h
83391@@ -95,7 +95,7 @@ int __must_check v4l2_device_register(struct device *dev, struct v4l2_device *v4
83392 this function returns 0. If the name ends with a digit (e.g. cx18),
83393 then the name will be set to cx18-0 since cx180 looks really odd. */
83394 int v4l2_device_set_name(struct v4l2_device *v4l2_dev, const char *basename,
83395- atomic_t *instance);
83396+ atomic_unchecked_t *instance);
83397
83398 /* Set v4l2_dev->dev to NULL. Call when the USB parent disconnects.
83399 Since the parent disappears this ensures that v4l2_dev doesn't have an
83400diff --git a/include/net/9p/transport.h b/include/net/9p/transport.h
83401index 9a36d92..0aafe2a 100644
83402--- a/include/net/9p/transport.h
83403+++ b/include/net/9p/transport.h
83404@@ -60,7 +60,7 @@ struct p9_trans_module {
83405 int (*cancel) (struct p9_client *, struct p9_req_t *req);
83406 int (*zc_request)(struct p9_client *, struct p9_req_t *,
83407 char *, char *, int , int, int, int);
83408-};
83409+} __do_const;
83410
83411 void v9fs_register_trans(struct p9_trans_module *m);
83412 void v9fs_unregister_trans(struct p9_trans_module *m);
83413diff --git a/include/net/af_unix.h b/include/net/af_unix.h
83414index a175ba4..196eb82 100644
83415--- a/include/net/af_unix.h
83416+++ b/include/net/af_unix.h
83417@@ -36,7 +36,7 @@ struct unix_skb_parms {
83418 u32 secid; /* Security ID */
83419 #endif
83420 u32 consumed;
83421-};
83422+} __randomize_layout;
83423
83424 #define UNIXCB(skb) (*(struct unix_skb_parms *)&((skb)->cb))
83425 #define UNIXSID(skb) (&UNIXCB((skb)).secid)
83426diff --git a/include/net/bluetooth/l2cap.h b/include/net/bluetooth/l2cap.h
83427index dbc4a89..4a59b5d 100644
83428--- a/include/net/bluetooth/l2cap.h
83429+++ b/include/net/bluetooth/l2cap.h
83430@@ -600,7 +600,7 @@ struct l2cap_ops {
83431 long (*get_sndtimeo) (struct l2cap_chan *chan);
83432 struct sk_buff *(*alloc_skb) (struct l2cap_chan *chan,
83433 unsigned long len, int nb);
83434-};
83435+} __do_const;
83436
83437 struct l2cap_conn {
83438 struct hci_conn *hcon;
83439diff --git a/include/net/caif/cfctrl.h b/include/net/caif/cfctrl.h
83440index f2ae33d..c457cf0 100644
83441--- a/include/net/caif/cfctrl.h
83442+++ b/include/net/caif/cfctrl.h
83443@@ -52,7 +52,7 @@ struct cfctrl_rsp {
83444 void (*radioset_rsp)(void);
83445 void (*reject_rsp)(struct cflayer *layer, u8 linkid,
83446 struct cflayer *client_layer);
83447-};
83448+} __no_const;
83449
83450 /* Link Setup Parameters for CAIF-Links. */
83451 struct cfctrl_link_param {
83452@@ -101,8 +101,8 @@ struct cfctrl_request_info {
83453 struct cfctrl {
83454 struct cfsrvl serv;
83455 struct cfctrl_rsp res;
83456- atomic_t req_seq_no;
83457- atomic_t rsp_seq_no;
83458+ atomic_unchecked_t req_seq_no;
83459+ atomic_unchecked_t rsp_seq_no;
83460 struct list_head list;
83461 /* Protects from simultaneous access to first_req list */
83462 spinlock_t info_list_lock;
83463diff --git a/include/net/flow.h b/include/net/flow.h
83464index d23e7fa..e188307 100644
83465--- a/include/net/flow.h
83466+++ b/include/net/flow.h
83467@@ -221,6 +221,6 @@ struct flow_cache_object *flow_cache_lookup(struct net *net,
83468
83469 void flow_cache_flush(void);
83470 void flow_cache_flush_deferred(void);
83471-extern atomic_t flow_cache_genid;
83472+extern atomic_unchecked_t flow_cache_genid;
83473
83474 #endif
83475diff --git a/include/net/genetlink.h b/include/net/genetlink.h
83476index 93695f0..766d71c 100644
83477--- a/include/net/genetlink.h
83478+++ b/include/net/genetlink.h
83479@@ -120,7 +120,7 @@ struct genl_ops {
83480 u8 cmd;
83481 u8 internal_flags;
83482 u8 flags;
83483-};
83484+} __do_const;
83485
83486 int __genl_register_family(struct genl_family *family);
83487
83488diff --git a/include/net/gro_cells.h b/include/net/gro_cells.h
83489index 734d9b5..48a9a4b 100644
83490--- a/include/net/gro_cells.h
83491+++ b/include/net/gro_cells.h
83492@@ -29,7 +29,7 @@ static inline void gro_cells_receive(struct gro_cells *gcells, struct sk_buff *s
83493 cell += skb_get_rx_queue(skb) & gcells->gro_cells_mask;
83494
83495 if (skb_queue_len(&cell->napi_skbs) > netdev_max_backlog) {
83496- atomic_long_inc(&dev->rx_dropped);
83497+ atomic_long_inc_unchecked(&dev->rx_dropped);
83498 kfree_skb(skb);
83499 return;
83500 }
83501diff --git a/include/net/inet_connection_sock.h b/include/net/inet_connection_sock.h
83502index c55aeed..b3393f4 100644
83503--- a/include/net/inet_connection_sock.h
83504+++ b/include/net/inet_connection_sock.h
83505@@ -62,7 +62,7 @@ struct inet_connection_sock_af_ops {
83506 void (*addr2sockaddr)(struct sock *sk, struct sockaddr *);
83507 int (*bind_conflict)(const struct sock *sk,
83508 const struct inet_bind_bucket *tb, bool relax);
83509-};
83510+} __do_const;
83511
83512 /** inet_connection_sock - INET connection oriented sock
83513 *
83514diff --git a/include/net/inetpeer.h b/include/net/inetpeer.h
83515index 6efe73c..fa94270 100644
83516--- a/include/net/inetpeer.h
83517+++ b/include/net/inetpeer.h
83518@@ -47,8 +47,8 @@ struct inet_peer {
83519 */
83520 union {
83521 struct {
83522- atomic_t rid; /* Frag reception counter */
83523- atomic_t ip_id_count; /* IP ID for the next packet */
83524+ atomic_unchecked_t rid; /* Frag reception counter */
83525+ atomic_unchecked_t ip_id_count; /* IP ID for the next packet */
83526 };
83527 struct rcu_head rcu;
83528 struct inet_peer *gc_next;
83529@@ -177,16 +177,13 @@ static inline void inet_peer_refcheck(const struct inet_peer *p)
83530 /* can be called with or without local BH being disabled */
83531 static inline int inet_getid(struct inet_peer *p, int more)
83532 {
83533- int old, new;
83534+ int id;
83535 more++;
83536 inet_peer_refcheck(p);
83537- do {
83538- old = atomic_read(&p->ip_id_count);
83539- new = old + more;
83540- if (!new)
83541- new = 1;
83542- } while (atomic_cmpxchg(&p->ip_id_count, old, new) != old);
83543- return new;
83544+ id = atomic_add_return_unchecked(more, &p->ip_id_count);
83545+ if (!id)
83546+ id = atomic_inc_return_unchecked(&p->ip_id_count);
83547+ return id;
83548 }
83549
83550 #endif /* _NET_INETPEER_H */
83551diff --git a/include/net/ip.h b/include/net/ip.h
83552index 23be0fd..0cb3e2c 100644
83553--- a/include/net/ip.h
83554+++ b/include/net/ip.h
83555@@ -214,7 +214,7 @@ static inline void snmp_mib_free(void __percpu *ptr[SNMP_ARRAY_SZ])
83556
83557 void inet_get_local_port_range(struct net *net, int *low, int *high);
83558
83559-extern unsigned long *sysctl_local_reserved_ports;
83560+extern unsigned long sysctl_local_reserved_ports[65536 / 8 / sizeof(unsigned long)];
83561 static inline int inet_is_reserved_local_port(int port)
83562 {
83563 return test_bit(port, sysctl_local_reserved_ports);
83564diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h
83565index 9922093..a1755d6 100644
83566--- a/include/net/ip_fib.h
83567+++ b/include/net/ip_fib.h
83568@@ -169,7 +169,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh);
83569
83570 #define FIB_RES_SADDR(net, res) \
83571 ((FIB_RES_NH(res).nh_saddr_genid == \
83572- atomic_read(&(net)->ipv4.dev_addr_genid)) ? \
83573+ atomic_read_unchecked(&(net)->ipv4.dev_addr_genid)) ? \
83574 FIB_RES_NH(res).nh_saddr : \
83575 fib_info_update_nh_saddr((net), &FIB_RES_NH(res)))
83576 #define FIB_RES_GW(res) (FIB_RES_NH(res).nh_gw)
83577diff --git a/include/net/ip_vs.h b/include/net/ip_vs.h
83578index 5679d92..2e7a690 100644
83579--- a/include/net/ip_vs.h
83580+++ b/include/net/ip_vs.h
83581@@ -558,7 +558,7 @@ struct ip_vs_conn {
83582 struct ip_vs_conn *control; /* Master control connection */
83583 atomic_t n_control; /* Number of controlled ones */
83584 struct ip_vs_dest *dest; /* real server */
83585- atomic_t in_pkts; /* incoming packet counter */
83586+ atomic_unchecked_t in_pkts; /* incoming packet counter */
83587
83588 /* packet transmitter for different forwarding methods. If it
83589 mangles the packet, it must return NF_DROP or better NF_STOLEN,
83590@@ -705,7 +705,7 @@ struct ip_vs_dest {
83591 __be16 port; /* port number of the server */
83592 union nf_inet_addr addr; /* IP address of the server */
83593 volatile unsigned int flags; /* dest status flags */
83594- atomic_t conn_flags; /* flags to copy to conn */
83595+ atomic_unchecked_t conn_flags; /* flags to copy to conn */
83596 atomic_t weight; /* server weight */
83597
83598 atomic_t refcnt; /* reference counter */
83599@@ -960,11 +960,11 @@ struct netns_ipvs {
83600 /* ip_vs_lblc */
83601 int sysctl_lblc_expiration;
83602 struct ctl_table_header *lblc_ctl_header;
83603- struct ctl_table *lblc_ctl_table;
83604+ ctl_table_no_const *lblc_ctl_table;
83605 /* ip_vs_lblcr */
83606 int sysctl_lblcr_expiration;
83607 struct ctl_table_header *lblcr_ctl_header;
83608- struct ctl_table *lblcr_ctl_table;
83609+ ctl_table_no_const *lblcr_ctl_table;
83610 /* ip_vs_est */
83611 struct list_head est_list; /* estimator list */
83612 spinlock_t est_lock;
83613diff --git a/include/net/irda/ircomm_tty.h b/include/net/irda/ircomm_tty.h
83614index 8d4f588..2e37ad2 100644
83615--- a/include/net/irda/ircomm_tty.h
83616+++ b/include/net/irda/ircomm_tty.h
83617@@ -33,6 +33,7 @@
83618 #include <linux/termios.h>
83619 #include <linux/timer.h>
83620 #include <linux/tty.h> /* struct tty_struct */
83621+#include <asm/local.h>
83622
83623 #include <net/irda/irias_object.h>
83624 #include <net/irda/ircomm_core.h>
83625diff --git a/include/net/iucv/af_iucv.h b/include/net/iucv/af_iucv.h
83626index 714cc9a..ea05f3e 100644
83627--- a/include/net/iucv/af_iucv.h
83628+++ b/include/net/iucv/af_iucv.h
83629@@ -149,7 +149,7 @@ struct iucv_skb_cb {
83630 struct iucv_sock_list {
83631 struct hlist_head head;
83632 rwlock_t lock;
83633- atomic_t autobind_name;
83634+ atomic_unchecked_t autobind_name;
83635 };
83636
83637 unsigned int iucv_sock_poll(struct file *file, struct socket *sock,
83638diff --git a/include/net/llc_c_ac.h b/include/net/llc_c_ac.h
83639index f3be818..bf46196 100644
83640--- a/include/net/llc_c_ac.h
83641+++ b/include/net/llc_c_ac.h
83642@@ -87,7 +87,7 @@
83643 #define LLC_CONN_AC_STOP_SENDACK_TMR 70
83644 #define LLC_CONN_AC_START_SENDACK_TMR_IF_NOT_RUNNING 71
83645
83646-typedef int (*llc_conn_action_t)(struct sock *sk, struct sk_buff *skb);
83647+typedef int (* const llc_conn_action_t)(struct sock *sk, struct sk_buff *skb);
83648
83649 int llc_conn_ac_clear_remote_busy(struct sock *sk, struct sk_buff *skb);
83650 int llc_conn_ac_conn_ind(struct sock *sk, struct sk_buff *skb);
83651diff --git a/include/net/llc_c_ev.h b/include/net/llc_c_ev.h
83652index 3948cf1..83b28c4 100644
83653--- a/include/net/llc_c_ev.h
83654+++ b/include/net/llc_c_ev.h
83655@@ -125,8 +125,8 @@ static __inline__ struct llc_conn_state_ev *llc_conn_ev(struct sk_buff *skb)
83656 return (struct llc_conn_state_ev *)skb->cb;
83657 }
83658
83659-typedef int (*llc_conn_ev_t)(struct sock *sk, struct sk_buff *skb);
83660-typedef int (*llc_conn_ev_qfyr_t)(struct sock *sk, struct sk_buff *skb);
83661+typedef int (* const llc_conn_ev_t)(struct sock *sk, struct sk_buff *skb);
83662+typedef int (* const llc_conn_ev_qfyr_t)(struct sock *sk, struct sk_buff *skb);
83663
83664 int llc_conn_ev_conn_req(struct sock *sk, struct sk_buff *skb);
83665 int llc_conn_ev_data_req(struct sock *sk, struct sk_buff *skb);
83666diff --git a/include/net/llc_c_st.h b/include/net/llc_c_st.h
83667index 0e79cfb..f46db31 100644
83668--- a/include/net/llc_c_st.h
83669+++ b/include/net/llc_c_st.h
83670@@ -37,7 +37,7 @@ struct llc_conn_state_trans {
83671 u8 next_state;
83672 llc_conn_ev_qfyr_t *ev_qualifiers;
83673 llc_conn_action_t *ev_actions;
83674-};
83675+} __do_const;
83676
83677 struct llc_conn_state {
83678 u8 current_state;
83679diff --git a/include/net/llc_s_ac.h b/include/net/llc_s_ac.h
83680index a61b98c..aade1eb 100644
83681--- a/include/net/llc_s_ac.h
83682+++ b/include/net/llc_s_ac.h
83683@@ -23,7 +23,7 @@
83684 #define SAP_ACT_TEST_IND 9
83685
83686 /* All action functions must look like this */
83687-typedef int (*llc_sap_action_t)(struct llc_sap *sap, struct sk_buff *skb);
83688+typedef int (* const llc_sap_action_t)(struct llc_sap *sap, struct sk_buff *skb);
83689
83690 int llc_sap_action_unitdata_ind(struct llc_sap *sap, struct sk_buff *skb);
83691 int llc_sap_action_send_ui(struct llc_sap *sap, struct sk_buff *skb);
83692diff --git a/include/net/llc_s_st.h b/include/net/llc_s_st.h
83693index 567c681..cd73ac0 100644
83694--- a/include/net/llc_s_st.h
83695+++ b/include/net/llc_s_st.h
83696@@ -20,7 +20,7 @@ struct llc_sap_state_trans {
83697 llc_sap_ev_t ev;
83698 u8 next_state;
83699 llc_sap_action_t *ev_actions;
83700-};
83701+} __do_const;
83702
83703 struct llc_sap_state {
83704 u8 curr_state;
83705diff --git a/include/net/mac80211.h b/include/net/mac80211.h
83706index f4ab2fb..71a85ba 100644
83707--- a/include/net/mac80211.h
83708+++ b/include/net/mac80211.h
83709@@ -4476,7 +4476,7 @@ struct rate_control_ops {
83710 void (*add_sta_debugfs)(void *priv, void *priv_sta,
83711 struct dentry *dir);
83712 void (*remove_sta_debugfs)(void *priv, void *priv_sta);
83713-};
83714+} __do_const;
83715
83716 static inline int rate_supported(struct ieee80211_sta *sta,
83717 enum ieee80211_band band,
83718diff --git a/include/net/neighbour.h b/include/net/neighbour.h
83719index 7277caf..fd095bc 100644
83720--- a/include/net/neighbour.h
83721+++ b/include/net/neighbour.h
83722@@ -163,7 +163,7 @@ struct neigh_ops {
83723 void (*error_report)(struct neighbour *, struct sk_buff *);
83724 int (*output)(struct neighbour *, struct sk_buff *);
83725 int (*connected_output)(struct neighbour *, struct sk_buff *);
83726-};
83727+} __do_const;
83728
83729 struct pneigh_entry {
83730 struct pneigh_entry *next;
83731@@ -203,7 +203,6 @@ struct neigh_table {
83732 void (*proxy_redo)(struct sk_buff *skb);
83733 char *id;
83734 struct neigh_parms parms;
83735- /* HACK. gc_* should follow parms without a gap! */
83736 int gc_interval;
83737 int gc_thresh1;
83738 int gc_thresh2;
83739@@ -218,7 +217,7 @@ struct neigh_table {
83740 struct neigh_statistics __percpu *stats;
83741 struct neigh_hash_table __rcu *nht;
83742 struct pneigh_entry **phash_buckets;
83743-};
83744+} __randomize_layout;
83745
83746 static inline int neigh_parms_family(struct neigh_parms *p)
83747 {
83748diff --git a/include/net/net_namespace.h b/include/net/net_namespace.h
83749index 991dcd9..ab58d00 100644
83750--- a/include/net/net_namespace.h
83751+++ b/include/net/net_namespace.h
83752@@ -124,8 +124,8 @@ struct net {
83753 struct netns_ipvs *ipvs;
83754 #endif
83755 struct sock *diag_nlsk;
83756- atomic_t fnhe_genid;
83757-};
83758+ atomic_unchecked_t fnhe_genid;
83759+} __randomize_layout;
83760
83761 /*
83762 * ifindex generation is per-net namespace, and loopback is
83763@@ -289,7 +289,11 @@ static inline struct net *read_pnet(struct net * const *pnet)
83764 #define __net_init __init
83765 #define __net_exit __exit_refok
83766 #define __net_initdata __initdata
83767+#ifdef CONSTIFY_PLUGIN
83768 #define __net_initconst __initconst
83769+#else
83770+#define __net_initconst __initdata
83771+#endif
83772 #endif
83773
83774 struct pernet_operations {
83775@@ -299,7 +303,7 @@ struct pernet_operations {
83776 void (*exit_batch)(struct list_head *net_exit_list);
83777 int *id;
83778 size_t size;
83779-};
83780+} __do_const;
83781
83782 /*
83783 * Use these carefully. If you implement a network device and it
83784@@ -347,23 +351,23 @@ static inline void unregister_net_sysctl_table(struct ctl_table_header *header)
83785
83786 static inline int rt_genid_ipv4(struct net *net)
83787 {
83788- return atomic_read(&net->ipv4.rt_genid);
83789+ return atomic_read_unchecked(&net->ipv4.rt_genid);
83790 }
83791
83792 static inline void rt_genid_bump_ipv4(struct net *net)
83793 {
83794- atomic_inc(&net->ipv4.rt_genid);
83795+ atomic_inc_unchecked(&net->ipv4.rt_genid);
83796 }
83797
83798 #if IS_ENABLED(CONFIG_IPV6)
83799 static inline int rt_genid_ipv6(struct net *net)
83800 {
83801- return atomic_read(&net->ipv6.rt_genid);
83802+ return atomic_read_unchecked(&net->ipv6.rt_genid);
83803 }
83804
83805 static inline void rt_genid_bump_ipv6(struct net *net)
83806 {
83807- atomic_inc(&net->ipv6.rt_genid);
83808+ atomic_inc_unchecked(&net->ipv6.rt_genid);
83809 }
83810 #else
83811 static inline int rt_genid_ipv6(struct net *net)
83812@@ -385,12 +389,12 @@ static inline void rt_genid_bump_all(struct net *net)
83813
83814 static inline int fnhe_genid(struct net *net)
83815 {
83816- return atomic_read(&net->fnhe_genid);
83817+ return atomic_read_unchecked(&net->fnhe_genid);
83818 }
83819
83820 static inline void fnhe_genid_bump(struct net *net)
83821 {
83822- atomic_inc(&net->fnhe_genid);
83823+ atomic_inc_unchecked(&net->fnhe_genid);
83824 }
83825
83826 #endif /* __NET_NET_NAMESPACE_H */
83827diff --git a/include/net/netdma.h b/include/net/netdma.h
83828index 8ba8ce2..99b7fff 100644
83829--- a/include/net/netdma.h
83830+++ b/include/net/netdma.h
83831@@ -24,7 +24,7 @@
83832 #include <linux/dmaengine.h>
83833 #include <linux/skbuff.h>
83834
83835-int dma_skb_copy_datagram_iovec(struct dma_chan* chan,
83836+int __intentional_overflow(3,5) dma_skb_copy_datagram_iovec(struct dma_chan* chan,
83837 struct sk_buff *skb, int offset, struct iovec *to,
83838 size_t len, struct dma_pinned_list *pinned_list);
83839
83840diff --git a/include/net/netfilter/nf_conntrack_extend.h b/include/net/netfilter/nf_conntrack_extend.h
83841index 956b175..55d1504 100644
83842--- a/include/net/netfilter/nf_conntrack_extend.h
83843+++ b/include/net/netfilter/nf_conntrack_extend.h
83844@@ -47,8 +47,8 @@ enum nf_ct_ext_id {
83845 /* Extensions: optional stuff which isn't permanently in struct. */
83846 struct nf_ct_ext {
83847 struct rcu_head rcu;
83848- u8 offset[NF_CT_EXT_NUM];
83849- u8 len;
83850+ u16 offset[NF_CT_EXT_NUM];
83851+ u16 len;
83852 char data[0];
83853 };
83854
83855diff --git a/include/net/netlink.h b/include/net/netlink.h
83856index 2b47eaa..6d5bcc2 100644
83857--- a/include/net/netlink.h
83858+++ b/include/net/netlink.h
83859@@ -521,7 +521,7 @@ static inline void *nlmsg_get_pos(struct sk_buff *skb)
83860 static inline void nlmsg_trim(struct sk_buff *skb, const void *mark)
83861 {
83862 if (mark)
83863- skb_trim(skb, (unsigned char *) mark - skb->data);
83864+ skb_trim(skb, (const unsigned char *) mark - skb->data);
83865 }
83866
83867 /**
83868diff --git a/include/net/netns/conntrack.h b/include/net/netns/conntrack.h
83869index fbcc7fa..03c7e51 100644
83870--- a/include/net/netns/conntrack.h
83871+++ b/include/net/netns/conntrack.h
83872@@ -12,10 +12,10 @@ struct nf_conntrack_ecache;
83873 struct nf_proto_net {
83874 #ifdef CONFIG_SYSCTL
83875 struct ctl_table_header *ctl_table_header;
83876- struct ctl_table *ctl_table;
83877+ ctl_table_no_const *ctl_table;
83878 #ifdef CONFIG_NF_CONNTRACK_PROC_COMPAT
83879 struct ctl_table_header *ctl_compat_header;
83880- struct ctl_table *ctl_compat_table;
83881+ ctl_table_no_const *ctl_compat_table;
83882 #endif
83883 #endif
83884 unsigned int users;
83885@@ -58,7 +58,7 @@ struct nf_ip_net {
83886 struct nf_icmp_net icmpv6;
83887 #if defined(CONFIG_SYSCTL) && defined(CONFIG_NF_CONNTRACK_PROC_COMPAT)
83888 struct ctl_table_header *ctl_table_header;
83889- struct ctl_table *ctl_table;
83890+ ctl_table_no_const *ctl_table;
83891 #endif
83892 };
83893
83894diff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h
83895index 80f500a..f0c23c2 100644
83896--- a/include/net/netns/ipv4.h
83897+++ b/include/net/netns/ipv4.h
83898@@ -74,7 +74,7 @@ struct netns_ipv4 {
83899
83900 kgid_t sysctl_ping_group_range[2];
83901
83902- atomic_t dev_addr_genid;
83903+ atomic_unchecked_t dev_addr_genid;
83904
83905 #ifdef CONFIG_IP_MROUTE
83906 #ifndef CONFIG_IP_MROUTE_MULTIPLE_TABLES
83907@@ -84,6 +84,6 @@ struct netns_ipv4 {
83908 struct fib_rules_ops *mr_rules_ops;
83909 #endif
83910 #endif
83911- atomic_t rt_genid;
83912+ atomic_unchecked_t rt_genid;
83913 };
83914 #endif
83915diff --git a/include/net/netns/ipv6.h b/include/net/netns/ipv6.h
83916index 21edaf1..4c5faae 100644
83917--- a/include/net/netns/ipv6.h
83918+++ b/include/net/netns/ipv6.h
83919@@ -73,8 +73,8 @@ struct netns_ipv6 {
83920 struct fib_rules_ops *mr6_rules_ops;
83921 #endif
83922 #endif
83923- atomic_t dev_addr_genid;
83924- atomic_t rt_genid;
83925+ atomic_unchecked_t dev_addr_genid;
83926+ atomic_unchecked_t rt_genid;
83927 };
83928
83929 #if IS_ENABLED(CONFIG_NF_DEFRAG_IPV6)
83930diff --git a/include/net/ping.h b/include/net/ping.h
83931index 026479b..d9b2829 100644
83932--- a/include/net/ping.h
83933+++ b/include/net/ping.h
83934@@ -54,7 +54,7 @@ struct ping_iter_state {
83935
83936 extern struct proto ping_prot;
83937 #if IS_ENABLED(CONFIG_IPV6)
83938-extern struct pingv6_ops pingv6_ops;
83939+extern struct pingv6_ops *pingv6_ops;
83940 #endif
83941
83942 struct pingfakehdr {
83943diff --git a/include/net/protocol.h b/include/net/protocol.h
83944index a7e986b..dc67bce 100644
83945--- a/include/net/protocol.h
83946+++ b/include/net/protocol.h
83947@@ -49,7 +49,7 @@ struct net_protocol {
83948 * socket lookup?
83949 */
83950 icmp_strict_tag_validation:1;
83951-};
83952+} __do_const;
83953
83954 #if IS_ENABLED(CONFIG_IPV6)
83955 struct inet6_protocol {
83956@@ -62,7 +62,7 @@ struct inet6_protocol {
83957 u8 type, u8 code, int offset,
83958 __be32 info);
83959 unsigned int flags; /* INET6_PROTO_xxx */
83960-};
83961+} __do_const;
83962
83963 #define INET6_PROTO_NOPOLICY 0x1
83964 #define INET6_PROTO_FINAL 0x2
83965diff --git a/include/net/rtnetlink.h b/include/net/rtnetlink.h
83966index 661e45d..54c39df 100644
83967--- a/include/net/rtnetlink.h
83968+++ b/include/net/rtnetlink.h
83969@@ -93,7 +93,7 @@ struct rtnl_link_ops {
83970 int (*fill_slave_info)(struct sk_buff *skb,
83971 const struct net_device *dev,
83972 const struct net_device *slave_dev);
83973-};
83974+} __do_const;
83975
83976 int __rtnl_link_register(struct rtnl_link_ops *ops);
83977 void __rtnl_link_unregister(struct rtnl_link_ops *ops);
83978diff --git a/include/net/sctp/checksum.h b/include/net/sctp/checksum.h
83979index 4a5b9a3..ca27d73 100644
83980--- a/include/net/sctp/checksum.h
83981+++ b/include/net/sctp/checksum.h
83982@@ -61,8 +61,8 @@ static inline __le32 sctp_compute_cksum(const struct sk_buff *skb,
83983 unsigned int offset)
83984 {
83985 struct sctphdr *sh = sctp_hdr(skb);
83986- __le32 ret, old = sh->checksum;
83987- const struct skb_checksum_ops ops = {
83988+ __le32 ret, old = sh->checksum;
83989+ static const struct skb_checksum_ops ops = {
83990 .update = sctp_csum_update,
83991 .combine = sctp_csum_combine,
83992 };
83993diff --git a/include/net/sctp/sm.h b/include/net/sctp/sm.h
83994index 7f4eeb3..37e8fe1 100644
83995--- a/include/net/sctp/sm.h
83996+++ b/include/net/sctp/sm.h
83997@@ -80,7 +80,7 @@ typedef void (sctp_timer_event_t) (unsigned long);
83998 typedef struct {
83999 sctp_state_fn_t *fn;
84000 const char *name;
84001-} sctp_sm_table_entry_t;
84002+} __do_const sctp_sm_table_entry_t;
84003
84004 /* A naming convention of "sctp_sf_xxx" applies to all the state functions
84005 * currently in use.
84006@@ -292,7 +292,7 @@ __u32 sctp_generate_tag(const struct sctp_endpoint *);
84007 __u32 sctp_generate_tsn(const struct sctp_endpoint *);
84008
84009 /* Extern declarations for major data structures. */
84010-extern sctp_timer_event_t *sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES];
84011+extern sctp_timer_event_t * const sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES];
84012
84013
84014 /* Get the size of a DATA chunk payload. */
84015diff --git a/include/net/sctp/structs.h b/include/net/sctp/structs.h
84016index 6ee76c8..45f2609 100644
84017--- a/include/net/sctp/structs.h
84018+++ b/include/net/sctp/structs.h
84019@@ -507,7 +507,7 @@ struct sctp_pf {
84020 struct sctp_association *asoc);
84021 void (*addr_v4map) (struct sctp_sock *, union sctp_addr *);
84022 struct sctp_af *af;
84023-};
84024+} __do_const;
84025
84026
84027 /* Structure to track chunk fragments that have been acked, but peer
84028diff --git a/include/net/sock.h b/include/net/sock.h
84029index b9586a1..b2948c0 100644
84030--- a/include/net/sock.h
84031+++ b/include/net/sock.h
84032@@ -348,7 +348,7 @@ struct sock {
84033 unsigned int sk_napi_id;
84034 unsigned int sk_ll_usec;
84035 #endif
84036- atomic_t sk_drops;
84037+ atomic_unchecked_t sk_drops;
84038 int sk_rcvbuf;
84039
84040 struct sk_filter __rcu *sk_filter;
84041@@ -1036,7 +1036,7 @@ struct proto {
84042 void (*destroy_cgroup)(struct mem_cgroup *memcg);
84043 struct cg_proto *(*proto_cgroup)(struct mem_cgroup *memcg);
84044 #endif
84045-};
84046+} __randomize_layout;
84047
84048 /*
84049 * Bits in struct cg_proto.flags
84050@@ -1223,7 +1223,7 @@ static inline u64 memcg_memory_allocated_read(struct cg_proto *prot)
84051 return ret >> PAGE_SHIFT;
84052 }
84053
84054-static inline long
84055+static inline long __intentional_overflow(-1)
84056 sk_memory_allocated(const struct sock *sk)
84057 {
84058 struct proto *prot = sk->sk_prot;
84059@@ -1368,7 +1368,7 @@ struct sock_iocb {
84060 struct scm_cookie *scm;
84061 struct msghdr *msg, async_msg;
84062 struct kiocb *kiocb;
84063-};
84064+} __randomize_layout;
84065
84066 static inline struct sock_iocb *kiocb_to_siocb(struct kiocb *iocb)
84067 {
84068@@ -1830,7 +1830,7 @@ static inline void sk_nocaps_add(struct sock *sk, netdev_features_t flags)
84069 }
84070
84071 static inline int skb_do_copy_data_nocache(struct sock *sk, struct sk_buff *skb,
84072- char __user *from, char *to,
84073+ char __user *from, unsigned char *to,
84074 int copy, int offset)
84075 {
84076 if (skb->ip_summed == CHECKSUM_NONE) {
84077@@ -2092,7 +2092,7 @@ static inline void sk_stream_moderate_sndbuf(struct sock *sk)
84078 }
84079 }
84080
84081-struct sk_buff *sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
84082+struct sk_buff * __intentional_overflow(0) sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
84083
84084 /**
84085 * sk_page_frag - return an appropriate page_frag
84086diff --git a/include/net/tcp.h b/include/net/tcp.h
84087index 743acce..44a58b0 100644
84088--- a/include/net/tcp.h
84089+++ b/include/net/tcp.h
84090@@ -541,7 +541,7 @@ void tcp_retransmit_timer(struct sock *sk);
84091 void tcp_xmit_retransmit_queue(struct sock *);
84092 void tcp_simple_retransmit(struct sock *);
84093 int tcp_trim_head(struct sock *, struct sk_buff *, u32);
84094-int tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
84095+int __intentional_overflow(3) tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
84096
84097 void tcp_send_probe0(struct sock *);
84098 void tcp_send_partial(struct sock *);
84099@@ -710,8 +710,8 @@ struct tcp_skb_cb {
84100 struct inet6_skb_parm h6;
84101 #endif
84102 } header; /* For incoming frames */
84103- __u32 seq; /* Starting sequence number */
84104- __u32 end_seq; /* SEQ + FIN + SYN + datalen */
84105+ __u32 seq __intentional_overflow(0); /* Starting sequence number */
84106+ __u32 end_seq __intentional_overflow(0); /* SEQ + FIN + SYN + datalen */
84107 __u32 when; /* used to compute rtt's */
84108 __u8 tcp_flags; /* TCP header flags. (tcp[13]) */
84109
84110@@ -725,7 +725,7 @@ struct tcp_skb_cb {
84111
84112 __u8 ip_dsfield; /* IPv4 tos or IPv6 dsfield */
84113 /* 1 byte hole */
84114- __u32 ack_seq; /* Sequence number ACK'd */
84115+ __u32 ack_seq __intentional_overflow(0); /* Sequence number ACK'd */
84116 };
84117
84118 #define TCP_SKB_CB(__skb) ((struct tcp_skb_cb *)&((__skb)->cb[0]))
84119diff --git a/include/net/xfrm.h b/include/net/xfrm.h
84120index fb5654a..4457522 100644
84121--- a/include/net/xfrm.h
84122+++ b/include/net/xfrm.h
84123@@ -286,7 +286,6 @@ struct xfrm_dst;
84124 struct xfrm_policy_afinfo {
84125 unsigned short family;
84126 struct dst_ops *dst_ops;
84127- void (*garbage_collect)(struct net *net);
84128 struct dst_entry *(*dst_lookup)(struct net *net, int tos,
84129 const xfrm_address_t *saddr,
84130 const xfrm_address_t *daddr);
84131@@ -304,7 +303,7 @@ struct xfrm_policy_afinfo {
84132 struct net_device *dev,
84133 const struct flowi *fl);
84134 struct dst_entry *(*blackhole_route)(struct net *net, struct dst_entry *orig);
84135-};
84136+} __do_const;
84137
84138 int xfrm_policy_register_afinfo(struct xfrm_policy_afinfo *afinfo);
84139 int xfrm_policy_unregister_afinfo(struct xfrm_policy_afinfo *afinfo);
84140@@ -343,7 +342,7 @@ struct xfrm_state_afinfo {
84141 int (*transport_finish)(struct sk_buff *skb,
84142 int async);
84143 void (*local_error)(struct sk_buff *skb, u32 mtu);
84144-};
84145+} __do_const;
84146
84147 int xfrm_state_register_afinfo(struct xfrm_state_afinfo *afinfo);
84148 int xfrm_state_unregister_afinfo(struct xfrm_state_afinfo *afinfo);
84149@@ -428,7 +427,7 @@ struct xfrm_mode {
84150 struct module *owner;
84151 unsigned int encap;
84152 int flags;
84153-};
84154+} __do_const;
84155
84156 /* Flags for xfrm_mode. */
84157 enum {
84158@@ -525,7 +524,7 @@ struct xfrm_policy {
84159 struct timer_list timer;
84160
84161 struct flow_cache_object flo;
84162- atomic_t genid;
84163+ atomic_unchecked_t genid;
84164 u32 priority;
84165 u32 index;
84166 struct xfrm_mark mark;
84167@@ -1165,6 +1164,7 @@ static inline void xfrm_sk_free_policy(struct sock *sk)
84168 }
84169
84170 void xfrm_garbage_collect(struct net *net);
84171+void xfrm_garbage_collect_deferred(struct net *net);
84172
84173 #else
84174
84175@@ -1203,6 +1203,9 @@ static inline int xfrm6_policy_check_reverse(struct sock *sk, int dir,
84176 static inline void xfrm_garbage_collect(struct net *net)
84177 {
84178 }
84179+static inline void xfrm_garbage_collect_deferred(struct net *net)
84180+{
84181+}
84182 #endif
84183
84184 static __inline__
84185diff --git a/include/rdma/iw_cm.h b/include/rdma/iw_cm.h
84186index 1017e0b..227aa4d 100644
84187--- a/include/rdma/iw_cm.h
84188+++ b/include/rdma/iw_cm.h
84189@@ -122,7 +122,7 @@ struct iw_cm_verbs {
84190 int backlog);
84191
84192 int (*destroy_listen)(struct iw_cm_id *cm_id);
84193-};
84194+} __no_const;
84195
84196 /**
84197 * iw_create_cm_id - Create an IW CM identifier.
84198diff --git a/include/scsi/libfc.h b/include/scsi/libfc.h
84199index 52beadf..598734c 100644
84200--- a/include/scsi/libfc.h
84201+++ b/include/scsi/libfc.h
84202@@ -771,6 +771,7 @@ struct libfc_function_template {
84203 */
84204 void (*disc_stop_final) (struct fc_lport *);
84205 };
84206+typedef struct libfc_function_template __no_const libfc_function_template_no_const;
84207
84208 /**
84209 * struct fc_disc - Discovery context
84210@@ -875,7 +876,7 @@ struct fc_lport {
84211 struct fc_vport *vport;
84212
84213 /* Operational Information */
84214- struct libfc_function_template tt;
84215+ libfc_function_template_no_const tt;
84216 u8 link_up;
84217 u8 qfull;
84218 enum fc_lport_state state;
84219diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
84220index d65fbec..f80fef2 100644
84221--- a/include/scsi/scsi_device.h
84222+++ b/include/scsi/scsi_device.h
84223@@ -180,9 +180,9 @@ struct scsi_device {
84224 unsigned int max_device_blocked; /* what device_blocked counts down from */
84225 #define SCSI_DEFAULT_DEVICE_BLOCKED 3
84226
84227- atomic_t iorequest_cnt;
84228- atomic_t iodone_cnt;
84229- atomic_t ioerr_cnt;
84230+ atomic_unchecked_t iorequest_cnt;
84231+ atomic_unchecked_t iodone_cnt;
84232+ atomic_unchecked_t ioerr_cnt;
84233
84234 struct device sdev_gendev,
84235 sdev_dev;
84236diff --git a/include/scsi/scsi_transport_fc.h b/include/scsi/scsi_transport_fc.h
84237index b797e8f..8e2c3aa 100644
84238--- a/include/scsi/scsi_transport_fc.h
84239+++ b/include/scsi/scsi_transport_fc.h
84240@@ -751,7 +751,8 @@ struct fc_function_template {
84241 unsigned long show_host_system_hostname:1;
84242
84243 unsigned long disable_target_scan:1;
84244-};
84245+} __do_const;
84246+typedef struct fc_function_template __no_const fc_function_template_no_const;
84247
84248
84249 /**
84250diff --git a/include/sound/compress_driver.h b/include/sound/compress_driver.h
84251index ae6c3b8..fd748ac 100644
84252--- a/include/sound/compress_driver.h
84253+++ b/include/sound/compress_driver.h
84254@@ -128,7 +128,7 @@ struct snd_compr_ops {
84255 struct snd_compr_caps *caps);
84256 int (*get_codec_caps) (struct snd_compr_stream *stream,
84257 struct snd_compr_codec_caps *codec);
84258-};
84259+} __no_const;
84260
84261 /**
84262 * struct snd_compr: Compressed device
84263diff --git a/include/sound/soc.h b/include/sound/soc.h
84264index 9a00147..d814573 100644
84265--- a/include/sound/soc.h
84266+++ b/include/sound/soc.h
84267@@ -770,7 +770,7 @@ struct snd_soc_codec_driver {
84268 /* probe ordering - for components with runtime dependencies */
84269 int probe_order;
84270 int remove_order;
84271-};
84272+} __do_const;
84273
84274 /* SoC platform interface */
84275 struct snd_soc_platform_driver {
84276@@ -816,7 +816,7 @@ struct snd_soc_platform_driver {
84277 unsigned int (*read)(struct snd_soc_platform *, unsigned int);
84278 int (*write)(struct snd_soc_platform *, unsigned int, unsigned int);
84279 int (*bespoke_trigger)(struct snd_pcm_substream *, int);
84280-};
84281+} __do_const;
84282
84283 struct snd_soc_platform {
84284 const char *name;
84285diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h
84286index 1772fad..282e3e2 100644
84287--- a/include/target/target_core_base.h
84288+++ b/include/target/target_core_base.h
84289@@ -754,7 +754,7 @@ struct se_device {
84290 atomic_long_t write_bytes;
84291 /* Active commands on this virtual SE device */
84292 atomic_t simple_cmds;
84293- atomic_t dev_ordered_id;
84294+ atomic_unchecked_t dev_ordered_id;
84295 atomic_t dev_ordered_sync;
84296 atomic_t dev_qf_count;
84297 int export_count;
84298diff --git a/include/trace/events/fs.h b/include/trace/events/fs.h
84299new file mode 100644
84300index 0000000..fb634b7
84301--- /dev/null
84302+++ b/include/trace/events/fs.h
84303@@ -0,0 +1,53 @@
84304+#undef TRACE_SYSTEM
84305+#define TRACE_SYSTEM fs
84306+
84307+#if !defined(_TRACE_FS_H) || defined(TRACE_HEADER_MULTI_READ)
84308+#define _TRACE_FS_H
84309+
84310+#include <linux/fs.h>
84311+#include <linux/tracepoint.h>
84312+
84313+TRACE_EVENT(do_sys_open,
84314+
84315+ TP_PROTO(const char *filename, int flags, int mode),
84316+
84317+ TP_ARGS(filename, flags, mode),
84318+
84319+ TP_STRUCT__entry(
84320+ __string( filename, filename )
84321+ __field( int, flags )
84322+ __field( int, mode )
84323+ ),
84324+
84325+ TP_fast_assign(
84326+ __assign_str(filename, filename);
84327+ __entry->flags = flags;
84328+ __entry->mode = mode;
84329+ ),
84330+
84331+ TP_printk("\"%s\" %x %o",
84332+ __get_str(filename), __entry->flags, __entry->mode)
84333+);
84334+
84335+TRACE_EVENT(open_exec,
84336+
84337+ TP_PROTO(const char *filename),
84338+
84339+ TP_ARGS(filename),
84340+
84341+ TP_STRUCT__entry(
84342+ __string( filename, filename )
84343+ ),
84344+
84345+ TP_fast_assign(
84346+ __assign_str(filename, filename);
84347+ ),
84348+
84349+ TP_printk("\"%s\"",
84350+ __get_str(filename))
84351+);
84352+
84353+#endif /* _TRACE_FS_H */
84354+
84355+/* This part must be outside protection */
84356+#include <trace/define_trace.h>
84357diff --git a/include/trace/events/irq.h b/include/trace/events/irq.h
84358index 1c09820..7f5ec79 100644
84359--- a/include/trace/events/irq.h
84360+++ b/include/trace/events/irq.h
84361@@ -36,7 +36,7 @@ struct softirq_action;
84362 */
84363 TRACE_EVENT(irq_handler_entry,
84364
84365- TP_PROTO(int irq, struct irqaction *action),
84366+ TP_PROTO(int irq, const struct irqaction *action),
84367
84368 TP_ARGS(irq, action),
84369
84370@@ -66,7 +66,7 @@ TRACE_EVENT(irq_handler_entry,
84371 */
84372 TRACE_EVENT(irq_handler_exit,
84373
84374- TP_PROTO(int irq, struct irqaction *action, int ret),
84375+ TP_PROTO(int irq, const struct irqaction *action, int ret),
84376
84377 TP_ARGS(irq, action, ret),
84378
84379diff --git a/include/uapi/linux/a.out.h b/include/uapi/linux/a.out.h
84380index 7caf44c..23c6f27 100644
84381--- a/include/uapi/linux/a.out.h
84382+++ b/include/uapi/linux/a.out.h
84383@@ -39,6 +39,14 @@ enum machine_type {
84384 M_MIPS2 = 152 /* MIPS R6000/R4000 binary */
84385 };
84386
84387+/* Constants for the N_FLAGS field */
84388+#define F_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
84389+#define F_PAX_EMUTRAMP 2 /* Emulate trampolines */
84390+#define F_PAX_MPROTECT 4 /* Restrict mprotect() */
84391+#define F_PAX_RANDMMAP 8 /* Randomize mmap() base */
84392+/*#define F_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
84393+#define F_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
84394+
84395 #if !defined (N_MAGIC)
84396 #define N_MAGIC(exec) ((exec).a_info & 0xffff)
84397 #endif
84398diff --git a/include/uapi/linux/bcache.h b/include/uapi/linux/bcache.h
84399index 22b6ad3..aeba37e 100644
84400--- a/include/uapi/linux/bcache.h
84401+++ b/include/uapi/linux/bcache.h
84402@@ -5,6 +5,7 @@
84403 * Bcache on disk data structures
84404 */
84405
84406+#include <linux/compiler.h>
84407 #include <asm/types.h>
84408
84409 #define BITMASK(name, type, field, offset, size) \
84410@@ -20,8 +21,8 @@ static inline void SET_##name(type *k, __u64 v) \
84411 /* Btree keys - all units are in sectors */
84412
84413 struct bkey {
84414- __u64 high;
84415- __u64 low;
84416+ __u64 high __intentional_overflow(-1);
84417+ __u64 low __intentional_overflow(-1);
84418 __u64 ptr[];
84419 };
84420
84421diff --git a/include/uapi/linux/byteorder/little_endian.h b/include/uapi/linux/byteorder/little_endian.h
84422index d876736..ccce5c0 100644
84423--- a/include/uapi/linux/byteorder/little_endian.h
84424+++ b/include/uapi/linux/byteorder/little_endian.h
84425@@ -42,51 +42,51 @@
84426
84427 static inline __le64 __cpu_to_le64p(const __u64 *p)
84428 {
84429- return (__force __le64)*p;
84430+ return (__force const __le64)*p;
84431 }
84432-static inline __u64 __le64_to_cpup(const __le64 *p)
84433+static inline __u64 __intentional_overflow(-1) __le64_to_cpup(const __le64 *p)
84434 {
84435- return (__force __u64)*p;
84436+ return (__force const __u64)*p;
84437 }
84438 static inline __le32 __cpu_to_le32p(const __u32 *p)
84439 {
84440- return (__force __le32)*p;
84441+ return (__force const __le32)*p;
84442 }
84443 static inline __u32 __le32_to_cpup(const __le32 *p)
84444 {
84445- return (__force __u32)*p;
84446+ return (__force const __u32)*p;
84447 }
84448 static inline __le16 __cpu_to_le16p(const __u16 *p)
84449 {
84450- return (__force __le16)*p;
84451+ return (__force const __le16)*p;
84452 }
84453 static inline __u16 __le16_to_cpup(const __le16 *p)
84454 {
84455- return (__force __u16)*p;
84456+ return (__force const __u16)*p;
84457 }
84458 static inline __be64 __cpu_to_be64p(const __u64 *p)
84459 {
84460- return (__force __be64)__swab64p(p);
84461+ return (__force const __be64)__swab64p(p);
84462 }
84463 static inline __u64 __be64_to_cpup(const __be64 *p)
84464 {
84465- return __swab64p((__u64 *)p);
84466+ return __swab64p((const __u64 *)p);
84467 }
84468 static inline __be32 __cpu_to_be32p(const __u32 *p)
84469 {
84470- return (__force __be32)__swab32p(p);
84471+ return (__force const __be32)__swab32p(p);
84472 }
84473-static inline __u32 __be32_to_cpup(const __be32 *p)
84474+static inline __u32 __intentional_overflow(-1) __be32_to_cpup(const __be32 *p)
84475 {
84476- return __swab32p((__u32 *)p);
84477+ return __swab32p((const __u32 *)p);
84478 }
84479 static inline __be16 __cpu_to_be16p(const __u16 *p)
84480 {
84481- return (__force __be16)__swab16p(p);
84482+ return (__force const __be16)__swab16p(p);
84483 }
84484 static inline __u16 __be16_to_cpup(const __be16 *p)
84485 {
84486- return __swab16p((__u16 *)p);
84487+ return __swab16p((const __u16 *)p);
84488 }
84489 #define __cpu_to_le64s(x) do { (void)(x); } while (0)
84490 #define __le64_to_cpus(x) do { (void)(x); } while (0)
84491diff --git a/include/uapi/linux/elf.h b/include/uapi/linux/elf.h
84492index ef6103b..d4e65dd 100644
84493--- a/include/uapi/linux/elf.h
84494+++ b/include/uapi/linux/elf.h
84495@@ -37,6 +37,17 @@ typedef __s64 Elf64_Sxword;
84496 #define PT_GNU_EH_FRAME 0x6474e550
84497
84498 #define PT_GNU_STACK (PT_LOOS + 0x474e551)
84499+#define PT_GNU_RELRO (PT_LOOS + 0x474e552)
84500+
84501+#define PT_PAX_FLAGS (PT_LOOS + 0x5041580)
84502+
84503+/* Constants for the e_flags field */
84504+#define EF_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
84505+#define EF_PAX_EMUTRAMP 2 /* Emulate trampolines */
84506+#define EF_PAX_MPROTECT 4 /* Restrict mprotect() */
84507+#define EF_PAX_RANDMMAP 8 /* Randomize mmap() base */
84508+/*#define EF_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
84509+#define EF_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
84510
84511 /*
84512 * Extended Numbering
84513@@ -94,6 +105,8 @@ typedef __s64 Elf64_Sxword;
84514 #define DT_DEBUG 21
84515 #define DT_TEXTREL 22
84516 #define DT_JMPREL 23
84517+#define DT_FLAGS 30
84518+ #define DF_TEXTREL 0x00000004
84519 #define DT_ENCODING 32
84520 #define OLD_DT_LOOS 0x60000000
84521 #define DT_LOOS 0x6000000d
84522@@ -240,6 +253,19 @@ typedef struct elf64_hdr {
84523 #define PF_W 0x2
84524 #define PF_X 0x1
84525
84526+#define PF_PAGEEXEC (1U << 4) /* Enable PAGEEXEC */
84527+#define PF_NOPAGEEXEC (1U << 5) /* Disable PAGEEXEC */
84528+#define PF_SEGMEXEC (1U << 6) /* Enable SEGMEXEC */
84529+#define PF_NOSEGMEXEC (1U << 7) /* Disable SEGMEXEC */
84530+#define PF_MPROTECT (1U << 8) /* Enable MPROTECT */
84531+#define PF_NOMPROTECT (1U << 9) /* Disable MPROTECT */
84532+/*#define PF_RANDEXEC (1U << 10)*/ /* Enable RANDEXEC */
84533+/*#define PF_NORANDEXEC (1U << 11)*/ /* Disable RANDEXEC */
84534+#define PF_EMUTRAMP (1U << 12) /* Enable EMUTRAMP */
84535+#define PF_NOEMUTRAMP (1U << 13) /* Disable EMUTRAMP */
84536+#define PF_RANDMMAP (1U << 14) /* Enable RANDMMAP */
84537+#define PF_NORANDMMAP (1U << 15) /* Disable RANDMMAP */
84538+
84539 typedef struct elf32_phdr{
84540 Elf32_Word p_type;
84541 Elf32_Off p_offset;
84542@@ -332,6 +358,8 @@ typedef struct elf64_shdr {
84543 #define EI_OSABI 7
84544 #define EI_PAD 8
84545
84546+#define EI_PAX 14
84547+
84548 #define ELFMAG0 0x7f /* EI_MAG */
84549 #define ELFMAG1 'E'
84550 #define ELFMAG2 'L'
84551diff --git a/include/uapi/linux/personality.h b/include/uapi/linux/personality.h
84552index aa169c4..6a2771d 100644
84553--- a/include/uapi/linux/personality.h
84554+++ b/include/uapi/linux/personality.h
84555@@ -30,6 +30,7 @@ enum {
84556 #define PER_CLEAR_ON_SETID (READ_IMPLIES_EXEC | \
84557 ADDR_NO_RANDOMIZE | \
84558 ADDR_COMPAT_LAYOUT | \
84559+ ADDR_LIMIT_3GB | \
84560 MMAP_PAGE_ZERO)
84561
84562 /*
84563diff --git a/include/uapi/linux/screen_info.h b/include/uapi/linux/screen_info.h
84564index 7530e74..e714828 100644
84565--- a/include/uapi/linux/screen_info.h
84566+++ b/include/uapi/linux/screen_info.h
84567@@ -43,7 +43,8 @@ struct screen_info {
84568 __u16 pages; /* 0x32 */
84569 __u16 vesa_attributes; /* 0x34 */
84570 __u32 capabilities; /* 0x36 */
84571- __u8 _reserved[6]; /* 0x3a */
84572+ __u16 vesapm_size; /* 0x3a */
84573+ __u8 _reserved[4]; /* 0x3c */
84574 } __attribute__((packed));
84575
84576 #define VIDEO_TYPE_MDA 0x10 /* Monochrome Text Display */
84577diff --git a/include/uapi/linux/swab.h b/include/uapi/linux/swab.h
84578index 0e011eb..82681b1 100644
84579--- a/include/uapi/linux/swab.h
84580+++ b/include/uapi/linux/swab.h
84581@@ -43,7 +43,7 @@
84582 * ___swab16, ___swab32, ___swab64, ___swahw32, ___swahb32
84583 */
84584
84585-static inline __attribute_const__ __u16 __fswab16(__u16 val)
84586+static inline __intentional_overflow(-1) __attribute_const__ __u16 __fswab16(__u16 val)
84587 {
84588 #ifdef __HAVE_BUILTIN_BSWAP16__
84589 return __builtin_bswap16(val);
84590@@ -54,7 +54,7 @@ static inline __attribute_const__ __u16 __fswab16(__u16 val)
84591 #endif
84592 }
84593
84594-static inline __attribute_const__ __u32 __fswab32(__u32 val)
84595+static inline __intentional_overflow(-1) __attribute_const__ __u32 __fswab32(__u32 val)
84596 {
84597 #ifdef __HAVE_BUILTIN_BSWAP32__
84598 return __builtin_bswap32(val);
84599@@ -65,7 +65,7 @@ static inline __attribute_const__ __u32 __fswab32(__u32 val)
84600 #endif
84601 }
84602
84603-static inline __attribute_const__ __u64 __fswab64(__u64 val)
84604+static inline __intentional_overflow(-1) __attribute_const__ __u64 __fswab64(__u64 val)
84605 {
84606 #ifdef __HAVE_BUILTIN_BSWAP64__
84607 return __builtin_bswap64(val);
84608diff --git a/include/uapi/linux/sysctl.h b/include/uapi/linux/sysctl.h
84609index 6d67213..552fdd9 100644
84610--- a/include/uapi/linux/sysctl.h
84611+++ b/include/uapi/linux/sysctl.h
84612@@ -155,8 +155,6 @@ enum
84613 KERN_PANIC_ON_NMI=76, /* int: whether we will panic on an unrecovered */
84614 };
84615
84616-
84617-
84618 /* CTL_VM names: */
84619 enum
84620 {
84621diff --git a/include/uapi/linux/videodev2.h b/include/uapi/linux/videodev2.h
84622index fe94bb9..c9e51c2 100644
84623--- a/include/uapi/linux/videodev2.h
84624+++ b/include/uapi/linux/videodev2.h
84625@@ -1227,7 +1227,7 @@ struct v4l2_ext_control {
84626 union {
84627 __s32 value;
84628 __s64 value64;
84629- char *string;
84630+ char __user *string;
84631 };
84632 } __attribute__ ((packed));
84633
84634diff --git a/include/uapi/linux/xattr.h b/include/uapi/linux/xattr.h
84635index c38355c..17a57bc 100644
84636--- a/include/uapi/linux/xattr.h
84637+++ b/include/uapi/linux/xattr.h
84638@@ -73,5 +73,9 @@
84639 #define XATTR_POSIX_ACL_DEFAULT "posix_acl_default"
84640 #define XATTR_NAME_POSIX_ACL_DEFAULT XATTR_SYSTEM_PREFIX XATTR_POSIX_ACL_DEFAULT
84641
84642+/* User namespace */
84643+#define XATTR_PAX_PREFIX XATTR_USER_PREFIX "pax."
84644+#define XATTR_PAX_FLAGS_SUFFIX "flags"
84645+#define XATTR_NAME_PAX_FLAGS XATTR_PAX_PREFIX XATTR_PAX_FLAGS_SUFFIX
84646
84647 #endif /* _UAPI_LINUX_XATTR_H */
84648diff --git a/include/video/udlfb.h b/include/video/udlfb.h
84649index f9466fa..f4e2b81 100644
84650--- a/include/video/udlfb.h
84651+++ b/include/video/udlfb.h
84652@@ -53,10 +53,10 @@ struct dlfb_data {
84653 u32 pseudo_palette[256];
84654 int blank_mode; /*one of FB_BLANK_ */
84655 /* blit-only rendering path metrics, exposed through sysfs */
84656- atomic_t bytes_rendered; /* raw pixel-bytes driver asked to render */
84657- atomic_t bytes_identical; /* saved effort with backbuffer comparison */
84658- atomic_t bytes_sent; /* to usb, after compression including overhead */
84659- atomic_t cpu_kcycles_used; /* transpired during pixel processing */
84660+ atomic_unchecked_t bytes_rendered; /* raw pixel-bytes driver asked to render */
84661+ atomic_unchecked_t bytes_identical; /* saved effort with backbuffer comparison */
84662+ atomic_unchecked_t bytes_sent; /* to usb, after compression including overhead */
84663+ atomic_unchecked_t cpu_kcycles_used; /* transpired during pixel processing */
84664 };
84665
84666 #define NR_USB_REQUEST_I2C_SUB_IO 0x02
84667diff --git a/include/video/uvesafb.h b/include/video/uvesafb.h
84668index 30f5362..8ed8ac9 100644
84669--- a/include/video/uvesafb.h
84670+++ b/include/video/uvesafb.h
84671@@ -122,6 +122,7 @@ struct uvesafb_par {
84672 u8 ypan; /* 0 - nothing, 1 - ypan, 2 - ywrap */
84673 u8 pmi_setpal; /* PMI for palette changes */
84674 u16 *pmi_base; /* protected mode interface location */
84675+ u8 *pmi_code; /* protected mode code location */
84676 void *pmi_start;
84677 void *pmi_pal;
84678 u8 *vbe_state_orig; /*
84679diff --git a/init/Kconfig b/init/Kconfig
84680index d56cb03..7e6d5dc 100644
84681--- a/init/Kconfig
84682+++ b/init/Kconfig
84683@@ -1079,6 +1079,7 @@ endif # CGROUPS
84684
84685 config CHECKPOINT_RESTORE
84686 bool "Checkpoint/restore support" if EXPERT
84687+ depends on !GRKERNSEC
84688 default n
84689 help
84690 Enables additional kernel features in a sake of checkpoint/restore.
84691@@ -1545,7 +1546,7 @@ config SLUB_DEBUG
84692
84693 config COMPAT_BRK
84694 bool "Disable heap randomization"
84695- default y
84696+ default n
84697 help
84698 Randomizing heap placement makes heap exploits harder, but it
84699 also breaks ancient binaries (including anything libc5 based).
84700@@ -1833,7 +1834,7 @@ config INIT_ALL_POSSIBLE
84701 config STOP_MACHINE
84702 bool
84703 default y
84704- depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU
84705+ depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU || GRKERNSEC
84706 help
84707 Need stop_machine() primitive.
84708
84709diff --git a/init/Makefile b/init/Makefile
84710index 7bc47ee..6da2dc7 100644
84711--- a/init/Makefile
84712+++ b/init/Makefile
84713@@ -2,6 +2,9 @@
84714 # Makefile for the linux kernel.
84715 #
84716
84717+ccflags-y := $(GCC_PLUGINS_CFLAGS)
84718+asflags-y := $(GCC_PLUGINS_AFLAGS)
84719+
84720 obj-y := main.o version.o mounts.o
84721 ifneq ($(CONFIG_BLK_DEV_INITRD),y)
84722 obj-y += noinitramfs.o
84723diff --git a/init/do_mounts.c b/init/do_mounts.c
84724index 8e5addc..c96ea61 100644
84725--- a/init/do_mounts.c
84726+++ b/init/do_mounts.c
84727@@ -359,11 +359,11 @@ static void __init get_fs_names(char *page)
84728 static int __init do_mount_root(char *name, char *fs, int flags, void *data)
84729 {
84730 struct super_block *s;
84731- int err = sys_mount(name, "/root", fs, flags, data);
84732+ int err = sys_mount((char __force_user *)name, (char __force_user *)"/root", (char __force_user *)fs, flags, (void __force_user *)data);
84733 if (err)
84734 return err;
84735
84736- sys_chdir("/root");
84737+ sys_chdir((const char __force_user *)"/root");
84738 s = current->fs->pwd.dentry->d_sb;
84739 ROOT_DEV = s->s_dev;
84740 printk(KERN_INFO
84741@@ -484,18 +484,18 @@ void __init change_floppy(char *fmt, ...)
84742 va_start(args, fmt);
84743 vsprintf(buf, fmt, args);
84744 va_end(args);
84745- fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0);
84746+ fd = sys_open((char __user *)"/dev/root", O_RDWR | O_NDELAY, 0);
84747 if (fd >= 0) {
84748 sys_ioctl(fd, FDEJECT, 0);
84749 sys_close(fd);
84750 }
84751 printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf);
84752- fd = sys_open("/dev/console", O_RDWR, 0);
84753+ fd = sys_open((__force const char __user *)"/dev/console", O_RDWR, 0);
84754 if (fd >= 0) {
84755 sys_ioctl(fd, TCGETS, (long)&termios);
84756 termios.c_lflag &= ~ICANON;
84757 sys_ioctl(fd, TCSETSF, (long)&termios);
84758- sys_read(fd, &c, 1);
84759+ sys_read(fd, (char __user *)&c, 1);
84760 termios.c_lflag |= ICANON;
84761 sys_ioctl(fd, TCSETSF, (long)&termios);
84762 sys_close(fd);
84763@@ -589,8 +589,8 @@ void __init prepare_namespace(void)
84764 mount_root();
84765 out:
84766 devtmpfs_mount("dev");
84767- sys_mount(".", "/", NULL, MS_MOVE, NULL);
84768- sys_chroot(".");
84769+ sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
84770+ sys_chroot((const char __force_user *)".");
84771 }
84772
84773 static bool is_tmpfs;
84774diff --git a/init/do_mounts.h b/init/do_mounts.h
84775index f5b978a..69dbfe8 100644
84776--- a/init/do_mounts.h
84777+++ b/init/do_mounts.h
84778@@ -15,15 +15,15 @@ extern int root_mountflags;
84779
84780 static inline int create_dev(char *name, dev_t dev)
84781 {
84782- sys_unlink(name);
84783- return sys_mknod(name, S_IFBLK|0600, new_encode_dev(dev));
84784+ sys_unlink((char __force_user *)name);
84785+ return sys_mknod((char __force_user *)name, S_IFBLK|0600, new_encode_dev(dev));
84786 }
84787
84788 #if BITS_PER_LONG == 32
84789 static inline u32 bstat(char *name)
84790 {
84791 struct stat64 stat;
84792- if (sys_stat64(name, &stat) != 0)
84793+ if (sys_stat64((char __force_user *)name, (struct stat64 __force_user *)&stat) != 0)
84794 return 0;
84795 if (!S_ISBLK(stat.st_mode))
84796 return 0;
84797@@ -35,7 +35,7 @@ static inline u32 bstat(char *name)
84798 static inline u32 bstat(char *name)
84799 {
84800 struct stat stat;
84801- if (sys_newstat(name, &stat) != 0)
84802+ if (sys_newstat((const char __force_user *)name, (struct stat __force_user *)&stat) != 0)
84803 return 0;
84804 if (!S_ISBLK(stat.st_mode))
84805 return 0;
84806diff --git a/init/do_mounts_initrd.c b/init/do_mounts_initrd.c
84807index 3e0878e..8a9d7a0 100644
84808--- a/init/do_mounts_initrd.c
84809+++ b/init/do_mounts_initrd.c
84810@@ -37,13 +37,13 @@ static int init_linuxrc(struct subprocess_info *info, struct cred *new)
84811 {
84812 sys_unshare(CLONE_FS | CLONE_FILES);
84813 /* stdin/stdout/stderr for /linuxrc */
84814- sys_open("/dev/console", O_RDWR, 0);
84815+ sys_open((const char __force_user *)"/dev/console", O_RDWR, 0);
84816 sys_dup(0);
84817 sys_dup(0);
84818 /* move initrd over / and chdir/chroot in initrd root */
84819- sys_chdir("/root");
84820- sys_mount(".", "/", NULL, MS_MOVE, NULL);
84821- sys_chroot(".");
84822+ sys_chdir((const char __force_user *)"/root");
84823+ sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
84824+ sys_chroot((const char __force_user *)".");
84825 sys_setsid();
84826 return 0;
84827 }
84828@@ -59,8 +59,8 @@ static void __init handle_initrd(void)
84829 create_dev("/dev/root.old", Root_RAM0);
84830 /* mount initrd on rootfs' /root */
84831 mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY);
84832- sys_mkdir("/old", 0700);
84833- sys_chdir("/old");
84834+ sys_mkdir((const char __force_user *)"/old", 0700);
84835+ sys_chdir((const char __force_user *)"/old");
84836
84837 /* try loading default modules from initrd */
84838 load_default_modules();
84839@@ -80,31 +80,31 @@ static void __init handle_initrd(void)
84840 current->flags &= ~PF_FREEZER_SKIP;
84841
84842 /* move initrd to rootfs' /old */
84843- sys_mount("..", ".", NULL, MS_MOVE, NULL);
84844+ sys_mount((char __force_user *)"..", (char __force_user *)".", NULL, MS_MOVE, NULL);
84845 /* switch root and cwd back to / of rootfs */
84846- sys_chroot("..");
84847+ sys_chroot((const char __force_user *)"..");
84848
84849 if (new_decode_dev(real_root_dev) == Root_RAM0) {
84850- sys_chdir("/old");
84851+ sys_chdir((const char __force_user *)"/old");
84852 return;
84853 }
84854
84855- sys_chdir("/");
84856+ sys_chdir((const char __force_user *)"/");
84857 ROOT_DEV = new_decode_dev(real_root_dev);
84858 mount_root();
84859
84860 printk(KERN_NOTICE "Trying to move old root to /initrd ... ");
84861- error = sys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL);
84862+ error = sys_mount((char __force_user *)"/old", (char __force_user *)"/root/initrd", NULL, MS_MOVE, NULL);
84863 if (!error)
84864 printk("okay\n");
84865 else {
84866- int fd = sys_open("/dev/root.old", O_RDWR, 0);
84867+ int fd = sys_open((const char __force_user *)"/dev/root.old", O_RDWR, 0);
84868 if (error == -ENOENT)
84869 printk("/initrd does not exist. Ignored.\n");
84870 else
84871 printk("failed\n");
84872 printk(KERN_NOTICE "Unmounting old root\n");
84873- sys_umount("/old", MNT_DETACH);
84874+ sys_umount((char __force_user *)"/old", MNT_DETACH);
84875 printk(KERN_NOTICE "Trying to free ramdisk memory ... ");
84876 if (fd < 0) {
84877 error = fd;
84878@@ -127,11 +127,11 @@ int __init initrd_load(void)
84879 * mounted in the normal path.
84880 */
84881 if (rd_load_image("/initrd.image") && ROOT_DEV != Root_RAM0) {
84882- sys_unlink("/initrd.image");
84883+ sys_unlink((const char __force_user *)"/initrd.image");
84884 handle_initrd();
84885 return 1;
84886 }
84887 }
84888- sys_unlink("/initrd.image");
84889+ sys_unlink((const char __force_user *)"/initrd.image");
84890 return 0;
84891 }
84892diff --git a/init/do_mounts_md.c b/init/do_mounts_md.c
84893index 8cb6db5..d729f50 100644
84894--- a/init/do_mounts_md.c
84895+++ b/init/do_mounts_md.c
84896@@ -180,7 +180,7 @@ static void __init md_setup_drive(void)
84897 partitioned ? "_d" : "", minor,
84898 md_setup_args[ent].device_names);
84899
84900- fd = sys_open(name, 0, 0);
84901+ fd = sys_open((char __force_user *)name, 0, 0);
84902 if (fd < 0) {
84903 printk(KERN_ERR "md: open failed - cannot start "
84904 "array %s\n", name);
84905@@ -243,7 +243,7 @@ static void __init md_setup_drive(void)
84906 * array without it
84907 */
84908 sys_close(fd);
84909- fd = sys_open(name, 0, 0);
84910+ fd = sys_open((char __force_user *)name, 0, 0);
84911 sys_ioctl(fd, BLKRRPART, 0);
84912 }
84913 sys_close(fd);
84914@@ -293,7 +293,7 @@ static void __init autodetect_raid(void)
84915
84916 wait_for_device_probe();
84917
84918- fd = sys_open("/dev/md0", 0, 0);
84919+ fd = sys_open((const char __force_user *) "/dev/md0", 0, 0);
84920 if (fd >= 0) {
84921 sys_ioctl(fd, RAID_AUTORUN, raid_autopart);
84922 sys_close(fd);
84923diff --git a/init/init_task.c b/init/init_task.c
84924index ba0a7f36..2bcf1d5 100644
84925--- a/init/init_task.c
84926+++ b/init/init_task.c
84927@@ -22,5 +22,9 @@ EXPORT_SYMBOL(init_task);
84928 * Initial thread structure. Alignment of this is handled by a special
84929 * linker map entry.
84930 */
84931+#ifdef CONFIG_X86
84932+union thread_union init_thread_union __init_task_data;
84933+#else
84934 union thread_union init_thread_union __init_task_data =
84935 { INIT_THREAD_INFO(init_task) };
84936+#endif
84937diff --git a/init/initramfs.c b/init/initramfs.c
84938index 93b6139..8d628b7 100644
84939--- a/init/initramfs.c
84940+++ b/init/initramfs.c
84941@@ -84,7 +84,7 @@ static void __init free_hash(void)
84942 }
84943 }
84944
84945-static long __init do_utime(char *filename, time_t mtime)
84946+static long __init do_utime(char __force_user *filename, time_t mtime)
84947 {
84948 struct timespec t[2];
84949
84950@@ -119,7 +119,7 @@ static void __init dir_utime(void)
84951 struct dir_entry *de, *tmp;
84952 list_for_each_entry_safe(de, tmp, &dir_list, list) {
84953 list_del(&de->list);
84954- do_utime(de->name, de->mtime);
84955+ do_utime((char __force_user *)de->name, de->mtime);
84956 kfree(de->name);
84957 kfree(de);
84958 }
84959@@ -281,7 +281,7 @@ static int __init maybe_link(void)
84960 if (nlink >= 2) {
84961 char *old = find_link(major, minor, ino, mode, collected);
84962 if (old)
84963- return (sys_link(old, collected) < 0) ? -1 : 1;
84964+ return (sys_link((char __force_user *)old, (char __force_user *)collected) < 0) ? -1 : 1;
84965 }
84966 return 0;
84967 }
84968@@ -290,11 +290,11 @@ static void __init clean_path(char *path, umode_t mode)
84969 {
84970 struct stat st;
84971
84972- if (!sys_newlstat(path, &st) && (st.st_mode^mode) & S_IFMT) {
84973+ if (!sys_newlstat((char __force_user *)path, (struct stat __force_user *)&st) && (st.st_mode^mode) & S_IFMT) {
84974 if (S_ISDIR(st.st_mode))
84975- sys_rmdir(path);
84976+ sys_rmdir((char __force_user *)path);
84977 else
84978- sys_unlink(path);
84979+ sys_unlink((char __force_user *)path);
84980 }
84981 }
84982
84983@@ -315,7 +315,7 @@ static int __init do_name(void)
84984 int openflags = O_WRONLY|O_CREAT;
84985 if (ml != 1)
84986 openflags |= O_TRUNC;
84987- wfd = sys_open(collected, openflags, mode);
84988+ wfd = sys_open((char __force_user *)collected, openflags, mode);
84989
84990 if (wfd >= 0) {
84991 sys_fchown(wfd, uid, gid);
84992@@ -327,17 +327,17 @@ static int __init do_name(void)
84993 }
84994 }
84995 } else if (S_ISDIR(mode)) {
84996- sys_mkdir(collected, mode);
84997- sys_chown(collected, uid, gid);
84998- sys_chmod(collected, mode);
84999+ sys_mkdir((char __force_user *)collected, mode);
85000+ sys_chown((char __force_user *)collected, uid, gid);
85001+ sys_chmod((char __force_user *)collected, mode);
85002 dir_add(collected, mtime);
85003 } else if (S_ISBLK(mode) || S_ISCHR(mode) ||
85004 S_ISFIFO(mode) || S_ISSOCK(mode)) {
85005 if (maybe_link() == 0) {
85006- sys_mknod(collected, mode, rdev);
85007- sys_chown(collected, uid, gid);
85008- sys_chmod(collected, mode);
85009- do_utime(collected, mtime);
85010+ sys_mknod((char __force_user *)collected, mode, rdev);
85011+ sys_chown((char __force_user *)collected, uid, gid);
85012+ sys_chmod((char __force_user *)collected, mode);
85013+ do_utime((char __force_user *)collected, mtime);
85014 }
85015 }
85016 return 0;
85017@@ -346,15 +346,15 @@ static int __init do_name(void)
85018 static int __init do_copy(void)
85019 {
85020 if (count >= body_len) {
85021- sys_write(wfd, victim, body_len);
85022+ sys_write(wfd, (char __force_user *)victim, body_len);
85023 sys_close(wfd);
85024- do_utime(vcollected, mtime);
85025+ do_utime((char __force_user *)vcollected, mtime);
85026 kfree(vcollected);
85027 eat(body_len);
85028 state = SkipIt;
85029 return 0;
85030 } else {
85031- sys_write(wfd, victim, count);
85032+ sys_write(wfd, (char __force_user *)victim, count);
85033 body_len -= count;
85034 eat(count);
85035 return 1;
85036@@ -365,9 +365,9 @@ static int __init do_symlink(void)
85037 {
85038 collected[N_ALIGN(name_len) + body_len] = '\0';
85039 clean_path(collected, 0);
85040- sys_symlink(collected + N_ALIGN(name_len), collected);
85041- sys_lchown(collected, uid, gid);
85042- do_utime(collected, mtime);
85043+ sys_symlink((char __force_user *)collected + N_ALIGN(name_len), (char __force_user *)collected);
85044+ sys_lchown((char __force_user *)collected, uid, gid);
85045+ do_utime((char __force_user *)collected, mtime);
85046 state = SkipIt;
85047 next_state = Reset;
85048 return 0;
85049diff --git a/init/main.c b/init/main.c
85050index 9c7fd4c..650b4f1 100644
85051--- a/init/main.c
85052+++ b/init/main.c
85053@@ -97,6 +97,8 @@ extern void radix_tree_init(void);
85054 static inline void mark_rodata_ro(void) { }
85055 #endif
85056
85057+extern void grsecurity_init(void);
85058+
85059 /*
85060 * Debug helper: via this flag we know that we are in 'early bootup code'
85061 * where only the boot processor is running with IRQ disabled. This means
85062@@ -158,6 +160,75 @@ static int __init set_reset_devices(char *str)
85063
85064 __setup("reset_devices", set_reset_devices);
85065
85066+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
85067+kgid_t grsec_proc_gid = KGIDT_INIT(CONFIG_GRKERNSEC_PROC_GID);
85068+static int __init setup_grsec_proc_gid(char *str)
85069+{
85070+ grsec_proc_gid = KGIDT_INIT(simple_strtol(str, NULL, 0));
85071+ return 1;
85072+}
85073+__setup("grsec_proc_gid=", setup_grsec_proc_gid);
85074+#endif
85075+
85076+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
85077+unsigned long pax_user_shadow_base __read_only;
85078+EXPORT_SYMBOL(pax_user_shadow_base);
85079+extern char pax_enter_kernel_user[];
85080+extern char pax_exit_kernel_user[];
85081+#endif
85082+
85083+#if defined(CONFIG_X86) && defined(CONFIG_PAX_MEMORY_UDEREF)
85084+static int __init setup_pax_nouderef(char *str)
85085+{
85086+#ifdef CONFIG_X86_32
85087+ unsigned int cpu;
85088+ struct desc_struct *gdt;
85089+
85090+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
85091+ gdt = get_cpu_gdt_table(cpu);
85092+ gdt[GDT_ENTRY_KERNEL_DS].type = 3;
85093+ gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
85094+ gdt[GDT_ENTRY_DEFAULT_USER_CS].limit = 0xf;
85095+ gdt[GDT_ENTRY_DEFAULT_USER_DS].limit = 0xf;
85096+ }
85097+ loadsegment(ds, __KERNEL_DS);
85098+ loadsegment(es, __KERNEL_DS);
85099+ loadsegment(ss, __KERNEL_DS);
85100+#else
85101+ memcpy(pax_enter_kernel_user, (unsigned char []){0xc3}, 1);
85102+ memcpy(pax_exit_kernel_user, (unsigned char []){0xc3}, 1);
85103+ clone_pgd_mask = ~(pgdval_t)0UL;
85104+ pax_user_shadow_base = 0UL;
85105+ setup_clear_cpu_cap(X86_FEATURE_PCID);
85106+ setup_clear_cpu_cap(X86_FEATURE_INVPCID);
85107+#endif
85108+
85109+ return 0;
85110+}
85111+early_param("pax_nouderef", setup_pax_nouderef);
85112+
85113+#ifdef CONFIG_X86_64
85114+static int __init setup_pax_weakuderef(char *str)
85115+{
85116+ if (clone_pgd_mask != ~(pgdval_t)0UL)
85117+ pax_user_shadow_base = 1UL << TASK_SIZE_MAX_SHIFT;
85118+ return 1;
85119+}
85120+__setup("pax_weakuderef", setup_pax_weakuderef);
85121+#endif
85122+#endif
85123+
85124+#ifdef CONFIG_PAX_SOFTMODE
85125+int pax_softmode;
85126+
85127+static int __init setup_pax_softmode(char *str)
85128+{
85129+ get_option(&str, &pax_softmode);
85130+ return 1;
85131+}
85132+__setup("pax_softmode=", setup_pax_softmode);
85133+#endif
85134+
85135 static const char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
85136 const char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
85137 static const char *panic_later, *panic_param;
85138@@ -688,25 +759,24 @@ int __init_or_module do_one_initcall(initcall_t fn)
85139 {
85140 int count = preempt_count();
85141 int ret;
85142- char msgbuf[64];
85143+ const char *msg1 = "", *msg2 = "";
85144
85145 if (initcall_debug)
85146 ret = do_one_initcall_debug(fn);
85147 else
85148 ret = fn();
85149
85150- msgbuf[0] = 0;
85151-
85152 if (preempt_count() != count) {
85153- sprintf(msgbuf, "preemption imbalance ");
85154+ msg1 = " preemption imbalance";
85155 preempt_count_set(count);
85156 }
85157 if (irqs_disabled()) {
85158- strlcat(msgbuf, "disabled interrupts ", sizeof(msgbuf));
85159+ msg2 = " disabled interrupts";
85160 local_irq_enable();
85161 }
85162- WARN(msgbuf[0], "initcall %pF returned with %s\n", fn, msgbuf);
85163+ WARN(*msg1 || *msg2, "initcall %pF returned with%s%s\n", fn, msg1, msg2);
85164
85165+ add_latent_entropy();
85166 return ret;
85167 }
85168
85169@@ -813,8 +883,8 @@ static int run_init_process(const char *init_filename)
85170 {
85171 argv_init[0] = init_filename;
85172 return do_execve(getname_kernel(init_filename),
85173- (const char __user *const __user *)argv_init,
85174- (const char __user *const __user *)envp_init);
85175+ (const char __user *const __force_user *)argv_init,
85176+ (const char __user *const __force_user *)envp_init);
85177 }
85178
85179 static int try_to_run_init_process(const char *init_filename)
85180@@ -831,6 +901,10 @@ static int try_to_run_init_process(const char *init_filename)
85181 return ret;
85182 }
85183
85184+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
85185+extern int gr_init_ran;
85186+#endif
85187+
85188 static noinline void __init kernel_init_freeable(void);
85189
85190 static int __ref kernel_init(void *unused)
85191@@ -855,6 +929,11 @@ static int __ref kernel_init(void *unused)
85192 ramdisk_execute_command, ret);
85193 }
85194
85195+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
85196+ /* if no initrd was used, be extra sure we enforce chroot restrictions */
85197+ gr_init_ran = 1;
85198+#endif
85199+
85200 /*
85201 * We try each of these until one succeeds.
85202 *
85203@@ -910,7 +989,7 @@ static noinline void __init kernel_init_freeable(void)
85204 do_basic_setup();
85205
85206 /* Open the /dev/console on the rootfs, this should never fail */
85207- if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
85208+ if (sys_open((const char __force_user *) "/dev/console", O_RDWR, 0) < 0)
85209 pr_err("Warning: unable to open an initial console.\n");
85210
85211 (void) sys_dup(0);
85212@@ -923,11 +1002,13 @@ static noinline void __init kernel_init_freeable(void)
85213 if (!ramdisk_execute_command)
85214 ramdisk_execute_command = "/init";
85215
85216- if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
85217+ if (sys_access((const char __force_user *) ramdisk_execute_command, 0) != 0) {
85218 ramdisk_execute_command = NULL;
85219 prepare_namespace();
85220 }
85221
85222+ grsecurity_init();
85223+
85224 /*
85225 * Ok, we have completed the initial bootup, and
85226 * we're essentially up and running. Get rid of the
85227diff --git a/ipc/compat.c b/ipc/compat.c
85228index f486b00..442867f 100644
85229--- a/ipc/compat.c
85230+++ b/ipc/compat.c
85231@@ -399,7 +399,7 @@ COMPAT_SYSCALL_DEFINE6(ipc, u32, call, int, first, int, second,
85232 COMPAT_SHMLBA);
85233 if (err < 0)
85234 return err;
85235- return put_user(raddr, (compat_ulong_t *)compat_ptr(third));
85236+ return put_user(raddr, (compat_ulong_t __user *)compat_ptr(third));
85237 }
85238 case SHMDT:
85239 return sys_shmdt(compat_ptr(ptr));
85240diff --git a/ipc/ipc_sysctl.c b/ipc/ipc_sysctl.c
85241index 1702864..797fa84 100644
85242--- a/ipc/ipc_sysctl.c
85243+++ b/ipc/ipc_sysctl.c
85244@@ -30,7 +30,7 @@ static void *get_ipc(ctl_table *table)
85245 static int proc_ipc_dointvec(ctl_table *table, int write,
85246 void __user *buffer, size_t *lenp, loff_t *ppos)
85247 {
85248- struct ctl_table ipc_table;
85249+ ctl_table_no_const ipc_table;
85250
85251 memcpy(&ipc_table, table, sizeof(ipc_table));
85252 ipc_table.data = get_ipc(table);
85253@@ -41,7 +41,7 @@ static int proc_ipc_dointvec(ctl_table *table, int write,
85254 static int proc_ipc_dointvec_minmax(ctl_table *table, int write,
85255 void __user *buffer, size_t *lenp, loff_t *ppos)
85256 {
85257- struct ctl_table ipc_table;
85258+ ctl_table_no_const ipc_table;
85259
85260 memcpy(&ipc_table, table, sizeof(ipc_table));
85261 ipc_table.data = get_ipc(table);
85262@@ -65,7 +65,7 @@ static int proc_ipc_dointvec_minmax_orphans(ctl_table *table, int write,
85263 static int proc_ipc_callback_dointvec_minmax(ctl_table *table, int write,
85264 void __user *buffer, size_t *lenp, loff_t *ppos)
85265 {
85266- struct ctl_table ipc_table;
85267+ ctl_table_no_const ipc_table;
85268 size_t lenp_bef = *lenp;
85269 int rc;
85270
85271@@ -88,7 +88,7 @@ static int proc_ipc_callback_dointvec_minmax(ctl_table *table, int write,
85272 static int proc_ipc_doulongvec_minmax(ctl_table *table, int write,
85273 void __user *buffer, size_t *lenp, loff_t *ppos)
85274 {
85275- struct ctl_table ipc_table;
85276+ ctl_table_no_const ipc_table;
85277 memcpy(&ipc_table, table, sizeof(ipc_table));
85278 ipc_table.data = get_ipc(table);
85279
85280@@ -122,7 +122,7 @@ static void ipc_auto_callback(int val)
85281 static int proc_ipcauto_dointvec_minmax(ctl_table *table, int write,
85282 void __user *buffer, size_t *lenp, loff_t *ppos)
85283 {
85284- struct ctl_table ipc_table;
85285+ ctl_table_no_const ipc_table;
85286 size_t lenp_bef = *lenp;
85287 int oldval;
85288 int rc;
85289diff --git a/ipc/mq_sysctl.c b/ipc/mq_sysctl.c
85290index 5bb8bfe..a38ec05 100644
85291--- a/ipc/mq_sysctl.c
85292+++ b/ipc/mq_sysctl.c
85293@@ -25,7 +25,7 @@ static void *get_mq(ctl_table *table)
85294 static int proc_mq_dointvec(ctl_table *table, int write,
85295 void __user *buffer, size_t *lenp, loff_t *ppos)
85296 {
85297- struct ctl_table mq_table;
85298+ ctl_table_no_const mq_table;
85299 memcpy(&mq_table, table, sizeof(mq_table));
85300 mq_table.data = get_mq(table);
85301
85302@@ -35,7 +35,7 @@ static int proc_mq_dointvec(ctl_table *table, int write,
85303 static int proc_mq_dointvec_minmax(ctl_table *table, int write,
85304 void __user *buffer, size_t *lenp, loff_t *ppos)
85305 {
85306- struct ctl_table mq_table;
85307+ ctl_table_no_const mq_table;
85308 memcpy(&mq_table, table, sizeof(mq_table));
85309 mq_table.data = get_mq(table);
85310
85311diff --git a/ipc/mqueue.c b/ipc/mqueue.c
85312index c3b3117..1efa933 100644
85313--- a/ipc/mqueue.c
85314+++ b/ipc/mqueue.c
85315@@ -278,6 +278,7 @@ static struct inode *mqueue_get_inode(struct super_block *sb,
85316 mq_bytes = mq_treesize + (info->attr.mq_maxmsg *
85317 info->attr.mq_msgsize);
85318
85319+ gr_learn_resource(current, RLIMIT_MSGQUEUE, u->mq_bytes + mq_bytes, 1);
85320 spin_lock(&mq_lock);
85321 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
85322 u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE)) {
85323diff --git a/ipc/msg.c b/ipc/msg.c
85324index 6498531..b0ff3c8 100644
85325--- a/ipc/msg.c
85326+++ b/ipc/msg.c
85327@@ -303,18 +303,19 @@ static inline int msg_security(struct kern_ipc_perm *ipcp, int msgflg)
85328 return security_msg_queue_associate(msq, msgflg);
85329 }
85330
85331+static struct ipc_ops msg_ops = {
85332+ .getnew = newque,
85333+ .associate = msg_security,
85334+ .more_checks = NULL
85335+};
85336+
85337 SYSCALL_DEFINE2(msgget, key_t, key, int, msgflg)
85338 {
85339 struct ipc_namespace *ns;
85340- struct ipc_ops msg_ops;
85341 struct ipc_params msg_params;
85342
85343 ns = current->nsproxy->ipc_ns;
85344
85345- msg_ops.getnew = newque;
85346- msg_ops.associate = msg_security;
85347- msg_ops.more_checks = NULL;
85348-
85349 msg_params.key = key;
85350 msg_params.flg = msgflg;
85351
85352diff --git a/ipc/sem.c b/ipc/sem.c
85353index bee5554..e9af81dd 100644
85354--- a/ipc/sem.c
85355+++ b/ipc/sem.c
85356@@ -561,10 +561,15 @@ static inline int sem_more_checks(struct kern_ipc_perm *ipcp,
85357 return 0;
85358 }
85359
85360+static struct ipc_ops sem_ops = {
85361+ .getnew = newary,
85362+ .associate = sem_security,
85363+ .more_checks = sem_more_checks
85364+};
85365+
85366 SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
85367 {
85368 struct ipc_namespace *ns;
85369- struct ipc_ops sem_ops;
85370 struct ipc_params sem_params;
85371
85372 ns = current->nsproxy->ipc_ns;
85373@@ -572,10 +577,6 @@ SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
85374 if (nsems < 0 || nsems > ns->sc_semmsl)
85375 return -EINVAL;
85376
85377- sem_ops.getnew = newary;
85378- sem_ops.associate = sem_security;
85379- sem_ops.more_checks = sem_more_checks;
85380-
85381 sem_params.key = key;
85382 sem_params.flg = semflg;
85383 sem_params.u.nsems = nsems;
85384diff --git a/ipc/shm.c b/ipc/shm.c
85385index 7645961..afc7f02 100644
85386--- a/ipc/shm.c
85387+++ b/ipc/shm.c
85388@@ -72,6 +72,14 @@ static void shm_destroy(struct ipc_namespace *ns, struct shmid_kernel *shp);
85389 static int sysvipc_shm_proc_show(struct seq_file *s, void *it);
85390 #endif
85391
85392+#ifdef CONFIG_GRKERNSEC
85393+extern int gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
85394+ const time_t shm_createtime, const kuid_t cuid,
85395+ const int shmid);
85396+extern int gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
85397+ const time_t shm_createtime);
85398+#endif
85399+
85400 void shm_init_ns(struct ipc_namespace *ns)
85401 {
85402 ns->shm_ctlmax = SHMMAX;
85403@@ -553,6 +561,14 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params)
85404 shp->shm_lprid = 0;
85405 shp->shm_atim = shp->shm_dtim = 0;
85406 shp->shm_ctim = get_seconds();
85407+#ifdef CONFIG_GRKERNSEC
85408+ {
85409+ struct timespec timeval;
85410+ do_posix_clock_monotonic_gettime(&timeval);
85411+
85412+ shp->shm_createtime = timeval.tv_sec;
85413+ }
85414+#endif
85415 shp->shm_segsz = size;
85416 shp->shm_nattch = 0;
85417 shp->shm_file = file;
85418@@ -606,18 +622,19 @@ static inline int shm_more_checks(struct kern_ipc_perm *ipcp,
85419 return 0;
85420 }
85421
85422+static struct ipc_ops shm_ops = {
85423+ .getnew = newseg,
85424+ .associate = shm_security,
85425+ .more_checks = shm_more_checks
85426+};
85427+
85428 SYSCALL_DEFINE3(shmget, key_t, key, size_t, size, int, shmflg)
85429 {
85430 struct ipc_namespace *ns;
85431- struct ipc_ops shm_ops;
85432 struct ipc_params shm_params;
85433
85434 ns = current->nsproxy->ipc_ns;
85435
85436- shm_ops.getnew = newseg;
85437- shm_ops.associate = shm_security;
85438- shm_ops.more_checks = shm_more_checks;
85439-
85440 shm_params.key = key;
85441 shm_params.flg = shmflg;
85442 shm_params.u.size = size;
85443@@ -1088,6 +1105,12 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
85444 f_mode = FMODE_READ | FMODE_WRITE;
85445 }
85446 if (shmflg & SHM_EXEC) {
85447+
85448+#ifdef CONFIG_PAX_MPROTECT
85449+ if (current->mm->pax_flags & MF_PAX_MPROTECT)
85450+ goto out;
85451+#endif
85452+
85453 prot |= PROT_EXEC;
85454 acc_mode |= S_IXUGO;
85455 }
85456@@ -1112,6 +1135,15 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
85457 if (err)
85458 goto out_unlock;
85459
85460+#ifdef CONFIG_GRKERNSEC
85461+ if (!gr_handle_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime,
85462+ shp->shm_perm.cuid, shmid) ||
85463+ !gr_chroot_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime)) {
85464+ err = -EACCES;
85465+ goto out_unlock;
85466+ }
85467+#endif
85468+
85469 ipc_lock_object(&shp->shm_perm);
85470
85471 /* check if shm_destroy() is tearing down shp */
85472@@ -1124,6 +1156,9 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
85473 path = shp->shm_file->f_path;
85474 path_get(&path);
85475 shp->shm_nattch++;
85476+#ifdef CONFIG_GRKERNSEC
85477+ shp->shm_lapid = current->pid;
85478+#endif
85479 size = i_size_read(path.dentry->d_inode);
85480 ipc_unlock_object(&shp->shm_perm);
85481 rcu_read_unlock();
85482diff --git a/ipc/util.c b/ipc/util.c
85483index e1b4c6d..8174204 100644
85484--- a/ipc/util.c
85485+++ b/ipc/util.c
85486@@ -71,6 +71,8 @@ struct ipc_proc_iface {
85487 int (*show)(struct seq_file *, void *);
85488 };
85489
85490+extern int gr_ipc_permitted(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp, int requested_mode, int granted_mode);
85491+
85492 static void ipc_memory_notifier(struct work_struct *work)
85493 {
85494 ipcns_notify(IPCNS_MEMCHANGED);
85495@@ -537,6 +539,10 @@ int ipcperms(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp, short flag)
85496 granted_mode >>= 6;
85497 else if (in_group_p(ipcp->cgid) || in_group_p(ipcp->gid))
85498 granted_mode >>= 3;
85499+
85500+ if (!gr_ipc_permitted(ns, ipcp, requested_mode, granted_mode))
85501+ return -1;
85502+
85503 /* is there some bit set in requested_mode but not in granted_mode? */
85504 if ((requested_mode & ~granted_mode & 0007) &&
85505 !ns_capable(ns->user_ns, CAP_IPC_OWNER))
85506diff --git a/kernel/acct.c b/kernel/acct.c
85507index 8d6e145..33e0b1e 100644
85508--- a/kernel/acct.c
85509+++ b/kernel/acct.c
85510@@ -556,7 +556,7 @@ static void do_acct_process(struct bsd_acct_struct *acct,
85511 */
85512 flim = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
85513 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY;
85514- file->f_op->write(file, (char *)&ac,
85515+ file->f_op->write(file, (char __force_user *)&ac,
85516 sizeof(acct_t), &file->f_pos);
85517 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = flim;
85518 set_fs(fs);
85519diff --git a/kernel/audit.c b/kernel/audit.c
85520index 95a20f3..e1cb300 100644
85521--- a/kernel/audit.c
85522+++ b/kernel/audit.c
85523@@ -122,7 +122,7 @@ u32 audit_sig_sid = 0;
85524 3) suppressed due to audit_rate_limit
85525 4) suppressed due to audit_backlog_limit
85526 */
85527-static atomic_t audit_lost = ATOMIC_INIT(0);
85528+static atomic_unchecked_t audit_lost = ATOMIC_INIT(0);
85529
85530 /* The netlink socket. */
85531 static struct sock *audit_sock;
85532@@ -256,7 +256,7 @@ void audit_log_lost(const char *message)
85533 unsigned long now;
85534 int print;
85535
85536- atomic_inc(&audit_lost);
85537+ atomic_inc_unchecked(&audit_lost);
85538
85539 print = (audit_failure == AUDIT_FAIL_PANIC || !audit_rate_limit);
85540
85541@@ -273,7 +273,7 @@ void audit_log_lost(const char *message)
85542 if (print) {
85543 if (printk_ratelimit())
85544 pr_warn("audit_lost=%u audit_rate_limit=%u audit_backlog_limit=%u\n",
85545- atomic_read(&audit_lost),
85546+ atomic_read_unchecked(&audit_lost),
85547 audit_rate_limit,
85548 audit_backlog_limit);
85549 audit_panic(message);
85550@@ -803,7 +803,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
85551 s.pid = audit_pid;
85552 s.rate_limit = audit_rate_limit;
85553 s.backlog_limit = audit_backlog_limit;
85554- s.lost = atomic_read(&audit_lost);
85555+ s.lost = atomic_read_unchecked(&audit_lost);
85556 s.backlog = skb_queue_len(&audit_skb_queue);
85557 s.version = AUDIT_VERSION_LATEST;
85558 s.backlog_wait_time = audit_backlog_wait_time;
85559diff --git a/kernel/auditsc.c b/kernel/auditsc.c
85560index 7aef2f4..db6ced2 100644
85561--- a/kernel/auditsc.c
85562+++ b/kernel/auditsc.c
85563@@ -1945,7 +1945,7 @@ int auditsc_get_stamp(struct audit_context *ctx,
85564 }
85565
85566 /* global counter which is incremented every time something logs in */
85567-static atomic_t session_id = ATOMIC_INIT(0);
85568+static atomic_unchecked_t session_id = ATOMIC_INIT(0);
85569
85570 static int audit_set_loginuid_perm(kuid_t loginuid)
85571 {
85572@@ -2014,7 +2014,7 @@ int audit_set_loginuid(kuid_t loginuid)
85573
85574 /* are we setting or clearing? */
85575 if (uid_valid(loginuid))
85576- sessionid = (unsigned int)atomic_inc_return(&session_id);
85577+ sessionid = (unsigned int)atomic_inc_return_unchecked(&session_id);
85578
85579 task->sessionid = sessionid;
85580 task->loginuid = loginuid;
85581diff --git a/kernel/capability.c b/kernel/capability.c
85582index 34019c5..363f279 100644
85583--- a/kernel/capability.c
85584+++ b/kernel/capability.c
85585@@ -202,6 +202,9 @@ SYSCALL_DEFINE2(capget, cap_user_header_t, header, cap_user_data_t, dataptr)
85586 * before modification is attempted and the application
85587 * fails.
85588 */
85589+ if (tocopy > ARRAY_SIZE(kdata))
85590+ return -EFAULT;
85591+
85592 if (copy_to_user(dataptr, kdata, tocopy
85593 * sizeof(struct __user_cap_data_struct))) {
85594 return -EFAULT;
85595@@ -303,10 +306,11 @@ bool has_ns_capability(struct task_struct *t,
85596 int ret;
85597
85598 rcu_read_lock();
85599- ret = security_capable(__task_cred(t), ns, cap);
85600+ ret = security_capable(__task_cred(t), ns, cap) == 0 &&
85601+ gr_task_is_capable(t, __task_cred(t), cap);
85602 rcu_read_unlock();
85603
85604- return (ret == 0);
85605+ return ret;
85606 }
85607
85608 /**
85609@@ -343,10 +347,10 @@ bool has_ns_capability_noaudit(struct task_struct *t,
85610 int ret;
85611
85612 rcu_read_lock();
85613- ret = security_capable_noaudit(__task_cred(t), ns, cap);
85614+ ret = security_capable_noaudit(__task_cred(t), ns, cap) == 0 && gr_task_is_capable_nolog(t, cap);
85615 rcu_read_unlock();
85616
85617- return (ret == 0);
85618+ return ret;
85619 }
85620
85621 /**
85622@@ -384,7 +388,7 @@ bool ns_capable(struct user_namespace *ns, int cap)
85623 BUG();
85624 }
85625
85626- if (security_capable(current_cred(), ns, cap) == 0) {
85627+ if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable(cap)) {
85628 current->flags |= PF_SUPERPRIV;
85629 return true;
85630 }
85631@@ -392,6 +396,21 @@ bool ns_capable(struct user_namespace *ns, int cap)
85632 }
85633 EXPORT_SYMBOL(ns_capable);
85634
85635+bool ns_capable_nolog(struct user_namespace *ns, int cap)
85636+{
85637+ if (unlikely(!cap_valid(cap))) {
85638+ printk(KERN_CRIT "capable_nolog() called with invalid cap=%u\n", cap);
85639+ BUG();
85640+ }
85641+
85642+ if (security_capable_noaudit(current_cred(), ns, cap) == 0 && gr_is_capable_nolog(cap)) {
85643+ current->flags |= PF_SUPERPRIV;
85644+ return true;
85645+ }
85646+ return false;
85647+}
85648+EXPORT_SYMBOL(ns_capable_nolog);
85649+
85650 /**
85651 * file_ns_capable - Determine if the file's opener had a capability in effect
85652 * @file: The file we want to check
85653@@ -432,6 +451,12 @@ bool capable(int cap)
85654 }
85655 EXPORT_SYMBOL(capable);
85656
85657+bool capable_nolog(int cap)
85658+{
85659+ return ns_capable_nolog(&init_user_ns, cap);
85660+}
85661+EXPORT_SYMBOL(capable_nolog);
85662+
85663 /**
85664 * inode_capable - Check superior capability over inode
85665 * @inode: The inode in question
85666@@ -453,3 +478,11 @@ bool inode_capable(const struct inode *inode, int cap)
85667 return ns_capable(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
85668 }
85669 EXPORT_SYMBOL(inode_capable);
85670+
85671+bool inode_capable_nolog(const struct inode *inode, int cap)
85672+{
85673+ struct user_namespace *ns = current_user_ns();
85674+
85675+ return ns_capable_nolog(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
85676+}
85677+EXPORT_SYMBOL(inode_capable_nolog);
85678diff --git a/kernel/cgroup.c b/kernel/cgroup.c
85679index 0c753dd..dd7d3d6 100644
85680--- a/kernel/cgroup.c
85681+++ b/kernel/cgroup.c
85682@@ -5372,7 +5372,7 @@ static int cgroup_css_links_read(struct seq_file *seq, void *v)
85683 struct css_set *cset = link->cset;
85684 struct task_struct *task;
85685 int count = 0;
85686- seq_printf(seq, "css_set %p\n", cset);
85687+ seq_printf(seq, "css_set %pK\n", cset);
85688 list_for_each_entry(task, &cset->tasks, cg_list) {
85689 if (count++ > MAX_TASKS_SHOWN_PER_CSS) {
85690 seq_puts(seq, " ...\n");
85691diff --git a/kernel/compat.c b/kernel/compat.c
85692index 0a09e48..b46b3d78 100644
85693--- a/kernel/compat.c
85694+++ b/kernel/compat.c
85695@@ -13,6 +13,7 @@
85696
85697 #include <linux/linkage.h>
85698 #include <linux/compat.h>
85699+#include <linux/module.h>
85700 #include <linux/errno.h>
85701 #include <linux/time.h>
85702 #include <linux/signal.h>
85703@@ -220,7 +221,7 @@ static long compat_nanosleep_restart(struct restart_block *restart)
85704 mm_segment_t oldfs;
85705 long ret;
85706
85707- restart->nanosleep.rmtp = (struct timespec __user *) &rmt;
85708+ restart->nanosleep.rmtp = (struct timespec __force_user *) &rmt;
85709 oldfs = get_fs();
85710 set_fs(KERNEL_DS);
85711 ret = hrtimer_nanosleep_restart(restart);
85712@@ -252,7 +253,7 @@ asmlinkage long compat_sys_nanosleep(struct compat_timespec __user *rqtp,
85713 oldfs = get_fs();
85714 set_fs(KERNEL_DS);
85715 ret = hrtimer_nanosleep(&tu,
85716- rmtp ? (struct timespec __user *)&rmt : NULL,
85717+ rmtp ? (struct timespec __force_user *)&rmt : NULL,
85718 HRTIMER_MODE_REL, CLOCK_MONOTONIC);
85719 set_fs(oldfs);
85720
85721@@ -361,7 +362,7 @@ asmlinkage long compat_sys_sigpending(compat_old_sigset_t __user *set)
85722 mm_segment_t old_fs = get_fs();
85723
85724 set_fs(KERNEL_DS);
85725- ret = sys_sigpending((old_sigset_t __user *) &s);
85726+ ret = sys_sigpending((old_sigset_t __force_user *) &s);
85727 set_fs(old_fs);
85728 if (ret == 0)
85729 ret = put_user(s, set);
85730@@ -451,7 +452,7 @@ asmlinkage long compat_sys_old_getrlimit(unsigned int resource,
85731 mm_segment_t old_fs = get_fs();
85732
85733 set_fs(KERNEL_DS);
85734- ret = sys_old_getrlimit(resource, &r);
85735+ ret = sys_old_getrlimit(resource, (struct rlimit __force_user *)&r);
85736 set_fs(old_fs);
85737
85738 if (!ret) {
85739@@ -533,8 +534,8 @@ COMPAT_SYSCALL_DEFINE4(wait4,
85740 set_fs (KERNEL_DS);
85741 ret = sys_wait4(pid,
85742 (stat_addr ?
85743- (unsigned int __user *) &status : NULL),
85744- options, (struct rusage __user *) &r);
85745+ (unsigned int __force_user *) &status : NULL),
85746+ options, (struct rusage __force_user *) &r);
85747 set_fs (old_fs);
85748
85749 if (ret > 0) {
85750@@ -560,8 +561,8 @@ COMPAT_SYSCALL_DEFINE5(waitid,
85751 memset(&info, 0, sizeof(info));
85752
85753 set_fs(KERNEL_DS);
85754- ret = sys_waitid(which, pid, (siginfo_t __user *)&info, options,
85755- uru ? (struct rusage __user *)&ru : NULL);
85756+ ret = sys_waitid(which, pid, (siginfo_t __force_user *)&info, options,
85757+ uru ? (struct rusage __force_user *)&ru : NULL);
85758 set_fs(old_fs);
85759
85760 if ((ret < 0) || (info.si_signo == 0))
85761@@ -695,8 +696,8 @@ long compat_sys_timer_settime(timer_t timer_id, int flags,
85762 oldfs = get_fs();
85763 set_fs(KERNEL_DS);
85764 err = sys_timer_settime(timer_id, flags,
85765- (struct itimerspec __user *) &newts,
85766- (struct itimerspec __user *) &oldts);
85767+ (struct itimerspec __force_user *) &newts,
85768+ (struct itimerspec __force_user *) &oldts);
85769 set_fs(oldfs);
85770 if (!err && old && put_compat_itimerspec(old, &oldts))
85771 return -EFAULT;
85772@@ -713,7 +714,7 @@ long compat_sys_timer_gettime(timer_t timer_id,
85773 oldfs = get_fs();
85774 set_fs(KERNEL_DS);
85775 err = sys_timer_gettime(timer_id,
85776- (struct itimerspec __user *) &ts);
85777+ (struct itimerspec __force_user *) &ts);
85778 set_fs(oldfs);
85779 if (!err && put_compat_itimerspec(setting, &ts))
85780 return -EFAULT;
85781@@ -732,7 +733,7 @@ long compat_sys_clock_settime(clockid_t which_clock,
85782 oldfs = get_fs();
85783 set_fs(KERNEL_DS);
85784 err = sys_clock_settime(which_clock,
85785- (struct timespec __user *) &ts);
85786+ (struct timespec __force_user *) &ts);
85787 set_fs(oldfs);
85788 return err;
85789 }
85790@@ -747,7 +748,7 @@ long compat_sys_clock_gettime(clockid_t which_clock,
85791 oldfs = get_fs();
85792 set_fs(KERNEL_DS);
85793 err = sys_clock_gettime(which_clock,
85794- (struct timespec __user *) &ts);
85795+ (struct timespec __force_user *) &ts);
85796 set_fs(oldfs);
85797 if (!err && put_compat_timespec(&ts, tp))
85798 return -EFAULT;
85799@@ -767,7 +768,7 @@ long compat_sys_clock_adjtime(clockid_t which_clock,
85800
85801 oldfs = get_fs();
85802 set_fs(KERNEL_DS);
85803- ret = sys_clock_adjtime(which_clock, (struct timex __user *) &txc);
85804+ ret = sys_clock_adjtime(which_clock, (struct timex __force_user *) &txc);
85805 set_fs(oldfs);
85806
85807 err = compat_put_timex(utp, &txc);
85808@@ -787,7 +788,7 @@ long compat_sys_clock_getres(clockid_t which_clock,
85809 oldfs = get_fs();
85810 set_fs(KERNEL_DS);
85811 err = sys_clock_getres(which_clock,
85812- (struct timespec __user *) &ts);
85813+ (struct timespec __force_user *) &ts);
85814 set_fs(oldfs);
85815 if (!err && tp && put_compat_timespec(&ts, tp))
85816 return -EFAULT;
85817@@ -799,9 +800,9 @@ static long compat_clock_nanosleep_restart(struct restart_block *restart)
85818 long err;
85819 mm_segment_t oldfs;
85820 struct timespec tu;
85821- struct compat_timespec *rmtp = restart->nanosleep.compat_rmtp;
85822+ struct compat_timespec __user *rmtp = restart->nanosleep.compat_rmtp;
85823
85824- restart->nanosleep.rmtp = (struct timespec __user *) &tu;
85825+ restart->nanosleep.rmtp = (struct timespec __force_user *) &tu;
85826 oldfs = get_fs();
85827 set_fs(KERNEL_DS);
85828 err = clock_nanosleep_restart(restart);
85829@@ -833,8 +834,8 @@ long compat_sys_clock_nanosleep(clockid_t which_clock, int flags,
85830 oldfs = get_fs();
85831 set_fs(KERNEL_DS);
85832 err = sys_clock_nanosleep(which_clock, flags,
85833- (struct timespec __user *) &in,
85834- (struct timespec __user *) &out);
85835+ (struct timespec __force_user *) &in,
85836+ (struct timespec __force_user *) &out);
85837 set_fs(oldfs);
85838
85839 if ((err == -ERESTART_RESTARTBLOCK) && rmtp &&
85840@@ -1128,7 +1129,7 @@ COMPAT_SYSCALL_DEFINE2(sched_rr_get_interval,
85841 mm_segment_t old_fs = get_fs();
85842
85843 set_fs(KERNEL_DS);
85844- ret = sys_sched_rr_get_interval(pid, (struct timespec __user *)&t);
85845+ ret = sys_sched_rr_get_interval(pid, (struct timespec __force_user *)&t);
85846 set_fs(old_fs);
85847 if (put_compat_timespec(&t, interval))
85848 return -EFAULT;
85849diff --git a/kernel/configs.c b/kernel/configs.c
85850index c18b1f1..b9a0132 100644
85851--- a/kernel/configs.c
85852+++ b/kernel/configs.c
85853@@ -74,8 +74,19 @@ static int __init ikconfig_init(void)
85854 struct proc_dir_entry *entry;
85855
85856 /* create the current config file */
85857+#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
85858+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_HIDESYM)
85859+ entry = proc_create("config.gz", S_IFREG | S_IRUSR, NULL,
85860+ &ikconfig_file_ops);
85861+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
85862+ entry = proc_create("config.gz", S_IFREG | S_IRUSR | S_IRGRP, NULL,
85863+ &ikconfig_file_ops);
85864+#endif
85865+#else
85866 entry = proc_create("config.gz", S_IFREG | S_IRUGO, NULL,
85867 &ikconfig_file_ops);
85868+#endif
85869+
85870 if (!entry)
85871 return -ENOMEM;
85872
85873diff --git a/kernel/cred.c b/kernel/cred.c
85874index e0573a4..3874e41 100644
85875--- a/kernel/cred.c
85876+++ b/kernel/cred.c
85877@@ -164,6 +164,16 @@ void exit_creds(struct task_struct *tsk)
85878 validate_creds(cred);
85879 alter_cred_subscribers(cred, -1);
85880 put_cred(cred);
85881+
85882+#ifdef CONFIG_GRKERNSEC_SETXID
85883+ cred = (struct cred *) tsk->delayed_cred;
85884+ if (cred != NULL) {
85885+ tsk->delayed_cred = NULL;
85886+ validate_creds(cred);
85887+ alter_cred_subscribers(cred, -1);
85888+ put_cred(cred);
85889+ }
85890+#endif
85891 }
85892
85893 /**
85894@@ -411,7 +421,7 @@ static bool cred_cap_issubset(const struct cred *set, const struct cred *subset)
85895 * Always returns 0 thus allowing this function to be tail-called at the end
85896 * of, say, sys_setgid().
85897 */
85898-int commit_creds(struct cred *new)
85899+static int __commit_creds(struct cred *new)
85900 {
85901 struct task_struct *task = current;
85902 const struct cred *old = task->real_cred;
85903@@ -430,6 +440,8 @@ int commit_creds(struct cred *new)
85904
85905 get_cred(new); /* we will require a ref for the subj creds too */
85906
85907+ gr_set_role_label(task, new->uid, new->gid);
85908+
85909 /* dumpability changes */
85910 if (!uid_eq(old->euid, new->euid) ||
85911 !gid_eq(old->egid, new->egid) ||
85912@@ -479,6 +491,102 @@ int commit_creds(struct cred *new)
85913 put_cred(old);
85914 return 0;
85915 }
85916+#ifdef CONFIG_GRKERNSEC_SETXID
85917+extern int set_user(struct cred *new);
85918+
85919+void gr_delayed_cred_worker(void)
85920+{
85921+ const struct cred *new = current->delayed_cred;
85922+ struct cred *ncred;
85923+
85924+ current->delayed_cred = NULL;
85925+
85926+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID) && new != NULL) {
85927+ // from doing get_cred on it when queueing this
85928+ put_cred(new);
85929+ return;
85930+ } else if (new == NULL)
85931+ return;
85932+
85933+ ncred = prepare_creds();
85934+ if (!ncred)
85935+ goto die;
85936+ // uids
85937+ ncred->uid = new->uid;
85938+ ncred->euid = new->euid;
85939+ ncred->suid = new->suid;
85940+ ncred->fsuid = new->fsuid;
85941+ // gids
85942+ ncred->gid = new->gid;
85943+ ncred->egid = new->egid;
85944+ ncred->sgid = new->sgid;
85945+ ncred->fsgid = new->fsgid;
85946+ // groups
85947+ if (set_groups(ncred, new->group_info) < 0) {
85948+ abort_creds(ncred);
85949+ goto die;
85950+ }
85951+ // caps
85952+ ncred->securebits = new->securebits;
85953+ ncred->cap_inheritable = new->cap_inheritable;
85954+ ncred->cap_permitted = new->cap_permitted;
85955+ ncred->cap_effective = new->cap_effective;
85956+ ncred->cap_bset = new->cap_bset;
85957+
85958+ if (set_user(ncred)) {
85959+ abort_creds(ncred);
85960+ goto die;
85961+ }
85962+
85963+ // from doing get_cred on it when queueing this
85964+ put_cred(new);
85965+
85966+ __commit_creds(ncred);
85967+ return;
85968+die:
85969+ // from doing get_cred on it when queueing this
85970+ put_cred(new);
85971+ do_group_exit(SIGKILL);
85972+}
85973+#endif
85974+
85975+int commit_creds(struct cred *new)
85976+{
85977+#ifdef CONFIG_GRKERNSEC_SETXID
85978+ int ret;
85979+ int schedule_it = 0;
85980+ struct task_struct *t;
85981+
85982+ /* we won't get called with tasklist_lock held for writing
85983+ and interrupts disabled as the cred struct in that case is
85984+ init_cred
85985+ */
85986+ if (grsec_enable_setxid && !current_is_single_threaded() &&
85987+ uid_eq(current_uid(), GLOBAL_ROOT_UID) &&
85988+ !uid_eq(new->uid, GLOBAL_ROOT_UID)) {
85989+ schedule_it = 1;
85990+ }
85991+ ret = __commit_creds(new);
85992+ if (schedule_it) {
85993+ rcu_read_lock();
85994+ read_lock(&tasklist_lock);
85995+ for (t = next_thread(current); t != current;
85996+ t = next_thread(t)) {
85997+ if (t->delayed_cred == NULL) {
85998+ t->delayed_cred = get_cred(new);
85999+ set_tsk_thread_flag(t, TIF_GRSEC_SETXID);
86000+ set_tsk_need_resched(t);
86001+ }
86002+ }
86003+ read_unlock(&tasklist_lock);
86004+ rcu_read_unlock();
86005+ }
86006+ return ret;
86007+#else
86008+ return __commit_creds(new);
86009+#endif
86010+}
86011+
86012 EXPORT_SYMBOL(commit_creds);
86013
86014 /**
86015diff --git a/kernel/debug/debug_core.c b/kernel/debug/debug_core.c
86016index 334b398..9145fb1 100644
86017--- a/kernel/debug/debug_core.c
86018+++ b/kernel/debug/debug_core.c
86019@@ -123,7 +123,7 @@ static DEFINE_RAW_SPINLOCK(dbg_slave_lock);
86020 */
86021 static atomic_t masters_in_kgdb;
86022 static atomic_t slaves_in_kgdb;
86023-static atomic_t kgdb_break_tasklet_var;
86024+static atomic_unchecked_t kgdb_break_tasklet_var;
86025 atomic_t kgdb_setting_breakpoint;
86026
86027 struct task_struct *kgdb_usethread;
86028@@ -133,7 +133,7 @@ int kgdb_single_step;
86029 static pid_t kgdb_sstep_pid;
86030
86031 /* to keep track of the CPU which is doing the single stepping*/
86032-atomic_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
86033+atomic_unchecked_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
86034
86035 /*
86036 * If you are debugging a problem where roundup (the collection of
86037@@ -541,7 +541,7 @@ return_normal:
86038 * kernel will only try for the value of sstep_tries before
86039 * giving up and continuing on.
86040 */
86041- if (atomic_read(&kgdb_cpu_doing_single_step) != -1 &&
86042+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1 &&
86043 (kgdb_info[cpu].task &&
86044 kgdb_info[cpu].task->pid != kgdb_sstep_pid) && --sstep_tries) {
86045 atomic_set(&kgdb_active, -1);
86046@@ -639,8 +639,8 @@ cpu_master_loop:
86047 }
86048
86049 kgdb_restore:
86050- if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
86051- int sstep_cpu = atomic_read(&kgdb_cpu_doing_single_step);
86052+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
86053+ int sstep_cpu = atomic_read_unchecked(&kgdb_cpu_doing_single_step);
86054 if (kgdb_info[sstep_cpu].task)
86055 kgdb_sstep_pid = kgdb_info[sstep_cpu].task->pid;
86056 else
86057@@ -917,18 +917,18 @@ static void kgdb_unregister_callbacks(void)
86058 static void kgdb_tasklet_bpt(unsigned long ing)
86059 {
86060 kgdb_breakpoint();
86061- atomic_set(&kgdb_break_tasklet_var, 0);
86062+ atomic_set_unchecked(&kgdb_break_tasklet_var, 0);
86063 }
86064
86065 static DECLARE_TASKLET(kgdb_tasklet_breakpoint, kgdb_tasklet_bpt, 0);
86066
86067 void kgdb_schedule_breakpoint(void)
86068 {
86069- if (atomic_read(&kgdb_break_tasklet_var) ||
86070+ if (atomic_read_unchecked(&kgdb_break_tasklet_var) ||
86071 atomic_read(&kgdb_active) != -1 ||
86072 atomic_read(&kgdb_setting_breakpoint))
86073 return;
86074- atomic_inc(&kgdb_break_tasklet_var);
86075+ atomic_inc_unchecked(&kgdb_break_tasklet_var);
86076 tasklet_schedule(&kgdb_tasklet_breakpoint);
86077 }
86078 EXPORT_SYMBOL_GPL(kgdb_schedule_breakpoint);
86079diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c
86080index 0b097c8..11dd5c5 100644
86081--- a/kernel/debug/kdb/kdb_main.c
86082+++ b/kernel/debug/kdb/kdb_main.c
86083@@ -1977,7 +1977,7 @@ static int kdb_lsmod(int argc, const char **argv)
86084 continue;
86085
86086 kdb_printf("%-20s%8u 0x%p ", mod->name,
86087- mod->core_size, (void *)mod);
86088+ mod->core_size_rx + mod->core_size_rw, (void *)mod);
86089 #ifdef CONFIG_MODULE_UNLOAD
86090 kdb_printf("%4ld ", module_refcount(mod));
86091 #endif
86092@@ -1987,7 +1987,7 @@ static int kdb_lsmod(int argc, const char **argv)
86093 kdb_printf(" (Loading)");
86094 else
86095 kdb_printf(" (Live)");
86096- kdb_printf(" 0x%p", mod->module_core);
86097+ kdb_printf(" 0x%p 0x%p", mod->module_core_rx, mod->module_core_rw);
86098
86099 #ifdef CONFIG_MODULE_UNLOAD
86100 {
86101diff --git a/kernel/events/core.c b/kernel/events/core.c
86102index fa0b2d4..67a1c7a 100644
86103--- a/kernel/events/core.c
86104+++ b/kernel/events/core.c
86105@@ -158,8 +158,15 @@ static struct srcu_struct pmus_srcu;
86106 * 0 - disallow raw tracepoint access for unpriv
86107 * 1 - disallow cpu events for unpriv
86108 * 2 - disallow kernel profiling for unpriv
86109+ * 3 - disallow all unpriv perf event use
86110 */
86111-int sysctl_perf_event_paranoid __read_mostly = 1;
86112+#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
86113+int sysctl_perf_event_legitimately_concerned __read_mostly = 3;
86114+#elif defined(CONFIG_GRKERNSEC_HIDESYM)
86115+int sysctl_perf_event_legitimately_concerned __read_mostly = 2;
86116+#else
86117+int sysctl_perf_event_legitimately_concerned __read_mostly = 1;
86118+#endif
86119
86120 /* Minimum for 512 kiB + 1 user control page */
86121 int sysctl_perf_event_mlock __read_mostly = 512 + (PAGE_SIZE / 1024); /* 'free' kiB per user */
86122@@ -185,7 +192,7 @@ void update_perf_cpu_limits(void)
86123
86124 tmp *= sysctl_perf_cpu_time_max_percent;
86125 do_div(tmp, 100);
86126- ACCESS_ONCE(perf_sample_allowed_ns) = tmp;
86127+ ACCESS_ONCE_RW(perf_sample_allowed_ns) = tmp;
86128 }
86129
86130 static int perf_rotate_context(struct perf_cpu_context *cpuctx);
86131@@ -272,7 +279,7 @@ void perf_sample_event_took(u64 sample_len_ns)
86132 update_perf_cpu_limits();
86133 }
86134
86135-static atomic64_t perf_event_id;
86136+static atomic64_unchecked_t perf_event_id;
86137
86138 static void cpu_ctx_sched_out(struct perf_cpu_context *cpuctx,
86139 enum event_type_t event_type);
86140@@ -2986,7 +2993,7 @@ static void __perf_event_read(void *info)
86141
86142 static inline u64 perf_event_count(struct perf_event *event)
86143 {
86144- return local64_read(&event->count) + atomic64_read(&event->child_count);
86145+ return local64_read(&event->count) + atomic64_read_unchecked(&event->child_count);
86146 }
86147
86148 static u64 perf_event_read(struct perf_event *event)
86149@@ -3354,9 +3361,9 @@ u64 perf_event_read_value(struct perf_event *event, u64 *enabled, u64 *running)
86150 mutex_lock(&event->child_mutex);
86151 total += perf_event_read(event);
86152 *enabled += event->total_time_enabled +
86153- atomic64_read(&event->child_total_time_enabled);
86154+ atomic64_read_unchecked(&event->child_total_time_enabled);
86155 *running += event->total_time_running +
86156- atomic64_read(&event->child_total_time_running);
86157+ atomic64_read_unchecked(&event->child_total_time_running);
86158
86159 list_for_each_entry(child, &event->child_list, child_list) {
86160 total += perf_event_read(child);
86161@@ -3785,10 +3792,10 @@ void perf_event_update_userpage(struct perf_event *event)
86162 userpg->offset -= local64_read(&event->hw.prev_count);
86163
86164 userpg->time_enabled = enabled +
86165- atomic64_read(&event->child_total_time_enabled);
86166+ atomic64_read_unchecked(&event->child_total_time_enabled);
86167
86168 userpg->time_running = running +
86169- atomic64_read(&event->child_total_time_running);
86170+ atomic64_read_unchecked(&event->child_total_time_running);
86171
86172 arch_perf_update_userpage(userpg, now);
86173
86174@@ -4339,7 +4346,7 @@ perf_output_sample_ustack(struct perf_output_handle *handle, u64 dump_size,
86175
86176 /* Data. */
86177 sp = perf_user_stack_pointer(regs);
86178- rem = __output_copy_user(handle, (void *) sp, dump_size);
86179+ rem = __output_copy_user(handle, (void __user *) sp, dump_size);
86180 dyn_size = dump_size - rem;
86181
86182 perf_output_skip(handle, rem);
86183@@ -4430,11 +4437,11 @@ static void perf_output_read_one(struct perf_output_handle *handle,
86184 values[n++] = perf_event_count(event);
86185 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
86186 values[n++] = enabled +
86187- atomic64_read(&event->child_total_time_enabled);
86188+ atomic64_read_unchecked(&event->child_total_time_enabled);
86189 }
86190 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
86191 values[n++] = running +
86192- atomic64_read(&event->child_total_time_running);
86193+ atomic64_read_unchecked(&event->child_total_time_running);
86194 }
86195 if (read_format & PERF_FORMAT_ID)
86196 values[n++] = primary_event_id(event);
86197@@ -6704,7 +6711,7 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu,
86198 event->parent = parent_event;
86199
86200 event->ns = get_pid_ns(task_active_pid_ns(current));
86201- event->id = atomic64_inc_return(&perf_event_id);
86202+ event->id = atomic64_inc_return_unchecked(&perf_event_id);
86203
86204 event->state = PERF_EVENT_STATE_INACTIVE;
86205
86206@@ -7004,6 +7011,11 @@ SYSCALL_DEFINE5(perf_event_open,
86207 if (flags & ~PERF_FLAG_ALL)
86208 return -EINVAL;
86209
86210+#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
86211+ if (perf_paranoid_any() && !capable(CAP_SYS_ADMIN))
86212+ return -EACCES;
86213+#endif
86214+
86215 err = perf_copy_attr(attr_uptr, &attr);
86216 if (err)
86217 return err;
86218@@ -7339,10 +7351,10 @@ static void sync_child_event(struct perf_event *child_event,
86219 /*
86220 * Add back the child's count to the parent's count:
86221 */
86222- atomic64_add(child_val, &parent_event->child_count);
86223- atomic64_add(child_event->total_time_enabled,
86224+ atomic64_add_unchecked(child_val, &parent_event->child_count);
86225+ atomic64_add_unchecked(child_event->total_time_enabled,
86226 &parent_event->child_total_time_enabled);
86227- atomic64_add(child_event->total_time_running,
86228+ atomic64_add_unchecked(child_event->total_time_running,
86229 &parent_event->child_total_time_running);
86230
86231 /*
86232diff --git a/kernel/events/internal.h b/kernel/events/internal.h
86233index 569b2187..19940d9 100644
86234--- a/kernel/events/internal.h
86235+++ b/kernel/events/internal.h
86236@@ -81,10 +81,10 @@ static inline unsigned long perf_data_size(struct ring_buffer *rb)
86237 return rb->nr_pages << (PAGE_SHIFT + page_order(rb));
86238 }
86239
86240-#define DEFINE_OUTPUT_COPY(func_name, memcpy_func) \
86241+#define DEFINE_OUTPUT_COPY(func_name, memcpy_func, user) \
86242 static inline unsigned long \
86243 func_name(struct perf_output_handle *handle, \
86244- const void *buf, unsigned long len) \
86245+ const void user *buf, unsigned long len) \
86246 { \
86247 unsigned long size, written; \
86248 \
86249@@ -117,7 +117,7 @@ memcpy_common(void *dst, const void *src, unsigned long n)
86250 return 0;
86251 }
86252
86253-DEFINE_OUTPUT_COPY(__output_copy, memcpy_common)
86254+DEFINE_OUTPUT_COPY(__output_copy, memcpy_common, )
86255
86256 static inline unsigned long
86257 memcpy_skip(void *dst, const void *src, unsigned long n)
86258@@ -125,7 +125,7 @@ memcpy_skip(void *dst, const void *src, unsigned long n)
86259 return 0;
86260 }
86261
86262-DEFINE_OUTPUT_COPY(__output_skip, memcpy_skip)
86263+DEFINE_OUTPUT_COPY(__output_skip, memcpy_skip, )
86264
86265 #ifndef arch_perf_out_copy_user
86266 #define arch_perf_out_copy_user arch_perf_out_copy_user
86267@@ -143,7 +143,7 @@ arch_perf_out_copy_user(void *dst, const void *src, unsigned long n)
86268 }
86269 #endif
86270
86271-DEFINE_OUTPUT_COPY(__output_copy_user, arch_perf_out_copy_user)
86272+DEFINE_OUTPUT_COPY(__output_copy_user, arch_perf_out_copy_user, __user)
86273
86274 /* Callchain handling */
86275 extern struct perf_callchain_entry *
86276diff --git a/kernel/events/uprobes.c b/kernel/events/uprobes.c
86277index 307d87c..6466cbe 100644
86278--- a/kernel/events/uprobes.c
86279+++ b/kernel/events/uprobes.c
86280@@ -1666,7 +1666,7 @@ static int is_trap_at_addr(struct mm_struct *mm, unsigned long vaddr)
86281 {
86282 struct page *page;
86283 uprobe_opcode_t opcode;
86284- int result;
86285+ long result;
86286
86287 pagefault_disable();
86288 result = __copy_from_user_inatomic(&opcode, (void __user*)vaddr,
86289diff --git a/kernel/exit.c b/kernel/exit.c
86290index 81b3d67..ef189a4 100644
86291--- a/kernel/exit.c
86292+++ b/kernel/exit.c
86293@@ -173,6 +173,10 @@ void release_task(struct task_struct * p)
86294 struct task_struct *leader;
86295 int zap_leader;
86296 repeat:
86297+#ifdef CONFIG_NET
86298+ gr_del_task_from_ip_table(p);
86299+#endif
86300+
86301 /* don't need to get the RCU readlock here - the process is dead and
86302 * can't be modifying its own credentials. But shut RCU-lockdep up */
86303 rcu_read_lock();
86304@@ -330,7 +334,7 @@ int allow_signal(int sig)
86305 * know it'll be handled, so that they don't get converted to
86306 * SIGKILL or just silently dropped.
86307 */
86308- current->sighand->action[(sig)-1].sa.sa_handler = (void __user *)2;
86309+ current->sighand->action[(sig)-1].sa.sa_handler = (__force void __user *)2;
86310 recalc_sigpending();
86311 spin_unlock_irq(&current->sighand->siglock);
86312 return 0;
86313@@ -706,6 +710,8 @@ void do_exit(long code)
86314 struct task_struct *tsk = current;
86315 int group_dead;
86316
86317+ set_fs(USER_DS);
86318+
86319 profile_task_exit(tsk);
86320
86321 WARN_ON(blk_needs_flush_plug(tsk));
86322@@ -722,7 +728,6 @@ void do_exit(long code)
86323 * mm_release()->clear_child_tid() from writing to a user-controlled
86324 * kernel address.
86325 */
86326- set_fs(USER_DS);
86327
86328 ptrace_event(PTRACE_EVENT_EXIT, code);
86329
86330@@ -781,6 +786,9 @@ void do_exit(long code)
86331 tsk->exit_code = code;
86332 taskstats_exit(tsk, group_dead);
86333
86334+ gr_acl_handle_psacct(tsk, code);
86335+ gr_acl_handle_exit();
86336+
86337 exit_mm(tsk);
86338
86339 if (group_dead)
86340@@ -900,7 +908,7 @@ SYSCALL_DEFINE1(exit, int, error_code)
86341 * Take down every thread in the group. This is called by fatal signals
86342 * as well as by sys_exit_group (below).
86343 */
86344-void
86345+__noreturn void
86346 do_group_exit(int exit_code)
86347 {
86348 struct signal_struct *sig = current->signal;
86349diff --git a/kernel/fork.c b/kernel/fork.c
86350index a17621c..b77fef8 100644
86351--- a/kernel/fork.c
86352+++ b/kernel/fork.c
86353@@ -319,7 +319,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
86354 *stackend = STACK_END_MAGIC; /* for overflow detection */
86355
86356 #ifdef CONFIG_CC_STACKPROTECTOR
86357- tsk->stack_canary = get_random_int();
86358+ tsk->stack_canary = pax_get_random_long();
86359 #endif
86360
86361 /*
86362@@ -345,12 +345,80 @@ free_tsk:
86363 }
86364
86365 #ifdef CONFIG_MMU
86366-static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
86367+static struct vm_area_struct *dup_vma(struct mm_struct *mm, struct mm_struct *oldmm, struct vm_area_struct *mpnt)
86368+{
86369+ struct vm_area_struct *tmp;
86370+ unsigned long charge;
86371+ struct file *file;
86372+ int retval;
86373+
86374+ charge = 0;
86375+ if (mpnt->vm_flags & VM_ACCOUNT) {
86376+ unsigned long len = vma_pages(mpnt);
86377+
86378+ if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
86379+ goto fail_nomem;
86380+ charge = len;
86381+ }
86382+ tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
86383+ if (!tmp)
86384+ goto fail_nomem;
86385+ *tmp = *mpnt;
86386+ tmp->vm_mm = mm;
86387+ INIT_LIST_HEAD(&tmp->anon_vma_chain);
86388+ retval = vma_dup_policy(mpnt, tmp);
86389+ if (retval)
86390+ goto fail_nomem_policy;
86391+ if (anon_vma_fork(tmp, mpnt))
86392+ goto fail_nomem_anon_vma_fork;
86393+ tmp->vm_flags &= ~VM_LOCKED;
86394+ tmp->vm_next = tmp->vm_prev = NULL;
86395+ tmp->vm_mirror = NULL;
86396+ file = tmp->vm_file;
86397+ if (file) {
86398+ struct inode *inode = file_inode(file);
86399+ struct address_space *mapping = file->f_mapping;
86400+
86401+ get_file(file);
86402+ if (tmp->vm_flags & VM_DENYWRITE)
86403+ atomic_dec(&inode->i_writecount);
86404+ mutex_lock(&mapping->i_mmap_mutex);
86405+ if (tmp->vm_flags & VM_SHARED)
86406+ mapping->i_mmap_writable++;
86407+ flush_dcache_mmap_lock(mapping);
86408+ /* insert tmp into the share list, just after mpnt */
86409+ if (unlikely(tmp->vm_flags & VM_NONLINEAR))
86410+ vma_nonlinear_insert(tmp, &mapping->i_mmap_nonlinear);
86411+ else
86412+ vma_interval_tree_insert_after(tmp, mpnt, &mapping->i_mmap);
86413+ flush_dcache_mmap_unlock(mapping);
86414+ mutex_unlock(&mapping->i_mmap_mutex);
86415+ }
86416+
86417+ /*
86418+ * Clear hugetlb-related page reserves for children. This only
86419+ * affects MAP_PRIVATE mappings. Faults generated by the child
86420+ * are not guaranteed to succeed, even if read-only
86421+ */
86422+ if (is_vm_hugetlb_page(tmp))
86423+ reset_vma_resv_huge_pages(tmp);
86424+
86425+ return tmp;
86426+
86427+fail_nomem_anon_vma_fork:
86428+ mpol_put(vma_policy(tmp));
86429+fail_nomem_policy:
86430+ kmem_cache_free(vm_area_cachep, tmp);
86431+fail_nomem:
86432+ vm_unacct_memory(charge);
86433+ return NULL;
86434+}
86435+
86436+static __latent_entropy int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
86437 {
86438 struct vm_area_struct *mpnt, *tmp, *prev, **pprev;
86439 struct rb_node **rb_link, *rb_parent;
86440 int retval;
86441- unsigned long charge;
86442
86443 uprobe_start_dup_mmap();
86444 down_write(&oldmm->mmap_sem);
86445@@ -379,55 +447,15 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
86446
86447 prev = NULL;
86448 for (mpnt = oldmm->mmap; mpnt; mpnt = mpnt->vm_next) {
86449- struct file *file;
86450-
86451 if (mpnt->vm_flags & VM_DONTCOPY) {
86452 vm_stat_account(mm, mpnt->vm_flags, mpnt->vm_file,
86453 -vma_pages(mpnt));
86454 continue;
86455 }
86456- charge = 0;
86457- if (mpnt->vm_flags & VM_ACCOUNT) {
86458- unsigned long len = vma_pages(mpnt);
86459-
86460- if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
86461- goto fail_nomem;
86462- charge = len;
86463- }
86464- tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
86465- if (!tmp)
86466- goto fail_nomem;
86467- *tmp = *mpnt;
86468- INIT_LIST_HEAD(&tmp->anon_vma_chain);
86469- retval = vma_dup_policy(mpnt, tmp);
86470- if (retval)
86471- goto fail_nomem_policy;
86472- tmp->vm_mm = mm;
86473- if (anon_vma_fork(tmp, mpnt))
86474- goto fail_nomem_anon_vma_fork;
86475- tmp->vm_flags &= ~VM_LOCKED;
86476- tmp->vm_next = tmp->vm_prev = NULL;
86477- file = tmp->vm_file;
86478- if (file) {
86479- struct inode *inode = file_inode(file);
86480- struct address_space *mapping = file->f_mapping;
86481-
86482- get_file(file);
86483- if (tmp->vm_flags & VM_DENYWRITE)
86484- atomic_dec(&inode->i_writecount);
86485- mutex_lock(&mapping->i_mmap_mutex);
86486- if (tmp->vm_flags & VM_SHARED)
86487- mapping->i_mmap_writable++;
86488- flush_dcache_mmap_lock(mapping);
86489- /* insert tmp into the share list, just after mpnt */
86490- if (unlikely(tmp->vm_flags & VM_NONLINEAR))
86491- vma_nonlinear_insert(tmp,
86492- &mapping->i_mmap_nonlinear);
86493- else
86494- vma_interval_tree_insert_after(tmp, mpnt,
86495- &mapping->i_mmap);
86496- flush_dcache_mmap_unlock(mapping);
86497- mutex_unlock(&mapping->i_mmap_mutex);
86498+ tmp = dup_vma(mm, oldmm, mpnt);
86499+ if (!tmp) {
86500+ retval = -ENOMEM;
86501+ goto out;
86502 }
86503
86504 /*
86505@@ -459,6 +487,31 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
86506 if (retval)
86507 goto out;
86508 }
86509+
86510+#ifdef CONFIG_PAX_SEGMEXEC
86511+ if (oldmm->pax_flags & MF_PAX_SEGMEXEC) {
86512+ struct vm_area_struct *mpnt_m;
86513+
86514+ for (mpnt = oldmm->mmap, mpnt_m = mm->mmap; mpnt; mpnt = mpnt->vm_next, mpnt_m = mpnt_m->vm_next) {
86515+ BUG_ON(!mpnt_m || mpnt_m->vm_mirror || mpnt->vm_mm != oldmm || mpnt_m->vm_mm != mm);
86516+
86517+ if (!mpnt->vm_mirror)
86518+ continue;
86519+
86520+ if (mpnt->vm_end <= SEGMEXEC_TASK_SIZE) {
86521+ BUG_ON(mpnt->vm_mirror->vm_mirror != mpnt);
86522+ mpnt->vm_mirror = mpnt_m;
86523+ } else {
86524+ BUG_ON(mpnt->vm_mirror->vm_mirror == mpnt || mpnt->vm_mirror->vm_mirror->vm_mm != mm);
86525+ mpnt_m->vm_mirror = mpnt->vm_mirror->vm_mirror;
86526+ mpnt_m->vm_mirror->vm_mirror = mpnt_m;
86527+ mpnt->vm_mirror->vm_mirror = mpnt;
86528+ }
86529+ }
86530+ BUG_ON(mpnt_m);
86531+ }
86532+#endif
86533+
86534 /* a new mm has just been created */
86535 arch_dup_mmap(oldmm, mm);
86536 retval = 0;
86537@@ -468,14 +521,6 @@ out:
86538 up_write(&oldmm->mmap_sem);
86539 uprobe_end_dup_mmap();
86540 return retval;
86541-fail_nomem_anon_vma_fork:
86542- mpol_put(vma_policy(tmp));
86543-fail_nomem_policy:
86544- kmem_cache_free(vm_area_cachep, tmp);
86545-fail_nomem:
86546- retval = -ENOMEM;
86547- vm_unacct_memory(charge);
86548- goto out;
86549 }
86550
86551 static inline int mm_alloc_pgd(struct mm_struct *mm)
86552@@ -689,8 +734,8 @@ struct mm_struct *mm_access(struct task_struct *task, unsigned int mode)
86553 return ERR_PTR(err);
86554
86555 mm = get_task_mm(task);
86556- if (mm && mm != current->mm &&
86557- !ptrace_may_access(task, mode)) {
86558+ if (mm && ((mm != current->mm && !ptrace_may_access(task, mode)) ||
86559+ (mode == PTRACE_MODE_ATTACH && (gr_handle_proc_ptrace(task) || gr_acl_handle_procpidmem(task))))) {
86560 mmput(mm);
86561 mm = ERR_PTR(-EACCES);
86562 }
86563@@ -906,13 +951,20 @@ static int copy_fs(unsigned long clone_flags, struct task_struct *tsk)
86564 spin_unlock(&fs->lock);
86565 return -EAGAIN;
86566 }
86567- fs->users++;
86568+ atomic_inc(&fs->users);
86569 spin_unlock(&fs->lock);
86570 return 0;
86571 }
86572 tsk->fs = copy_fs_struct(fs);
86573 if (!tsk->fs)
86574 return -ENOMEM;
86575+ /* Carry through gr_chroot_dentry and is_chrooted instead
86576+ of recomputing it here. Already copied when the task struct
86577+ is duplicated. This allows pivot_root to not be treated as
86578+ a chroot
86579+ */
86580+ //gr_set_chroot_entries(tsk, &tsk->fs->root);
86581+
86582 return 0;
86583 }
86584
86585@@ -1130,7 +1182,7 @@ init_task_pid(struct task_struct *task, enum pid_type type, struct pid *pid)
86586 * parts of the process environment (as per the clone
86587 * flags). The actual kick-off is left to the caller.
86588 */
86589-static struct task_struct *copy_process(unsigned long clone_flags,
86590+static __latent_entropy struct task_struct *copy_process(unsigned long clone_flags,
86591 unsigned long stack_start,
86592 unsigned long stack_size,
86593 int __user *child_tidptr,
86594@@ -1202,6 +1254,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
86595 DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
86596 #endif
86597 retval = -EAGAIN;
86598+
86599+ gr_learn_resource(p, RLIMIT_NPROC, atomic_read(&p->real_cred->user->processes), 0);
86600+
86601 if (atomic_read(&p->real_cred->user->processes) >=
86602 task_rlimit(p, RLIMIT_NPROC)) {
86603 if (p->real_cred->user != INIT_USER &&
86604@@ -1449,6 +1504,11 @@ static struct task_struct *copy_process(unsigned long clone_flags,
86605 goto bad_fork_free_pid;
86606 }
86607
86608+ /* synchronizes with gr_set_acls()
86609+ we need to call this past the point of no return for fork()
86610+ */
86611+ gr_copy_label(p);
86612+
86613 if (likely(p->pid)) {
86614 ptrace_init_task(p, (clone_flags & CLONE_PTRACE) || trace);
86615
86616@@ -1537,6 +1597,8 @@ bad_fork_cleanup_count:
86617 bad_fork_free:
86618 free_task(p);
86619 fork_out:
86620+ gr_log_forkfail(retval);
86621+
86622 return ERR_PTR(retval);
86623 }
86624
86625@@ -1598,6 +1660,7 @@ long do_fork(unsigned long clone_flags,
86626
86627 p = copy_process(clone_flags, stack_start, stack_size,
86628 child_tidptr, NULL, trace);
86629+ add_latent_entropy();
86630 /*
86631 * Do this prior waking up the new thread - the thread pointer
86632 * might get invalid after that point, if the thread exits quickly.
86633@@ -1612,6 +1675,8 @@ long do_fork(unsigned long clone_flags,
86634 if (clone_flags & CLONE_PARENT_SETTID)
86635 put_user(nr, parent_tidptr);
86636
86637+ gr_handle_brute_check();
86638+
86639 if (clone_flags & CLONE_VFORK) {
86640 p->vfork_done = &vfork;
86641 init_completion(&vfork);
86642@@ -1728,7 +1793,7 @@ void __init proc_caches_init(void)
86643 mm_cachep = kmem_cache_create("mm_struct",
86644 sizeof(struct mm_struct), ARCH_MIN_MMSTRUCT_ALIGN,
86645 SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_NOTRACK, NULL);
86646- vm_area_cachep = KMEM_CACHE(vm_area_struct, SLAB_PANIC);
86647+ vm_area_cachep = KMEM_CACHE(vm_area_struct, SLAB_PANIC | SLAB_NO_SANITIZE);
86648 mmap_init();
86649 nsproxy_cache_init();
86650 }
86651@@ -1768,7 +1833,7 @@ static int unshare_fs(unsigned long unshare_flags, struct fs_struct **new_fsp)
86652 return 0;
86653
86654 /* don't need lock here; in the worst case we'll do useless copy */
86655- if (fs->users == 1)
86656+ if (atomic_read(&fs->users) == 1)
86657 return 0;
86658
86659 *new_fsp = copy_fs_struct(fs);
86660@@ -1875,7 +1940,8 @@ SYSCALL_DEFINE1(unshare, unsigned long, unshare_flags)
86661 fs = current->fs;
86662 spin_lock(&fs->lock);
86663 current->fs = new_fs;
86664- if (--fs->users)
86665+ gr_set_chroot_entries(current, &current->fs->root);
86666+ if (atomic_dec_return(&fs->users))
86667 new_fs = NULL;
86668 else
86669 new_fs = fs;
86670diff --git a/kernel/futex.c b/kernel/futex.c
86671index 6801b37..bb6becca 100644
86672--- a/kernel/futex.c
86673+++ b/kernel/futex.c
86674@@ -54,6 +54,7 @@
86675 #include <linux/mount.h>
86676 #include <linux/pagemap.h>
86677 #include <linux/syscalls.h>
86678+#include <linux/ptrace.h>
86679 #include <linux/signal.h>
86680 #include <linux/export.h>
86681 #include <linux/magic.h>
86682@@ -380,6 +381,11 @@ get_futex_key(u32 __user *uaddr, int fshared, union futex_key *key, int rw)
86683 struct page *page, *page_head;
86684 int err, ro = 0;
86685
86686+#ifdef CONFIG_PAX_SEGMEXEC
86687+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && address >= SEGMEXEC_TASK_SIZE)
86688+ return -EFAULT;
86689+#endif
86690+
86691 /*
86692 * The futex address must be "naturally" aligned.
86693 */
86694@@ -579,7 +585,7 @@ static int cmpxchg_futex_value_locked(u32 *curval, u32 __user *uaddr,
86695
86696 static int get_futex_value_locked(u32 *dest, u32 __user *from)
86697 {
86698- int ret;
86699+ unsigned long ret;
86700
86701 pagefault_disable();
86702 ret = __copy_from_user_inatomic(dest, from, sizeof(u32));
86703@@ -2886,6 +2892,7 @@ static void __init futex_detect_cmpxchg(void)
86704 {
86705 #ifndef CONFIG_HAVE_FUTEX_CMPXCHG
86706 u32 curval;
86707+ mm_segment_t oldfs;
86708
86709 /*
86710 * This will fail and we want it. Some arch implementations do
86711@@ -2897,8 +2904,11 @@ static void __init futex_detect_cmpxchg(void)
86712 * implementation, the non-functional ones will return
86713 * -ENOSYS.
86714 */
86715+ oldfs = get_fs();
86716+ set_fs(USER_DS);
86717 if (cmpxchg_futex_value_locked(&curval, NULL, 0, 0) == -EFAULT)
86718 futex_cmpxchg_enabled = 1;
86719+ set_fs(oldfs);
86720 #endif
86721 }
86722
86723diff --git a/kernel/futex_compat.c b/kernel/futex_compat.c
86724index f9f44fd..29885e4 100644
86725--- a/kernel/futex_compat.c
86726+++ b/kernel/futex_compat.c
86727@@ -32,7 +32,7 @@ fetch_robust_entry(compat_uptr_t *uentry, struct robust_list __user **entry,
86728 return 0;
86729 }
86730
86731-static void __user *futex_uaddr(struct robust_list __user *entry,
86732+static void __user __intentional_overflow(-1) *futex_uaddr(struct robust_list __user *entry,
86733 compat_long_t futex_offset)
86734 {
86735 compat_uptr_t base = ptr_to_compat(entry);
86736diff --git a/kernel/gcov/base.c b/kernel/gcov/base.c
86737index f45b75b..bfac6d5 100644
86738--- a/kernel/gcov/base.c
86739+++ b/kernel/gcov/base.c
86740@@ -108,11 +108,6 @@ void gcov_enable_events(void)
86741 }
86742
86743 #ifdef CONFIG_MODULES
86744-static inline int within(void *addr, void *start, unsigned long size)
86745-{
86746- return ((addr >= start) && (addr < start + size));
86747-}
86748-
86749 /* Update list and generate events when modules are unloaded. */
86750 static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
86751 void *data)
86752@@ -127,7 +122,7 @@ static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
86753
86754 /* Remove entries located in module from linked list. */
86755 while ((info = gcov_info_next(info))) {
86756- if (within(info, mod->module_core, mod->core_size)) {
86757+ if (within_module_core_rw((unsigned long)info, mod)) {
86758 gcov_info_unlink(prev, info);
86759 if (gcov_events_enabled)
86760 gcov_event(GCOV_REMOVE, info);
86761diff --git a/kernel/hrtimer.c b/kernel/hrtimer.c
86762index 0909436..6037d22 100644
86763--- a/kernel/hrtimer.c
86764+++ b/kernel/hrtimer.c
86765@@ -1439,7 +1439,7 @@ void hrtimer_peek_ahead_timers(void)
86766 local_irq_restore(flags);
86767 }
86768
86769-static void run_hrtimer_softirq(struct softirq_action *h)
86770+static __latent_entropy void run_hrtimer_softirq(void)
86771 {
86772 hrtimer_peek_ahead_timers();
86773 }
86774diff --git a/kernel/irq_work.c b/kernel/irq_work.c
86775index 55fcce6..0e4cf34 100644
86776--- a/kernel/irq_work.c
86777+++ b/kernel/irq_work.c
86778@@ -189,12 +189,13 @@ static int irq_work_cpu_notify(struct notifier_block *self,
86779 return NOTIFY_OK;
86780 }
86781
86782-static struct notifier_block cpu_notify;
86783+static struct notifier_block cpu_notify = {
86784+ .notifier_call = irq_work_cpu_notify,
86785+ .priority = 0,
86786+};
86787
86788 static __init int irq_work_init_cpu_notifier(void)
86789 {
86790- cpu_notify.notifier_call = irq_work_cpu_notify;
86791- cpu_notify.priority = 0;
86792 register_cpu_notifier(&cpu_notify);
86793 return 0;
86794 }
86795diff --git a/kernel/jump_label.c b/kernel/jump_label.c
86796index 9019f15..9a3c42e 100644
86797--- a/kernel/jump_label.c
86798+++ b/kernel/jump_label.c
86799@@ -14,6 +14,7 @@
86800 #include <linux/err.h>
86801 #include <linux/static_key.h>
86802 #include <linux/jump_label_ratelimit.h>
86803+#include <linux/mm.h>
86804
86805 #ifdef HAVE_JUMP_LABEL
86806
86807@@ -51,7 +52,9 @@ jump_label_sort_entries(struct jump_entry *start, struct jump_entry *stop)
86808
86809 size = (((unsigned long)stop - (unsigned long)start)
86810 / sizeof(struct jump_entry));
86811+ pax_open_kernel();
86812 sort(start, size, sizeof(struct jump_entry), jump_label_cmp, NULL);
86813+ pax_close_kernel();
86814 }
86815
86816 static void jump_label_update(struct static_key *key, int enable);
86817@@ -363,10 +366,12 @@ static void jump_label_invalidate_module_init(struct module *mod)
86818 struct jump_entry *iter_stop = iter_start + mod->num_jump_entries;
86819 struct jump_entry *iter;
86820
86821+ pax_open_kernel();
86822 for (iter = iter_start; iter < iter_stop; iter++) {
86823 if (within_module_init(iter->code, mod))
86824 iter->code = 0;
86825 }
86826+ pax_close_kernel();
86827 }
86828
86829 static int
86830diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
86831index 3127ad5..159d880 100644
86832--- a/kernel/kallsyms.c
86833+++ b/kernel/kallsyms.c
86834@@ -11,6 +11,9 @@
86835 * Changed the compression method from stem compression to "table lookup"
86836 * compression (see scripts/kallsyms.c for a more complete description)
86837 */
86838+#ifdef CONFIG_GRKERNSEC_HIDESYM
86839+#define __INCLUDED_BY_HIDESYM 1
86840+#endif
86841 #include <linux/kallsyms.h>
86842 #include <linux/module.h>
86843 #include <linux/init.h>
86844@@ -53,12 +56,33 @@ extern const unsigned long kallsyms_markers[] __attribute__((weak));
86845
86846 static inline int is_kernel_inittext(unsigned long addr)
86847 {
86848+ if (system_state != SYSTEM_BOOTING)
86849+ return 0;
86850+
86851 if (addr >= (unsigned long)_sinittext
86852 && addr <= (unsigned long)_einittext)
86853 return 1;
86854 return 0;
86855 }
86856
86857+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
86858+#ifdef CONFIG_MODULES
86859+static inline int is_module_text(unsigned long addr)
86860+{
86861+ if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END)
86862+ return 1;
86863+
86864+ addr = ktla_ktva(addr);
86865+ return (unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END;
86866+}
86867+#else
86868+static inline int is_module_text(unsigned long addr)
86869+{
86870+ return 0;
86871+}
86872+#endif
86873+#endif
86874+
86875 static inline int is_kernel_text(unsigned long addr)
86876 {
86877 if ((addr >= (unsigned long)_stext && addr <= (unsigned long)_etext) ||
86878@@ -69,13 +93,28 @@ static inline int is_kernel_text(unsigned long addr)
86879
86880 static inline int is_kernel(unsigned long addr)
86881 {
86882+
86883+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
86884+ if (is_kernel_text(addr) || is_kernel_inittext(addr))
86885+ return 1;
86886+
86887+ if (ktla_ktva((unsigned long)_text) <= addr && addr < (unsigned long)_end)
86888+#else
86889 if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end)
86890+#endif
86891+
86892 return 1;
86893 return in_gate_area_no_mm(addr);
86894 }
86895
86896 static int is_ksym_addr(unsigned long addr)
86897 {
86898+
86899+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
86900+ if (is_module_text(addr))
86901+ return 0;
86902+#endif
86903+
86904 if (all_var)
86905 return is_kernel(addr);
86906
86907@@ -480,7 +519,6 @@ static unsigned long get_ksymbol_core(struct kallsym_iter *iter)
86908
86909 static void reset_iter(struct kallsym_iter *iter, loff_t new_pos)
86910 {
86911- iter->name[0] = '\0';
86912 iter->nameoff = get_symbol_offset(new_pos);
86913 iter->pos = new_pos;
86914 }
86915@@ -528,6 +566,11 @@ static int s_show(struct seq_file *m, void *p)
86916 {
86917 struct kallsym_iter *iter = m->private;
86918
86919+#ifdef CONFIG_GRKERNSEC_HIDESYM
86920+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID))
86921+ return 0;
86922+#endif
86923+
86924 /* Some debugging symbols have no name. Ignore them. */
86925 if (!iter->name[0])
86926 return 0;
86927@@ -541,6 +584,7 @@ static int s_show(struct seq_file *m, void *p)
86928 */
86929 type = iter->exported ? toupper(iter->type) :
86930 tolower(iter->type);
86931+
86932 seq_printf(m, "%pK %c %s\t[%s]\n", (void *)iter->value,
86933 type, iter->name, iter->module_name);
86934 } else
86935@@ -566,7 +610,7 @@ static int kallsyms_open(struct inode *inode, struct file *file)
86936 struct kallsym_iter *iter;
86937 int ret;
86938
86939- iter = kmalloc(sizeof(*iter), GFP_KERNEL);
86940+ iter = kzalloc(sizeof(*iter), GFP_KERNEL);
86941 if (!iter)
86942 return -ENOMEM;
86943 reset_iter(iter, 0);
86944diff --git a/kernel/kcmp.c b/kernel/kcmp.c
86945index e30ac0f..3528cac 100644
86946--- a/kernel/kcmp.c
86947+++ b/kernel/kcmp.c
86948@@ -99,6 +99,10 @@ SYSCALL_DEFINE5(kcmp, pid_t, pid1, pid_t, pid2, int, type,
86949 struct task_struct *task1, *task2;
86950 int ret;
86951
86952+#ifdef CONFIG_GRKERNSEC
86953+ return -ENOSYS;
86954+#endif
86955+
86956 rcu_read_lock();
86957
86958 /*
86959diff --git a/kernel/kexec.c b/kernel/kexec.c
86960index 60bafbe..a120f4f 100644
86961--- a/kernel/kexec.c
86962+++ b/kernel/kexec.c
86963@@ -1045,7 +1045,8 @@ asmlinkage long compat_sys_kexec_load(unsigned long entry,
86964 unsigned long flags)
86965 {
86966 struct compat_kexec_segment in;
86967- struct kexec_segment out, __user *ksegments;
86968+ struct kexec_segment out;
86969+ struct kexec_segment __user *ksegments;
86970 unsigned long i, result;
86971
86972 /* Don't allow clients that don't understand the native
86973diff --git a/kernel/kmod.c b/kernel/kmod.c
86974index 6b375af..eaff670 100644
86975--- a/kernel/kmod.c
86976+++ b/kernel/kmod.c
86977@@ -75,7 +75,7 @@ static void free_modprobe_argv(struct subprocess_info *info)
86978 kfree(info->argv);
86979 }
86980
86981-static int call_modprobe(char *module_name, int wait)
86982+static int call_modprobe(char *module_name, char *module_param, int wait)
86983 {
86984 struct subprocess_info *info;
86985 static char *envp[] = {
86986@@ -85,7 +85,7 @@ static int call_modprobe(char *module_name, int wait)
86987 NULL
86988 };
86989
86990- char **argv = kmalloc(sizeof(char *[5]), GFP_KERNEL);
86991+ char **argv = kmalloc(sizeof(char *[6]), GFP_KERNEL);
86992 if (!argv)
86993 goto out;
86994
86995@@ -97,7 +97,8 @@ static int call_modprobe(char *module_name, int wait)
86996 argv[1] = "-q";
86997 argv[2] = "--";
86998 argv[3] = module_name; /* check free_modprobe_argv() */
86999- argv[4] = NULL;
87000+ argv[4] = module_param;
87001+ argv[5] = NULL;
87002
87003 info = call_usermodehelper_setup(modprobe_path, argv, envp, GFP_KERNEL,
87004 NULL, free_modprobe_argv, NULL);
87005@@ -129,9 +130,8 @@ out:
87006 * If module auto-loading support is disabled then this function
87007 * becomes a no-operation.
87008 */
87009-int __request_module(bool wait, const char *fmt, ...)
87010+static int ____request_module(bool wait, char *module_param, const char *fmt, va_list ap)
87011 {
87012- va_list args;
87013 char module_name[MODULE_NAME_LEN];
87014 unsigned int max_modprobes;
87015 int ret;
87016@@ -150,9 +150,7 @@ int __request_module(bool wait, const char *fmt, ...)
87017 if (!modprobe_path[0])
87018 return 0;
87019
87020- va_start(args, fmt);
87021- ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, args);
87022- va_end(args);
87023+ ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, ap);
87024 if (ret >= MODULE_NAME_LEN)
87025 return -ENAMETOOLONG;
87026
87027@@ -160,6 +158,20 @@ int __request_module(bool wait, const char *fmt, ...)
87028 if (ret)
87029 return ret;
87030
87031+#ifdef CONFIG_GRKERNSEC_MODHARDEN
87032+ if (uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
87033+ /* hack to workaround consolekit/udisks stupidity */
87034+ read_lock(&tasklist_lock);
87035+ if (!strcmp(current->comm, "mount") &&
87036+ current->real_parent && !strncmp(current->real_parent->comm, "udisk", 5)) {
87037+ read_unlock(&tasklist_lock);
87038+ printk(KERN_ALERT "grsec: denied attempt to auto-load fs module %.64s by udisks\n", module_name);
87039+ return -EPERM;
87040+ }
87041+ read_unlock(&tasklist_lock);
87042+ }
87043+#endif
87044+
87045 /* If modprobe needs a service that is in a module, we get a recursive
87046 * loop. Limit the number of running kmod threads to max_threads/2 or
87047 * MAX_KMOD_CONCURRENT, whichever is the smaller. A cleaner method
87048@@ -188,11 +200,52 @@ int __request_module(bool wait, const char *fmt, ...)
87049
87050 trace_module_request(module_name, wait, _RET_IP_);
87051
87052- ret = call_modprobe(module_name, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
87053+ ret = call_modprobe(module_name, module_param, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
87054
87055 atomic_dec(&kmod_concurrent);
87056 return ret;
87057 }
87058+
87059+int ___request_module(bool wait, char *module_param, const char *fmt, ...)
87060+{
87061+ va_list args;
87062+ int ret;
87063+
87064+ va_start(args, fmt);
87065+ ret = ____request_module(wait, module_param, fmt, args);
87066+ va_end(args);
87067+
87068+ return ret;
87069+}
87070+
87071+int __request_module(bool wait, const char *fmt, ...)
87072+{
87073+ va_list args;
87074+ int ret;
87075+
87076+#ifdef CONFIG_GRKERNSEC_MODHARDEN
87077+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
87078+ char module_param[MODULE_NAME_LEN];
87079+
87080+ memset(module_param, 0, sizeof(module_param));
87081+
87082+ snprintf(module_param, sizeof(module_param) - 1, "grsec_modharden_normal%u_", GR_GLOBAL_UID(current_uid()));
87083+
87084+ va_start(args, fmt);
87085+ ret = ____request_module(wait, module_param, fmt, args);
87086+ va_end(args);
87087+
87088+ return ret;
87089+ }
87090+#endif
87091+
87092+ va_start(args, fmt);
87093+ ret = ____request_module(wait, NULL, fmt, args);
87094+ va_end(args);
87095+
87096+ return ret;
87097+}
87098+
87099 EXPORT_SYMBOL(__request_module);
87100 #endif /* CONFIG_MODULES */
87101
87102@@ -218,6 +271,20 @@ static int ____call_usermodehelper(void *data)
87103 */
87104 set_user_nice(current, 0);
87105
87106+#ifdef CONFIG_GRKERNSEC
87107+ /* this is race-free as far as userland is concerned as we copied
87108+ out the path to be used prior to this point and are now operating
87109+ on that copy
87110+ */
87111+ if ((strncmp(sub_info->path, "/sbin/", 6) && strncmp(sub_info->path, "/usr/lib/", 9) &&
87112+ strncmp(sub_info->path, "/lib/", 5) && strncmp(sub_info->path, "/lib64/", 7) &&
87113+ strcmp(sub_info->path, "/usr/share/apport/apport")) || strstr(sub_info->path, "..")) {
87114+ printk(KERN_ALERT "grsec: denied exec of usermode helper binary %.950s located outside of /sbin and system library paths\n", sub_info->path);
87115+ retval = -EPERM;
87116+ goto fail;
87117+ }
87118+#endif
87119+
87120 retval = -ENOMEM;
87121 new = prepare_kernel_cred(current);
87122 if (!new)
87123@@ -240,8 +307,8 @@ static int ____call_usermodehelper(void *data)
87124 commit_creds(new);
87125
87126 retval = do_execve(getname_kernel(sub_info->path),
87127- (const char __user *const __user *)sub_info->argv,
87128- (const char __user *const __user *)sub_info->envp);
87129+ (const char __user *const __force_user *)sub_info->argv,
87130+ (const char __user *const __force_user *)sub_info->envp);
87131 if (!retval)
87132 return 0;
87133
87134@@ -260,6 +327,10 @@ static int call_helper(void *data)
87135
87136 static void call_usermodehelper_freeinfo(struct subprocess_info *info)
87137 {
87138+#ifdef CONFIG_GRKERNSEC
87139+ kfree(info->path);
87140+ info->path = info->origpath;
87141+#endif
87142 if (info->cleanup)
87143 (*info->cleanup)(info);
87144 kfree(info);
87145@@ -303,7 +374,7 @@ static int wait_for_helper(void *data)
87146 *
87147 * Thus the __user pointer cast is valid here.
87148 */
87149- sys_wait4(pid, (int __user *)&ret, 0, NULL);
87150+ sys_wait4(pid, (int __force_user *)&ret, 0, NULL);
87151
87152 /*
87153 * If ret is 0, either ____call_usermodehelper failed and the
87154@@ -542,7 +613,12 @@ struct subprocess_info *call_usermodehelper_setup(char *path, char **argv,
87155 goto out;
87156
87157 INIT_WORK(&sub_info->work, __call_usermodehelper);
87158+#ifdef CONFIG_GRKERNSEC
87159+ sub_info->origpath = path;
87160+ sub_info->path = kstrdup(path, gfp_mask);
87161+#else
87162 sub_info->path = path;
87163+#endif
87164 sub_info->argv = argv;
87165 sub_info->envp = envp;
87166
87167@@ -650,7 +726,7 @@ EXPORT_SYMBOL(call_usermodehelper);
87168 static int proc_cap_handler(struct ctl_table *table, int write,
87169 void __user *buffer, size_t *lenp, loff_t *ppos)
87170 {
87171- struct ctl_table t;
87172+ ctl_table_no_const t;
87173 unsigned long cap_array[_KERNEL_CAPABILITY_U32S];
87174 kernel_cap_t new_cap;
87175 int err, i;
87176diff --git a/kernel/kprobes.c b/kernel/kprobes.c
87177index ceeadfc..11c18b6 100644
87178--- a/kernel/kprobes.c
87179+++ b/kernel/kprobes.c
87180@@ -31,6 +31,9 @@
87181 * <jkenisto@us.ibm.com> and Prasanna S Panchamukhi
87182 * <prasanna@in.ibm.com> added function-return probes.
87183 */
87184+#ifdef CONFIG_GRKERNSEC_HIDESYM
87185+#define __INCLUDED_BY_HIDESYM 1
87186+#endif
87187 #include <linux/kprobes.h>
87188 #include <linux/hash.h>
87189 #include <linux/init.h>
87190@@ -135,12 +138,12 @@ enum kprobe_slot_state {
87191
87192 static void *alloc_insn_page(void)
87193 {
87194- return module_alloc(PAGE_SIZE);
87195+ return module_alloc_exec(PAGE_SIZE);
87196 }
87197
87198 static void free_insn_page(void *page)
87199 {
87200- module_free(NULL, page);
87201+ module_free_exec(NULL, page);
87202 }
87203
87204 struct kprobe_insn_cache kprobe_insn_slots = {
87205@@ -2151,11 +2154,11 @@ static void __kprobes report_probe(struct seq_file *pi, struct kprobe *p,
87206 kprobe_type = "k";
87207
87208 if (sym)
87209- seq_printf(pi, "%p %s %s+0x%x %s ",
87210+ seq_printf(pi, "%pK %s %s+0x%x %s ",
87211 p->addr, kprobe_type, sym, offset,
87212 (modname ? modname : " "));
87213 else
87214- seq_printf(pi, "%p %s %p ",
87215+ seq_printf(pi, "%pK %s %pK ",
87216 p->addr, kprobe_type, p->addr);
87217
87218 if (!pp)
87219diff --git a/kernel/ksysfs.c b/kernel/ksysfs.c
87220index d945a94..0b7f45f 100644
87221--- a/kernel/ksysfs.c
87222+++ b/kernel/ksysfs.c
87223@@ -46,6 +46,8 @@ static ssize_t uevent_helper_store(struct kobject *kobj,
87224 {
87225 if (count+1 > UEVENT_HELPER_PATH_LEN)
87226 return -ENOENT;
87227+ if (!capable(CAP_SYS_ADMIN))
87228+ return -EPERM;
87229 memcpy(uevent_helper, buf, count);
87230 uevent_helper[count] = '\0';
87231 if (count && uevent_helper[count-1] == '\n')
87232@@ -172,7 +174,7 @@ static ssize_t notes_read(struct file *filp, struct kobject *kobj,
87233 return count;
87234 }
87235
87236-static struct bin_attribute notes_attr = {
87237+static bin_attribute_no_const notes_attr __read_only = {
87238 .attr = {
87239 .name = "notes",
87240 .mode = S_IRUGO,
87241diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c
87242index eb8a547..321d8e1 100644
87243--- a/kernel/locking/lockdep.c
87244+++ b/kernel/locking/lockdep.c
87245@@ -597,6 +597,10 @@ static int static_obj(void *obj)
87246 end = (unsigned long) &_end,
87247 addr = (unsigned long) obj;
87248
87249+#ifdef CONFIG_PAX_KERNEXEC
87250+ start = ktla_ktva(start);
87251+#endif
87252+
87253 /*
87254 * static variable?
87255 */
87256@@ -738,6 +742,7 @@ register_lock_class(struct lockdep_map *lock, unsigned int subclass, int force)
87257 if (!static_obj(lock->key)) {
87258 debug_locks_off();
87259 printk("INFO: trying to register non-static key.\n");
87260+ printk("lock:%pS key:%pS.\n", lock, lock->key);
87261 printk("the code is fine but needs lockdep annotation.\n");
87262 printk("turning off the locking correctness validator.\n");
87263 dump_stack();
87264@@ -3082,7 +3087,7 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass,
87265 if (!class)
87266 return 0;
87267 }
87268- atomic_inc((atomic_t *)&class->ops);
87269+ atomic_long_inc_unchecked((atomic_long_unchecked_t *)&class->ops);
87270 if (very_verbose(class)) {
87271 printk("\nacquire class [%p] %s", class->key, class->name);
87272 if (class->name_version > 1)
87273diff --git a/kernel/locking/lockdep_proc.c b/kernel/locking/lockdep_proc.c
87274index ef43ac4..2720dfa 100644
87275--- a/kernel/locking/lockdep_proc.c
87276+++ b/kernel/locking/lockdep_proc.c
87277@@ -65,7 +65,7 @@ static int l_show(struct seq_file *m, void *v)
87278 return 0;
87279 }
87280
87281- seq_printf(m, "%p", class->key);
87282+ seq_printf(m, "%pK", class->key);
87283 #ifdef CONFIG_DEBUG_LOCKDEP
87284 seq_printf(m, " OPS:%8ld", class->ops);
87285 #endif
87286@@ -83,7 +83,7 @@ static int l_show(struct seq_file *m, void *v)
87287
87288 list_for_each_entry(entry, &class->locks_after, entry) {
87289 if (entry->distance == 1) {
87290- seq_printf(m, " -> [%p] ", entry->class->key);
87291+ seq_printf(m, " -> [%pK] ", entry->class->key);
87292 print_name(m, entry->class);
87293 seq_puts(m, "\n");
87294 }
87295@@ -152,7 +152,7 @@ static int lc_show(struct seq_file *m, void *v)
87296 if (!class->key)
87297 continue;
87298
87299- seq_printf(m, "[%p] ", class->key);
87300+ seq_printf(m, "[%pK] ", class->key);
87301 print_name(m, class);
87302 seq_puts(m, "\n");
87303 }
87304@@ -496,7 +496,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
87305 if (!i)
87306 seq_line(m, '-', 40-namelen, namelen);
87307
87308- snprintf(ip, sizeof(ip), "[<%p>]",
87309+ snprintf(ip, sizeof(ip), "[<%pK>]",
87310 (void *)class->contention_point[i]);
87311 seq_printf(m, "%40s %14lu %29s %pS\n",
87312 name, stats->contention_point[i],
87313@@ -511,7 +511,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
87314 if (!i)
87315 seq_line(m, '-', 40-namelen, namelen);
87316
87317- snprintf(ip, sizeof(ip), "[<%p>]",
87318+ snprintf(ip, sizeof(ip), "[<%pK>]",
87319 (void *)class->contending_point[i]);
87320 seq_printf(m, "%40s %14lu %29s %pS\n",
87321 name, stats->contending_point[i],
87322diff --git a/kernel/locking/mutex-debug.c b/kernel/locking/mutex-debug.c
87323index faf6f5b..dc9070a 100644
87324--- a/kernel/locking/mutex-debug.c
87325+++ b/kernel/locking/mutex-debug.c
87326@@ -49,21 +49,21 @@ void debug_mutex_free_waiter(struct mutex_waiter *waiter)
87327 }
87328
87329 void debug_mutex_add_waiter(struct mutex *lock, struct mutex_waiter *waiter,
87330- struct thread_info *ti)
87331+ struct task_struct *task)
87332 {
87333 SMP_DEBUG_LOCKS_WARN_ON(!spin_is_locked(&lock->wait_lock));
87334
87335 /* Mark the current thread as blocked on the lock: */
87336- ti->task->blocked_on = waiter;
87337+ task->blocked_on = waiter;
87338 }
87339
87340 void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
87341- struct thread_info *ti)
87342+ struct task_struct *task)
87343 {
87344 DEBUG_LOCKS_WARN_ON(list_empty(&waiter->list));
87345- DEBUG_LOCKS_WARN_ON(waiter->task != ti->task);
87346- DEBUG_LOCKS_WARN_ON(ti->task->blocked_on != waiter);
87347- ti->task->blocked_on = NULL;
87348+ DEBUG_LOCKS_WARN_ON(waiter->task != task);
87349+ DEBUG_LOCKS_WARN_ON(task->blocked_on != waiter);
87350+ task->blocked_on = NULL;
87351
87352 list_del_init(&waiter->list);
87353 waiter->task = NULL;
87354diff --git a/kernel/locking/mutex-debug.h b/kernel/locking/mutex-debug.h
87355index 0799fd3..d06ae3b 100644
87356--- a/kernel/locking/mutex-debug.h
87357+++ b/kernel/locking/mutex-debug.h
87358@@ -20,9 +20,9 @@ extern void debug_mutex_wake_waiter(struct mutex *lock,
87359 extern void debug_mutex_free_waiter(struct mutex_waiter *waiter);
87360 extern void debug_mutex_add_waiter(struct mutex *lock,
87361 struct mutex_waiter *waiter,
87362- struct thread_info *ti);
87363+ struct task_struct *task);
87364 extern void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
87365- struct thread_info *ti);
87366+ struct task_struct *task);
87367 extern void debug_mutex_unlock(struct mutex *lock);
87368 extern void debug_mutex_init(struct mutex *lock, const char *name,
87369 struct lock_class_key *key);
87370diff --git a/kernel/locking/mutex.c b/kernel/locking/mutex.c
87371index 4dd6e4c..df52693 100644
87372--- a/kernel/locking/mutex.c
87373+++ b/kernel/locking/mutex.c
87374@@ -135,7 +135,7 @@ void mspin_lock(struct mspin_node **lock, struct mspin_node *node)
87375 node->locked = 1;
87376 return;
87377 }
87378- ACCESS_ONCE(prev->next) = node;
87379+ ACCESS_ONCE_RW(prev->next) = node;
87380 smp_wmb();
87381 /* Wait until the lock holder passes the lock down */
87382 while (!ACCESS_ONCE(node->locked))
87383@@ -156,7 +156,7 @@ static void mspin_unlock(struct mspin_node **lock, struct mspin_node *node)
87384 while (!(next = ACCESS_ONCE(node->next)))
87385 arch_mutex_cpu_relax();
87386 }
87387- ACCESS_ONCE(next->locked) = 1;
87388+ ACCESS_ONCE_RW(next->locked) = 1;
87389 smp_wmb();
87390 }
87391
87392@@ -520,7 +520,7 @@ slowpath:
87393 goto skip_wait;
87394
87395 debug_mutex_lock_common(lock, &waiter);
87396- debug_mutex_add_waiter(lock, &waiter, task_thread_info(task));
87397+ debug_mutex_add_waiter(lock, &waiter, task);
87398
87399 /* add waiting tasks to the end of the waitqueue (FIFO): */
87400 list_add_tail(&waiter.list, &lock->wait_list);
87401@@ -564,7 +564,7 @@ slowpath:
87402 schedule_preempt_disabled();
87403 spin_lock_mutex(&lock->wait_lock, flags);
87404 }
87405- mutex_remove_waiter(lock, &waiter, current_thread_info());
87406+ mutex_remove_waiter(lock, &waiter, task);
87407 /* set it to 0 if there are no waiters left: */
87408 if (likely(list_empty(&lock->wait_list)))
87409 atomic_set(&lock->count, 0);
87410@@ -601,7 +601,7 @@ skip_wait:
87411 return 0;
87412
87413 err:
87414- mutex_remove_waiter(lock, &waiter, task_thread_info(task));
87415+ mutex_remove_waiter(lock, &waiter, task);
87416 spin_unlock_mutex(&lock->wait_lock, flags);
87417 debug_mutex_free_waiter(&waiter);
87418 mutex_release(&lock->dep_map, 1, ip);
87419diff --git a/kernel/locking/rtmutex-tester.c b/kernel/locking/rtmutex-tester.c
87420index 1d96dd0..994ff19 100644
87421--- a/kernel/locking/rtmutex-tester.c
87422+++ b/kernel/locking/rtmutex-tester.c
87423@@ -22,7 +22,7 @@
87424 #define MAX_RT_TEST_MUTEXES 8
87425
87426 static spinlock_t rttest_lock;
87427-static atomic_t rttest_event;
87428+static atomic_unchecked_t rttest_event;
87429
87430 struct test_thread_data {
87431 int opcode;
87432@@ -63,7 +63,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
87433
87434 case RTTEST_LOCKCONT:
87435 td->mutexes[td->opdata] = 1;
87436- td->event = atomic_add_return(1, &rttest_event);
87437+ td->event = atomic_add_return_unchecked(1, &rttest_event);
87438 return 0;
87439
87440 case RTTEST_RESET:
87441@@ -76,7 +76,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
87442 return 0;
87443
87444 case RTTEST_RESETEVENT:
87445- atomic_set(&rttest_event, 0);
87446+ atomic_set_unchecked(&rttest_event, 0);
87447 return 0;
87448
87449 default:
87450@@ -93,9 +93,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
87451 return ret;
87452
87453 td->mutexes[id] = 1;
87454- td->event = atomic_add_return(1, &rttest_event);
87455+ td->event = atomic_add_return_unchecked(1, &rttest_event);
87456 rt_mutex_lock(&mutexes[id]);
87457- td->event = atomic_add_return(1, &rttest_event);
87458+ td->event = atomic_add_return_unchecked(1, &rttest_event);
87459 td->mutexes[id] = 4;
87460 return 0;
87461
87462@@ -106,9 +106,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
87463 return ret;
87464
87465 td->mutexes[id] = 1;
87466- td->event = atomic_add_return(1, &rttest_event);
87467+ td->event = atomic_add_return_unchecked(1, &rttest_event);
87468 ret = rt_mutex_lock_interruptible(&mutexes[id], 0);
87469- td->event = atomic_add_return(1, &rttest_event);
87470+ td->event = atomic_add_return_unchecked(1, &rttest_event);
87471 td->mutexes[id] = ret ? 0 : 4;
87472 return ret ? -EINTR : 0;
87473
87474@@ -117,9 +117,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
87475 if (id < 0 || id >= MAX_RT_TEST_MUTEXES || td->mutexes[id] != 4)
87476 return ret;
87477
87478- td->event = atomic_add_return(1, &rttest_event);
87479+ td->event = atomic_add_return_unchecked(1, &rttest_event);
87480 rt_mutex_unlock(&mutexes[id]);
87481- td->event = atomic_add_return(1, &rttest_event);
87482+ td->event = atomic_add_return_unchecked(1, &rttest_event);
87483 td->mutexes[id] = 0;
87484 return 0;
87485
87486@@ -166,7 +166,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
87487 break;
87488
87489 td->mutexes[dat] = 2;
87490- td->event = atomic_add_return(1, &rttest_event);
87491+ td->event = atomic_add_return_unchecked(1, &rttest_event);
87492 break;
87493
87494 default:
87495@@ -186,7 +186,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
87496 return;
87497
87498 td->mutexes[dat] = 3;
87499- td->event = atomic_add_return(1, &rttest_event);
87500+ td->event = atomic_add_return_unchecked(1, &rttest_event);
87501 break;
87502
87503 case RTTEST_LOCKNOWAIT:
87504@@ -198,7 +198,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
87505 return;
87506
87507 td->mutexes[dat] = 1;
87508- td->event = atomic_add_return(1, &rttest_event);
87509+ td->event = atomic_add_return_unchecked(1, &rttest_event);
87510 return;
87511
87512 default:
87513diff --git a/kernel/module.c b/kernel/module.c
87514index d24fcf2..2af3fd9 100644
87515--- a/kernel/module.c
87516+++ b/kernel/module.c
87517@@ -61,6 +61,7 @@
87518 #include <linux/pfn.h>
87519 #include <linux/bsearch.h>
87520 #include <linux/fips.h>
87521+#include <linux/grsecurity.h>
87522 #include <uapi/linux/module.h>
87523 #include "module-internal.h"
87524
87525@@ -157,7 +158,8 @@ static BLOCKING_NOTIFIER_HEAD(module_notify_list);
87526
87527 /* Bounds of module allocation, for speeding __module_address.
87528 * Protected by module_mutex. */
87529-static unsigned long module_addr_min = -1UL, module_addr_max = 0;
87530+static unsigned long module_addr_min_rw = -1UL, module_addr_max_rw = 0;
87531+static unsigned long module_addr_min_rx = -1UL, module_addr_max_rx = 0;
87532
87533 int register_module_notifier(struct notifier_block * nb)
87534 {
87535@@ -324,7 +326,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
87536 return true;
87537
87538 list_for_each_entry_rcu(mod, &modules, list) {
87539- struct symsearch arr[] = {
87540+ struct symsearch modarr[] = {
87541 { mod->syms, mod->syms + mod->num_syms, mod->crcs,
87542 NOT_GPL_ONLY, false },
87543 { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms,
87544@@ -349,7 +351,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
87545 if (mod->state == MODULE_STATE_UNFORMED)
87546 continue;
87547
87548- if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data))
87549+ if (each_symbol_in_section(modarr, ARRAY_SIZE(modarr), mod, fn, data))
87550 return true;
87551 }
87552 return false;
87553@@ -489,7 +491,7 @@ static int percpu_modalloc(struct module *mod, struct load_info *info)
87554 if (!pcpusec->sh_size)
87555 return 0;
87556
87557- if (align > PAGE_SIZE) {
87558+ if (align-1 >= PAGE_SIZE) {
87559 pr_warn("%s: per-cpu alignment %li > %li\n",
87560 mod->name, align, PAGE_SIZE);
87561 align = PAGE_SIZE;
87562@@ -1062,7 +1064,7 @@ struct module_attribute module_uevent =
87563 static ssize_t show_coresize(struct module_attribute *mattr,
87564 struct module_kobject *mk, char *buffer)
87565 {
87566- return sprintf(buffer, "%u\n", mk->mod->core_size);
87567+ return sprintf(buffer, "%u\n", mk->mod->core_size_rx + mk->mod->core_size_rw);
87568 }
87569
87570 static struct module_attribute modinfo_coresize =
87571@@ -1071,7 +1073,7 @@ static struct module_attribute modinfo_coresize =
87572 static ssize_t show_initsize(struct module_attribute *mattr,
87573 struct module_kobject *mk, char *buffer)
87574 {
87575- return sprintf(buffer, "%u\n", mk->mod->init_size);
87576+ return sprintf(buffer, "%u\n", mk->mod->init_size_rx + mk->mod->init_size_rw);
87577 }
87578
87579 static struct module_attribute modinfo_initsize =
87580@@ -1163,12 +1165,29 @@ static int check_version(Elf_Shdr *sechdrs,
87581 goto bad_version;
87582 }
87583
87584+#ifdef CONFIG_GRKERNSEC_RANDSTRUCT
87585+ /*
87586+ * avoid potentially printing jibberish on attempted load
87587+ * of a module randomized with a different seed
87588+ */
87589+ pr_warn("no symbol version for %s\n", symname);
87590+#else
87591 pr_warn("%s: no symbol version for %s\n", mod->name, symname);
87592+#endif
87593 return 0;
87594
87595 bad_version:
87596+#ifdef CONFIG_GRKERNSEC_RANDSTRUCT
87597+ /*
87598+ * avoid potentially printing jibberish on attempted load
87599+ * of a module randomized with a different seed
87600+ */
87601+ printk("attempted module disagrees about version of symbol %s\n",
87602+ symname);
87603+#else
87604 printk("%s: disagrees about version of symbol %s\n",
87605 mod->name, symname);
87606+#endif
87607 return 0;
87608 }
87609
87610@@ -1284,7 +1303,7 @@ resolve_symbol_wait(struct module *mod,
87611 */
87612 #ifdef CONFIG_SYSFS
87613
87614-#ifdef CONFIG_KALLSYMS
87615+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
87616 static inline bool sect_empty(const Elf_Shdr *sect)
87617 {
87618 return !(sect->sh_flags & SHF_ALLOC) || sect->sh_size == 0;
87619@@ -1424,7 +1443,7 @@ static void add_notes_attrs(struct module *mod, const struct load_info *info)
87620 {
87621 unsigned int notes, loaded, i;
87622 struct module_notes_attrs *notes_attrs;
87623- struct bin_attribute *nattr;
87624+ bin_attribute_no_const *nattr;
87625
87626 /* failed to create section attributes, so can't create notes */
87627 if (!mod->sect_attrs)
87628@@ -1536,7 +1555,7 @@ static void del_usage_links(struct module *mod)
87629 static int module_add_modinfo_attrs(struct module *mod)
87630 {
87631 struct module_attribute *attr;
87632- struct module_attribute *temp_attr;
87633+ module_attribute_no_const *temp_attr;
87634 int error = 0;
87635 int i;
87636
87637@@ -1757,21 +1776,21 @@ static void set_section_ro_nx(void *base,
87638
87639 static void unset_module_core_ro_nx(struct module *mod)
87640 {
87641- set_page_attributes(mod->module_core + mod->core_text_size,
87642- mod->module_core + mod->core_size,
87643+ set_page_attributes(mod->module_core_rw,
87644+ mod->module_core_rw + mod->core_size_rw,
87645 set_memory_x);
87646- set_page_attributes(mod->module_core,
87647- mod->module_core + mod->core_ro_size,
87648+ set_page_attributes(mod->module_core_rx,
87649+ mod->module_core_rx + mod->core_size_rx,
87650 set_memory_rw);
87651 }
87652
87653 static void unset_module_init_ro_nx(struct module *mod)
87654 {
87655- set_page_attributes(mod->module_init + mod->init_text_size,
87656- mod->module_init + mod->init_size,
87657+ set_page_attributes(mod->module_init_rw,
87658+ mod->module_init_rw + mod->init_size_rw,
87659 set_memory_x);
87660- set_page_attributes(mod->module_init,
87661- mod->module_init + mod->init_ro_size,
87662+ set_page_attributes(mod->module_init_rx,
87663+ mod->module_init_rx + mod->init_size_rx,
87664 set_memory_rw);
87665 }
87666
87667@@ -1784,14 +1803,14 @@ void set_all_modules_text_rw(void)
87668 list_for_each_entry_rcu(mod, &modules, list) {
87669 if (mod->state == MODULE_STATE_UNFORMED)
87670 continue;
87671- if ((mod->module_core) && (mod->core_text_size)) {
87672- set_page_attributes(mod->module_core,
87673- mod->module_core + mod->core_text_size,
87674+ if ((mod->module_core_rx) && (mod->core_size_rx)) {
87675+ set_page_attributes(mod->module_core_rx,
87676+ mod->module_core_rx + mod->core_size_rx,
87677 set_memory_rw);
87678 }
87679- if ((mod->module_init) && (mod->init_text_size)) {
87680- set_page_attributes(mod->module_init,
87681- mod->module_init + mod->init_text_size,
87682+ if ((mod->module_init_rx) && (mod->init_size_rx)) {
87683+ set_page_attributes(mod->module_init_rx,
87684+ mod->module_init_rx + mod->init_size_rx,
87685 set_memory_rw);
87686 }
87687 }
87688@@ -1807,14 +1826,14 @@ void set_all_modules_text_ro(void)
87689 list_for_each_entry_rcu(mod, &modules, list) {
87690 if (mod->state == MODULE_STATE_UNFORMED)
87691 continue;
87692- if ((mod->module_core) && (mod->core_text_size)) {
87693- set_page_attributes(mod->module_core,
87694- mod->module_core + mod->core_text_size,
87695+ if ((mod->module_core_rx) && (mod->core_size_rx)) {
87696+ set_page_attributes(mod->module_core_rx,
87697+ mod->module_core_rx + mod->core_size_rx,
87698 set_memory_ro);
87699 }
87700- if ((mod->module_init) && (mod->init_text_size)) {
87701- set_page_attributes(mod->module_init,
87702- mod->module_init + mod->init_text_size,
87703+ if ((mod->module_init_rx) && (mod->init_size_rx)) {
87704+ set_page_attributes(mod->module_init_rx,
87705+ mod->module_init_rx + mod->init_size_rx,
87706 set_memory_ro);
87707 }
87708 }
87709@@ -1865,16 +1884,19 @@ static void free_module(struct module *mod)
87710
87711 /* This may be NULL, but that's OK */
87712 unset_module_init_ro_nx(mod);
87713- module_free(mod, mod->module_init);
87714+ module_free(mod, mod->module_init_rw);
87715+ module_free_exec(mod, mod->module_init_rx);
87716 kfree(mod->args);
87717 percpu_modfree(mod);
87718
87719 /* Free lock-classes: */
87720- lockdep_free_key_range(mod->module_core, mod->core_size);
87721+ lockdep_free_key_range(mod->module_core_rx, mod->core_size_rx);
87722+ lockdep_free_key_range(mod->module_core_rw, mod->core_size_rw);
87723
87724 /* Finally, free the core (containing the module structure) */
87725 unset_module_core_ro_nx(mod);
87726- module_free(mod, mod->module_core);
87727+ module_free_exec(mod, mod->module_core_rx);
87728+ module_free(mod, mod->module_core_rw);
87729
87730 #ifdef CONFIG_MPU
87731 update_protections(current->mm);
87732@@ -1943,9 +1965,31 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
87733 int ret = 0;
87734 const struct kernel_symbol *ksym;
87735
87736+#ifdef CONFIG_GRKERNSEC_MODHARDEN
87737+ int is_fs_load = 0;
87738+ int register_filesystem_found = 0;
87739+ char *p;
87740+
87741+ p = strstr(mod->args, "grsec_modharden_fs");
87742+ if (p) {
87743+ char *endptr = p + sizeof("grsec_modharden_fs") - 1;
87744+ /* copy \0 as well */
87745+ memmove(p, endptr, strlen(mod->args) - (unsigned int)(endptr - mod->args) + 1);
87746+ is_fs_load = 1;
87747+ }
87748+#endif
87749+
87750 for (i = 1; i < symsec->sh_size / sizeof(Elf_Sym); i++) {
87751 const char *name = info->strtab + sym[i].st_name;
87752
87753+#ifdef CONFIG_GRKERNSEC_MODHARDEN
87754+ /* it's a real shame this will never get ripped and copied
87755+ upstream! ;(
87756+ */
87757+ if (is_fs_load && !strcmp(name, "register_filesystem"))
87758+ register_filesystem_found = 1;
87759+#endif
87760+
87761 switch (sym[i].st_shndx) {
87762 case SHN_COMMON:
87763 /* We compiled with -fno-common. These are not
87764@@ -1966,7 +2010,9 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
87765 ksym = resolve_symbol_wait(mod, info, name);
87766 /* Ok if resolved. */
87767 if (ksym && !IS_ERR(ksym)) {
87768+ pax_open_kernel();
87769 sym[i].st_value = ksym->value;
87770+ pax_close_kernel();
87771 break;
87772 }
87773
87774@@ -1985,11 +2031,20 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
87775 secbase = (unsigned long)mod_percpu(mod);
87776 else
87777 secbase = info->sechdrs[sym[i].st_shndx].sh_addr;
87778+ pax_open_kernel();
87779 sym[i].st_value += secbase;
87780+ pax_close_kernel();
87781 break;
87782 }
87783 }
87784
87785+#ifdef CONFIG_GRKERNSEC_MODHARDEN
87786+ if (is_fs_load && !register_filesystem_found) {
87787+ printk(KERN_ALERT "grsec: Denied attempt to load non-fs module %.64s through mount\n", mod->name);
87788+ ret = -EPERM;
87789+ }
87790+#endif
87791+
87792 return ret;
87793 }
87794
87795@@ -2073,22 +2128,12 @@ static void layout_sections(struct module *mod, struct load_info *info)
87796 || s->sh_entsize != ~0UL
87797 || strstarts(sname, ".init"))
87798 continue;
87799- s->sh_entsize = get_offset(mod, &mod->core_size, s, i);
87800+ if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
87801+ s->sh_entsize = get_offset(mod, &mod->core_size_rw, s, i);
87802+ else
87803+ s->sh_entsize = get_offset(mod, &mod->core_size_rx, s, i);
87804 pr_debug("\t%s\n", sname);
87805 }
87806- switch (m) {
87807- case 0: /* executable */
87808- mod->core_size = debug_align(mod->core_size);
87809- mod->core_text_size = mod->core_size;
87810- break;
87811- case 1: /* RO: text and ro-data */
87812- mod->core_size = debug_align(mod->core_size);
87813- mod->core_ro_size = mod->core_size;
87814- break;
87815- case 3: /* whole core */
87816- mod->core_size = debug_align(mod->core_size);
87817- break;
87818- }
87819 }
87820
87821 pr_debug("Init section allocation order:\n");
87822@@ -2102,23 +2147,13 @@ static void layout_sections(struct module *mod, struct load_info *info)
87823 || s->sh_entsize != ~0UL
87824 || !strstarts(sname, ".init"))
87825 continue;
87826- s->sh_entsize = (get_offset(mod, &mod->init_size, s, i)
87827- | INIT_OFFSET_MASK);
87828+ if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
87829+ s->sh_entsize = get_offset(mod, &mod->init_size_rw, s, i);
87830+ else
87831+ s->sh_entsize = get_offset(mod, &mod->init_size_rx, s, i);
87832+ s->sh_entsize |= INIT_OFFSET_MASK;
87833 pr_debug("\t%s\n", sname);
87834 }
87835- switch (m) {
87836- case 0: /* executable */
87837- mod->init_size = debug_align(mod->init_size);
87838- mod->init_text_size = mod->init_size;
87839- break;
87840- case 1: /* RO: text and ro-data */
87841- mod->init_size = debug_align(mod->init_size);
87842- mod->init_ro_size = mod->init_size;
87843- break;
87844- case 3: /* whole init */
87845- mod->init_size = debug_align(mod->init_size);
87846- break;
87847- }
87848 }
87849 }
87850
87851@@ -2291,7 +2326,7 @@ static void layout_symtab(struct module *mod, struct load_info *info)
87852
87853 /* Put symbol section at end of init part of module. */
87854 symsect->sh_flags |= SHF_ALLOC;
87855- symsect->sh_entsize = get_offset(mod, &mod->init_size, symsect,
87856+ symsect->sh_entsize = get_offset(mod, &mod->init_size_rx, symsect,
87857 info->index.sym) | INIT_OFFSET_MASK;
87858 pr_debug("\t%s\n", info->secstrings + symsect->sh_name);
87859
87860@@ -2308,13 +2343,13 @@ static void layout_symtab(struct module *mod, struct load_info *info)
87861 }
87862
87863 /* Append room for core symbols at end of core part. */
87864- info->symoffs = ALIGN(mod->core_size, symsect->sh_addralign ?: 1);
87865- info->stroffs = mod->core_size = info->symoffs + ndst * sizeof(Elf_Sym);
87866- mod->core_size += strtab_size;
87867+ info->symoffs = ALIGN(mod->core_size_rx, symsect->sh_addralign ?: 1);
87868+ info->stroffs = mod->core_size_rx = info->symoffs + ndst * sizeof(Elf_Sym);
87869+ mod->core_size_rx += strtab_size;
87870
87871 /* Put string table section at end of init part of module. */
87872 strsect->sh_flags |= SHF_ALLOC;
87873- strsect->sh_entsize = get_offset(mod, &mod->init_size, strsect,
87874+ strsect->sh_entsize = get_offset(mod, &mod->init_size_rx, strsect,
87875 info->index.str) | INIT_OFFSET_MASK;
87876 pr_debug("\t%s\n", info->secstrings + strsect->sh_name);
87877 }
87878@@ -2332,12 +2367,14 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
87879 /* Make sure we get permanent strtab: don't use info->strtab. */
87880 mod->strtab = (void *)info->sechdrs[info->index.str].sh_addr;
87881
87882+ pax_open_kernel();
87883+
87884 /* Set types up while we still have access to sections. */
87885 for (i = 0; i < mod->num_symtab; i++)
87886 mod->symtab[i].st_info = elf_type(&mod->symtab[i], info);
87887
87888- mod->core_symtab = dst = mod->module_core + info->symoffs;
87889- mod->core_strtab = s = mod->module_core + info->stroffs;
87890+ mod->core_symtab = dst = mod->module_core_rx + info->symoffs;
87891+ mod->core_strtab = s = mod->module_core_rx + info->stroffs;
87892 src = mod->symtab;
87893 for (ndst = i = 0; i < mod->num_symtab; i++) {
87894 if (i == 0 ||
87895@@ -2349,6 +2386,8 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
87896 }
87897 }
87898 mod->core_num_syms = ndst;
87899+
87900+ pax_close_kernel();
87901 }
87902 #else
87903 static inline void layout_symtab(struct module *mod, struct load_info *info)
87904@@ -2382,17 +2421,33 @@ void * __weak module_alloc(unsigned long size)
87905 return vmalloc_exec(size);
87906 }
87907
87908-static void *module_alloc_update_bounds(unsigned long size)
87909+static void *module_alloc_update_bounds_rw(unsigned long size)
87910 {
87911 void *ret = module_alloc(size);
87912
87913 if (ret) {
87914 mutex_lock(&module_mutex);
87915 /* Update module bounds. */
87916- if ((unsigned long)ret < module_addr_min)
87917- module_addr_min = (unsigned long)ret;
87918- if ((unsigned long)ret + size > module_addr_max)
87919- module_addr_max = (unsigned long)ret + size;
87920+ if ((unsigned long)ret < module_addr_min_rw)
87921+ module_addr_min_rw = (unsigned long)ret;
87922+ if ((unsigned long)ret + size > module_addr_max_rw)
87923+ module_addr_max_rw = (unsigned long)ret + size;
87924+ mutex_unlock(&module_mutex);
87925+ }
87926+ return ret;
87927+}
87928+
87929+static void *module_alloc_update_bounds_rx(unsigned long size)
87930+{
87931+ void *ret = module_alloc_exec(size);
87932+
87933+ if (ret) {
87934+ mutex_lock(&module_mutex);
87935+ /* Update module bounds. */
87936+ if ((unsigned long)ret < module_addr_min_rx)
87937+ module_addr_min_rx = (unsigned long)ret;
87938+ if ((unsigned long)ret + size > module_addr_max_rx)
87939+ module_addr_max_rx = (unsigned long)ret + size;
87940 mutex_unlock(&module_mutex);
87941 }
87942 return ret;
87943@@ -2649,7 +2704,15 @@ static struct module *setup_load_info(struct load_info *info, int flags)
87944 mod = (void *)info->sechdrs[info->index.mod].sh_addr;
87945
87946 if (info->index.sym == 0) {
87947+#ifdef CONFIG_GRKERNSEC_RANDSTRUCT
87948+ /*
87949+ * avoid potentially printing jibberish on attempted load
87950+ * of a module randomized with a different seed
87951+ */
87952+ pr_warn("module has no symbols (stripped?)\n");
87953+#else
87954 pr_warn("%s: module has no symbols (stripped?)\n", mod->name);
87955+#endif
87956 return ERR_PTR(-ENOEXEC);
87957 }
87958
87959@@ -2665,8 +2728,14 @@ static struct module *setup_load_info(struct load_info *info, int flags)
87960 static int check_modinfo(struct module *mod, struct load_info *info, int flags)
87961 {
87962 const char *modmagic = get_modinfo(info, "vermagic");
87963+ const char *license = get_modinfo(info, "license");
87964 int err;
87965
87966+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
87967+ if (!license || !license_is_gpl_compatible(license))
87968+ return -ENOEXEC;
87969+#endif
87970+
87971 if (flags & MODULE_INIT_IGNORE_VERMAGIC)
87972 modmagic = NULL;
87973
87974@@ -2691,7 +2760,7 @@ static int check_modinfo(struct module *mod, struct load_info *info, int flags)
87975 }
87976
87977 /* Set up license info based on the info section */
87978- set_license(mod, get_modinfo(info, "license"));
87979+ set_license(mod, license);
87980
87981 return 0;
87982 }
87983@@ -2785,7 +2854,7 @@ static int move_module(struct module *mod, struct load_info *info)
87984 void *ptr;
87985
87986 /* Do the allocs. */
87987- ptr = module_alloc_update_bounds(mod->core_size);
87988+ ptr = module_alloc_update_bounds_rw(mod->core_size_rw);
87989 /*
87990 * The pointer to this block is stored in the module structure
87991 * which is inside the block. Just mark it as not being a
87992@@ -2795,11 +2864,11 @@ static int move_module(struct module *mod, struct load_info *info)
87993 if (!ptr)
87994 return -ENOMEM;
87995
87996- memset(ptr, 0, mod->core_size);
87997- mod->module_core = ptr;
87998+ memset(ptr, 0, mod->core_size_rw);
87999+ mod->module_core_rw = ptr;
88000
88001- if (mod->init_size) {
88002- ptr = module_alloc_update_bounds(mod->init_size);
88003+ if (mod->init_size_rw) {
88004+ ptr = module_alloc_update_bounds_rw(mod->init_size_rw);
88005 /*
88006 * The pointer to this block is stored in the module structure
88007 * which is inside the block. This block doesn't need to be
88008@@ -2808,13 +2877,45 @@ static int move_module(struct module *mod, struct load_info *info)
88009 */
88010 kmemleak_ignore(ptr);
88011 if (!ptr) {
88012- module_free(mod, mod->module_core);
88013+ module_free(mod, mod->module_core_rw);
88014 return -ENOMEM;
88015 }
88016- memset(ptr, 0, mod->init_size);
88017- mod->module_init = ptr;
88018+ memset(ptr, 0, mod->init_size_rw);
88019+ mod->module_init_rw = ptr;
88020 } else
88021- mod->module_init = NULL;
88022+ mod->module_init_rw = NULL;
88023+
88024+ ptr = module_alloc_update_bounds_rx(mod->core_size_rx);
88025+ kmemleak_not_leak(ptr);
88026+ if (!ptr) {
88027+ if (mod->module_init_rw)
88028+ module_free(mod, mod->module_init_rw);
88029+ module_free(mod, mod->module_core_rw);
88030+ return -ENOMEM;
88031+ }
88032+
88033+ pax_open_kernel();
88034+ memset(ptr, 0, mod->core_size_rx);
88035+ pax_close_kernel();
88036+ mod->module_core_rx = ptr;
88037+
88038+ if (mod->init_size_rx) {
88039+ ptr = module_alloc_update_bounds_rx(mod->init_size_rx);
88040+ kmemleak_ignore(ptr);
88041+ if (!ptr && mod->init_size_rx) {
88042+ module_free_exec(mod, mod->module_core_rx);
88043+ if (mod->module_init_rw)
88044+ module_free(mod, mod->module_init_rw);
88045+ module_free(mod, mod->module_core_rw);
88046+ return -ENOMEM;
88047+ }
88048+
88049+ pax_open_kernel();
88050+ memset(ptr, 0, mod->init_size_rx);
88051+ pax_close_kernel();
88052+ mod->module_init_rx = ptr;
88053+ } else
88054+ mod->module_init_rx = NULL;
88055
88056 /* Transfer each section which specifies SHF_ALLOC */
88057 pr_debug("final section addresses:\n");
88058@@ -2825,16 +2926,45 @@ static int move_module(struct module *mod, struct load_info *info)
88059 if (!(shdr->sh_flags & SHF_ALLOC))
88060 continue;
88061
88062- if (shdr->sh_entsize & INIT_OFFSET_MASK)
88063- dest = mod->module_init
88064- + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
88065- else
88066- dest = mod->module_core + shdr->sh_entsize;
88067+ if (shdr->sh_entsize & INIT_OFFSET_MASK) {
88068+ if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
88069+ dest = mod->module_init_rw
88070+ + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
88071+ else
88072+ dest = mod->module_init_rx
88073+ + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
88074+ } else {
88075+ if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
88076+ dest = mod->module_core_rw + shdr->sh_entsize;
88077+ else
88078+ dest = mod->module_core_rx + shdr->sh_entsize;
88079+ }
88080+
88081+ if (shdr->sh_type != SHT_NOBITS) {
88082+
88083+#ifdef CONFIG_PAX_KERNEXEC
88084+#ifdef CONFIG_X86_64
88085+ if ((shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_EXECINSTR))
88086+ set_memory_x((unsigned long)dest, (shdr->sh_size + PAGE_SIZE) >> PAGE_SHIFT);
88087+#endif
88088+ if (!(shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_ALLOC)) {
88089+ pax_open_kernel();
88090+ memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
88091+ pax_close_kernel();
88092+ } else
88093+#endif
88094
88095- if (shdr->sh_type != SHT_NOBITS)
88096 memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
88097+ }
88098 /* Update sh_addr to point to copy in image. */
88099- shdr->sh_addr = (unsigned long)dest;
88100+
88101+#ifdef CONFIG_PAX_KERNEXEC
88102+ if (shdr->sh_flags & SHF_EXECINSTR)
88103+ shdr->sh_addr = ktva_ktla((unsigned long)dest);
88104+ else
88105+#endif
88106+
88107+ shdr->sh_addr = (unsigned long)dest;
88108 pr_debug("\t0x%lx %s\n",
88109 (long)shdr->sh_addr, info->secstrings + shdr->sh_name);
88110 }
88111@@ -2891,12 +3021,12 @@ static void flush_module_icache(const struct module *mod)
88112 * Do it before processing of module parameters, so the module
88113 * can provide parameter accessor functions of its own.
88114 */
88115- if (mod->module_init)
88116- flush_icache_range((unsigned long)mod->module_init,
88117- (unsigned long)mod->module_init
88118- + mod->init_size);
88119- flush_icache_range((unsigned long)mod->module_core,
88120- (unsigned long)mod->module_core + mod->core_size);
88121+ if (mod->module_init_rx)
88122+ flush_icache_range((unsigned long)mod->module_init_rx,
88123+ (unsigned long)mod->module_init_rx
88124+ + mod->init_size_rx);
88125+ flush_icache_range((unsigned long)mod->module_core_rx,
88126+ (unsigned long)mod->module_core_rx + mod->core_size_rx);
88127
88128 set_fs(old_fs);
88129 }
88130@@ -2953,8 +3083,10 @@ static struct module *layout_and_allocate(struct load_info *info, int flags)
88131 static void module_deallocate(struct module *mod, struct load_info *info)
88132 {
88133 percpu_modfree(mod);
88134- module_free(mod, mod->module_init);
88135- module_free(mod, mod->module_core);
88136+ module_free_exec(mod, mod->module_init_rx);
88137+ module_free_exec(mod, mod->module_core_rx);
88138+ module_free(mod, mod->module_init_rw);
88139+ module_free(mod, mod->module_core_rw);
88140 }
88141
88142 int __weak module_finalize(const Elf_Ehdr *hdr,
88143@@ -2967,7 +3099,9 @@ int __weak module_finalize(const Elf_Ehdr *hdr,
88144 static int post_relocation(struct module *mod, const struct load_info *info)
88145 {
88146 /* Sort exception table now relocations are done. */
88147+ pax_open_kernel();
88148 sort_extable(mod->extable, mod->extable + mod->num_exentries);
88149+ pax_close_kernel();
88150
88151 /* Copy relocated percpu area over. */
88152 percpu_modcopy(mod, (void *)info->sechdrs[info->index.pcpu].sh_addr,
88153@@ -3021,16 +3155,16 @@ static int do_init_module(struct module *mod)
88154 MODULE_STATE_COMING, mod);
88155
88156 /* Set RO and NX regions for core */
88157- set_section_ro_nx(mod->module_core,
88158- mod->core_text_size,
88159- mod->core_ro_size,
88160- mod->core_size);
88161+ set_section_ro_nx(mod->module_core_rx,
88162+ mod->core_size_rx,
88163+ mod->core_size_rx,
88164+ mod->core_size_rx);
88165
88166 /* Set RO and NX regions for init */
88167- set_section_ro_nx(mod->module_init,
88168- mod->init_text_size,
88169- mod->init_ro_size,
88170- mod->init_size);
88171+ set_section_ro_nx(mod->module_init_rx,
88172+ mod->init_size_rx,
88173+ mod->init_size_rx,
88174+ mod->init_size_rx);
88175
88176 do_mod_ctors(mod);
88177 /* Start the module */
88178@@ -3091,11 +3225,12 @@ static int do_init_module(struct module *mod)
88179 mod->strtab = mod->core_strtab;
88180 #endif
88181 unset_module_init_ro_nx(mod);
88182- module_free(mod, mod->module_init);
88183- mod->module_init = NULL;
88184- mod->init_size = 0;
88185- mod->init_ro_size = 0;
88186- mod->init_text_size = 0;
88187+ module_free(mod, mod->module_init_rw);
88188+ module_free_exec(mod, mod->module_init_rx);
88189+ mod->module_init_rw = NULL;
88190+ mod->module_init_rx = NULL;
88191+ mod->init_size_rw = 0;
88192+ mod->init_size_rx = 0;
88193 mutex_unlock(&module_mutex);
88194 wake_up_all(&module_wq);
88195
88196@@ -3238,9 +3373,38 @@ static int load_module(struct load_info *info, const char __user *uargs,
88197 if (err)
88198 goto free_unload;
88199
88200+ /* Now copy in args */
88201+ mod->args = strndup_user(uargs, ~0UL >> 1);
88202+ if (IS_ERR(mod->args)) {
88203+ err = PTR_ERR(mod->args);
88204+ goto free_unload;
88205+ }
88206+
88207 /* Set up MODINFO_ATTR fields */
88208 setup_modinfo(mod, info);
88209
88210+#ifdef CONFIG_GRKERNSEC_MODHARDEN
88211+ {
88212+ char *p, *p2;
88213+
88214+ if (strstr(mod->args, "grsec_modharden_netdev")) {
88215+ 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);
88216+ err = -EPERM;
88217+ goto free_modinfo;
88218+ } else if ((p = strstr(mod->args, "grsec_modharden_normal"))) {
88219+ p += sizeof("grsec_modharden_normal") - 1;
88220+ p2 = strstr(p, "_");
88221+ if (p2) {
88222+ *p2 = '\0';
88223+ printk(KERN_ALERT "grsec: denied kernel module auto-load of %.64s by uid %.9s\n", mod->name, p);
88224+ *p2 = '_';
88225+ }
88226+ err = -EPERM;
88227+ goto free_modinfo;
88228+ }
88229+ }
88230+#endif
88231+
88232 /* Fix up syms, so that st_value is a pointer to location. */
88233 err = simplify_symbols(mod, info);
88234 if (err < 0)
88235@@ -3256,13 +3420,6 @@ static int load_module(struct load_info *info, const char __user *uargs,
88236
88237 flush_module_icache(mod);
88238
88239- /* Now copy in args */
88240- mod->args = strndup_user(uargs, ~0UL >> 1);
88241- if (IS_ERR(mod->args)) {
88242- err = PTR_ERR(mod->args);
88243- goto free_arch_cleanup;
88244- }
88245-
88246 dynamic_debug_setup(info->debug, info->num_debug);
88247
88248 /* Finally it's fully formed, ready to start executing. */
88249@@ -3297,11 +3454,10 @@ static int load_module(struct load_info *info, const char __user *uargs,
88250 ddebug_cleanup:
88251 dynamic_debug_remove(info->debug);
88252 synchronize_sched();
88253- kfree(mod->args);
88254- free_arch_cleanup:
88255 module_arch_cleanup(mod);
88256 free_modinfo:
88257 free_modinfo(mod);
88258+ kfree(mod->args);
88259 free_unload:
88260 module_unload_free(mod);
88261 unlink_mod:
88262@@ -3384,10 +3540,16 @@ static const char *get_ksymbol(struct module *mod,
88263 unsigned long nextval;
88264
88265 /* At worse, next value is at end of module */
88266- if (within_module_init(addr, mod))
88267- nextval = (unsigned long)mod->module_init+mod->init_text_size;
88268+ if (within_module_init_rx(addr, mod))
88269+ nextval = (unsigned long)mod->module_init_rx+mod->init_size_rx;
88270+ else if (within_module_init_rw(addr, mod))
88271+ nextval = (unsigned long)mod->module_init_rw+mod->init_size_rw;
88272+ else if (within_module_core_rx(addr, mod))
88273+ nextval = (unsigned long)mod->module_core_rx+mod->core_size_rx;
88274+ else if (within_module_core_rw(addr, mod))
88275+ nextval = (unsigned long)mod->module_core_rw+mod->core_size_rw;
88276 else
88277- nextval = (unsigned long)mod->module_core+mod->core_text_size;
88278+ return NULL;
88279
88280 /* Scan for closest preceding symbol, and next symbol. (ELF
88281 starts real symbols at 1). */
88282@@ -3638,7 +3800,7 @@ static int m_show(struct seq_file *m, void *p)
88283 return 0;
88284
88285 seq_printf(m, "%s %u",
88286- mod->name, mod->init_size + mod->core_size);
88287+ mod->name, mod->init_size_rx + mod->init_size_rw + mod->core_size_rx + mod->core_size_rw);
88288 print_unload_info(m, mod);
88289
88290 /* Informative for users. */
88291@@ -3647,7 +3809,7 @@ static int m_show(struct seq_file *m, void *p)
88292 mod->state == MODULE_STATE_COMING ? "Loading":
88293 "Live");
88294 /* Used by oprofile and other similar tools. */
88295- seq_printf(m, " 0x%pK", mod->module_core);
88296+ seq_printf(m, " 0x%pK 0x%pK", mod->module_core_rx, mod->module_core_rw);
88297
88298 /* Taints info */
88299 if (mod->taints)
88300@@ -3683,7 +3845,17 @@ static const struct file_operations proc_modules_operations = {
88301
88302 static int __init proc_modules_init(void)
88303 {
88304+#ifndef CONFIG_GRKERNSEC_HIDESYM
88305+#ifdef CONFIG_GRKERNSEC_PROC_USER
88306+ proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
88307+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
88308+ proc_create("modules", S_IRUSR | S_IRGRP, NULL, &proc_modules_operations);
88309+#else
88310 proc_create("modules", 0, NULL, &proc_modules_operations);
88311+#endif
88312+#else
88313+ proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
88314+#endif
88315 return 0;
88316 }
88317 module_init(proc_modules_init);
88318@@ -3744,14 +3916,14 @@ struct module *__module_address(unsigned long addr)
88319 {
88320 struct module *mod;
88321
88322- if (addr < module_addr_min || addr > module_addr_max)
88323+ if ((addr < module_addr_min_rx || addr > module_addr_max_rx) &&
88324+ (addr < module_addr_min_rw || addr > module_addr_max_rw))
88325 return NULL;
88326
88327 list_for_each_entry_rcu(mod, &modules, list) {
88328 if (mod->state == MODULE_STATE_UNFORMED)
88329 continue;
88330- if (within_module_core(addr, mod)
88331- || within_module_init(addr, mod))
88332+ if (within_module_init(addr, mod) || within_module_core(addr, mod))
88333 return mod;
88334 }
88335 return NULL;
88336@@ -3786,11 +3958,20 @@ bool is_module_text_address(unsigned long addr)
88337 */
88338 struct module *__module_text_address(unsigned long addr)
88339 {
88340- struct module *mod = __module_address(addr);
88341+ struct module *mod;
88342+
88343+#ifdef CONFIG_X86_32
88344+ addr = ktla_ktva(addr);
88345+#endif
88346+
88347+ if (addr < module_addr_min_rx || addr > module_addr_max_rx)
88348+ return NULL;
88349+
88350+ mod = __module_address(addr);
88351+
88352 if (mod) {
88353 /* Make sure it's within the text section. */
88354- if (!within(addr, mod->module_init, mod->init_text_size)
88355- && !within(addr, mod->module_core, mod->core_text_size))
88356+ if (!within_module_init_rx(addr, mod) && !within_module_core_rx(addr, mod))
88357 mod = NULL;
88358 }
88359 return mod;
88360diff --git a/kernel/notifier.c b/kernel/notifier.c
88361index 2d5cc4c..d9ea600 100644
88362--- a/kernel/notifier.c
88363+++ b/kernel/notifier.c
88364@@ -5,6 +5,7 @@
88365 #include <linux/rcupdate.h>
88366 #include <linux/vmalloc.h>
88367 #include <linux/reboot.h>
88368+#include <linux/mm.h>
88369
88370 /*
88371 * Notifier list for kernel code which wants to be called
88372@@ -24,10 +25,12 @@ static int notifier_chain_register(struct notifier_block **nl,
88373 while ((*nl) != NULL) {
88374 if (n->priority > (*nl)->priority)
88375 break;
88376- nl = &((*nl)->next);
88377+ nl = (struct notifier_block **)&((*nl)->next);
88378 }
88379- n->next = *nl;
88380+ pax_open_kernel();
88381+ *(const void **)&n->next = *nl;
88382 rcu_assign_pointer(*nl, n);
88383+ pax_close_kernel();
88384 return 0;
88385 }
88386
88387@@ -39,10 +42,12 @@ static int notifier_chain_cond_register(struct notifier_block **nl,
88388 return 0;
88389 if (n->priority > (*nl)->priority)
88390 break;
88391- nl = &((*nl)->next);
88392+ nl = (struct notifier_block **)&((*nl)->next);
88393 }
88394- n->next = *nl;
88395+ pax_open_kernel();
88396+ *(const void **)&n->next = *nl;
88397 rcu_assign_pointer(*nl, n);
88398+ pax_close_kernel();
88399 return 0;
88400 }
88401
88402@@ -51,10 +56,12 @@ static int notifier_chain_unregister(struct notifier_block **nl,
88403 {
88404 while ((*nl) != NULL) {
88405 if ((*nl) == n) {
88406+ pax_open_kernel();
88407 rcu_assign_pointer(*nl, n->next);
88408+ pax_close_kernel();
88409 return 0;
88410 }
88411- nl = &((*nl)->next);
88412+ nl = (struct notifier_block **)&((*nl)->next);
88413 }
88414 return -ENOENT;
88415 }
88416diff --git a/kernel/padata.c b/kernel/padata.c
88417index 161402f..598814c 100644
88418--- a/kernel/padata.c
88419+++ b/kernel/padata.c
88420@@ -54,7 +54,7 @@ static int padata_cpu_hash(struct parallel_data *pd)
88421 * seq_nr mod. number of cpus in use.
88422 */
88423
88424- seq_nr = atomic_inc_return(&pd->seq_nr);
88425+ seq_nr = atomic_inc_return_unchecked(&pd->seq_nr);
88426 cpu_index = seq_nr % cpumask_weight(pd->cpumask.pcpu);
88427
88428 return padata_index_to_cpu(pd, cpu_index);
88429@@ -428,7 +428,7 @@ static struct parallel_data *padata_alloc_pd(struct padata_instance *pinst,
88430 padata_init_pqueues(pd);
88431 padata_init_squeues(pd);
88432 setup_timer(&pd->timer, padata_reorder_timer, (unsigned long)pd);
88433- atomic_set(&pd->seq_nr, -1);
88434+ atomic_set_unchecked(&pd->seq_nr, -1);
88435 atomic_set(&pd->reorder_objects, 0);
88436 atomic_set(&pd->refcnt, 0);
88437 pd->pinst = pinst;
88438diff --git a/kernel/panic.c b/kernel/panic.c
88439index 6d63003..486a109 100644
88440--- a/kernel/panic.c
88441+++ b/kernel/panic.c
88442@@ -52,7 +52,7 @@ EXPORT_SYMBOL(panic_blink);
88443 /*
88444 * Stop ourself in panic -- architecture code may override this
88445 */
88446-void __weak panic_smp_self_stop(void)
88447+void __weak __noreturn panic_smp_self_stop(void)
88448 {
88449 while (1)
88450 cpu_relax();
88451@@ -407,7 +407,7 @@ static void warn_slowpath_common(const char *file, int line, void *caller,
88452 disable_trace_on_warning();
88453
88454 pr_warn("------------[ cut here ]------------\n");
88455- pr_warn("WARNING: CPU: %d PID: %d at %s:%d %pS()\n",
88456+ pr_warn("WARNING: CPU: %d PID: %d at %s:%d %pA()\n",
88457 raw_smp_processor_id(), current->pid, file, line, caller);
88458
88459 if (args)
88460@@ -461,7 +461,8 @@ EXPORT_SYMBOL(warn_slowpath_null);
88461 */
88462 void __stack_chk_fail(void)
88463 {
88464- panic("stack-protector: Kernel stack is corrupted in: %p\n",
88465+ dump_stack();
88466+ panic("stack-protector: Kernel stack is corrupted in: %pA\n",
88467 __builtin_return_address(0));
88468 }
88469 EXPORT_SYMBOL(__stack_chk_fail);
88470diff --git a/kernel/pid.c b/kernel/pid.c
88471index 9b9a266..c20ef80 100644
88472--- a/kernel/pid.c
88473+++ b/kernel/pid.c
88474@@ -33,6 +33,7 @@
88475 #include <linux/rculist.h>
88476 #include <linux/bootmem.h>
88477 #include <linux/hash.h>
88478+#include <linux/security.h>
88479 #include <linux/pid_namespace.h>
88480 #include <linux/init_task.h>
88481 #include <linux/syscalls.h>
88482@@ -47,7 +48,7 @@ struct pid init_struct_pid = INIT_STRUCT_PID;
88483
88484 int pid_max = PID_MAX_DEFAULT;
88485
88486-#define RESERVED_PIDS 300
88487+#define RESERVED_PIDS 500
88488
88489 int pid_max_min = RESERVED_PIDS + 1;
88490 int pid_max_max = PID_MAX_LIMIT;
88491@@ -445,10 +446,18 @@ EXPORT_SYMBOL(pid_task);
88492 */
88493 struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
88494 {
88495+ struct task_struct *task;
88496+
88497 rcu_lockdep_assert(rcu_read_lock_held(),
88498 "find_task_by_pid_ns() needs rcu_read_lock()"
88499 " protection");
88500- return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
88501+
88502+ task = pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
88503+
88504+ if (gr_pid_is_chrooted(task))
88505+ return NULL;
88506+
88507+ return task;
88508 }
88509
88510 struct task_struct *find_task_by_vpid(pid_t vnr)
88511@@ -456,6 +465,14 @@ struct task_struct *find_task_by_vpid(pid_t vnr)
88512 return find_task_by_pid_ns(vnr, task_active_pid_ns(current));
88513 }
88514
88515+struct task_struct *find_task_by_vpid_unrestricted(pid_t vnr)
88516+{
88517+ rcu_lockdep_assert(rcu_read_lock_held(),
88518+ "find_task_by_pid_ns() needs rcu_read_lock()"
88519+ " protection");
88520+ return pid_task(find_pid_ns(vnr, task_active_pid_ns(current)), PIDTYPE_PID);
88521+}
88522+
88523 struct pid *get_task_pid(struct task_struct *task, enum pid_type type)
88524 {
88525 struct pid *pid;
88526diff --git a/kernel/pid_namespace.c b/kernel/pid_namespace.c
88527index db95d8e..a0ca23f 100644
88528--- a/kernel/pid_namespace.c
88529+++ b/kernel/pid_namespace.c
88530@@ -253,7 +253,7 @@ static int pid_ns_ctl_handler(struct ctl_table *table, int write,
88531 void __user *buffer, size_t *lenp, loff_t *ppos)
88532 {
88533 struct pid_namespace *pid_ns = task_active_pid_ns(current);
88534- struct ctl_table tmp = *table;
88535+ ctl_table_no_const tmp = *table;
88536
88537 if (write && !ns_capable(pid_ns->user_ns, CAP_SYS_ADMIN))
88538 return -EPERM;
88539diff --git a/kernel/posix-cpu-timers.c b/kernel/posix-cpu-timers.c
88540index 3b89464..5e38379 100644
88541--- a/kernel/posix-cpu-timers.c
88542+++ b/kernel/posix-cpu-timers.c
88543@@ -1464,14 +1464,14 @@ struct k_clock clock_posix_cpu = {
88544
88545 static __init int init_posix_cpu_timers(void)
88546 {
88547- struct k_clock process = {
88548+ static struct k_clock process = {
88549 .clock_getres = process_cpu_clock_getres,
88550 .clock_get = process_cpu_clock_get,
88551 .timer_create = process_cpu_timer_create,
88552 .nsleep = process_cpu_nsleep,
88553 .nsleep_restart = process_cpu_nsleep_restart,
88554 };
88555- struct k_clock thread = {
88556+ static struct k_clock thread = {
88557 .clock_getres = thread_cpu_clock_getres,
88558 .clock_get = thread_cpu_clock_get,
88559 .timer_create = thread_cpu_timer_create,
88560diff --git a/kernel/posix-timers.c b/kernel/posix-timers.c
88561index 424c2d4..679242f 100644
88562--- a/kernel/posix-timers.c
88563+++ b/kernel/posix-timers.c
88564@@ -43,6 +43,7 @@
88565 #include <linux/hash.h>
88566 #include <linux/posix-clock.h>
88567 #include <linux/posix-timers.h>
88568+#include <linux/grsecurity.h>
88569 #include <linux/syscalls.h>
88570 #include <linux/wait.h>
88571 #include <linux/workqueue.h>
88572@@ -122,7 +123,7 @@ static DEFINE_SPINLOCK(hash_lock);
88573 * which we beg off on and pass to do_sys_settimeofday().
88574 */
88575
88576-static struct k_clock posix_clocks[MAX_CLOCKS];
88577+static struct k_clock *posix_clocks[MAX_CLOCKS];
88578
88579 /*
88580 * These ones are defined below.
88581@@ -275,7 +276,7 @@ static int posix_get_tai(clockid_t which_clock, struct timespec *tp)
88582 */
88583 static __init int init_posix_timers(void)
88584 {
88585- struct k_clock clock_realtime = {
88586+ static struct k_clock clock_realtime = {
88587 .clock_getres = hrtimer_get_res,
88588 .clock_get = posix_clock_realtime_get,
88589 .clock_set = posix_clock_realtime_set,
88590@@ -287,7 +288,7 @@ static __init int init_posix_timers(void)
88591 .timer_get = common_timer_get,
88592 .timer_del = common_timer_del,
88593 };
88594- struct k_clock clock_monotonic = {
88595+ static struct k_clock clock_monotonic = {
88596 .clock_getres = hrtimer_get_res,
88597 .clock_get = posix_ktime_get_ts,
88598 .nsleep = common_nsleep,
88599@@ -297,19 +298,19 @@ static __init int init_posix_timers(void)
88600 .timer_get = common_timer_get,
88601 .timer_del = common_timer_del,
88602 };
88603- struct k_clock clock_monotonic_raw = {
88604+ static struct k_clock clock_monotonic_raw = {
88605 .clock_getres = hrtimer_get_res,
88606 .clock_get = posix_get_monotonic_raw,
88607 };
88608- struct k_clock clock_realtime_coarse = {
88609+ static struct k_clock clock_realtime_coarse = {
88610 .clock_getres = posix_get_coarse_res,
88611 .clock_get = posix_get_realtime_coarse,
88612 };
88613- struct k_clock clock_monotonic_coarse = {
88614+ static struct k_clock clock_monotonic_coarse = {
88615 .clock_getres = posix_get_coarse_res,
88616 .clock_get = posix_get_monotonic_coarse,
88617 };
88618- struct k_clock clock_tai = {
88619+ static struct k_clock clock_tai = {
88620 .clock_getres = hrtimer_get_res,
88621 .clock_get = posix_get_tai,
88622 .nsleep = common_nsleep,
88623@@ -319,7 +320,7 @@ static __init int init_posix_timers(void)
88624 .timer_get = common_timer_get,
88625 .timer_del = common_timer_del,
88626 };
88627- struct k_clock clock_boottime = {
88628+ static struct k_clock clock_boottime = {
88629 .clock_getres = hrtimer_get_res,
88630 .clock_get = posix_get_boottime,
88631 .nsleep = common_nsleep,
88632@@ -531,7 +532,7 @@ void posix_timers_register_clock(const clockid_t clock_id,
88633 return;
88634 }
88635
88636- posix_clocks[clock_id] = *new_clock;
88637+ posix_clocks[clock_id] = new_clock;
88638 }
88639 EXPORT_SYMBOL_GPL(posix_timers_register_clock);
88640
88641@@ -577,9 +578,9 @@ static struct k_clock *clockid_to_kclock(const clockid_t id)
88642 return (id & CLOCKFD_MASK) == CLOCKFD ?
88643 &clock_posix_dynamic : &clock_posix_cpu;
88644
88645- if (id >= MAX_CLOCKS || !posix_clocks[id].clock_getres)
88646+ if (id >= MAX_CLOCKS || !posix_clocks[id] || !posix_clocks[id]->clock_getres)
88647 return NULL;
88648- return &posix_clocks[id];
88649+ return posix_clocks[id];
88650 }
88651
88652 static int common_timer_create(struct k_itimer *new_timer)
88653@@ -597,7 +598,7 @@ SYSCALL_DEFINE3(timer_create, const clockid_t, which_clock,
88654 struct k_clock *kc = clockid_to_kclock(which_clock);
88655 struct k_itimer *new_timer;
88656 int error, new_timer_id;
88657- sigevent_t event;
88658+ sigevent_t event = { };
88659 int it_id_set = IT_ID_NOT_SET;
88660
88661 if (!kc)
88662@@ -1011,6 +1012,13 @@ SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,
88663 if (copy_from_user(&new_tp, tp, sizeof (*tp)))
88664 return -EFAULT;
88665
88666+ /* only the CLOCK_REALTIME clock can be set, all other clocks
88667+ have their clock_set fptr set to a nosettime dummy function
88668+ CLOCK_REALTIME has a NULL clock_set fptr which causes it to
88669+ call common_clock_set, which calls do_sys_settimeofday, which
88670+ we hook
88671+ */
88672+
88673 return kc->clock_set(which_clock, &new_tp);
88674 }
88675
88676diff --git a/kernel/power/Kconfig b/kernel/power/Kconfig
88677index 2fac9cc..56fef29 100644
88678--- a/kernel/power/Kconfig
88679+++ b/kernel/power/Kconfig
88680@@ -24,6 +24,8 @@ config HIBERNATE_CALLBACKS
88681 config HIBERNATION
88682 bool "Hibernation (aka 'suspend to disk')"
88683 depends on SWAP && ARCH_HIBERNATION_POSSIBLE
88684+ depends on !GRKERNSEC_KMEM
88685+ depends on !PAX_MEMORY_SANITIZE
88686 select HIBERNATE_CALLBACKS
88687 select LZO_COMPRESS
88688 select LZO_DECOMPRESS
88689diff --git a/kernel/power/process.c b/kernel/power/process.c
88690index 06ec886..9dba35e 100644
88691--- a/kernel/power/process.c
88692+++ b/kernel/power/process.c
88693@@ -34,6 +34,7 @@ static int try_to_freeze_tasks(bool user_only)
88694 unsigned int elapsed_msecs;
88695 bool wakeup = false;
88696 int sleep_usecs = USEC_PER_MSEC;
88697+ bool timedout = false;
88698
88699 do_gettimeofday(&start);
88700
88701@@ -44,13 +45,20 @@ static int try_to_freeze_tasks(bool user_only)
88702
88703 while (true) {
88704 todo = 0;
88705+ if (time_after(jiffies, end_time))
88706+ timedout = true;
88707 read_lock(&tasklist_lock);
88708 do_each_thread(g, p) {
88709 if (p == current || !freeze_task(p))
88710 continue;
88711
88712- if (!freezer_should_skip(p))
88713+ if (!freezer_should_skip(p)) {
88714 todo++;
88715+ if (timedout) {
88716+ printk(KERN_ERR "Task refusing to freeze:\n");
88717+ sched_show_task(p);
88718+ }
88719+ }
88720 } while_each_thread(g, p);
88721 read_unlock(&tasklist_lock);
88722
88723@@ -59,7 +67,7 @@ static int try_to_freeze_tasks(bool user_only)
88724 todo += wq_busy;
88725 }
88726
88727- if (!todo || time_after(jiffies, end_time))
88728+ if (!todo || timedout)
88729 break;
88730
88731 if (pm_wakeup_pending()) {
88732diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
88733index 4dae9cb..039ffbb 100644
88734--- a/kernel/printk/printk.c
88735+++ b/kernel/printk/printk.c
88736@@ -385,6 +385,11 @@ static int check_syslog_permissions(int type, bool from_file)
88737 if (from_file && type != SYSLOG_ACTION_OPEN)
88738 return 0;
88739
88740+#ifdef CONFIG_GRKERNSEC_DMESG
88741+ if (grsec_enable_dmesg && !capable(CAP_SYSLOG) && !capable_nolog(CAP_SYS_ADMIN))
88742+ return -EPERM;
88743+#endif
88744+
88745 if (syslog_action_restricted(type)) {
88746 if (capable(CAP_SYSLOG))
88747 return 0;
88748diff --git a/kernel/profile.c b/kernel/profile.c
88749index ebdd9c1..612ee05 100644
88750--- a/kernel/profile.c
88751+++ b/kernel/profile.c
88752@@ -37,7 +37,7 @@ struct profile_hit {
88753 #define NR_PROFILE_HIT (PAGE_SIZE/sizeof(struct profile_hit))
88754 #define NR_PROFILE_GRP (NR_PROFILE_HIT/PROFILE_GRPSZ)
88755
88756-static atomic_t *prof_buffer;
88757+static atomic_unchecked_t *prof_buffer;
88758 static unsigned long prof_len, prof_shift;
88759
88760 int prof_on __read_mostly;
88761@@ -260,7 +260,7 @@ static void profile_flip_buffers(void)
88762 hits[i].pc = 0;
88763 continue;
88764 }
88765- atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
88766+ atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
88767 hits[i].hits = hits[i].pc = 0;
88768 }
88769 }
88770@@ -321,9 +321,9 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
88771 * Add the current hit(s) and flush the write-queue out
88772 * to the global buffer:
88773 */
88774- atomic_add(nr_hits, &prof_buffer[pc]);
88775+ atomic_add_unchecked(nr_hits, &prof_buffer[pc]);
88776 for (i = 0; i < NR_PROFILE_HIT; ++i) {
88777- atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
88778+ atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
88779 hits[i].pc = hits[i].hits = 0;
88780 }
88781 out:
88782@@ -398,7 +398,7 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
88783 {
88784 unsigned long pc;
88785 pc = ((unsigned long)__pc - (unsigned long)_stext) >> prof_shift;
88786- atomic_add(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
88787+ atomic_add_unchecked(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
88788 }
88789 #endif /* !CONFIG_SMP */
88790
88791@@ -494,7 +494,7 @@ read_profile(struct file *file, char __user *buf, size_t count, loff_t *ppos)
88792 return -EFAULT;
88793 buf++; p++; count--; read++;
88794 }
88795- pnt = (char *)prof_buffer + p - sizeof(atomic_t);
88796+ pnt = (char *)prof_buffer + p - sizeof(atomic_unchecked_t);
88797 if (copy_to_user(buf, (void *)pnt, count))
88798 return -EFAULT;
88799 read += count;
88800@@ -525,7 +525,7 @@ static ssize_t write_profile(struct file *file, const char __user *buf,
88801 }
88802 #endif
88803 profile_discard_flip_buffers();
88804- memset(prof_buffer, 0, prof_len * sizeof(atomic_t));
88805+ memset(prof_buffer, 0, prof_len * sizeof(atomic_unchecked_t));
88806 return count;
88807 }
88808
88809diff --git a/kernel/ptrace.c b/kernel/ptrace.c
88810index 1f4bcb3..99cf7ab 100644
88811--- a/kernel/ptrace.c
88812+++ b/kernel/ptrace.c
88813@@ -327,7 +327,7 @@ static int ptrace_attach(struct task_struct *task, long request,
88814 if (seize)
88815 flags |= PT_SEIZED;
88816 rcu_read_lock();
88817- if (ns_capable(__task_cred(task)->user_ns, CAP_SYS_PTRACE))
88818+ if (ns_capable_nolog(__task_cred(task)->user_ns, CAP_SYS_PTRACE))
88819 flags |= PT_PTRACE_CAP;
88820 rcu_read_unlock();
88821 task->ptrace = flags;
88822@@ -538,7 +538,7 @@ int ptrace_readdata(struct task_struct *tsk, unsigned long src, char __user *dst
88823 break;
88824 return -EIO;
88825 }
88826- if (copy_to_user(dst, buf, retval))
88827+ if (retval > sizeof(buf) || copy_to_user(dst, buf, retval))
88828 return -EFAULT;
88829 copied += retval;
88830 src += retval;
88831@@ -806,7 +806,7 @@ int ptrace_request(struct task_struct *child, long request,
88832 bool seized = child->ptrace & PT_SEIZED;
88833 int ret = -EIO;
88834 siginfo_t siginfo, *si;
88835- void __user *datavp = (void __user *) data;
88836+ void __user *datavp = (__force void __user *) data;
88837 unsigned long __user *datalp = datavp;
88838 unsigned long flags;
88839
88840@@ -1052,14 +1052,21 @@ SYSCALL_DEFINE4(ptrace, long, request, long, pid, unsigned long, addr,
88841 goto out;
88842 }
88843
88844+ if (gr_handle_ptrace(child, request)) {
88845+ ret = -EPERM;
88846+ goto out_put_task_struct;
88847+ }
88848+
88849 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
88850 ret = ptrace_attach(child, request, addr, data);
88851 /*
88852 * Some architectures need to do book-keeping after
88853 * a ptrace attach.
88854 */
88855- if (!ret)
88856+ if (!ret) {
88857 arch_ptrace_attach(child);
88858+ gr_audit_ptrace(child);
88859+ }
88860 goto out_put_task_struct;
88861 }
88862
88863@@ -1087,7 +1094,7 @@ int generic_ptrace_peekdata(struct task_struct *tsk, unsigned long addr,
88864 copied = access_process_vm(tsk, addr, &tmp, sizeof(tmp), 0);
88865 if (copied != sizeof(tmp))
88866 return -EIO;
88867- return put_user(tmp, (unsigned long __user *)data);
88868+ return put_user(tmp, (__force unsigned long __user *)data);
88869 }
88870
88871 int generic_ptrace_pokedata(struct task_struct *tsk, unsigned long addr,
88872@@ -1181,7 +1188,7 @@ int compat_ptrace_request(struct task_struct *child, compat_long_t request,
88873 }
88874
88875 asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
88876- compat_long_t addr, compat_long_t data)
88877+ compat_ulong_t addr, compat_ulong_t data)
88878 {
88879 struct task_struct *child;
88880 long ret;
88881@@ -1197,14 +1204,21 @@ asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
88882 goto out;
88883 }
88884
88885+ if (gr_handle_ptrace(child, request)) {
88886+ ret = -EPERM;
88887+ goto out_put_task_struct;
88888+ }
88889+
88890 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
88891 ret = ptrace_attach(child, request, addr, data);
88892 /*
88893 * Some architectures need to do book-keeping after
88894 * a ptrace attach.
88895 */
88896- if (!ret)
88897+ if (!ret) {
88898 arch_ptrace_attach(child);
88899+ gr_audit_ptrace(child);
88900+ }
88901 goto out_put_task_struct;
88902 }
88903
88904diff --git a/kernel/rcu/srcu.c b/kernel/rcu/srcu.c
88905index 3318d82..1a5b2d1 100644
88906--- a/kernel/rcu/srcu.c
88907+++ b/kernel/rcu/srcu.c
88908@@ -300,9 +300,9 @@ int __srcu_read_lock(struct srcu_struct *sp)
88909
88910 idx = ACCESS_ONCE(sp->completed) & 0x1;
88911 preempt_disable();
88912- ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
88913+ ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
88914 smp_mb(); /* B */ /* Avoid leaking the critical section. */
88915- ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
88916+ ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
88917 preempt_enable();
88918 return idx;
88919 }
88920diff --git a/kernel/rcu/tiny.c b/kernel/rcu/tiny.c
88921index 1254f31..16258dc 100644
88922--- a/kernel/rcu/tiny.c
88923+++ b/kernel/rcu/tiny.c
88924@@ -46,7 +46,7 @@
88925 /* Forward declarations for tiny_plugin.h. */
88926 struct rcu_ctrlblk;
88927 static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp);
88928-static void rcu_process_callbacks(struct softirq_action *unused);
88929+static void rcu_process_callbacks(void);
88930 static void __call_rcu(struct rcu_head *head,
88931 void (*func)(struct rcu_head *rcu),
88932 struct rcu_ctrlblk *rcp);
88933@@ -312,7 +312,7 @@ static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp)
88934 false));
88935 }
88936
88937-static void rcu_process_callbacks(struct softirq_action *unused)
88938+static __latent_entropy void rcu_process_callbacks(void)
88939 {
88940 __rcu_process_callbacks(&rcu_sched_ctrlblk);
88941 __rcu_process_callbacks(&rcu_bh_ctrlblk);
88942diff --git a/kernel/rcu/torture.c b/kernel/rcu/torture.c
88943index 732f8ae..42c1919 100644
88944--- a/kernel/rcu/torture.c
88945+++ b/kernel/rcu/torture.c
88946@@ -174,12 +174,12 @@ static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_count) =
88947 { 0 };
88948 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_batch) =
88949 { 0 };
88950-static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
88951-static atomic_t n_rcu_torture_alloc;
88952-static atomic_t n_rcu_torture_alloc_fail;
88953-static atomic_t n_rcu_torture_free;
88954-static atomic_t n_rcu_torture_mberror;
88955-static atomic_t n_rcu_torture_error;
88956+static atomic_unchecked_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
88957+static atomic_unchecked_t n_rcu_torture_alloc;
88958+static atomic_unchecked_t n_rcu_torture_alloc_fail;
88959+static atomic_unchecked_t n_rcu_torture_free;
88960+static atomic_unchecked_t n_rcu_torture_mberror;
88961+static atomic_unchecked_t n_rcu_torture_error;
88962 static long n_rcu_torture_barrier_error;
88963 static long n_rcu_torture_boost_ktrerror;
88964 static long n_rcu_torture_boost_rterror;
88965@@ -297,11 +297,11 @@ rcu_torture_alloc(void)
88966
88967 spin_lock_bh(&rcu_torture_lock);
88968 if (list_empty(&rcu_torture_freelist)) {
88969- atomic_inc(&n_rcu_torture_alloc_fail);
88970+ atomic_inc_unchecked(&n_rcu_torture_alloc_fail);
88971 spin_unlock_bh(&rcu_torture_lock);
88972 return NULL;
88973 }
88974- atomic_inc(&n_rcu_torture_alloc);
88975+ atomic_inc_unchecked(&n_rcu_torture_alloc);
88976 p = rcu_torture_freelist.next;
88977 list_del_init(p);
88978 spin_unlock_bh(&rcu_torture_lock);
88979@@ -314,7 +314,7 @@ rcu_torture_alloc(void)
88980 static void
88981 rcu_torture_free(struct rcu_torture *p)
88982 {
88983- atomic_inc(&n_rcu_torture_free);
88984+ atomic_inc_unchecked(&n_rcu_torture_free);
88985 spin_lock_bh(&rcu_torture_lock);
88986 list_add_tail(&p->rtort_free, &rcu_torture_freelist);
88987 spin_unlock_bh(&rcu_torture_lock);
88988@@ -435,7 +435,7 @@ rcu_torture_cb(struct rcu_head *p)
88989 i = rp->rtort_pipe_count;
88990 if (i > RCU_TORTURE_PIPE_LEN)
88991 i = RCU_TORTURE_PIPE_LEN;
88992- atomic_inc(&rcu_torture_wcount[i]);
88993+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
88994 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
88995 rp->rtort_mbtest = 0;
88996 rcu_torture_free(rp);
88997@@ -823,7 +823,7 @@ rcu_torture_writer(void *arg)
88998 i = old_rp->rtort_pipe_count;
88999 if (i > RCU_TORTURE_PIPE_LEN)
89000 i = RCU_TORTURE_PIPE_LEN;
89001- atomic_inc(&rcu_torture_wcount[i]);
89002+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
89003 old_rp->rtort_pipe_count++;
89004 if (gp_normal == gp_exp)
89005 exp = !!(rcu_random(&rand) & 0x80);
89006@@ -841,7 +841,7 @@ rcu_torture_writer(void *arg)
89007 i = rp->rtort_pipe_count;
89008 if (i > RCU_TORTURE_PIPE_LEN)
89009 i = RCU_TORTURE_PIPE_LEN;
89010- atomic_inc(&rcu_torture_wcount[i]);
89011+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
89012 if (++rp->rtort_pipe_count >=
89013 RCU_TORTURE_PIPE_LEN) {
89014 rp->rtort_mbtest = 0;
89015@@ -940,7 +940,7 @@ static void rcu_torture_timer(unsigned long unused)
89016 return;
89017 }
89018 if (p->rtort_mbtest == 0)
89019- atomic_inc(&n_rcu_torture_mberror);
89020+ atomic_inc_unchecked(&n_rcu_torture_mberror);
89021 spin_lock(&rand_lock);
89022 cur_ops->read_delay(&rand);
89023 n_rcu_torture_timers++;
89024@@ -1010,7 +1010,7 @@ rcu_torture_reader(void *arg)
89025 continue;
89026 }
89027 if (p->rtort_mbtest == 0)
89028- atomic_inc(&n_rcu_torture_mberror);
89029+ atomic_inc_unchecked(&n_rcu_torture_mberror);
89030 cur_ops->read_delay(&rand);
89031 preempt_disable();
89032 pipe_count = p->rtort_pipe_count;
89033@@ -1068,15 +1068,15 @@ rcu_torture_printk(char *page)
89034 }
89035 page += sprintf(page, "%s%s ", torture_type, TORTURE_FLAG);
89036 page += sprintf(page,
89037- "rtc: %p ver: %lu tfle: %d rta: %d rtaf: %d rtf: %d ",
89038+ "rtc: %pP ver: %lu tfle: %d rta: %d rtaf: %d rtf: %d ",
89039 rcu_torture_current,
89040 rcu_torture_current_version,
89041 list_empty(&rcu_torture_freelist),
89042- atomic_read(&n_rcu_torture_alloc),
89043- atomic_read(&n_rcu_torture_alloc_fail),
89044- atomic_read(&n_rcu_torture_free));
89045+ atomic_read_unchecked(&n_rcu_torture_alloc),
89046+ atomic_read_unchecked(&n_rcu_torture_alloc_fail),
89047+ atomic_read_unchecked(&n_rcu_torture_free));
89048 page += sprintf(page, "rtmbe: %d rtbke: %ld rtbre: %ld ",
89049- atomic_read(&n_rcu_torture_mberror),
89050+ atomic_read_unchecked(&n_rcu_torture_mberror),
89051 n_rcu_torture_boost_ktrerror,
89052 n_rcu_torture_boost_rterror);
89053 page += sprintf(page, "rtbf: %ld rtb: %ld nt: %ld ",
89054@@ -1095,14 +1095,14 @@ rcu_torture_printk(char *page)
89055 n_barrier_attempts,
89056 n_rcu_torture_barrier_error);
89057 page += sprintf(page, "\n%s%s ", torture_type, TORTURE_FLAG);
89058- if (atomic_read(&n_rcu_torture_mberror) != 0 ||
89059+ if (atomic_read_unchecked(&n_rcu_torture_mberror) != 0 ||
89060 n_rcu_torture_barrier_error != 0 ||
89061 n_rcu_torture_boost_ktrerror != 0 ||
89062 n_rcu_torture_boost_rterror != 0 ||
89063 n_rcu_torture_boost_failure != 0 ||
89064 i > 1) {
89065 page += sprintf(page, "!!! ");
89066- atomic_inc(&n_rcu_torture_error);
89067+ atomic_inc_unchecked(&n_rcu_torture_error);
89068 WARN_ON_ONCE(1);
89069 }
89070 page += sprintf(page, "Reader Pipe: ");
89071@@ -1116,7 +1116,7 @@ rcu_torture_printk(char *page)
89072 page += sprintf(page, "Free-Block Circulation: ");
89073 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
89074 page += sprintf(page, " %d",
89075- atomic_read(&rcu_torture_wcount[i]));
89076+ atomic_read_unchecked(&rcu_torture_wcount[i]));
89077 }
89078 page += sprintf(page, "\n");
89079 if (cur_ops->stats)
89080@@ -1839,7 +1839,7 @@ rcu_torture_cleanup(void)
89081
89082 rcu_torture_stats_print(); /* -After- the stats thread is stopped! */
89083
89084- if (atomic_read(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
89085+ if (atomic_read_unchecked(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
89086 rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE");
89087 else if (n_online_successes != n_online_attempts ||
89088 n_offline_successes != n_offline_attempts)
89089@@ -1961,18 +1961,18 @@ rcu_torture_init(void)
89090
89091 rcu_torture_current = NULL;
89092 rcu_torture_current_version = 0;
89093- atomic_set(&n_rcu_torture_alloc, 0);
89094- atomic_set(&n_rcu_torture_alloc_fail, 0);
89095- atomic_set(&n_rcu_torture_free, 0);
89096- atomic_set(&n_rcu_torture_mberror, 0);
89097- atomic_set(&n_rcu_torture_error, 0);
89098+ atomic_set_unchecked(&n_rcu_torture_alloc, 0);
89099+ atomic_set_unchecked(&n_rcu_torture_alloc_fail, 0);
89100+ atomic_set_unchecked(&n_rcu_torture_free, 0);
89101+ atomic_set_unchecked(&n_rcu_torture_mberror, 0);
89102+ atomic_set_unchecked(&n_rcu_torture_error, 0);
89103 n_rcu_torture_barrier_error = 0;
89104 n_rcu_torture_boost_ktrerror = 0;
89105 n_rcu_torture_boost_rterror = 0;
89106 n_rcu_torture_boost_failure = 0;
89107 n_rcu_torture_boosts = 0;
89108 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
89109- atomic_set(&rcu_torture_wcount[i], 0);
89110+ atomic_set_unchecked(&rcu_torture_wcount[i], 0);
89111 for_each_possible_cpu(cpu) {
89112 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
89113 per_cpu(rcu_torture_count, cpu)[i] = 0;
89114diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c
89115index b3d116c..ebf6598 100644
89116--- a/kernel/rcu/tree.c
89117+++ b/kernel/rcu/tree.c
89118@@ -390,9 +390,9 @@ static void rcu_eqs_enter_common(struct rcu_dynticks *rdtp, long long oldval,
89119 rcu_prepare_for_idle(smp_processor_id());
89120 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
89121 smp_mb__before_atomic_inc(); /* See above. */
89122- atomic_inc(&rdtp->dynticks);
89123+ atomic_inc_unchecked(&rdtp->dynticks);
89124 smp_mb__after_atomic_inc(); /* Force ordering with next sojourn. */
89125- WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
89126+ WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
89127
89128 /*
89129 * It is illegal to enter an extended quiescent state while
89130@@ -510,10 +510,10 @@ static void rcu_eqs_exit_common(struct rcu_dynticks *rdtp, long long oldval,
89131 int user)
89132 {
89133 smp_mb__before_atomic_inc(); /* Force ordering w/previous sojourn. */
89134- atomic_inc(&rdtp->dynticks);
89135+ atomic_inc_unchecked(&rdtp->dynticks);
89136 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
89137 smp_mb__after_atomic_inc(); /* See above. */
89138- WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
89139+ WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
89140 rcu_cleanup_after_idle(smp_processor_id());
89141 trace_rcu_dyntick(TPS("End"), oldval, rdtp->dynticks_nesting);
89142 if (!user && !is_idle_task(current)) {
89143@@ -634,14 +634,14 @@ void rcu_nmi_enter(void)
89144 struct rcu_dynticks *rdtp = this_cpu_ptr(&rcu_dynticks);
89145
89146 if (rdtp->dynticks_nmi_nesting == 0 &&
89147- (atomic_read(&rdtp->dynticks) & 0x1))
89148+ (atomic_read_unchecked(&rdtp->dynticks) & 0x1))
89149 return;
89150 rdtp->dynticks_nmi_nesting++;
89151 smp_mb__before_atomic_inc(); /* Force delay from prior write. */
89152- atomic_inc(&rdtp->dynticks);
89153+ atomic_inc_unchecked(&rdtp->dynticks);
89154 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
89155 smp_mb__after_atomic_inc(); /* See above. */
89156- WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
89157+ WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
89158 }
89159
89160 /**
89161@@ -660,9 +660,9 @@ void rcu_nmi_exit(void)
89162 return;
89163 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
89164 smp_mb__before_atomic_inc(); /* See above. */
89165- atomic_inc(&rdtp->dynticks);
89166+ atomic_inc_unchecked(&rdtp->dynticks);
89167 smp_mb__after_atomic_inc(); /* Force delay to next write. */
89168- WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
89169+ WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
89170 }
89171
89172 /**
89173@@ -675,7 +675,7 @@ void rcu_nmi_exit(void)
89174 */
89175 bool notrace __rcu_is_watching(void)
89176 {
89177- return atomic_read(this_cpu_ptr(&rcu_dynticks.dynticks)) & 0x1;
89178+ return atomic_read_unchecked(this_cpu_ptr(&rcu_dynticks.dynticks)) & 0x1;
89179 }
89180
89181 /**
89182@@ -758,7 +758,7 @@ static int rcu_is_cpu_rrupt_from_idle(void)
89183 static int dyntick_save_progress_counter(struct rcu_data *rdp,
89184 bool *isidle, unsigned long *maxj)
89185 {
89186- rdp->dynticks_snap = atomic_add_return(0, &rdp->dynticks->dynticks);
89187+ rdp->dynticks_snap = atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
89188 rcu_sysidle_check_cpu(rdp, isidle, maxj);
89189 return (rdp->dynticks_snap & 0x1) == 0;
89190 }
89191@@ -781,7 +781,7 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp,
89192 unsigned int curr;
89193 unsigned int snap;
89194
89195- curr = (unsigned int)atomic_add_return(0, &rdp->dynticks->dynticks);
89196+ curr = (unsigned int)atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
89197 snap = (unsigned int)rdp->dynticks_snap;
89198
89199 /*
89200@@ -1450,9 +1450,9 @@ static int rcu_gp_init(struct rcu_state *rsp)
89201 rdp = this_cpu_ptr(rsp->rda);
89202 rcu_preempt_check_blocked_tasks(rnp);
89203 rnp->qsmask = rnp->qsmaskinit;
89204- ACCESS_ONCE(rnp->gpnum) = rsp->gpnum;
89205+ ACCESS_ONCE_RW(rnp->gpnum) = rsp->gpnum;
89206 WARN_ON_ONCE(rnp->completed != rsp->completed);
89207- ACCESS_ONCE(rnp->completed) = rsp->completed;
89208+ ACCESS_ONCE_RW(rnp->completed) = rsp->completed;
89209 if (rnp == rdp->mynode)
89210 __note_gp_changes(rsp, rnp, rdp);
89211 rcu_preempt_boost_start_gp(rnp);
89212@@ -1546,7 +1546,7 @@ static void rcu_gp_cleanup(struct rcu_state *rsp)
89213 rcu_for_each_node_breadth_first(rsp, rnp) {
89214 raw_spin_lock_irq(&rnp->lock);
89215 smp_mb__after_unlock_lock();
89216- ACCESS_ONCE(rnp->completed) = rsp->gpnum;
89217+ ACCESS_ONCE_RW(rnp->completed) = rsp->gpnum;
89218 rdp = this_cpu_ptr(rsp->rda);
89219 if (rnp == rdp->mynode)
89220 __note_gp_changes(rsp, rnp, rdp);
89221@@ -1912,7 +1912,7 @@ rcu_send_cbs_to_orphanage(int cpu, struct rcu_state *rsp,
89222 rsp->qlen += rdp->qlen;
89223 rdp->n_cbs_orphaned += rdp->qlen;
89224 rdp->qlen_lazy = 0;
89225- ACCESS_ONCE(rdp->qlen) = 0;
89226+ ACCESS_ONCE_RW(rdp->qlen) = 0;
89227 }
89228
89229 /*
89230@@ -2159,7 +2159,7 @@ static void rcu_do_batch(struct rcu_state *rsp, struct rcu_data *rdp)
89231 }
89232 smp_mb(); /* List handling before counting for rcu_barrier(). */
89233 rdp->qlen_lazy -= count_lazy;
89234- ACCESS_ONCE(rdp->qlen) -= count;
89235+ ACCESS_ONCE_RW(rdp->qlen) -= count;
89236 rdp->n_cbs_invoked += count;
89237
89238 /* Reinstate batch limit if we have worked down the excess. */
89239@@ -2362,7 +2362,7 @@ __rcu_process_callbacks(struct rcu_state *rsp)
89240 /*
89241 * Do RCU core processing for the current CPU.
89242 */
89243-static void rcu_process_callbacks(struct softirq_action *unused)
89244+static void rcu_process_callbacks(void)
89245 {
89246 struct rcu_state *rsp;
89247
89248@@ -2470,7 +2470,7 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
89249 WARN_ON_ONCE((unsigned long)head & 0x3); /* Misaligned rcu_head! */
89250 if (debug_rcu_head_queue(head)) {
89251 /* Probable double call_rcu(), so leak the callback. */
89252- ACCESS_ONCE(head->func) = rcu_leak_callback;
89253+ ACCESS_ONCE_RW(head->func) = rcu_leak_callback;
89254 WARN_ONCE(1, "__call_rcu(): Leaked duplicate callback\n");
89255 return;
89256 }
89257@@ -2498,7 +2498,7 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
89258 local_irq_restore(flags);
89259 return;
89260 }
89261- ACCESS_ONCE(rdp->qlen)++;
89262+ ACCESS_ONCE_RW(rdp->qlen)++;
89263 if (lazy)
89264 rdp->qlen_lazy++;
89265 else
89266@@ -2707,11 +2707,11 @@ void synchronize_sched_expedited(void)
89267 * counter wrap on a 32-bit system. Quite a few more CPUs would of
89268 * course be required on a 64-bit system.
89269 */
89270- if (ULONG_CMP_GE((ulong)atomic_long_read(&rsp->expedited_start),
89271+ if (ULONG_CMP_GE((ulong)atomic_long_read_unchecked(&rsp->expedited_start),
89272 (ulong)atomic_long_read(&rsp->expedited_done) +
89273 ULONG_MAX / 8)) {
89274 synchronize_sched();
89275- atomic_long_inc(&rsp->expedited_wrap);
89276+ atomic_long_inc_unchecked(&rsp->expedited_wrap);
89277 return;
89278 }
89279
89280@@ -2719,7 +2719,7 @@ void synchronize_sched_expedited(void)
89281 * Take a ticket. Note that atomic_inc_return() implies a
89282 * full memory barrier.
89283 */
89284- snap = atomic_long_inc_return(&rsp->expedited_start);
89285+ snap = atomic_long_inc_return_unchecked(&rsp->expedited_start);
89286 firstsnap = snap;
89287 get_online_cpus();
89288 WARN_ON_ONCE(cpu_is_offline(raw_smp_processor_id()));
89289@@ -2732,14 +2732,14 @@ void synchronize_sched_expedited(void)
89290 synchronize_sched_expedited_cpu_stop,
89291 NULL) == -EAGAIN) {
89292 put_online_cpus();
89293- atomic_long_inc(&rsp->expedited_tryfail);
89294+ atomic_long_inc_unchecked(&rsp->expedited_tryfail);
89295
89296 /* Check to see if someone else did our work for us. */
89297 s = atomic_long_read(&rsp->expedited_done);
89298 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
89299 /* ensure test happens before caller kfree */
89300 smp_mb__before_atomic_inc(); /* ^^^ */
89301- atomic_long_inc(&rsp->expedited_workdone1);
89302+ atomic_long_inc_unchecked(&rsp->expedited_workdone1);
89303 return;
89304 }
89305
89306@@ -2748,7 +2748,7 @@ void synchronize_sched_expedited(void)
89307 udelay(trycount * num_online_cpus());
89308 } else {
89309 wait_rcu_gp(call_rcu_sched);
89310- atomic_long_inc(&rsp->expedited_normal);
89311+ atomic_long_inc_unchecked(&rsp->expedited_normal);
89312 return;
89313 }
89314
89315@@ -2757,7 +2757,7 @@ void synchronize_sched_expedited(void)
89316 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
89317 /* ensure test happens before caller kfree */
89318 smp_mb__before_atomic_inc(); /* ^^^ */
89319- atomic_long_inc(&rsp->expedited_workdone2);
89320+ atomic_long_inc_unchecked(&rsp->expedited_workdone2);
89321 return;
89322 }
89323
89324@@ -2769,10 +2769,10 @@ void synchronize_sched_expedited(void)
89325 * period works for us.
89326 */
89327 get_online_cpus();
89328- snap = atomic_long_read(&rsp->expedited_start);
89329+ snap = atomic_long_read_unchecked(&rsp->expedited_start);
89330 smp_mb(); /* ensure read is before try_stop_cpus(). */
89331 }
89332- atomic_long_inc(&rsp->expedited_stoppedcpus);
89333+ atomic_long_inc_unchecked(&rsp->expedited_stoppedcpus);
89334
89335 /*
89336 * Everyone up to our most recent fetch is covered by our grace
89337@@ -2781,16 +2781,16 @@ void synchronize_sched_expedited(void)
89338 * than we did already did their update.
89339 */
89340 do {
89341- atomic_long_inc(&rsp->expedited_done_tries);
89342+ atomic_long_inc_unchecked(&rsp->expedited_done_tries);
89343 s = atomic_long_read(&rsp->expedited_done);
89344 if (ULONG_CMP_GE((ulong)s, (ulong)snap)) {
89345 /* ensure test happens before caller kfree */
89346 smp_mb__before_atomic_inc(); /* ^^^ */
89347- atomic_long_inc(&rsp->expedited_done_lost);
89348+ atomic_long_inc_unchecked(&rsp->expedited_done_lost);
89349 break;
89350 }
89351 } while (atomic_long_cmpxchg(&rsp->expedited_done, s, snap) != s);
89352- atomic_long_inc(&rsp->expedited_done_exit);
89353+ atomic_long_inc_unchecked(&rsp->expedited_done_exit);
89354
89355 put_online_cpus();
89356 }
89357@@ -2996,7 +2996,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
89358 * ACCESS_ONCE() to prevent the compiler from speculating
89359 * the increment to precede the early-exit check.
89360 */
89361- ACCESS_ONCE(rsp->n_barrier_done)++;
89362+ ACCESS_ONCE_RW(rsp->n_barrier_done)++;
89363 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 1);
89364 _rcu_barrier_trace(rsp, "Inc1", -1, rsp->n_barrier_done);
89365 smp_mb(); /* Order ->n_barrier_done increment with below mechanism. */
89366@@ -3046,7 +3046,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
89367
89368 /* Increment ->n_barrier_done to prevent duplicate work. */
89369 smp_mb(); /* Keep increment after above mechanism. */
89370- ACCESS_ONCE(rsp->n_barrier_done)++;
89371+ ACCESS_ONCE_RW(rsp->n_barrier_done)++;
89372 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 0);
89373 _rcu_barrier_trace(rsp, "Inc2", -1, rsp->n_barrier_done);
89374 smp_mb(); /* Keep increment before caller's subsequent code. */
89375@@ -3091,10 +3091,10 @@ rcu_boot_init_percpu_data(int cpu, struct rcu_state *rsp)
89376 rdp->grpmask = 1UL << (cpu - rdp->mynode->grplo);
89377 init_callback_list(rdp);
89378 rdp->qlen_lazy = 0;
89379- ACCESS_ONCE(rdp->qlen) = 0;
89380+ ACCESS_ONCE_RW(rdp->qlen) = 0;
89381 rdp->dynticks = &per_cpu(rcu_dynticks, cpu);
89382 WARN_ON_ONCE(rdp->dynticks->dynticks_nesting != DYNTICK_TASK_EXIT_IDLE);
89383- WARN_ON_ONCE(atomic_read(&rdp->dynticks->dynticks) != 1);
89384+ WARN_ON_ONCE(atomic_read_unchecked(&rdp->dynticks->dynticks) != 1);
89385 rdp->cpu = cpu;
89386 rdp->rsp = rsp;
89387 rcu_boot_init_nocb_percpu_data(rdp);
89388@@ -3128,8 +3128,8 @@ rcu_init_percpu_data(int cpu, struct rcu_state *rsp, int preemptible)
89389 init_callback_list(rdp); /* Re-enable callbacks on this CPU. */
89390 rdp->dynticks->dynticks_nesting = DYNTICK_TASK_EXIT_IDLE;
89391 rcu_sysidle_init_percpu_data(rdp->dynticks);
89392- atomic_set(&rdp->dynticks->dynticks,
89393- (atomic_read(&rdp->dynticks->dynticks) & ~0x1) + 1);
89394+ atomic_set_unchecked(&rdp->dynticks->dynticks,
89395+ (atomic_read_unchecked(&rdp->dynticks->dynticks) & ~0x1) + 1);
89396 raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */
89397
89398 /* Add CPU to rcu_node bitmasks. */
89399diff --git a/kernel/rcu/tree.h b/kernel/rcu/tree.h
89400index 8c19873..bf83c57 100644
89401--- a/kernel/rcu/tree.h
89402+++ b/kernel/rcu/tree.h
89403@@ -87,11 +87,11 @@ struct rcu_dynticks {
89404 long long dynticks_nesting; /* Track irq/process nesting level. */
89405 /* Process level is worth LLONG_MAX/2. */
89406 int dynticks_nmi_nesting; /* Track NMI nesting level. */
89407- atomic_t dynticks; /* Even value for idle, else odd. */
89408+ atomic_unchecked_t dynticks;/* Even value for idle, else odd. */
89409 #ifdef CONFIG_NO_HZ_FULL_SYSIDLE
89410 long long dynticks_idle_nesting;
89411 /* irq/process nesting level from idle. */
89412- atomic_t dynticks_idle; /* Even value for idle, else odd. */
89413+ atomic_unchecked_t dynticks_idle;/* Even value for idle, else odd. */
89414 /* "Idle" excludes userspace execution. */
89415 unsigned long dynticks_idle_jiffies;
89416 /* End of last non-NMI non-idle period. */
89417@@ -431,17 +431,17 @@ struct rcu_state {
89418 /* _rcu_barrier(). */
89419 /* End of fields guarded by barrier_mutex. */
89420
89421- atomic_long_t expedited_start; /* Starting ticket. */
89422- atomic_long_t expedited_done; /* Done ticket. */
89423- atomic_long_t expedited_wrap; /* # near-wrap incidents. */
89424- atomic_long_t expedited_tryfail; /* # acquisition failures. */
89425- atomic_long_t expedited_workdone1; /* # done by others #1. */
89426- atomic_long_t expedited_workdone2; /* # done by others #2. */
89427- atomic_long_t expedited_normal; /* # fallbacks to normal. */
89428- atomic_long_t expedited_stoppedcpus; /* # successful stop_cpus. */
89429- atomic_long_t expedited_done_tries; /* # tries to update _done. */
89430- atomic_long_t expedited_done_lost; /* # times beaten to _done. */
89431- atomic_long_t expedited_done_exit; /* # times exited _done loop. */
89432+ atomic_long_unchecked_t expedited_start; /* Starting ticket. */
89433+ atomic_long_t expedited_done; /* Done ticket. */
89434+ atomic_long_unchecked_t expedited_wrap; /* # near-wrap incidents. */
89435+ atomic_long_unchecked_t expedited_tryfail; /* # acquisition failures. */
89436+ atomic_long_unchecked_t expedited_workdone1; /* # done by others #1. */
89437+ atomic_long_unchecked_t expedited_workdone2; /* # done by others #2. */
89438+ atomic_long_unchecked_t expedited_normal; /* # fallbacks to normal. */
89439+ atomic_long_unchecked_t expedited_stoppedcpus; /* # successful stop_cpus. */
89440+ atomic_long_unchecked_t expedited_done_tries; /* # tries to update _done. */
89441+ atomic_long_unchecked_t expedited_done_lost; /* # times beaten to _done. */
89442+ atomic_long_unchecked_t expedited_done_exit; /* # times exited _done loop. */
89443
89444 unsigned long jiffies_force_qs; /* Time at which to invoke */
89445 /* force_quiescent_state(). */
89446diff --git a/kernel/rcu/tree_plugin.h b/kernel/rcu/tree_plugin.h
89447index 6e2ef4b..c15df94 100644
89448--- a/kernel/rcu/tree_plugin.h
89449+++ b/kernel/rcu/tree_plugin.h
89450@@ -758,7 +758,7 @@ static int rcu_preempted_readers_exp(struct rcu_node *rnp)
89451 static int sync_rcu_preempt_exp_done(struct rcu_node *rnp)
89452 {
89453 return !rcu_preempted_readers_exp(rnp) &&
89454- ACCESS_ONCE(rnp->expmask) == 0;
89455+ ACCESS_ONCE_RW(rnp->expmask) == 0;
89456 }
89457
89458 /*
89459@@ -920,7 +920,7 @@ void synchronize_rcu_expedited(void)
89460
89461 /* Clean up and exit. */
89462 smp_mb(); /* ensure expedited GP seen before counter increment. */
89463- ACCESS_ONCE(sync_rcu_preempt_exp_count)++;
89464+ ACCESS_ONCE_RW(sync_rcu_preempt_exp_count)++;
89465 unlock_mb_ret:
89466 mutex_unlock(&sync_rcu_preempt_exp_mutex);
89467 mb_ret:
89468@@ -1496,7 +1496,7 @@ static void rcu_boost_kthread_setaffinity(struct rcu_node *rnp, int outgoingcpu)
89469 free_cpumask_var(cm);
89470 }
89471
89472-static struct smp_hotplug_thread rcu_cpu_thread_spec = {
89473+static struct smp_hotplug_thread rcu_cpu_thread_spec __read_only = {
89474 .store = &rcu_cpu_kthread_task,
89475 .thread_should_run = rcu_cpu_kthread_should_run,
89476 .thread_fn = rcu_cpu_kthread,
89477@@ -1965,7 +1965,7 @@ static void print_cpu_stall_info(struct rcu_state *rsp, int cpu)
89478 print_cpu_stall_fast_no_hz(fast_no_hz, cpu);
89479 pr_err("\t%d: (%lu %s) idle=%03x/%llx/%d softirq=%u/%u %s\n",
89480 cpu, ticks_value, ticks_title,
89481- atomic_read(&rdtp->dynticks) & 0xfff,
89482+ atomic_read_unchecked(&rdtp->dynticks) & 0xfff,
89483 rdtp->dynticks_nesting, rdtp->dynticks_nmi_nesting,
89484 rdp->softirq_snap, kstat_softirqs_cpu(RCU_SOFTIRQ, cpu),
89485 fast_no_hz);
89486@@ -2129,7 +2129,7 @@ static void __call_rcu_nocb_enqueue(struct rcu_data *rdp,
89487
89488 /* Enqueue the callback on the nocb list and update counts. */
89489 old_rhpp = xchg(&rdp->nocb_tail, rhtp);
89490- ACCESS_ONCE(*old_rhpp) = rhp;
89491+ ACCESS_ONCE_RW(*old_rhpp) = rhp;
89492 atomic_long_add(rhcount, &rdp->nocb_q_count);
89493 atomic_long_add(rhcount_lazy, &rdp->nocb_q_count_lazy);
89494
89495@@ -2302,12 +2302,12 @@ static int rcu_nocb_kthread(void *arg)
89496 * Extract queued callbacks, update counts, and wait
89497 * for a grace period to elapse.
89498 */
89499- ACCESS_ONCE(rdp->nocb_head) = NULL;
89500+ ACCESS_ONCE_RW(rdp->nocb_head) = NULL;
89501 tail = xchg(&rdp->nocb_tail, &rdp->nocb_head);
89502 c = atomic_long_xchg(&rdp->nocb_q_count, 0);
89503 cl = atomic_long_xchg(&rdp->nocb_q_count_lazy, 0);
89504- ACCESS_ONCE(rdp->nocb_p_count) += c;
89505- ACCESS_ONCE(rdp->nocb_p_count_lazy) += cl;
89506+ ACCESS_ONCE_RW(rdp->nocb_p_count) += c;
89507+ ACCESS_ONCE_RW(rdp->nocb_p_count_lazy) += cl;
89508 rcu_nocb_wait_gp(rdp);
89509
89510 /* Each pass through the following loop invokes a callback. */
89511@@ -2333,8 +2333,8 @@ static int rcu_nocb_kthread(void *arg)
89512 list = next;
89513 }
89514 trace_rcu_batch_end(rdp->rsp->name, c, !!list, 0, 0, 1);
89515- ACCESS_ONCE(rdp->nocb_p_count) -= c;
89516- ACCESS_ONCE(rdp->nocb_p_count_lazy) -= cl;
89517+ ACCESS_ONCE_RW(rdp->nocb_p_count) -= c;
89518+ ACCESS_ONCE_RW(rdp->nocb_p_count_lazy) -= cl;
89519 rdp->n_nocbs_invoked += c;
89520 }
89521 return 0;
89522@@ -2351,7 +2351,7 @@ static void do_nocb_deferred_wakeup(struct rcu_data *rdp)
89523 {
89524 if (!rcu_nocb_need_deferred_wakeup(rdp))
89525 return;
89526- ACCESS_ONCE(rdp->nocb_defer_wakeup) = false;
89527+ ACCESS_ONCE_RW(rdp->nocb_defer_wakeup) = false;
89528 wake_up(&rdp->nocb_wq);
89529 trace_rcu_nocb_wake(rdp->rsp->name, rdp->cpu, TPS("DeferredWakeEmpty"));
89530 }
89531@@ -2377,7 +2377,7 @@ static void __init rcu_spawn_nocb_kthreads(struct rcu_state *rsp)
89532 t = kthread_run(rcu_nocb_kthread, rdp,
89533 "rcuo%c/%d", rsp->abbr, cpu);
89534 BUG_ON(IS_ERR(t));
89535- ACCESS_ONCE(rdp->nocb_kthread) = t;
89536+ ACCESS_ONCE_RW(rdp->nocb_kthread) = t;
89537 }
89538 }
89539
89540@@ -2513,11 +2513,11 @@ static void rcu_sysidle_enter(struct rcu_dynticks *rdtp, int irq)
89541
89542 /* Record start of fully idle period. */
89543 j = jiffies;
89544- ACCESS_ONCE(rdtp->dynticks_idle_jiffies) = j;
89545+ ACCESS_ONCE_RW(rdtp->dynticks_idle_jiffies) = j;
89546 smp_mb__before_atomic_inc();
89547- atomic_inc(&rdtp->dynticks_idle);
89548+ atomic_inc_unchecked(&rdtp->dynticks_idle);
89549 smp_mb__after_atomic_inc();
89550- WARN_ON_ONCE(atomic_read(&rdtp->dynticks_idle) & 0x1);
89551+ WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks_idle) & 0x1);
89552 }
89553
89554 /*
89555@@ -2582,9 +2582,9 @@ static void rcu_sysidle_exit(struct rcu_dynticks *rdtp, int irq)
89556
89557 /* Record end of idle period. */
89558 smp_mb__before_atomic_inc();
89559- atomic_inc(&rdtp->dynticks_idle);
89560+ atomic_inc_unchecked(&rdtp->dynticks_idle);
89561 smp_mb__after_atomic_inc();
89562- WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks_idle) & 0x1));
89563+ WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks_idle) & 0x1));
89564
89565 /*
89566 * If we are the timekeeping CPU, we are permitted to be non-idle
89567@@ -2625,7 +2625,7 @@ static void rcu_sysidle_check_cpu(struct rcu_data *rdp, bool *isidle,
89568 WARN_ON_ONCE(smp_processor_id() != tick_do_timer_cpu);
89569
89570 /* Pick up current idle and NMI-nesting counter and check. */
89571- cur = atomic_read(&rdtp->dynticks_idle);
89572+ cur = atomic_read_unchecked(&rdtp->dynticks_idle);
89573 if (cur & 0x1) {
89574 *isidle = false; /* We are not idle! */
89575 return;
89576@@ -2688,7 +2688,7 @@ static void rcu_sysidle(unsigned long j)
89577 case RCU_SYSIDLE_NOT:
89578
89579 /* First time all are idle, so note a short idle period. */
89580- ACCESS_ONCE(full_sysidle_state) = RCU_SYSIDLE_SHORT;
89581+ ACCESS_ONCE_RW(full_sysidle_state) = RCU_SYSIDLE_SHORT;
89582 break;
89583
89584 case RCU_SYSIDLE_SHORT:
89585@@ -2725,7 +2725,7 @@ static void rcu_sysidle(unsigned long j)
89586 static void rcu_sysidle_cancel(void)
89587 {
89588 smp_mb();
89589- ACCESS_ONCE(full_sysidle_state) = RCU_SYSIDLE_NOT;
89590+ ACCESS_ONCE_RW(full_sysidle_state) = RCU_SYSIDLE_NOT;
89591 }
89592
89593 /*
89594@@ -2773,7 +2773,7 @@ static void rcu_sysidle_cb(struct rcu_head *rhp)
89595 smp_mb(); /* grace period precedes setting inuse. */
89596
89597 rshp = container_of(rhp, struct rcu_sysidle_head, rh);
89598- ACCESS_ONCE(rshp->inuse) = 0;
89599+ ACCESS_ONCE_RW(rshp->inuse) = 0;
89600 }
89601
89602 /*
89603diff --git a/kernel/rcu/tree_trace.c b/kernel/rcu/tree_trace.c
89604index 4def475..8ffddde 100644
89605--- a/kernel/rcu/tree_trace.c
89606+++ b/kernel/rcu/tree_trace.c
89607@@ -121,7 +121,7 @@ static void print_one_rcu_data(struct seq_file *m, struct rcu_data *rdp)
89608 ulong2long(rdp->completed), ulong2long(rdp->gpnum),
89609 rdp->passed_quiesce, rdp->qs_pending);
89610 seq_printf(m, " dt=%d/%llx/%d df=%lu",
89611- atomic_read(&rdp->dynticks->dynticks),
89612+ atomic_read_unchecked(&rdp->dynticks->dynticks),
89613 rdp->dynticks->dynticks_nesting,
89614 rdp->dynticks->dynticks_nmi_nesting,
89615 rdp->dynticks_fqs);
89616@@ -182,17 +182,17 @@ static int show_rcuexp(struct seq_file *m, void *v)
89617 struct rcu_state *rsp = (struct rcu_state *)m->private;
89618
89619 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",
89620- atomic_long_read(&rsp->expedited_start),
89621+ atomic_long_read_unchecked(&rsp->expedited_start),
89622 atomic_long_read(&rsp->expedited_done),
89623- atomic_long_read(&rsp->expedited_wrap),
89624- atomic_long_read(&rsp->expedited_tryfail),
89625- atomic_long_read(&rsp->expedited_workdone1),
89626- atomic_long_read(&rsp->expedited_workdone2),
89627- atomic_long_read(&rsp->expedited_normal),
89628- atomic_long_read(&rsp->expedited_stoppedcpus),
89629- atomic_long_read(&rsp->expedited_done_tries),
89630- atomic_long_read(&rsp->expedited_done_lost),
89631- atomic_long_read(&rsp->expedited_done_exit));
89632+ atomic_long_read_unchecked(&rsp->expedited_wrap),
89633+ atomic_long_read_unchecked(&rsp->expedited_tryfail),
89634+ atomic_long_read_unchecked(&rsp->expedited_workdone1),
89635+ atomic_long_read_unchecked(&rsp->expedited_workdone2),
89636+ atomic_long_read_unchecked(&rsp->expedited_normal),
89637+ atomic_long_read_unchecked(&rsp->expedited_stoppedcpus),
89638+ atomic_long_read_unchecked(&rsp->expedited_done_tries),
89639+ atomic_long_read_unchecked(&rsp->expedited_done_lost),
89640+ atomic_long_read_unchecked(&rsp->expedited_done_exit));
89641 return 0;
89642 }
89643
89644diff --git a/kernel/rcu/update.c b/kernel/rcu/update.c
89645index c54609f..2e8829c 100644
89646--- a/kernel/rcu/update.c
89647+++ b/kernel/rcu/update.c
89648@@ -312,10 +312,10 @@ int rcu_jiffies_till_stall_check(void)
89649 * for CONFIG_RCU_CPU_STALL_TIMEOUT.
89650 */
89651 if (till_stall_check < 3) {
89652- ACCESS_ONCE(rcu_cpu_stall_timeout) = 3;
89653+ ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 3;
89654 till_stall_check = 3;
89655 } else if (till_stall_check > 300) {
89656- ACCESS_ONCE(rcu_cpu_stall_timeout) = 300;
89657+ ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 300;
89658 till_stall_check = 300;
89659 }
89660 return till_stall_check * HZ + RCU_STALL_DELAY_DELTA;
89661diff --git a/kernel/resource.c b/kernel/resource.c
89662index 3f285dc..5755f62 100644
89663--- a/kernel/resource.c
89664+++ b/kernel/resource.c
89665@@ -152,8 +152,18 @@ static const struct file_operations proc_iomem_operations = {
89666
89667 static int __init ioresources_init(void)
89668 {
89669+#ifdef CONFIG_GRKERNSEC_PROC_ADD
89670+#ifdef CONFIG_GRKERNSEC_PROC_USER
89671+ proc_create("ioports", S_IRUSR, NULL, &proc_ioports_operations);
89672+ proc_create("iomem", S_IRUSR, NULL, &proc_iomem_operations);
89673+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
89674+ proc_create("ioports", S_IRUSR | S_IRGRP, NULL, &proc_ioports_operations);
89675+ proc_create("iomem", S_IRUSR | S_IRGRP, NULL, &proc_iomem_operations);
89676+#endif
89677+#else
89678 proc_create("ioports", 0, NULL, &proc_ioports_operations);
89679 proc_create("iomem", 0, NULL, &proc_iomem_operations);
89680+#endif
89681 return 0;
89682 }
89683 __initcall(ioresources_init);
89684diff --git a/kernel/sched/auto_group.c b/kernel/sched/auto_group.c
89685index 4a07353..66b5291 100644
89686--- a/kernel/sched/auto_group.c
89687+++ b/kernel/sched/auto_group.c
89688@@ -11,7 +11,7 @@
89689
89690 unsigned int __read_mostly sysctl_sched_autogroup_enabled = 1;
89691 static struct autogroup autogroup_default;
89692-static atomic_t autogroup_seq_nr;
89693+static atomic_unchecked_t autogroup_seq_nr;
89694
89695 void __init autogroup_init(struct task_struct *init_task)
89696 {
89697@@ -79,7 +79,7 @@ static inline struct autogroup *autogroup_create(void)
89698
89699 kref_init(&ag->kref);
89700 init_rwsem(&ag->lock);
89701- ag->id = atomic_inc_return(&autogroup_seq_nr);
89702+ ag->id = atomic_inc_return_unchecked(&autogroup_seq_nr);
89703 ag->tg = tg;
89704 #ifdef CONFIG_RT_GROUP_SCHED
89705 /*
89706diff --git a/kernel/sched/completion.c b/kernel/sched/completion.c
89707index a63f4dc..349bbb0 100644
89708--- a/kernel/sched/completion.c
89709+++ b/kernel/sched/completion.c
89710@@ -204,7 +204,7 @@ EXPORT_SYMBOL(wait_for_completion_interruptible);
89711 * Return: -ERESTARTSYS if interrupted, 0 if timed out, positive (at least 1,
89712 * or number of jiffies left till timeout) if completed.
89713 */
89714-long __sched
89715+long __sched __intentional_overflow(-1)
89716 wait_for_completion_interruptible_timeout(struct completion *x,
89717 unsigned long timeout)
89718 {
89719@@ -221,7 +221,7 @@ EXPORT_SYMBOL(wait_for_completion_interruptible_timeout);
89720 *
89721 * Return: -ERESTARTSYS if interrupted, 0 if completed.
89722 */
89723-int __sched wait_for_completion_killable(struct completion *x)
89724+int __sched __intentional_overflow(-1) wait_for_completion_killable(struct completion *x)
89725 {
89726 long t = wait_for_common(x, MAX_SCHEDULE_TIMEOUT, TASK_KILLABLE);
89727 if (t == -ERESTARTSYS)
89728@@ -242,7 +242,7 @@ EXPORT_SYMBOL(wait_for_completion_killable);
89729 * Return: -ERESTARTSYS if interrupted, 0 if timed out, positive (at least 1,
89730 * or number of jiffies left till timeout) if completed.
89731 */
89732-long __sched
89733+long __sched __intentional_overflow(-1)
89734 wait_for_completion_killable_timeout(struct completion *x,
89735 unsigned long timeout)
89736 {
89737diff --git a/kernel/sched/core.c b/kernel/sched/core.c
89738index f5c6635..ab9f223 100644
89739--- a/kernel/sched/core.c
89740+++ b/kernel/sched/core.c
89741@@ -1775,7 +1775,7 @@ void set_numabalancing_state(bool enabled)
89742 int sysctl_numa_balancing(struct ctl_table *table, int write,
89743 void __user *buffer, size_t *lenp, loff_t *ppos)
89744 {
89745- struct ctl_table t;
89746+ ctl_table_no_const t;
89747 int err;
89748 int state = numabalancing_enabled;
89749
89750@@ -3049,6 +3049,8 @@ int can_nice(const struct task_struct *p, const int nice)
89751 /* convert nice value [19,-20] to rlimit style value [1,40] */
89752 int nice_rlim = 20 - nice;
89753
89754+ gr_learn_resource(p, RLIMIT_NICE, nice_rlim, 1);
89755+
89756 return (nice_rlim <= task_rlimit(p, RLIMIT_NICE) ||
89757 capable(CAP_SYS_NICE));
89758 }
89759@@ -3082,7 +3084,8 @@ SYSCALL_DEFINE1(nice, int, increment)
89760 if (nice > 19)
89761 nice = 19;
89762
89763- if (increment < 0 && !can_nice(current, nice))
89764+ if (increment < 0 && (!can_nice(current, nice) ||
89765+ gr_handle_chroot_nice()))
89766 return -EPERM;
89767
89768 retval = security_task_setnice(current, nice);
89769@@ -3332,6 +3335,7 @@ recheck:
89770 if (policy != p->policy && !rlim_rtprio)
89771 return -EPERM;
89772
89773+ gr_learn_resource(p, RLIMIT_RTPRIO, attr->sched_priority, 1);
89774 /* can't increase priority */
89775 if (attr->sched_priority > p->rt_priority &&
89776 attr->sched_priority > rlim_rtprio)
89777@@ -4781,7 +4785,7 @@ static void migrate_tasks(unsigned int dead_cpu)
89778
89779 #if defined(CONFIG_SCHED_DEBUG) && defined(CONFIG_SYSCTL)
89780
89781-static struct ctl_table sd_ctl_dir[] = {
89782+static ctl_table_no_const sd_ctl_dir[] __read_only = {
89783 {
89784 .procname = "sched_domain",
89785 .mode = 0555,
89786@@ -4798,17 +4802,17 @@ static struct ctl_table sd_ctl_root[] = {
89787 {}
89788 };
89789
89790-static struct ctl_table *sd_alloc_ctl_entry(int n)
89791+static ctl_table_no_const *sd_alloc_ctl_entry(int n)
89792 {
89793- struct ctl_table *entry =
89794+ ctl_table_no_const *entry =
89795 kcalloc(n, sizeof(struct ctl_table), GFP_KERNEL);
89796
89797 return entry;
89798 }
89799
89800-static void sd_free_ctl_entry(struct ctl_table **tablep)
89801+static void sd_free_ctl_entry(ctl_table_no_const *tablep)
89802 {
89803- struct ctl_table *entry;
89804+ ctl_table_no_const *entry;
89805
89806 /*
89807 * In the intermediate directories, both the child directory and
89808@@ -4816,22 +4820,25 @@ static void sd_free_ctl_entry(struct ctl_table **tablep)
89809 * will always be set. In the lowest directory the names are
89810 * static strings and all have proc handlers.
89811 */
89812- for (entry = *tablep; entry->mode; entry++) {
89813- if (entry->child)
89814- sd_free_ctl_entry(&entry->child);
89815+ for (entry = tablep; entry->mode; entry++) {
89816+ if (entry->child) {
89817+ sd_free_ctl_entry(entry->child);
89818+ pax_open_kernel();
89819+ entry->child = NULL;
89820+ pax_close_kernel();
89821+ }
89822 if (entry->proc_handler == NULL)
89823 kfree(entry->procname);
89824 }
89825
89826- kfree(*tablep);
89827- *tablep = NULL;
89828+ kfree(tablep);
89829 }
89830
89831 static int min_load_idx = 0;
89832 static int max_load_idx = CPU_LOAD_IDX_MAX-1;
89833
89834 static void
89835-set_table_entry(struct ctl_table *entry,
89836+set_table_entry(ctl_table_no_const *entry,
89837 const char *procname, void *data, int maxlen,
89838 umode_t mode, proc_handler *proc_handler,
89839 bool load_idx)
89840@@ -4851,7 +4858,7 @@ set_table_entry(struct ctl_table *entry,
89841 static struct ctl_table *
89842 sd_alloc_ctl_domain_table(struct sched_domain *sd)
89843 {
89844- struct ctl_table *table = sd_alloc_ctl_entry(13);
89845+ ctl_table_no_const *table = sd_alloc_ctl_entry(13);
89846
89847 if (table == NULL)
89848 return NULL;
89849@@ -4886,9 +4893,9 @@ sd_alloc_ctl_domain_table(struct sched_domain *sd)
89850 return table;
89851 }
89852
89853-static struct ctl_table *sd_alloc_ctl_cpu_table(int cpu)
89854+static ctl_table_no_const *sd_alloc_ctl_cpu_table(int cpu)
89855 {
89856- struct ctl_table *entry, *table;
89857+ ctl_table_no_const *entry, *table;
89858 struct sched_domain *sd;
89859 int domain_num = 0, i;
89860 char buf[32];
89861@@ -4915,11 +4922,13 @@ static struct ctl_table_header *sd_sysctl_header;
89862 static void register_sched_domain_sysctl(void)
89863 {
89864 int i, cpu_num = num_possible_cpus();
89865- struct ctl_table *entry = sd_alloc_ctl_entry(cpu_num + 1);
89866+ ctl_table_no_const *entry = sd_alloc_ctl_entry(cpu_num + 1);
89867 char buf[32];
89868
89869 WARN_ON(sd_ctl_dir[0].child);
89870+ pax_open_kernel();
89871 sd_ctl_dir[0].child = entry;
89872+ pax_close_kernel();
89873
89874 if (entry == NULL)
89875 return;
89876@@ -4942,8 +4951,12 @@ static void unregister_sched_domain_sysctl(void)
89877 if (sd_sysctl_header)
89878 unregister_sysctl_table(sd_sysctl_header);
89879 sd_sysctl_header = NULL;
89880- if (sd_ctl_dir[0].child)
89881- sd_free_ctl_entry(&sd_ctl_dir[0].child);
89882+ if (sd_ctl_dir[0].child) {
89883+ sd_free_ctl_entry(sd_ctl_dir[0].child);
89884+ pax_open_kernel();
89885+ sd_ctl_dir[0].child = NULL;
89886+ pax_close_kernel();
89887+ }
89888 }
89889 #else
89890 static void register_sched_domain_sysctl(void)
89891diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
89892index 9b4c4f3..665489b 100644
89893--- a/kernel/sched/fair.c
89894+++ b/kernel/sched/fair.c
89895@@ -1647,7 +1647,7 @@ void task_numa_fault(int last_cpupid, int node, int pages, int flags)
89896
89897 static void reset_ptenuma_scan(struct task_struct *p)
89898 {
89899- ACCESS_ONCE(p->mm->numa_scan_seq)++;
89900+ ACCESS_ONCE_RW(p->mm->numa_scan_seq)++;
89901 p->mm->numa_scan_offset = 0;
89902 }
89903
89904@@ -6851,7 +6851,7 @@ static void nohz_idle_balance(struct rq *this_rq, enum cpu_idle_type idle) { }
89905 * run_rebalance_domains is triggered when needed from the scheduler tick.
89906 * Also triggered for nohz idle balancing (with nohz_balancing_kick set).
89907 */
89908-static void run_rebalance_domains(struct softirq_action *h)
89909+static __latent_entropy void run_rebalance_domains(void)
89910 {
89911 struct rq *this_rq = this_rq();
89912 enum cpu_idle_type idle = this_rq->idle_balance ?
89913diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h
89914index f964add..dcd823d 100644
89915--- a/kernel/sched/sched.h
89916+++ b/kernel/sched/sched.h
89917@@ -1157,7 +1157,7 @@ struct sched_class {
89918 #ifdef CONFIG_FAIR_GROUP_SCHED
89919 void (*task_move_group) (struct task_struct *p, int on_rq);
89920 #endif
89921-};
89922+} __do_const;
89923
89924 #define sched_class_highest (&stop_sched_class)
89925 #define for_each_class(class) \
89926diff --git a/kernel/signal.c b/kernel/signal.c
89927index 52f881d..1e9f941 100644
89928--- a/kernel/signal.c
89929+++ b/kernel/signal.c
89930@@ -51,12 +51,12 @@ static struct kmem_cache *sigqueue_cachep;
89931
89932 int print_fatal_signals __read_mostly;
89933
89934-static void __user *sig_handler(struct task_struct *t, int sig)
89935+static __sighandler_t sig_handler(struct task_struct *t, int sig)
89936 {
89937 return t->sighand->action[sig - 1].sa.sa_handler;
89938 }
89939
89940-static int sig_handler_ignored(void __user *handler, int sig)
89941+static int sig_handler_ignored(__sighandler_t handler, int sig)
89942 {
89943 /* Is it explicitly or implicitly ignored? */
89944 return handler == SIG_IGN ||
89945@@ -65,7 +65,7 @@ static int sig_handler_ignored(void __user *handler, int sig)
89946
89947 static int sig_task_ignored(struct task_struct *t, int sig, bool force)
89948 {
89949- void __user *handler;
89950+ __sighandler_t handler;
89951
89952 handler = sig_handler(t, sig);
89953
89954@@ -369,6 +369,9 @@ __sigqueue_alloc(int sig, struct task_struct *t, gfp_t flags, int override_rlimi
89955 atomic_inc(&user->sigpending);
89956 rcu_read_unlock();
89957
89958+ if (!override_rlimit)
89959+ gr_learn_resource(t, RLIMIT_SIGPENDING, atomic_read(&user->sigpending), 1);
89960+
89961 if (override_rlimit ||
89962 atomic_read(&user->sigpending) <=
89963 task_rlimit(t, RLIMIT_SIGPENDING)) {
89964@@ -496,7 +499,7 @@ flush_signal_handlers(struct task_struct *t, int force_default)
89965
89966 int unhandled_signal(struct task_struct *tsk, int sig)
89967 {
89968- void __user *handler = tsk->sighand->action[sig-1].sa.sa_handler;
89969+ __sighandler_t handler = tsk->sighand->action[sig-1].sa.sa_handler;
89970 if (is_global_init(tsk))
89971 return 1;
89972 if (handler != SIG_IGN && handler != SIG_DFL)
89973@@ -816,6 +819,13 @@ static int check_kill_permission(int sig, struct siginfo *info,
89974 }
89975 }
89976
89977+ /* allow glibc communication via tgkill to other threads in our
89978+ thread group */
89979+ if ((info == SEND_SIG_NOINFO || info->si_code != SI_TKILL ||
89980+ sig != (SIGRTMIN+1) || task_tgid_vnr(t) != info->si_pid)
89981+ && gr_handle_signal(t, sig))
89982+ return -EPERM;
89983+
89984 return security_task_kill(t, info, sig, 0);
89985 }
89986
89987@@ -1199,7 +1209,7 @@ __group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
89988 return send_signal(sig, info, p, 1);
89989 }
89990
89991-static int
89992+int
89993 specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t)
89994 {
89995 return send_signal(sig, info, t, 0);
89996@@ -1236,6 +1246,7 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
89997 unsigned long int flags;
89998 int ret, blocked, ignored;
89999 struct k_sigaction *action;
90000+ int is_unhandled = 0;
90001
90002 spin_lock_irqsave(&t->sighand->siglock, flags);
90003 action = &t->sighand->action[sig-1];
90004@@ -1250,9 +1261,18 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
90005 }
90006 if (action->sa.sa_handler == SIG_DFL)
90007 t->signal->flags &= ~SIGNAL_UNKILLABLE;
90008+ if (action->sa.sa_handler == SIG_IGN || action->sa.sa_handler == SIG_DFL)
90009+ is_unhandled = 1;
90010 ret = specific_send_sig_info(sig, info, t);
90011 spin_unlock_irqrestore(&t->sighand->siglock, flags);
90012
90013+ /* only deal with unhandled signals, java etc trigger SIGSEGV during
90014+ normal operation */
90015+ if (is_unhandled) {
90016+ gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, t);
90017+ gr_handle_crash(t, sig);
90018+ }
90019+
90020 return ret;
90021 }
90022
90023@@ -1319,8 +1339,11 @@ int group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
90024 ret = check_kill_permission(sig, info, p);
90025 rcu_read_unlock();
90026
90027- if (!ret && sig)
90028+ if (!ret && sig) {
90029 ret = do_send_sig_info(sig, info, p, true);
90030+ if (!ret)
90031+ gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, p);
90032+ }
90033
90034 return ret;
90035 }
90036@@ -2926,7 +2949,15 @@ do_send_specific(pid_t tgid, pid_t pid, int sig, struct siginfo *info)
90037 int error = -ESRCH;
90038
90039 rcu_read_lock();
90040- p = find_task_by_vpid(pid);
90041+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
90042+ /* allow glibc communication via tgkill to other threads in our
90043+ thread group */
90044+ if (grsec_enable_chroot_findtask && info->si_code == SI_TKILL &&
90045+ sig == (SIGRTMIN+1) && tgid == info->si_pid)
90046+ p = find_task_by_vpid_unrestricted(pid);
90047+ else
90048+#endif
90049+ p = find_task_by_vpid(pid);
90050 if (p && (tgid <= 0 || task_tgid_vnr(p) == tgid)) {
90051 error = check_kill_permission(sig, info, p);
90052 /*
90053@@ -3239,8 +3270,8 @@ COMPAT_SYSCALL_DEFINE2(sigaltstack,
90054 }
90055 seg = get_fs();
90056 set_fs(KERNEL_DS);
90057- ret = do_sigaltstack((stack_t __force __user *) (uss_ptr ? &uss : NULL),
90058- (stack_t __force __user *) &uoss,
90059+ ret = do_sigaltstack((stack_t __force_user *) (uss_ptr ? &uss : NULL),
90060+ (stack_t __force_user *) &uoss,
90061 compat_user_stack_pointer());
90062 set_fs(seg);
90063 if (ret >= 0 && uoss_ptr) {
90064diff --git a/kernel/smpboot.c b/kernel/smpboot.c
90065index eb89e18..a4e6792 100644
90066--- a/kernel/smpboot.c
90067+++ b/kernel/smpboot.c
90068@@ -288,7 +288,7 @@ int smpboot_register_percpu_thread(struct smp_hotplug_thread *plug_thread)
90069 }
90070 smpboot_unpark_thread(plug_thread, cpu);
90071 }
90072- list_add(&plug_thread->list, &hotplug_threads);
90073+ pax_list_add(&plug_thread->list, &hotplug_threads);
90074 out:
90075 mutex_unlock(&smpboot_threads_lock);
90076 return ret;
90077@@ -305,7 +305,7 @@ void smpboot_unregister_percpu_thread(struct smp_hotplug_thread *plug_thread)
90078 {
90079 get_online_cpus();
90080 mutex_lock(&smpboot_threads_lock);
90081- list_del(&plug_thread->list);
90082+ pax_list_del(&plug_thread->list);
90083 smpboot_destroy_threads(plug_thread);
90084 mutex_unlock(&smpboot_threads_lock);
90085 put_online_cpus();
90086diff --git a/kernel/softirq.c b/kernel/softirq.c
90087index 490fcbb..1e502c6 100644
90088--- a/kernel/softirq.c
90089+++ b/kernel/softirq.c
90090@@ -52,7 +52,7 @@ irq_cpustat_t irq_stat[NR_CPUS] ____cacheline_aligned;
90091 EXPORT_SYMBOL(irq_stat);
90092 #endif
90093
90094-static struct softirq_action softirq_vec[NR_SOFTIRQS] __cacheline_aligned_in_smp;
90095+static struct softirq_action softirq_vec[NR_SOFTIRQS] __read_only __aligned(PAGE_SIZE);
90096
90097 DEFINE_PER_CPU(struct task_struct *, ksoftirqd);
90098
90099@@ -267,7 +267,7 @@ restart:
90100 kstat_incr_softirqs_this_cpu(vec_nr);
90101
90102 trace_softirq_entry(vec_nr);
90103- h->action(h);
90104+ h->action();
90105 trace_softirq_exit(vec_nr);
90106 if (unlikely(prev_count != preempt_count())) {
90107 pr_err("huh, entered softirq %u %s %p with preempt_count %08x, exited with %08x?\n",
90108@@ -427,7 +427,7 @@ void __raise_softirq_irqoff(unsigned int nr)
90109 or_softirq_pending(1UL << nr);
90110 }
90111
90112-void open_softirq(int nr, void (*action)(struct softirq_action *))
90113+void __init open_softirq(int nr, void (*action)(void))
90114 {
90115 softirq_vec[nr].action = action;
90116 }
90117@@ -479,7 +479,7 @@ void __tasklet_hi_schedule_first(struct tasklet_struct *t)
90118 }
90119 EXPORT_SYMBOL(__tasklet_hi_schedule_first);
90120
90121-static void tasklet_action(struct softirq_action *a)
90122+static void tasklet_action(void)
90123 {
90124 struct tasklet_struct *list;
90125
90126@@ -515,7 +515,7 @@ static void tasklet_action(struct softirq_action *a)
90127 }
90128 }
90129
90130-static void tasklet_hi_action(struct softirq_action *a)
90131+static __latent_entropy void tasklet_hi_action(void)
90132 {
90133 struct tasklet_struct *list;
90134
90135@@ -742,7 +742,7 @@ static struct notifier_block cpu_nfb = {
90136 .notifier_call = cpu_callback
90137 };
90138
90139-static struct smp_hotplug_thread softirq_threads = {
90140+static struct smp_hotplug_thread softirq_threads __read_only = {
90141 .store = &ksoftirqd,
90142 .thread_should_run = ksoftirqd_should_run,
90143 .thread_fn = run_ksoftirqd,
90144diff --git a/kernel/sys.c b/kernel/sys.c
90145index c0a58be..784c618 100644
90146--- a/kernel/sys.c
90147+++ b/kernel/sys.c
90148@@ -148,6 +148,12 @@ static int set_one_prio(struct task_struct *p, int niceval, int error)
90149 error = -EACCES;
90150 goto out;
90151 }
90152+
90153+ if (gr_handle_chroot_setpriority(p, niceval)) {
90154+ error = -EACCES;
90155+ goto out;
90156+ }
90157+
90158 no_nice = security_task_setnice(p, niceval);
90159 if (no_nice) {
90160 error = no_nice;
90161@@ -351,6 +357,9 @@ SYSCALL_DEFINE2(setregid, gid_t, rgid, gid_t, egid)
90162 goto error;
90163 }
90164
90165+ if (gr_check_group_change(new->gid, new->egid, INVALID_GID))
90166+ goto error;
90167+
90168 if (rgid != (gid_t) -1 ||
90169 (egid != (gid_t) -1 && !gid_eq(kegid, old->gid)))
90170 new->sgid = new->egid;
90171@@ -386,6 +395,10 @@ SYSCALL_DEFINE1(setgid, gid_t, gid)
90172 old = current_cred();
90173
90174 retval = -EPERM;
90175+
90176+ if (gr_check_group_change(kgid, kgid, kgid))
90177+ goto error;
90178+
90179 if (ns_capable(old->user_ns, CAP_SETGID))
90180 new->gid = new->egid = new->sgid = new->fsgid = kgid;
90181 else if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->sgid))
90182@@ -403,7 +416,7 @@ error:
90183 /*
90184 * change the user struct in a credentials set to match the new UID
90185 */
90186-static int set_user(struct cred *new)
90187+int set_user(struct cred *new)
90188 {
90189 struct user_struct *new_user;
90190
90191@@ -483,6 +496,9 @@ SYSCALL_DEFINE2(setreuid, uid_t, ruid, uid_t, euid)
90192 goto error;
90193 }
90194
90195+ if (gr_check_user_change(new->uid, new->euid, INVALID_UID))
90196+ goto error;
90197+
90198 if (!uid_eq(new->uid, old->uid)) {
90199 retval = set_user(new);
90200 if (retval < 0)
90201@@ -533,6 +549,12 @@ SYSCALL_DEFINE1(setuid, uid_t, uid)
90202 old = current_cred();
90203
90204 retval = -EPERM;
90205+
90206+ if (gr_check_crash_uid(kuid))
90207+ goto error;
90208+ if (gr_check_user_change(kuid, kuid, kuid))
90209+ goto error;
90210+
90211 if (ns_capable(old->user_ns, CAP_SETUID)) {
90212 new->suid = new->uid = kuid;
90213 if (!uid_eq(kuid, old->uid)) {
90214@@ -602,6 +624,9 @@ SYSCALL_DEFINE3(setresuid, uid_t, ruid, uid_t, euid, uid_t, suid)
90215 goto error;
90216 }
90217
90218+ if (gr_check_user_change(kruid, keuid, INVALID_UID))
90219+ goto error;
90220+
90221 if (ruid != (uid_t) -1) {
90222 new->uid = kruid;
90223 if (!uid_eq(kruid, old->uid)) {
90224@@ -684,6 +709,9 @@ SYSCALL_DEFINE3(setresgid, gid_t, rgid, gid_t, egid, gid_t, sgid)
90225 goto error;
90226 }
90227
90228+ if (gr_check_group_change(krgid, kegid, INVALID_GID))
90229+ goto error;
90230+
90231 if (rgid != (gid_t) -1)
90232 new->gid = krgid;
90233 if (egid != (gid_t) -1)
90234@@ -745,12 +773,16 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
90235 uid_eq(kuid, old->suid) || uid_eq(kuid, old->fsuid) ||
90236 ns_capable(old->user_ns, CAP_SETUID)) {
90237 if (!uid_eq(kuid, old->fsuid)) {
90238+ if (gr_check_user_change(INVALID_UID, INVALID_UID, kuid))
90239+ goto error;
90240+
90241 new->fsuid = kuid;
90242 if (security_task_fix_setuid(new, old, LSM_SETID_FS) == 0)
90243 goto change_okay;
90244 }
90245 }
90246
90247+error:
90248 abort_creds(new);
90249 return old_fsuid;
90250
90251@@ -783,12 +815,16 @@ SYSCALL_DEFINE1(setfsgid, gid_t, gid)
90252 if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->egid) ||
90253 gid_eq(kgid, old->sgid) || gid_eq(kgid, old->fsgid) ||
90254 ns_capable(old->user_ns, CAP_SETGID)) {
90255+ if (gr_check_group_change(INVALID_GID, INVALID_GID, kgid))
90256+ goto error;
90257+
90258 if (!gid_eq(kgid, old->fsgid)) {
90259 new->fsgid = kgid;
90260 goto change_okay;
90261 }
90262 }
90263
90264+error:
90265 abort_creds(new);
90266 return old_fsgid;
90267
90268@@ -1167,19 +1203,19 @@ SYSCALL_DEFINE1(olduname, struct oldold_utsname __user *, name)
90269 return -EFAULT;
90270
90271 down_read(&uts_sem);
90272- error = __copy_to_user(&name->sysname, &utsname()->sysname,
90273+ error = __copy_to_user(name->sysname, &utsname()->sysname,
90274 __OLD_UTS_LEN);
90275 error |= __put_user(0, name->sysname + __OLD_UTS_LEN);
90276- error |= __copy_to_user(&name->nodename, &utsname()->nodename,
90277+ error |= __copy_to_user(name->nodename, &utsname()->nodename,
90278 __OLD_UTS_LEN);
90279 error |= __put_user(0, name->nodename + __OLD_UTS_LEN);
90280- error |= __copy_to_user(&name->release, &utsname()->release,
90281+ error |= __copy_to_user(name->release, &utsname()->release,
90282 __OLD_UTS_LEN);
90283 error |= __put_user(0, name->release + __OLD_UTS_LEN);
90284- error |= __copy_to_user(&name->version, &utsname()->version,
90285+ error |= __copy_to_user(name->version, &utsname()->version,
90286 __OLD_UTS_LEN);
90287 error |= __put_user(0, name->version + __OLD_UTS_LEN);
90288- error |= __copy_to_user(&name->machine, &utsname()->machine,
90289+ error |= __copy_to_user(name->machine, &utsname()->machine,
90290 __OLD_UTS_LEN);
90291 error |= __put_user(0, name->machine + __OLD_UTS_LEN);
90292 up_read(&uts_sem);
90293@@ -1381,6 +1417,13 @@ int do_prlimit(struct task_struct *tsk, unsigned int resource,
90294 */
90295 new_rlim->rlim_cur = 1;
90296 }
90297+ /* Handle the case where a fork and setuid occur and then RLIMIT_NPROC
90298+ is changed to a lower value. Since tasks can be created by the same
90299+ user in between this limit change and an execve by this task, force
90300+ a recheck only for this task by setting PF_NPROC_EXCEEDED
90301+ */
90302+ if (resource == RLIMIT_NPROC && tsk->real_cred->user != INIT_USER)
90303+ tsk->flags |= PF_NPROC_EXCEEDED;
90304 }
90305 if (!retval) {
90306 if (old_rlim)
90307diff --git a/kernel/sysctl.c b/kernel/sysctl.c
90308index aae21e8..58d8c9a 100644
90309--- a/kernel/sysctl.c
90310+++ b/kernel/sysctl.c
90311@@ -94,7 +94,6 @@
90312
90313
90314 #if defined(CONFIG_SYSCTL)
90315-
90316 /* External variables not in a header file. */
90317 extern int max_threads;
90318 extern int suid_dumpable;
90319@@ -118,19 +117,18 @@ extern int blk_iopoll_enabled;
90320
90321 /* Constants used for minimum and maximum */
90322 #ifdef CONFIG_LOCKUP_DETECTOR
90323-static int sixty = 60;
90324+static int sixty __read_only = 60;
90325 #endif
90326
90327-static int __maybe_unused neg_one = -1;
90328-
90329-static int zero;
90330-static int __maybe_unused one = 1;
90331-static int __maybe_unused two = 2;
90332-static int __maybe_unused three = 3;
90333-static unsigned long one_ul = 1;
90334-static int one_hundred = 100;
90335+static int __maybe_unused neg_one __read_only = -1;
90336+static int zero __read_only = 0;
90337+static int __maybe_unused one __read_only = 1;
90338+static int __maybe_unused two __read_only = 2;
90339+static int __maybe_unused three __read_only = 3;
90340+static unsigned long one_ul __read_only = 1;
90341+static int one_hundred __read_only = 100;
90342 #ifdef CONFIG_PRINTK
90343-static int ten_thousand = 10000;
90344+static int ten_thousand __read_only = 10000;
90345 #endif
90346
90347 /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
90348@@ -182,10 +180,8 @@ static int proc_taint(struct ctl_table *table, int write,
90349 void __user *buffer, size_t *lenp, loff_t *ppos);
90350 #endif
90351
90352-#ifdef CONFIG_PRINTK
90353 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
90354 void __user *buffer, size_t *lenp, loff_t *ppos);
90355-#endif
90356
90357 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
90358 void __user *buffer, size_t *lenp, loff_t *ppos);
90359@@ -216,6 +212,8 @@ static int sysrq_sysctl_handler(ctl_table *table, int write,
90360
90361 #endif
90362
90363+extern struct ctl_table grsecurity_table[];
90364+
90365 static struct ctl_table kern_table[];
90366 static struct ctl_table vm_table[];
90367 static struct ctl_table fs_table[];
90368@@ -230,6 +228,20 @@ extern struct ctl_table epoll_table[];
90369 int sysctl_legacy_va_layout;
90370 #endif
90371
90372+#ifdef CONFIG_PAX_SOFTMODE
90373+static ctl_table pax_table[] = {
90374+ {
90375+ .procname = "softmode",
90376+ .data = &pax_softmode,
90377+ .maxlen = sizeof(unsigned int),
90378+ .mode = 0600,
90379+ .proc_handler = &proc_dointvec,
90380+ },
90381+
90382+ { }
90383+};
90384+#endif
90385+
90386 /* The default sysctl tables: */
90387
90388 static struct ctl_table sysctl_base_table[] = {
90389@@ -278,6 +290,22 @@ static int max_extfrag_threshold = 1000;
90390 #endif
90391
90392 static struct ctl_table kern_table[] = {
90393+#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
90394+ {
90395+ .procname = "grsecurity",
90396+ .mode = 0500,
90397+ .child = grsecurity_table,
90398+ },
90399+#endif
90400+
90401+#ifdef CONFIG_PAX_SOFTMODE
90402+ {
90403+ .procname = "pax",
90404+ .mode = 0500,
90405+ .child = pax_table,
90406+ },
90407+#endif
90408+
90409 {
90410 .procname = "sched_child_runs_first",
90411 .data = &sysctl_sched_child_runs_first,
90412@@ -640,7 +668,7 @@ static struct ctl_table kern_table[] = {
90413 .data = &modprobe_path,
90414 .maxlen = KMOD_PATH_LEN,
90415 .mode = 0644,
90416- .proc_handler = proc_dostring,
90417+ .proc_handler = proc_dostring_modpriv,
90418 },
90419 {
90420 .procname = "modules_disabled",
90421@@ -807,16 +835,20 @@ static struct ctl_table kern_table[] = {
90422 .extra1 = &zero,
90423 .extra2 = &one,
90424 },
90425+#endif
90426 {
90427 .procname = "kptr_restrict",
90428 .data = &kptr_restrict,
90429 .maxlen = sizeof(int),
90430 .mode = 0644,
90431 .proc_handler = proc_dointvec_minmax_sysadmin,
90432+#ifdef CONFIG_GRKERNSEC_HIDESYM
90433+ .extra1 = &two,
90434+#else
90435 .extra1 = &zero,
90436+#endif
90437 .extra2 = &two,
90438 },
90439-#endif
90440 {
90441 .procname = "ngroups_max",
90442 .data = &ngroups_max,
90443@@ -1061,10 +1093,17 @@ static struct ctl_table kern_table[] = {
90444 */
90445 {
90446 .procname = "perf_event_paranoid",
90447- .data = &sysctl_perf_event_paranoid,
90448- .maxlen = sizeof(sysctl_perf_event_paranoid),
90449+ .data = &sysctl_perf_event_legitimately_concerned,
90450+ .maxlen = sizeof(sysctl_perf_event_legitimately_concerned),
90451 .mode = 0644,
90452- .proc_handler = proc_dointvec,
90453+ /* go ahead, be a hero */
90454+ .proc_handler = proc_dointvec_minmax_sysadmin,
90455+ .extra1 = &neg_one,
90456+#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
90457+ .extra2 = &three,
90458+#else
90459+ .extra2 = &two,
90460+#endif
90461 },
90462 {
90463 .procname = "perf_event_mlock_kb",
90464@@ -1335,6 +1374,13 @@ static struct ctl_table vm_table[] = {
90465 .proc_handler = proc_dointvec_minmax,
90466 .extra1 = &zero,
90467 },
90468+ {
90469+ .procname = "heap_stack_gap",
90470+ .data = &sysctl_heap_stack_gap,
90471+ .maxlen = sizeof(sysctl_heap_stack_gap),
90472+ .mode = 0644,
90473+ .proc_handler = proc_doulongvec_minmax,
90474+ },
90475 #else
90476 {
90477 .procname = "nr_trim_pages",
90478@@ -1799,6 +1845,16 @@ int proc_dostring(struct ctl_table *table, int write,
90479 buffer, lenp, ppos);
90480 }
90481
90482+int proc_dostring_modpriv(struct ctl_table *table, int write,
90483+ void __user *buffer, size_t *lenp, loff_t *ppos)
90484+{
90485+ if (write && !capable(CAP_SYS_MODULE))
90486+ return -EPERM;
90487+
90488+ return _proc_do_string(table->data, table->maxlen, write,
90489+ buffer, lenp, ppos);
90490+}
90491+
90492 static size_t proc_skip_spaces(char **buf)
90493 {
90494 size_t ret;
90495@@ -1904,6 +1960,8 @@ static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
90496 len = strlen(tmp);
90497 if (len > *size)
90498 len = *size;
90499+ if (len > sizeof(tmp))
90500+ len = sizeof(tmp);
90501 if (copy_to_user(*buf, tmp, len))
90502 return -EFAULT;
90503 *size -= len;
90504@@ -2068,7 +2126,7 @@ int proc_dointvec(struct ctl_table *table, int write,
90505 static int proc_taint(struct ctl_table *table, int write,
90506 void __user *buffer, size_t *lenp, loff_t *ppos)
90507 {
90508- struct ctl_table t;
90509+ ctl_table_no_const t;
90510 unsigned long tmptaint = get_taint();
90511 int err;
90512
90513@@ -2096,7 +2154,6 @@ static int proc_taint(struct ctl_table *table, int write,
90514 return err;
90515 }
90516
90517-#ifdef CONFIG_PRINTK
90518 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
90519 void __user *buffer, size_t *lenp, loff_t *ppos)
90520 {
90521@@ -2105,7 +2162,6 @@ static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
90522
90523 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
90524 }
90525-#endif
90526
90527 struct do_proc_dointvec_minmax_conv_param {
90528 int *min;
90529@@ -2652,6 +2708,12 @@ int proc_dostring(struct ctl_table *table, int write,
90530 return -ENOSYS;
90531 }
90532
90533+int proc_dostring_modpriv(struct ctl_table *table, int write,
90534+ void __user *buffer, size_t *lenp, loff_t *ppos)
90535+{
90536+ return -ENOSYS;
90537+}
90538+
90539 int proc_dointvec(struct ctl_table *table, int write,
90540 void __user *buffer, size_t *lenp, loff_t *ppos)
90541 {
90542@@ -2708,5 +2770,6 @@ EXPORT_SYMBOL(proc_dointvec_minmax);
90543 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
90544 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
90545 EXPORT_SYMBOL(proc_dostring);
90546+EXPORT_SYMBOL(proc_dostring_modpriv);
90547 EXPORT_SYMBOL(proc_doulongvec_minmax);
90548 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
90549diff --git a/kernel/taskstats.c b/kernel/taskstats.c
90550index 13d2f7c..c93d0b0 100644
90551--- a/kernel/taskstats.c
90552+++ b/kernel/taskstats.c
90553@@ -28,9 +28,12 @@
90554 #include <linux/fs.h>
90555 #include <linux/file.h>
90556 #include <linux/pid_namespace.h>
90557+#include <linux/grsecurity.h>
90558 #include <net/genetlink.h>
90559 #include <linux/atomic.h>
90560
90561+extern int gr_is_taskstats_denied(int pid);
90562+
90563 /*
90564 * Maximum length of a cpumask that can be specified in
90565 * the TASKSTATS_CMD_ATTR_REGISTER/DEREGISTER_CPUMASK attribute
90566@@ -576,6 +579,9 @@ err:
90567
90568 static int taskstats_user_cmd(struct sk_buff *skb, struct genl_info *info)
90569 {
90570+ if (gr_is_taskstats_denied(current->pid))
90571+ return -EACCES;
90572+
90573 if (info->attrs[TASKSTATS_CMD_ATTR_REGISTER_CPUMASK])
90574 return cmd_attr_register_cpumask(info);
90575 else if (info->attrs[TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK])
90576diff --git a/kernel/time.c b/kernel/time.c
90577index 7c7964c..2a0d412 100644
90578--- a/kernel/time.c
90579+++ b/kernel/time.c
90580@@ -172,6 +172,11 @@ int do_sys_settimeofday(const struct timespec *tv, const struct timezone *tz)
90581 return error;
90582
90583 if (tz) {
90584+ /* we log in do_settimeofday called below, so don't log twice
90585+ */
90586+ if (!tv)
90587+ gr_log_timechange();
90588+
90589 sys_tz = *tz;
90590 update_vsyscall_tz();
90591 if (firsttime) {
90592diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
90593index 88c9c65..7497ebc 100644
90594--- a/kernel/time/alarmtimer.c
90595+++ b/kernel/time/alarmtimer.c
90596@@ -795,7 +795,7 @@ static int __init alarmtimer_init(void)
90597 struct platform_device *pdev;
90598 int error = 0;
90599 int i;
90600- struct k_clock alarm_clock = {
90601+ static struct k_clock alarm_clock = {
90602 .clock_getres = alarm_clock_getres,
90603 .clock_get = alarm_clock_get,
90604 .timer_create = alarm_timer_create,
90605diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
90606index 5b40279..81e58db 100644
90607--- a/kernel/time/timekeeping.c
90608+++ b/kernel/time/timekeeping.c
90609@@ -15,6 +15,7 @@
90610 #include <linux/init.h>
90611 #include <linux/mm.h>
90612 #include <linux/sched.h>
90613+#include <linux/grsecurity.h>
90614 #include <linux/syscore_ops.h>
90615 #include <linux/clocksource.h>
90616 #include <linux/jiffies.h>
90617@@ -501,6 +502,8 @@ int do_settimeofday(const struct timespec *tv)
90618 if (!timespec_valid_strict(tv))
90619 return -EINVAL;
90620
90621+ gr_log_timechange();
90622+
90623 raw_spin_lock_irqsave(&timekeeper_lock, flags);
90624 write_seqcount_begin(&timekeeper_seq);
90625
90626diff --git a/kernel/time/timer_list.c b/kernel/time/timer_list.c
90627index 61ed862..3b52c65 100644
90628--- a/kernel/time/timer_list.c
90629+++ b/kernel/time/timer_list.c
90630@@ -45,12 +45,16 @@ DECLARE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases);
90631
90632 static void print_name_offset(struct seq_file *m, void *sym)
90633 {
90634+#ifdef CONFIG_GRKERNSEC_HIDESYM
90635+ SEQ_printf(m, "<%p>", NULL);
90636+#else
90637 char symname[KSYM_NAME_LEN];
90638
90639 if (lookup_symbol_name((unsigned long)sym, symname) < 0)
90640 SEQ_printf(m, "<%pK>", sym);
90641 else
90642 SEQ_printf(m, "%s", symname);
90643+#endif
90644 }
90645
90646 static void
90647@@ -119,7 +123,11 @@ next_one:
90648 static void
90649 print_base(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
90650 {
90651+#ifdef CONFIG_GRKERNSEC_HIDESYM
90652+ SEQ_printf(m, " .base: %p\n", NULL);
90653+#else
90654 SEQ_printf(m, " .base: %pK\n", base);
90655+#endif
90656 SEQ_printf(m, " .index: %d\n",
90657 base->index);
90658 SEQ_printf(m, " .resolution: %Lu nsecs\n",
90659@@ -362,7 +370,11 @@ static int __init init_timer_list_procfs(void)
90660 {
90661 struct proc_dir_entry *pe;
90662
90663+#ifdef CONFIG_GRKERNSEC_PROC_ADD
90664+ pe = proc_create("timer_list", 0400, NULL, &timer_list_fops);
90665+#else
90666 pe = proc_create("timer_list", 0444, NULL, &timer_list_fops);
90667+#endif
90668 if (!pe)
90669 return -ENOMEM;
90670 return 0;
90671diff --git a/kernel/time/timer_stats.c b/kernel/time/timer_stats.c
90672index 1fb08f2..ca4bb1e 100644
90673--- a/kernel/time/timer_stats.c
90674+++ b/kernel/time/timer_stats.c
90675@@ -116,7 +116,7 @@ static ktime_t time_start, time_stop;
90676 static unsigned long nr_entries;
90677 static struct entry entries[MAX_ENTRIES];
90678
90679-static atomic_t overflow_count;
90680+static atomic_unchecked_t overflow_count;
90681
90682 /*
90683 * The entries are in a hash-table, for fast lookup:
90684@@ -140,7 +140,7 @@ static void reset_entries(void)
90685 nr_entries = 0;
90686 memset(entries, 0, sizeof(entries));
90687 memset(tstat_hash_table, 0, sizeof(tstat_hash_table));
90688- atomic_set(&overflow_count, 0);
90689+ atomic_set_unchecked(&overflow_count, 0);
90690 }
90691
90692 static struct entry *alloc_entry(void)
90693@@ -261,7 +261,7 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
90694 if (likely(entry))
90695 entry->count++;
90696 else
90697- atomic_inc(&overflow_count);
90698+ atomic_inc_unchecked(&overflow_count);
90699
90700 out_unlock:
90701 raw_spin_unlock_irqrestore(lock, flags);
90702@@ -269,12 +269,16 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
90703
90704 static void print_name_offset(struct seq_file *m, unsigned long addr)
90705 {
90706+#ifdef CONFIG_GRKERNSEC_HIDESYM
90707+ seq_printf(m, "<%p>", NULL);
90708+#else
90709 char symname[KSYM_NAME_LEN];
90710
90711 if (lookup_symbol_name(addr, symname) < 0)
90712- seq_printf(m, "<%p>", (void *)addr);
90713+ seq_printf(m, "<%pK>", (void *)addr);
90714 else
90715 seq_printf(m, "%s", symname);
90716+#endif
90717 }
90718
90719 static int tstats_show(struct seq_file *m, void *v)
90720@@ -300,8 +304,8 @@ static int tstats_show(struct seq_file *m, void *v)
90721
90722 seq_puts(m, "Timer Stats Version: v0.3\n");
90723 seq_printf(m, "Sample period: %ld.%03ld s\n", period.tv_sec, ms);
90724- if (atomic_read(&overflow_count))
90725- seq_printf(m, "Overflow: %d entries\n", atomic_read(&overflow_count));
90726+ if (atomic_read_unchecked(&overflow_count))
90727+ seq_printf(m, "Overflow: %d entries\n", atomic_read_unchecked(&overflow_count));
90728 seq_printf(m, "Collection: %s\n", timer_stats_active ? "active" : "inactive");
90729
90730 for (i = 0; i < nr_entries; i++) {
90731@@ -417,7 +421,11 @@ static int __init init_tstats_procfs(void)
90732 {
90733 struct proc_dir_entry *pe;
90734
90735+#ifdef CONFIG_GRKERNSEC_PROC_ADD
90736+ pe = proc_create("timer_stats", 0600, NULL, &tstats_fops);
90737+#else
90738 pe = proc_create("timer_stats", 0644, NULL, &tstats_fops);
90739+#endif
90740 if (!pe)
90741 return -ENOMEM;
90742 return 0;
90743diff --git a/kernel/timer.c b/kernel/timer.c
90744index accfd24..e00f0c0 100644
90745--- a/kernel/timer.c
90746+++ b/kernel/timer.c
90747@@ -1366,7 +1366,7 @@ void update_process_times(int user_tick)
90748 /*
90749 * This function runs timers and the timer-tq in bottom half context.
90750 */
90751-static void run_timer_softirq(struct softirq_action *h)
90752+static __latent_entropy void run_timer_softirq(void)
90753 {
90754 struct tvec_base *base = __this_cpu_read(tvec_bases);
90755
90756@@ -1429,7 +1429,7 @@ static void process_timeout(unsigned long __data)
90757 *
90758 * In all cases the return value is guaranteed to be non-negative.
90759 */
90760-signed long __sched schedule_timeout(signed long timeout)
90761+signed long __sched __intentional_overflow(-1) schedule_timeout(signed long timeout)
90762 {
90763 struct timer_list timer;
90764 unsigned long expire;
90765diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
90766index b418cb0..f879a3d 100644
90767--- a/kernel/trace/blktrace.c
90768+++ b/kernel/trace/blktrace.c
90769@@ -328,7 +328,7 @@ static ssize_t blk_dropped_read(struct file *filp, char __user *buffer,
90770 struct blk_trace *bt = filp->private_data;
90771 char buf[16];
90772
90773- snprintf(buf, sizeof(buf), "%u\n", atomic_read(&bt->dropped));
90774+ snprintf(buf, sizeof(buf), "%u\n", atomic_read_unchecked(&bt->dropped));
90775
90776 return simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
90777 }
90778@@ -386,7 +386,7 @@ static int blk_subbuf_start_callback(struct rchan_buf *buf, void *subbuf,
90779 return 1;
90780
90781 bt = buf->chan->private_data;
90782- atomic_inc(&bt->dropped);
90783+ atomic_inc_unchecked(&bt->dropped);
90784 return 0;
90785 }
90786
90787@@ -487,7 +487,7 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
90788
90789 bt->dir = dir;
90790 bt->dev = dev;
90791- atomic_set(&bt->dropped, 0);
90792+ atomic_set_unchecked(&bt->dropped, 0);
90793 INIT_LIST_HEAD(&bt->running_list);
90794
90795 ret = -EIO;
90796diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
90797index cd7f76d..553c805 100644
90798--- a/kernel/trace/ftrace.c
90799+++ b/kernel/trace/ftrace.c
90800@@ -1965,12 +1965,17 @@ ftrace_code_disable(struct module *mod, struct dyn_ftrace *rec)
90801 if (unlikely(ftrace_disabled))
90802 return 0;
90803
90804+ ret = ftrace_arch_code_modify_prepare();
90805+ FTRACE_WARN_ON(ret);
90806+ if (ret)
90807+ return 0;
90808+
90809 ret = ftrace_make_nop(mod, rec, MCOUNT_ADDR);
90810+ FTRACE_WARN_ON(ftrace_arch_code_modify_post_process());
90811 if (ret) {
90812 ftrace_bug(ret, ip);
90813- return 0;
90814 }
90815- return 1;
90816+ return ret ? 0 : 1;
90817 }
90818
90819 /*
90820@@ -4177,8 +4182,10 @@ static int ftrace_process_locs(struct module *mod,
90821 if (!count)
90822 return 0;
90823
90824+ pax_open_kernel();
90825 sort(start, count, sizeof(*start),
90826 ftrace_cmp_ips, ftrace_swap_ips);
90827+ pax_close_kernel();
90828
90829 start_pg = ftrace_allocate_pages(count);
90830 if (!start_pg)
90831@@ -4909,8 +4916,6 @@ ftrace_enable_sysctl(struct ctl_table *table, int write,
90832 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
90833
90834 static int ftrace_graph_active;
90835-static struct notifier_block ftrace_suspend_notifier;
90836-
90837 int ftrace_graph_entry_stub(struct ftrace_graph_ent *trace)
90838 {
90839 return 0;
90840@@ -5086,6 +5091,10 @@ static void update_function_graph_func(void)
90841 ftrace_graph_entry = ftrace_graph_entry_test;
90842 }
90843
90844+static struct notifier_block ftrace_suspend_notifier = {
90845+ .notifier_call = ftrace_suspend_notifier_call
90846+};
90847+
90848 int register_ftrace_graph(trace_func_graph_ret_t retfunc,
90849 trace_func_graph_ent_t entryfunc)
90850 {
90851@@ -5099,7 +5108,6 @@ int register_ftrace_graph(trace_func_graph_ret_t retfunc,
90852 goto out;
90853 }
90854
90855- ftrace_suspend_notifier.notifier_call = ftrace_suspend_notifier_call;
90856 register_pm_notifier(&ftrace_suspend_notifier);
90857
90858 ftrace_graph_active++;
90859diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c
90860index fc4da2d..f3e800b 100644
90861--- a/kernel/trace/ring_buffer.c
90862+++ b/kernel/trace/ring_buffer.c
90863@@ -352,9 +352,9 @@ struct buffer_data_page {
90864 */
90865 struct buffer_page {
90866 struct list_head list; /* list of buffer pages */
90867- local_t write; /* index for next write */
90868+ local_unchecked_t write; /* index for next write */
90869 unsigned read; /* index for next read */
90870- local_t entries; /* entries on this page */
90871+ local_unchecked_t entries; /* entries on this page */
90872 unsigned long real_end; /* real end of data */
90873 struct buffer_data_page *page; /* Actual data page */
90874 };
90875@@ -473,8 +473,8 @@ struct ring_buffer_per_cpu {
90876 unsigned long last_overrun;
90877 local_t entries_bytes;
90878 local_t entries;
90879- local_t overrun;
90880- local_t commit_overrun;
90881+ local_unchecked_t overrun;
90882+ local_unchecked_t commit_overrun;
90883 local_t dropped_events;
90884 local_t committing;
90885 local_t commits;
90886@@ -992,8 +992,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
90887 *
90888 * We add a counter to the write field to denote this.
90889 */
90890- old_write = local_add_return(RB_WRITE_INTCNT, &next_page->write);
90891- old_entries = local_add_return(RB_WRITE_INTCNT, &next_page->entries);
90892+ old_write = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->write);
90893+ old_entries = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->entries);
90894
90895 /*
90896 * Just make sure we have seen our old_write and synchronize
90897@@ -1021,8 +1021,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
90898 * cmpxchg to only update if an interrupt did not already
90899 * do it for us. If the cmpxchg fails, we don't care.
90900 */
90901- (void)local_cmpxchg(&next_page->write, old_write, val);
90902- (void)local_cmpxchg(&next_page->entries, old_entries, eval);
90903+ (void)local_cmpxchg_unchecked(&next_page->write, old_write, val);
90904+ (void)local_cmpxchg_unchecked(&next_page->entries, old_entries, eval);
90905
90906 /*
90907 * No need to worry about races with clearing out the commit.
90908@@ -1386,12 +1386,12 @@ static void rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer);
90909
90910 static inline unsigned long rb_page_entries(struct buffer_page *bpage)
90911 {
90912- return local_read(&bpage->entries) & RB_WRITE_MASK;
90913+ return local_read_unchecked(&bpage->entries) & RB_WRITE_MASK;
90914 }
90915
90916 static inline unsigned long rb_page_write(struct buffer_page *bpage)
90917 {
90918- return local_read(&bpage->write) & RB_WRITE_MASK;
90919+ return local_read_unchecked(&bpage->write) & RB_WRITE_MASK;
90920 }
90921
90922 static int
90923@@ -1486,7 +1486,7 @@ rb_remove_pages(struct ring_buffer_per_cpu *cpu_buffer, unsigned int nr_pages)
90924 * bytes consumed in ring buffer from here.
90925 * Increment overrun to account for the lost events.
90926 */
90927- local_add(page_entries, &cpu_buffer->overrun);
90928+ local_add_unchecked(page_entries, &cpu_buffer->overrun);
90929 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
90930 }
90931
90932@@ -2064,7 +2064,7 @@ rb_handle_head_page(struct ring_buffer_per_cpu *cpu_buffer,
90933 * it is our responsibility to update
90934 * the counters.
90935 */
90936- local_add(entries, &cpu_buffer->overrun);
90937+ local_add_unchecked(entries, &cpu_buffer->overrun);
90938 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
90939
90940 /*
90941@@ -2214,7 +2214,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
90942 if (tail == BUF_PAGE_SIZE)
90943 tail_page->real_end = 0;
90944
90945- local_sub(length, &tail_page->write);
90946+ local_sub_unchecked(length, &tail_page->write);
90947 return;
90948 }
90949
90950@@ -2249,7 +2249,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
90951 rb_event_set_padding(event);
90952
90953 /* Set the write back to the previous setting */
90954- local_sub(length, &tail_page->write);
90955+ local_sub_unchecked(length, &tail_page->write);
90956 return;
90957 }
90958
90959@@ -2261,7 +2261,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
90960
90961 /* Set write to end of buffer */
90962 length = (tail + length) - BUF_PAGE_SIZE;
90963- local_sub(length, &tail_page->write);
90964+ local_sub_unchecked(length, &tail_page->write);
90965 }
90966
90967 /*
90968@@ -2287,7 +2287,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
90969 * about it.
90970 */
90971 if (unlikely(next_page == commit_page)) {
90972- local_inc(&cpu_buffer->commit_overrun);
90973+ local_inc_unchecked(&cpu_buffer->commit_overrun);
90974 goto out_reset;
90975 }
90976
90977@@ -2343,7 +2343,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
90978 cpu_buffer->tail_page) &&
90979 (cpu_buffer->commit_page ==
90980 cpu_buffer->reader_page))) {
90981- local_inc(&cpu_buffer->commit_overrun);
90982+ local_inc_unchecked(&cpu_buffer->commit_overrun);
90983 goto out_reset;
90984 }
90985 }
90986@@ -2391,7 +2391,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
90987 length += RB_LEN_TIME_EXTEND;
90988
90989 tail_page = cpu_buffer->tail_page;
90990- write = local_add_return(length, &tail_page->write);
90991+ write = local_add_return_unchecked(length, &tail_page->write);
90992
90993 /* set write to only the index of the write */
90994 write &= RB_WRITE_MASK;
90995@@ -2415,7 +2415,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
90996 kmemcheck_annotate_bitfield(event, bitfield);
90997 rb_update_event(cpu_buffer, event, length, add_timestamp, delta);
90998
90999- local_inc(&tail_page->entries);
91000+ local_inc_unchecked(&tail_page->entries);
91001
91002 /*
91003 * If this is the first commit on the page, then update
91004@@ -2448,7 +2448,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
91005
91006 if (bpage->page == (void *)addr && rb_page_write(bpage) == old_index) {
91007 unsigned long write_mask =
91008- local_read(&bpage->write) & ~RB_WRITE_MASK;
91009+ local_read_unchecked(&bpage->write) & ~RB_WRITE_MASK;
91010 unsigned long event_length = rb_event_length(event);
91011 /*
91012 * This is on the tail page. It is possible that
91013@@ -2458,7 +2458,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
91014 */
91015 old_index += write_mask;
91016 new_index += write_mask;
91017- index = local_cmpxchg(&bpage->write, old_index, new_index);
91018+ index = local_cmpxchg_unchecked(&bpage->write, old_index, new_index);
91019 if (index == old_index) {
91020 /* update counters */
91021 local_sub(event_length, &cpu_buffer->entries_bytes);
91022@@ -2850,7 +2850,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
91023
91024 /* Do the likely case first */
91025 if (likely(bpage->page == (void *)addr)) {
91026- local_dec(&bpage->entries);
91027+ local_dec_unchecked(&bpage->entries);
91028 return;
91029 }
91030
91031@@ -2862,7 +2862,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
91032 start = bpage;
91033 do {
91034 if (bpage->page == (void *)addr) {
91035- local_dec(&bpage->entries);
91036+ local_dec_unchecked(&bpage->entries);
91037 return;
91038 }
91039 rb_inc_page(cpu_buffer, &bpage);
91040@@ -3146,7 +3146,7 @@ static inline unsigned long
91041 rb_num_of_entries(struct ring_buffer_per_cpu *cpu_buffer)
91042 {
91043 return local_read(&cpu_buffer->entries) -
91044- (local_read(&cpu_buffer->overrun) + cpu_buffer->read);
91045+ (local_read_unchecked(&cpu_buffer->overrun) + cpu_buffer->read);
91046 }
91047
91048 /**
91049@@ -3235,7 +3235,7 @@ unsigned long ring_buffer_overrun_cpu(struct ring_buffer *buffer, int cpu)
91050 return 0;
91051
91052 cpu_buffer = buffer->buffers[cpu];
91053- ret = local_read(&cpu_buffer->overrun);
91054+ ret = local_read_unchecked(&cpu_buffer->overrun);
91055
91056 return ret;
91057 }
91058@@ -3258,7 +3258,7 @@ ring_buffer_commit_overrun_cpu(struct ring_buffer *buffer, int cpu)
91059 return 0;
91060
91061 cpu_buffer = buffer->buffers[cpu];
91062- ret = local_read(&cpu_buffer->commit_overrun);
91063+ ret = local_read_unchecked(&cpu_buffer->commit_overrun);
91064
91065 return ret;
91066 }
91067@@ -3343,7 +3343,7 @@ unsigned long ring_buffer_overruns(struct ring_buffer *buffer)
91068 /* if you care about this being correct, lock the buffer */
91069 for_each_buffer_cpu(buffer, cpu) {
91070 cpu_buffer = buffer->buffers[cpu];
91071- overruns += local_read(&cpu_buffer->overrun);
91072+ overruns += local_read_unchecked(&cpu_buffer->overrun);
91073 }
91074
91075 return overruns;
91076@@ -3519,8 +3519,8 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
91077 /*
91078 * Reset the reader page to size zero.
91079 */
91080- local_set(&cpu_buffer->reader_page->write, 0);
91081- local_set(&cpu_buffer->reader_page->entries, 0);
91082+ local_set_unchecked(&cpu_buffer->reader_page->write, 0);
91083+ local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
91084 local_set(&cpu_buffer->reader_page->page->commit, 0);
91085 cpu_buffer->reader_page->real_end = 0;
91086
91087@@ -3554,7 +3554,7 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
91088 * want to compare with the last_overrun.
91089 */
91090 smp_mb();
91091- overwrite = local_read(&(cpu_buffer->overrun));
91092+ overwrite = local_read_unchecked(&(cpu_buffer->overrun));
91093
91094 /*
91095 * Here's the tricky part.
91096@@ -4124,8 +4124,8 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
91097
91098 cpu_buffer->head_page
91099 = list_entry(cpu_buffer->pages, struct buffer_page, list);
91100- local_set(&cpu_buffer->head_page->write, 0);
91101- local_set(&cpu_buffer->head_page->entries, 0);
91102+ local_set_unchecked(&cpu_buffer->head_page->write, 0);
91103+ local_set_unchecked(&cpu_buffer->head_page->entries, 0);
91104 local_set(&cpu_buffer->head_page->page->commit, 0);
91105
91106 cpu_buffer->head_page->read = 0;
91107@@ -4135,14 +4135,14 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
91108
91109 INIT_LIST_HEAD(&cpu_buffer->reader_page->list);
91110 INIT_LIST_HEAD(&cpu_buffer->new_pages);
91111- local_set(&cpu_buffer->reader_page->write, 0);
91112- local_set(&cpu_buffer->reader_page->entries, 0);
91113+ local_set_unchecked(&cpu_buffer->reader_page->write, 0);
91114+ local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
91115 local_set(&cpu_buffer->reader_page->page->commit, 0);
91116 cpu_buffer->reader_page->read = 0;
91117
91118 local_set(&cpu_buffer->entries_bytes, 0);
91119- local_set(&cpu_buffer->overrun, 0);
91120- local_set(&cpu_buffer->commit_overrun, 0);
91121+ local_set_unchecked(&cpu_buffer->overrun, 0);
91122+ local_set_unchecked(&cpu_buffer->commit_overrun, 0);
91123 local_set(&cpu_buffer->dropped_events, 0);
91124 local_set(&cpu_buffer->entries, 0);
91125 local_set(&cpu_buffer->committing, 0);
91126@@ -4547,8 +4547,8 @@ int ring_buffer_read_page(struct ring_buffer *buffer,
91127 rb_init_page(bpage);
91128 bpage = reader->page;
91129 reader->page = *data_page;
91130- local_set(&reader->write, 0);
91131- local_set(&reader->entries, 0);
91132+ local_set_unchecked(&reader->write, 0);
91133+ local_set_unchecked(&reader->entries, 0);
91134 reader->read = 0;
91135 *data_page = bpage;
91136
91137diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
91138index 24c1f23..781fd73f 100644
91139--- a/kernel/trace/trace.c
91140+++ b/kernel/trace/trace.c
91141@@ -3399,7 +3399,7 @@ int trace_keep_overwrite(struct tracer *tracer, u32 mask, int set)
91142 return 0;
91143 }
91144
91145-int set_tracer_flag(struct trace_array *tr, unsigned int mask, int enabled)
91146+int set_tracer_flag(struct trace_array *tr, unsigned long mask, int enabled)
91147 {
91148 /* do nothing if flag is already set */
91149 if (!!(trace_flags & mask) == !!enabled)
91150diff --git a/kernel/trace/trace.h b/kernel/trace/trace.h
91151index 02b592f..f971546 100644
91152--- a/kernel/trace/trace.h
91153+++ b/kernel/trace/trace.h
91154@@ -1233,7 +1233,7 @@ extern const char *__stop___tracepoint_str[];
91155 void trace_printk_init_buffers(void);
91156 void trace_printk_start_comm(void);
91157 int trace_keep_overwrite(struct tracer *tracer, u32 mask, int set);
91158-int set_tracer_flag(struct trace_array *tr, unsigned int mask, int enabled);
91159+int set_tracer_flag(struct trace_array *tr, unsigned long mask, int enabled);
91160
91161 /*
91162 * Normal trace_printk() and friends allocates special buffers
91163diff --git a/kernel/trace/trace_clock.c b/kernel/trace/trace_clock.c
91164index 26dc348..8708ca7 100644
91165--- a/kernel/trace/trace_clock.c
91166+++ b/kernel/trace/trace_clock.c
91167@@ -123,7 +123,7 @@ u64 notrace trace_clock_global(void)
91168 return now;
91169 }
91170
91171-static atomic64_t trace_counter;
91172+static atomic64_unchecked_t trace_counter;
91173
91174 /*
91175 * trace_clock_counter(): simply an atomic counter.
91176@@ -132,5 +132,5 @@ static atomic64_t trace_counter;
91177 */
91178 u64 notrace trace_clock_counter(void)
91179 {
91180- return atomic64_add_return(1, &trace_counter);
91181+ return atomic64_inc_return_unchecked(&trace_counter);
91182 }
91183diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
91184index 7b16d40..1b2875d 100644
91185--- a/kernel/trace/trace_events.c
91186+++ b/kernel/trace/trace_events.c
91187@@ -1681,7 +1681,6 @@ __trace_early_add_new_event(struct ftrace_event_call *call,
91188 return 0;
91189 }
91190
91191-struct ftrace_module_file_ops;
91192 static void __add_event_to_tracers(struct ftrace_event_call *call);
91193
91194 /* Add an additional event_call dynamically */
91195diff --git a/kernel/trace/trace_mmiotrace.c b/kernel/trace/trace_mmiotrace.c
91196index 0abd9b8..6a663a2 100644
91197--- a/kernel/trace/trace_mmiotrace.c
91198+++ b/kernel/trace/trace_mmiotrace.c
91199@@ -24,7 +24,7 @@ struct header_iter {
91200 static struct trace_array *mmio_trace_array;
91201 static bool overrun_detected;
91202 static unsigned long prev_overruns;
91203-static atomic_t dropped_count;
91204+static atomic_unchecked_t dropped_count;
91205
91206 static void mmio_reset_data(struct trace_array *tr)
91207 {
91208@@ -127,7 +127,7 @@ static void mmio_close(struct trace_iterator *iter)
91209
91210 static unsigned long count_overruns(struct trace_iterator *iter)
91211 {
91212- unsigned long cnt = atomic_xchg(&dropped_count, 0);
91213+ unsigned long cnt = atomic_xchg_unchecked(&dropped_count, 0);
91214 unsigned long over = ring_buffer_overruns(iter->trace_buffer->buffer);
91215
91216 if (over > prev_overruns)
91217@@ -317,7 +317,7 @@ static void __trace_mmiotrace_rw(struct trace_array *tr,
91218 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_RW,
91219 sizeof(*entry), 0, pc);
91220 if (!event) {
91221- atomic_inc(&dropped_count);
91222+ atomic_inc_unchecked(&dropped_count);
91223 return;
91224 }
91225 entry = ring_buffer_event_data(event);
91226@@ -347,7 +347,7 @@ static void __trace_mmiotrace_map(struct trace_array *tr,
91227 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_MAP,
91228 sizeof(*entry), 0, pc);
91229 if (!event) {
91230- atomic_inc(&dropped_count);
91231+ atomic_inc_unchecked(&dropped_count);
91232 return;
91233 }
91234 entry = ring_buffer_event_data(event);
91235diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
91236index ed32284..884d6c3 100644
91237--- a/kernel/trace/trace_output.c
91238+++ b/kernel/trace/trace_output.c
91239@@ -294,7 +294,7 @@ int trace_seq_path(struct trace_seq *s, const struct path *path)
91240
91241 p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len);
91242 if (!IS_ERR(p)) {
91243- p = mangle_path(s->buffer + s->len, p, "\n");
91244+ p = mangle_path(s->buffer + s->len, p, "\n\\");
91245 if (p) {
91246 s->len = p - s->buffer;
91247 return 1;
91248@@ -908,14 +908,16 @@ int register_ftrace_event(struct trace_event *event)
91249 goto out;
91250 }
91251
91252+ pax_open_kernel();
91253 if (event->funcs->trace == NULL)
91254- event->funcs->trace = trace_nop_print;
91255+ *(void **)&event->funcs->trace = trace_nop_print;
91256 if (event->funcs->raw == NULL)
91257- event->funcs->raw = trace_nop_print;
91258+ *(void **)&event->funcs->raw = trace_nop_print;
91259 if (event->funcs->hex == NULL)
91260- event->funcs->hex = trace_nop_print;
91261+ *(void **)&event->funcs->hex = trace_nop_print;
91262 if (event->funcs->binary == NULL)
91263- event->funcs->binary = trace_nop_print;
91264+ *(void **)&event->funcs->binary = trace_nop_print;
91265+ pax_close_kernel();
91266
91267 key = event->type & (EVENT_HASHSIZE - 1);
91268
91269diff --git a/kernel/trace/trace_stack.c b/kernel/trace/trace_stack.c
91270index e6be585..d73ae5e 100644
91271--- a/kernel/trace/trace_stack.c
91272+++ b/kernel/trace/trace_stack.c
91273@@ -68,7 +68,7 @@ check_stack(unsigned long ip, unsigned long *stack)
91274 return;
91275
91276 /* we do not handle interrupt stacks yet */
91277- if (!object_is_on_stack(stack))
91278+ if (!object_starts_on_stack(stack))
91279 return;
91280
91281 local_irq_save(flags);
91282diff --git a/kernel/user_namespace.c b/kernel/user_namespace.c
91283index 80a57af..7f5a7ff 100644
91284--- a/kernel/user_namespace.c
91285+++ b/kernel/user_namespace.c
91286@@ -82,6 +82,21 @@ int create_user_ns(struct cred *new)
91287 !kgid_has_mapping(parent_ns, group))
91288 return -EPERM;
91289
91290+#ifdef CONFIG_GRKERNSEC
91291+ /*
91292+ * This doesn't really inspire confidence:
91293+ * http://marc.info/?l=linux-kernel&m=135543612731939&w=2
91294+ * http://marc.info/?l=linux-kernel&m=135545831607095&w=2
91295+ * Increases kernel attack surface in areas developers
91296+ * previously cared little about ("low importance due
91297+ * to requiring "root" capability")
91298+ * To be removed when this code receives *proper* review
91299+ */
91300+ if (!capable(CAP_SYS_ADMIN) || !capable(CAP_SETUID) ||
91301+ !capable(CAP_SETGID))
91302+ return -EPERM;
91303+#endif
91304+
91305 ns = kmem_cache_zalloc(user_ns_cachep, GFP_KERNEL);
91306 if (!ns)
91307 return -ENOMEM;
91308@@ -865,7 +880,7 @@ static int userns_install(struct nsproxy *nsproxy, void *ns)
91309 if (atomic_read(&current->mm->mm_users) > 1)
91310 return -EINVAL;
91311
91312- if (current->fs->users != 1)
91313+ if (atomic_read(&current->fs->users) != 1)
91314 return -EINVAL;
91315
91316 if (!ns_capable(user_ns, CAP_SYS_ADMIN))
91317diff --git a/kernel/utsname_sysctl.c b/kernel/utsname_sysctl.c
91318index 4f69f9a..7c6f8f8 100644
91319--- a/kernel/utsname_sysctl.c
91320+++ b/kernel/utsname_sysctl.c
91321@@ -47,7 +47,7 @@ static void put_uts(ctl_table *table, int write, void *which)
91322 static int proc_do_uts_string(ctl_table *table, int write,
91323 void __user *buffer, size_t *lenp, loff_t *ppos)
91324 {
91325- struct ctl_table uts_table;
91326+ ctl_table_no_const uts_table;
91327 int r;
91328 memcpy(&uts_table, table, sizeof(uts_table));
91329 uts_table.data = get_uts(table, write);
91330diff --git a/kernel/watchdog.c b/kernel/watchdog.c
91331index 4431610..4265616 100644
91332--- a/kernel/watchdog.c
91333+++ b/kernel/watchdog.c
91334@@ -475,7 +475,7 @@ static int watchdog_nmi_enable(unsigned int cpu) { return 0; }
91335 static void watchdog_nmi_disable(unsigned int cpu) { return; }
91336 #endif /* CONFIG_HARDLOCKUP_DETECTOR */
91337
91338-static struct smp_hotplug_thread watchdog_threads = {
91339+static struct smp_hotplug_thread watchdog_threads __read_only = {
91340 .store = &softlockup_watchdog,
91341 .thread_should_run = watchdog_should_run,
91342 .thread_fn = watchdog,
91343diff --git a/kernel/workqueue.c b/kernel/workqueue.c
91344index 193e977..26dd63f 100644
91345--- a/kernel/workqueue.c
91346+++ b/kernel/workqueue.c
91347@@ -4678,7 +4678,7 @@ static void rebind_workers(struct worker_pool *pool)
91348 WARN_ON_ONCE(!(worker_flags & WORKER_UNBOUND));
91349 worker_flags |= WORKER_REBOUND;
91350 worker_flags &= ~WORKER_UNBOUND;
91351- ACCESS_ONCE(worker->flags) = worker_flags;
91352+ ACCESS_ONCE_RW(worker->flags) = worker_flags;
91353 }
91354
91355 spin_unlock_irq(&pool->lock);
91356diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
91357index a48abea..e108def 100644
91358--- a/lib/Kconfig.debug
91359+++ b/lib/Kconfig.debug
91360@@ -854,7 +854,7 @@ config DEBUG_MUTEXES
91361
91362 config DEBUG_WW_MUTEX_SLOWPATH
91363 bool "Wait/wound mutex debugging: Slowpath testing"
91364- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
91365+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
91366 select DEBUG_LOCK_ALLOC
91367 select DEBUG_SPINLOCK
91368 select DEBUG_MUTEXES
91369@@ -867,7 +867,7 @@ config DEBUG_WW_MUTEX_SLOWPATH
91370
91371 config DEBUG_LOCK_ALLOC
91372 bool "Lock debugging: detect incorrect freeing of live locks"
91373- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
91374+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
91375 select DEBUG_SPINLOCK
91376 select DEBUG_MUTEXES
91377 select LOCKDEP
91378@@ -881,7 +881,7 @@ config DEBUG_LOCK_ALLOC
91379
91380 config PROVE_LOCKING
91381 bool "Lock debugging: prove locking correctness"
91382- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
91383+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
91384 select LOCKDEP
91385 select DEBUG_SPINLOCK
91386 select DEBUG_MUTEXES
91387@@ -932,7 +932,7 @@ config LOCKDEP
91388
91389 config LOCK_STAT
91390 bool "Lock usage statistics"
91391- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
91392+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
91393 select LOCKDEP
91394 select DEBUG_SPINLOCK
91395 select DEBUG_MUTEXES
91396@@ -1394,6 +1394,7 @@ config LATENCYTOP
91397 depends on DEBUG_KERNEL
91398 depends on STACKTRACE_SUPPORT
91399 depends on PROC_FS
91400+ depends on !GRKERNSEC_HIDESYM
91401 select FRAME_POINTER if !MIPS && !PPC && !S390 && !MICROBLAZE && !ARM_UNWIND && !ARC
91402 select KALLSYMS
91403 select KALLSYMS_ALL
91404@@ -1410,7 +1411,7 @@ config ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS
91405 config DEBUG_STRICT_USER_COPY_CHECKS
91406 bool "Strict user copy size checks"
91407 depends on ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS
91408- depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING
91409+ depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING && !PAX_SIZE_OVERFLOW
91410 help
91411 Enabling this option turns a certain set of sanity checks for user
91412 copy operations into compile time failures.
91413@@ -1529,7 +1530,7 @@ endmenu # runtime tests
91414
91415 config PROVIDE_OHCI1394_DMA_INIT
91416 bool "Remote debugging over FireWire early on boot"
91417- depends on PCI && X86
91418+ depends on PCI && X86 && !GRKERNSEC
91419 help
91420 If you want to debug problems which hang or crash the kernel early
91421 on boot and the crashing machine has a FireWire port, you can use
91422diff --git a/lib/Makefile b/lib/Makefile
91423index 48140e3..de854e5 100644
91424--- a/lib/Makefile
91425+++ b/lib/Makefile
91426@@ -52,7 +52,7 @@ obj-$(CONFIG_GENERIC_HWEIGHT) += hweight.o
91427 obj-$(CONFIG_BTREE) += btree.o
91428 obj-$(CONFIG_ASSOCIATIVE_ARRAY) += assoc_array.o
91429 obj-$(CONFIG_DEBUG_PREEMPT) += smp_processor_id.o
91430-obj-$(CONFIG_DEBUG_LIST) += list_debug.o
91431+obj-y += list_debug.o
91432 obj-$(CONFIG_DEBUG_OBJECTS) += debugobjects.o
91433
91434 ifneq ($(CONFIG_HAVE_DEC_LOCK),y)
91435diff --git a/lib/average.c b/lib/average.c
91436index 114d1be..ab0350c 100644
91437--- a/lib/average.c
91438+++ b/lib/average.c
91439@@ -55,7 +55,7 @@ struct ewma *ewma_add(struct ewma *avg, unsigned long val)
91440 {
91441 unsigned long internal = ACCESS_ONCE(avg->internal);
91442
91443- ACCESS_ONCE(avg->internal) = internal ?
91444+ ACCESS_ONCE_RW(avg->internal) = internal ?
91445 (((internal << avg->weight) - internal) +
91446 (val << avg->factor)) >> avg->weight :
91447 (val << avg->factor);
91448diff --git a/lib/bitmap.c b/lib/bitmap.c
91449index 06f7e4f..f3cf2b0 100644
91450--- a/lib/bitmap.c
91451+++ b/lib/bitmap.c
91452@@ -422,7 +422,7 @@ int __bitmap_parse(const char *buf, unsigned int buflen,
91453 {
91454 int c, old_c, totaldigits, ndigits, nchunks, nbits;
91455 u32 chunk;
91456- const char __user __force *ubuf = (const char __user __force *)buf;
91457+ const char __user *ubuf = (const char __force_user *)buf;
91458
91459 bitmap_zero(maskp, nmaskbits);
91460
91461@@ -507,7 +507,7 @@ int bitmap_parse_user(const char __user *ubuf,
91462 {
91463 if (!access_ok(VERIFY_READ, ubuf, ulen))
91464 return -EFAULT;
91465- return __bitmap_parse((const char __force *)ubuf,
91466+ return __bitmap_parse((const char __force_kernel *)ubuf,
91467 ulen, 1, maskp, nmaskbits);
91468
91469 }
91470@@ -598,7 +598,7 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen,
91471 {
91472 unsigned a, b;
91473 int c, old_c, totaldigits;
91474- const char __user __force *ubuf = (const char __user __force *)buf;
91475+ const char __user *ubuf = (const char __force_user *)buf;
91476 int exp_digit, in_range;
91477
91478 totaldigits = c = 0;
91479@@ -698,7 +698,7 @@ int bitmap_parselist_user(const char __user *ubuf,
91480 {
91481 if (!access_ok(VERIFY_READ, ubuf, ulen))
91482 return -EFAULT;
91483- return __bitmap_parselist((const char __force *)ubuf,
91484+ return __bitmap_parselist((const char __force_kernel *)ubuf,
91485 ulen, 1, maskp, nmaskbits);
91486 }
91487 EXPORT_SYMBOL(bitmap_parselist_user);
91488diff --git a/lib/bug.c b/lib/bug.c
91489index 1686034..a9c00c8 100644
91490--- a/lib/bug.c
91491+++ b/lib/bug.c
91492@@ -134,6 +134,8 @@ enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs)
91493 return BUG_TRAP_TYPE_NONE;
91494
91495 bug = find_bug(bugaddr);
91496+ if (!bug)
91497+ return BUG_TRAP_TYPE_NONE;
91498
91499 file = NULL;
91500 line = 0;
91501diff --git a/lib/debugobjects.c b/lib/debugobjects.c
91502index e0731c3..ad66444 100644
91503--- a/lib/debugobjects.c
91504+++ b/lib/debugobjects.c
91505@@ -286,7 +286,7 @@ static void debug_object_is_on_stack(void *addr, int onstack)
91506 if (limit > 4)
91507 return;
91508
91509- is_on_stack = object_is_on_stack(addr);
91510+ is_on_stack = object_starts_on_stack(addr);
91511 if (is_on_stack == onstack)
91512 return;
91513
91514diff --git a/lib/devres.c b/lib/devres.c
91515index 8235331..5881053 100644
91516--- a/lib/devres.c
91517+++ b/lib/devres.c
91518@@ -81,7 +81,7 @@ EXPORT_SYMBOL(devm_ioremap_nocache);
91519 void devm_iounmap(struct device *dev, void __iomem *addr)
91520 {
91521 WARN_ON(devres_destroy(dev, devm_ioremap_release, devm_ioremap_match,
91522- (void *)addr));
91523+ (void __force *)addr));
91524 iounmap(addr);
91525 }
91526 EXPORT_SYMBOL(devm_iounmap);
91527@@ -224,7 +224,7 @@ void devm_ioport_unmap(struct device *dev, void __iomem *addr)
91528 {
91529 ioport_unmap(addr);
91530 WARN_ON(devres_destroy(dev, devm_ioport_map_release,
91531- devm_ioport_map_match, (void *)addr));
91532+ devm_ioport_map_match, (void __force *)addr));
91533 }
91534 EXPORT_SYMBOL(devm_ioport_unmap);
91535 #endif /* CONFIG_HAS_IOPORT */
91536diff --git a/lib/div64.c b/lib/div64.c
91537index 4382ad7..08aa558 100644
91538--- a/lib/div64.c
91539+++ b/lib/div64.c
91540@@ -59,7 +59,7 @@ uint32_t __attribute__((weak)) __div64_32(uint64_t *n, uint32_t base)
91541 EXPORT_SYMBOL(__div64_32);
91542
91543 #ifndef div_s64_rem
91544-s64 div_s64_rem(s64 dividend, s32 divisor, s32 *remainder)
91545+s64 __intentional_overflow(-1) div_s64_rem(s64 dividend, s32 divisor, s32 *remainder)
91546 {
91547 u64 quotient;
91548
91549@@ -130,7 +130,7 @@ EXPORT_SYMBOL(div64_u64_rem);
91550 * 'http://www.hackersdelight.org/HDcode/newCode/divDouble.c.txt'
91551 */
91552 #ifndef div64_u64
91553-u64 div64_u64(u64 dividend, u64 divisor)
91554+u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor)
91555 {
91556 u32 high = divisor >> 32;
91557 u64 quot;
91558diff --git a/lib/dma-debug.c b/lib/dma-debug.c
91559index 98f2d7e..899da5c 100644
91560--- a/lib/dma-debug.c
91561+++ b/lib/dma-debug.c
91562@@ -971,7 +971,7 @@ static int dma_debug_device_change(struct notifier_block *nb, unsigned long acti
91563
91564 void dma_debug_add_bus(struct bus_type *bus)
91565 {
91566- struct notifier_block *nb;
91567+ notifier_block_no_const *nb;
91568
91569 if (global_disable)
91570 return;
91571@@ -1148,7 +1148,7 @@ static void check_unmap(struct dma_debug_entry *ref)
91572
91573 static void check_for_stack(struct device *dev, void *addr)
91574 {
91575- if (object_is_on_stack(addr))
91576+ if (object_starts_on_stack(addr))
91577 err_printk(dev, NULL, "DMA-API: device driver maps memory from"
91578 "stack [addr=%p]\n", addr);
91579 }
91580diff --git a/lib/hash.c b/lib/hash.c
91581index fea973f..386626f 100644
91582--- a/lib/hash.c
91583+++ b/lib/hash.c
91584@@ -14,7 +14,7 @@
91585 #include <linux/hash.h>
91586 #include <linux/cache.h>
91587
91588-static struct fast_hash_ops arch_hash_ops __read_mostly = {
91589+static struct fast_hash_ops arch_hash_ops __read_only = {
91590 .hash = jhash,
91591 .hash2 = jhash2,
91592 };
91593diff --git a/lib/inflate.c b/lib/inflate.c
91594index 013a761..c28f3fc 100644
91595--- a/lib/inflate.c
91596+++ b/lib/inflate.c
91597@@ -269,7 +269,7 @@ static void free(void *where)
91598 malloc_ptr = free_mem_ptr;
91599 }
91600 #else
91601-#define malloc(a) kmalloc(a, GFP_KERNEL)
91602+#define malloc(a) kmalloc((a), GFP_KERNEL)
91603 #define free(a) kfree(a)
91604 #endif
91605
91606diff --git a/lib/ioremap.c b/lib/ioremap.c
91607index 0c9216c..863bd89 100644
91608--- a/lib/ioremap.c
91609+++ b/lib/ioremap.c
91610@@ -38,7 +38,7 @@ static inline int ioremap_pmd_range(pud_t *pud, unsigned long addr,
91611 unsigned long next;
91612
91613 phys_addr -= addr;
91614- pmd = pmd_alloc(&init_mm, pud, addr);
91615+ pmd = pmd_alloc_kernel(&init_mm, pud, addr);
91616 if (!pmd)
91617 return -ENOMEM;
91618 do {
91619@@ -56,7 +56,7 @@ static inline int ioremap_pud_range(pgd_t *pgd, unsigned long addr,
91620 unsigned long next;
91621
91622 phys_addr -= addr;
91623- pud = pud_alloc(&init_mm, pgd, addr);
91624+ pud = pud_alloc_kernel(&init_mm, pgd, addr);
91625 if (!pud)
91626 return -ENOMEM;
91627 do {
91628diff --git a/lib/is_single_threaded.c b/lib/is_single_threaded.c
91629index bd2bea9..6b3c95e 100644
91630--- a/lib/is_single_threaded.c
91631+++ b/lib/is_single_threaded.c
91632@@ -22,6 +22,9 @@ bool current_is_single_threaded(void)
91633 struct task_struct *p, *t;
91634 bool ret;
91635
91636+ if (!mm)
91637+ return true;
91638+
91639 if (atomic_read(&task->signal->live) != 1)
91640 return false;
91641
91642diff --git a/lib/kobject.c b/lib/kobject.c
91643index cb14aea..8c53cdb 100644
91644--- a/lib/kobject.c
91645+++ b/lib/kobject.c
91646@@ -931,9 +931,9 @@ EXPORT_SYMBOL_GPL(kset_create_and_add);
91647
91648
91649 static DEFINE_SPINLOCK(kobj_ns_type_lock);
91650-static const struct kobj_ns_type_operations *kobj_ns_ops_tbl[KOBJ_NS_TYPES];
91651+static const struct kobj_ns_type_operations *kobj_ns_ops_tbl[KOBJ_NS_TYPES] __read_only;
91652
91653-int kobj_ns_type_register(const struct kobj_ns_type_operations *ops)
91654+int __init kobj_ns_type_register(const struct kobj_ns_type_operations *ops)
91655 {
91656 enum kobj_ns_type type = ops->type;
91657 int error;
91658diff --git a/lib/list_debug.c b/lib/list_debug.c
91659index c24c2f7..f0296f4 100644
91660--- a/lib/list_debug.c
91661+++ b/lib/list_debug.c
91662@@ -11,7 +11,9 @@
91663 #include <linux/bug.h>
91664 #include <linux/kernel.h>
91665 #include <linux/rculist.h>
91666+#include <linux/mm.h>
91667
91668+#ifdef CONFIG_DEBUG_LIST
91669 /*
91670 * Insert a new entry between two known consecutive entries.
91671 *
91672@@ -19,21 +21,40 @@
91673 * the prev/next entries already!
91674 */
91675
91676+static bool __list_add_debug(struct list_head *new,
91677+ struct list_head *prev,
91678+ struct list_head *next)
91679+{
91680+ if (unlikely(next->prev != prev)) {
91681+ printk(KERN_ERR "list_add corruption. next->prev should be "
91682+ "prev (%p), but was %p. (next=%p).\n",
91683+ prev, next->prev, next);
91684+ BUG();
91685+ return false;
91686+ }
91687+ if (unlikely(prev->next != next)) {
91688+ printk(KERN_ERR "list_add corruption. prev->next should be "
91689+ "next (%p), but was %p. (prev=%p).\n",
91690+ next, prev->next, prev);
91691+ BUG();
91692+ return false;
91693+ }
91694+ if (unlikely(new == prev || new == next)) {
91695+ printk(KERN_ERR "list_add double add: new=%p, prev=%p, next=%p.\n",
91696+ new, prev, next);
91697+ BUG();
91698+ return false;
91699+ }
91700+ return true;
91701+}
91702+
91703 void __list_add(struct list_head *new,
91704- struct list_head *prev,
91705- struct list_head *next)
91706+ struct list_head *prev,
91707+ struct list_head *next)
91708 {
91709- WARN(next->prev != prev,
91710- "list_add corruption. next->prev should be "
91711- "prev (%p), but was %p. (next=%p).\n",
91712- prev, next->prev, next);
91713- WARN(prev->next != next,
91714- "list_add corruption. prev->next should be "
91715- "next (%p), but was %p. (prev=%p).\n",
91716- next, prev->next, prev);
91717- WARN(new == prev || new == next,
91718- "list_add double add: new=%p, prev=%p, next=%p.\n",
91719- new, prev, next);
91720+ if (!__list_add_debug(new, prev, next))
91721+ return;
91722+
91723 next->prev = new;
91724 new->next = next;
91725 new->prev = prev;
91726@@ -41,28 +62,46 @@ void __list_add(struct list_head *new,
91727 }
91728 EXPORT_SYMBOL(__list_add);
91729
91730-void __list_del_entry(struct list_head *entry)
91731+static bool __list_del_entry_debug(struct list_head *entry)
91732 {
91733 struct list_head *prev, *next;
91734
91735 prev = entry->prev;
91736 next = entry->next;
91737
91738- if (WARN(next == LIST_POISON1,
91739- "list_del corruption, %p->next is LIST_POISON1 (%p)\n",
91740- entry, LIST_POISON1) ||
91741- WARN(prev == LIST_POISON2,
91742- "list_del corruption, %p->prev is LIST_POISON2 (%p)\n",
91743- entry, LIST_POISON2) ||
91744- WARN(prev->next != entry,
91745- "list_del corruption. prev->next should be %p, "
91746- "but was %p\n", entry, prev->next) ||
91747- WARN(next->prev != entry,
91748- "list_del corruption. next->prev should be %p, "
91749- "but was %p\n", entry, next->prev))
91750+ if (unlikely(next == LIST_POISON1)) {
91751+ printk(KERN_ERR "list_del corruption, %p->next is LIST_POISON1 (%p)\n",
91752+ entry, LIST_POISON1);
91753+ BUG();
91754+ return false;
91755+ }
91756+ if (unlikely(prev == LIST_POISON2)) {
91757+ printk(KERN_ERR "list_del corruption, %p->prev is LIST_POISON2 (%p)\n",
91758+ entry, LIST_POISON2);
91759+ BUG();
91760+ return false;
91761+ }
91762+ if (unlikely(entry->prev->next != entry)) {
91763+ printk(KERN_ERR "list_del corruption. prev->next should be %p, "
91764+ "but was %p\n", entry, prev->next);
91765+ BUG();
91766+ return false;
91767+ }
91768+ if (unlikely(entry->next->prev != entry)) {
91769+ printk(KERN_ERR "list_del corruption. next->prev should be %p, "
91770+ "but was %p\n", entry, next->prev);
91771+ BUG();
91772+ return false;
91773+ }
91774+ return true;
91775+}
91776+
91777+void __list_del_entry(struct list_head *entry)
91778+{
91779+ if (!__list_del_entry_debug(entry))
91780 return;
91781
91782- __list_del(prev, next);
91783+ __list_del(entry->prev, entry->next);
91784 }
91785 EXPORT_SYMBOL(__list_del_entry);
91786
91787@@ -86,15 +125,85 @@ EXPORT_SYMBOL(list_del);
91788 void __list_add_rcu(struct list_head *new,
91789 struct list_head *prev, struct list_head *next)
91790 {
91791- WARN(next->prev != prev,
91792- "list_add_rcu corruption. next->prev should be prev (%p), but was %p. (next=%p).\n",
91793- prev, next->prev, next);
91794- WARN(prev->next != next,
91795- "list_add_rcu corruption. prev->next should be next (%p), but was %p. (prev=%p).\n",
91796- next, prev->next, prev);
91797+ if (!__list_add_debug(new, prev, next))
91798+ return;
91799+
91800 new->next = next;
91801 new->prev = prev;
91802 rcu_assign_pointer(list_next_rcu(prev), new);
91803 next->prev = new;
91804 }
91805 EXPORT_SYMBOL(__list_add_rcu);
91806+#endif
91807+
91808+void __pax_list_add(struct list_head *new, struct list_head *prev, struct list_head *next)
91809+{
91810+#ifdef CONFIG_DEBUG_LIST
91811+ if (!__list_add_debug(new, prev, next))
91812+ return;
91813+#endif
91814+
91815+ pax_open_kernel();
91816+ next->prev = new;
91817+ new->next = next;
91818+ new->prev = prev;
91819+ prev->next = new;
91820+ pax_close_kernel();
91821+}
91822+EXPORT_SYMBOL(__pax_list_add);
91823+
91824+void pax_list_del(struct list_head *entry)
91825+{
91826+#ifdef CONFIG_DEBUG_LIST
91827+ if (!__list_del_entry_debug(entry))
91828+ return;
91829+#endif
91830+
91831+ pax_open_kernel();
91832+ __list_del(entry->prev, entry->next);
91833+ entry->next = LIST_POISON1;
91834+ entry->prev = LIST_POISON2;
91835+ pax_close_kernel();
91836+}
91837+EXPORT_SYMBOL(pax_list_del);
91838+
91839+void pax_list_del_init(struct list_head *entry)
91840+{
91841+ pax_open_kernel();
91842+ __list_del(entry->prev, entry->next);
91843+ INIT_LIST_HEAD(entry);
91844+ pax_close_kernel();
91845+}
91846+EXPORT_SYMBOL(pax_list_del_init);
91847+
91848+void __pax_list_add_rcu(struct list_head *new,
91849+ struct list_head *prev, struct list_head *next)
91850+{
91851+#ifdef CONFIG_DEBUG_LIST
91852+ if (!__list_add_debug(new, prev, next))
91853+ return;
91854+#endif
91855+
91856+ pax_open_kernel();
91857+ new->next = next;
91858+ new->prev = prev;
91859+ rcu_assign_pointer(list_next_rcu(prev), new);
91860+ next->prev = new;
91861+ pax_close_kernel();
91862+}
91863+EXPORT_SYMBOL(__pax_list_add_rcu);
91864+
91865+void pax_list_del_rcu(struct list_head *entry)
91866+{
91867+#ifdef CONFIG_DEBUG_LIST
91868+ if (!__list_del_entry_debug(entry))
91869+ return;
91870+#endif
91871+
91872+ pax_open_kernel();
91873+ __list_del(entry->prev, entry->next);
91874+ entry->next = LIST_POISON1;
91875+ entry->prev = LIST_POISON2;
91876+ pax_close_kernel();
91877+}
91878+EXPORT_SYMBOL(pax_list_del_rcu);
91879diff --git a/lib/percpu-refcount.c b/lib/percpu-refcount.c
91880index 963b703..438bc51 100644
91881--- a/lib/percpu-refcount.c
91882+++ b/lib/percpu-refcount.c
91883@@ -29,7 +29,7 @@
91884 * can't hit 0 before we've added up all the percpu refs.
91885 */
91886
91887-#define PCPU_COUNT_BIAS (1U << 31)
91888+#define PCPU_COUNT_BIAS (1U << 30)
91889
91890 /**
91891 * percpu_ref_init - initialize a percpu refcount
91892diff --git a/lib/radix-tree.c b/lib/radix-tree.c
91893index bd4a8df..9e4804f 100644
91894--- a/lib/radix-tree.c
91895+++ b/lib/radix-tree.c
91896@@ -93,7 +93,7 @@ struct radix_tree_preload {
91897 int nr;
91898 struct radix_tree_node *nodes[RADIX_TREE_PRELOAD_SIZE];
91899 };
91900-static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads) = { 0, };
91901+static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads);
91902
91903 static inline void *ptr_to_indirect(void *ptr)
91904 {
91905diff --git a/lib/random32.c b/lib/random32.c
91906index 6148967..009bfe8 100644
91907--- a/lib/random32.c
91908+++ b/lib/random32.c
91909@@ -44,7 +44,7 @@
91910 static void __init prandom_state_selftest(void);
91911 #endif
91912
91913-static DEFINE_PER_CPU(struct rnd_state, net_rand_state);
91914+static DEFINE_PER_CPU(struct rnd_state, net_rand_state) __latent_entropy;
91915
91916 /**
91917 * prandom_u32_state - seeded pseudo-random number generator.
91918diff --git a/lib/rbtree.c b/lib/rbtree.c
91919index 65f4eff..2cfa167 100644
91920--- a/lib/rbtree.c
91921+++ b/lib/rbtree.c
91922@@ -380,7 +380,9 @@ static inline void dummy_copy(struct rb_node *old, struct rb_node *new) {}
91923 static inline void dummy_rotate(struct rb_node *old, struct rb_node *new) {}
91924
91925 static const struct rb_augment_callbacks dummy_callbacks = {
91926- dummy_propagate, dummy_copy, dummy_rotate
91927+ .propagate = dummy_propagate,
91928+ .copy = dummy_copy,
91929+ .rotate = dummy_rotate
91930 };
91931
91932 void rb_insert_color(struct rb_node *node, struct rb_root *root)
91933diff --git a/lib/show_mem.c b/lib/show_mem.c
91934index 0922579..9d7adb9 100644
91935--- a/lib/show_mem.c
91936+++ b/lib/show_mem.c
91937@@ -44,6 +44,6 @@ void show_mem(unsigned int filter)
91938 quicklist_total_size());
91939 #endif
91940 #ifdef CONFIG_MEMORY_FAILURE
91941- printk("%lu pages hwpoisoned\n", atomic_long_read(&num_poisoned_pages));
91942+ printk("%lu pages hwpoisoned\n", atomic_long_read_unchecked(&num_poisoned_pages));
91943 #endif
91944 }
91945diff --git a/lib/strncpy_from_user.c b/lib/strncpy_from_user.c
91946index bb2b201..46abaf9 100644
91947--- a/lib/strncpy_from_user.c
91948+++ b/lib/strncpy_from_user.c
91949@@ -21,7 +21,7 @@
91950 */
91951 static inline long do_strncpy_from_user(char *dst, const char __user *src, long count, unsigned long max)
91952 {
91953- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
91954+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
91955 long res = 0;
91956
91957 /*
91958diff --git a/lib/strnlen_user.c b/lib/strnlen_user.c
91959index a28df52..3d55877 100644
91960--- a/lib/strnlen_user.c
91961+++ b/lib/strnlen_user.c
91962@@ -26,7 +26,7 @@
91963 */
91964 static inline long do_strnlen_user(const char __user *src, unsigned long count, unsigned long max)
91965 {
91966- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
91967+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
91968 long align, res = 0;
91969 unsigned long c;
91970
91971diff --git a/lib/swiotlb.c b/lib/swiotlb.c
91972index b604b83..c0547f6 100644
91973--- a/lib/swiotlb.c
91974+++ b/lib/swiotlb.c
91975@@ -674,7 +674,7 @@ EXPORT_SYMBOL(swiotlb_alloc_coherent);
91976
91977 void
91978 swiotlb_free_coherent(struct device *hwdev, size_t size, void *vaddr,
91979- dma_addr_t dev_addr)
91980+ dma_addr_t dev_addr, struct dma_attrs *attrs)
91981 {
91982 phys_addr_t paddr = dma_to_phys(hwdev, dev_addr);
91983
91984diff --git a/lib/usercopy.c b/lib/usercopy.c
91985index 4f5b1dd..7cab418 100644
91986--- a/lib/usercopy.c
91987+++ b/lib/usercopy.c
91988@@ -7,3 +7,9 @@ void copy_from_user_overflow(void)
91989 WARN(1, "Buffer overflow detected!\n");
91990 }
91991 EXPORT_SYMBOL(copy_from_user_overflow);
91992+
91993+void copy_to_user_overflow(void)
91994+{
91995+ WARN(1, "Buffer overflow detected!\n");
91996+}
91997+EXPORT_SYMBOL(copy_to_user_overflow);
91998diff --git a/lib/vsprintf.c b/lib/vsprintf.c
91999index 185b6d3..823c48c 100644
92000--- a/lib/vsprintf.c
92001+++ b/lib/vsprintf.c
92002@@ -16,6 +16,9 @@
92003 * - scnprintf and vscnprintf
92004 */
92005
92006+#ifdef CONFIG_GRKERNSEC_HIDESYM
92007+#define __INCLUDED_BY_HIDESYM 1
92008+#endif
92009 #include <stdarg.h>
92010 #include <linux/module.h> /* for KSYM_SYMBOL_LEN */
92011 #include <linux/types.h>
92012@@ -1179,7 +1182,11 @@ char *address_val(char *buf, char *end, const void *addr,
92013 return number(buf, end, num, spec);
92014 }
92015
92016+#ifdef CONFIG_GRKERNSEC_HIDESYM
92017+int kptr_restrict __read_mostly = 2;
92018+#else
92019 int kptr_restrict __read_mostly;
92020+#endif
92021
92022 /*
92023 * Show a '%p' thing. A kernel extension is that the '%p' is followed
92024@@ -1192,6 +1199,7 @@ int kptr_restrict __read_mostly;
92025 * - 'f' For simple symbolic function names without offset
92026 * - 'S' For symbolic direct pointers with offset
92027 * - 's' For symbolic direct pointers without offset
92028+ * - 'A' For symbolic direct pointers with offset approved for use with GRKERNSEC_HIDESYM
92029 * - '[FfSs]R' as above with __builtin_extract_return_addr() translation
92030 * - 'B' For backtraced symbolic direct pointers with offset
92031 * - 'R' For decoded struct resource, e.g., [mem 0x0-0x1f 64bit pref]
92032@@ -1259,12 +1267,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
92033
92034 if (!ptr && *fmt != 'K') {
92035 /*
92036- * Print (null) with the same width as a pointer so it makes
92037+ * Print (nil) with the same width as a pointer so it makes
92038 * tabular output look nice.
92039 */
92040 if (spec.field_width == -1)
92041 spec.field_width = default_width;
92042- return string(buf, end, "(null)", spec);
92043+ return string(buf, end, "(nil)", spec);
92044 }
92045
92046 switch (*fmt) {
92047@@ -1274,6 +1282,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
92048 /* Fallthrough */
92049 case 'S':
92050 case 's':
92051+#ifdef CONFIG_GRKERNSEC_HIDESYM
92052+ break;
92053+#else
92054+ return symbol_string(buf, end, ptr, spec, fmt);
92055+#endif
92056+ case 'A':
92057 case 'B':
92058 return symbol_string(buf, end, ptr, spec, fmt);
92059 case 'R':
92060@@ -1329,6 +1343,8 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
92061 va_end(va);
92062 return buf;
92063 }
92064+ case 'P':
92065+ break;
92066 case 'K':
92067 /*
92068 * %pK cannot be used in IRQ context because its test
92069@@ -1386,6 +1402,21 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
92070 ((const struct file *)ptr)->f_path.dentry,
92071 spec, fmt);
92072 }
92073+
92074+#ifdef CONFIG_GRKERNSEC_HIDESYM
92075+ /* 'P' = approved pointers to copy to userland,
92076+ as in the /proc/kallsyms case, as we make it display nothing
92077+ for non-root users, and the real contents for root users
92078+ Also ignore 'K' pointers, since we force their NULLing for non-root users
92079+ above
92080+ */
92081+ if ((unsigned long)ptr > TASK_SIZE && *fmt != 'P' && *fmt != 'K' && is_usercopy_object(buf)) {
92082+ printk(KERN_ALERT "grsec: kernel infoleak detected! Please report this log to spender@grsecurity.net.\n");
92083+ dump_stack();
92084+ ptr = NULL;
92085+ }
92086+#endif
92087+
92088 spec.flags |= SMALL;
92089 if (spec.field_width == -1) {
92090 spec.field_width = default_width;
92091@@ -2107,11 +2138,11 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
92092 typeof(type) value; \
92093 if (sizeof(type) == 8) { \
92094 args = PTR_ALIGN(args, sizeof(u32)); \
92095- *(u32 *)&value = *(u32 *)args; \
92096- *((u32 *)&value + 1) = *(u32 *)(args + 4); \
92097+ *(u32 *)&value = *(const u32 *)args; \
92098+ *((u32 *)&value + 1) = *(const u32 *)(args + 4); \
92099 } else { \
92100 args = PTR_ALIGN(args, sizeof(type)); \
92101- value = *(typeof(type) *)args; \
92102+ value = *(const typeof(type) *)args; \
92103 } \
92104 args += sizeof(type); \
92105 value; \
92106@@ -2174,7 +2205,7 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
92107 case FORMAT_TYPE_STR: {
92108 const char *str_arg = args;
92109 args += strlen(str_arg) + 1;
92110- str = string(str, end, (char *)str_arg, spec);
92111+ str = string(str, end, str_arg, spec);
92112 break;
92113 }
92114
92115diff --git a/localversion-grsec b/localversion-grsec
92116new file mode 100644
92117index 0000000..7cd6065
92118--- /dev/null
92119+++ b/localversion-grsec
92120@@ -0,0 +1 @@
92121+-grsec
92122diff --git a/mm/Kconfig b/mm/Kconfig
92123index 2888024..c15a810 100644
92124--- a/mm/Kconfig
92125+++ b/mm/Kconfig
92126@@ -326,10 +326,11 @@ config KSM
92127 root has set /sys/kernel/mm/ksm/run to 1 (if CONFIG_SYSFS is set).
92128
92129 config DEFAULT_MMAP_MIN_ADDR
92130- int "Low address space to protect from user allocation"
92131+ int "Low address space to protect from user allocation"
92132 depends on MMU
92133- default 4096
92134- help
92135+ default 32768 if ALPHA || ARM || PARISC || SPARC32
92136+ default 65536
92137+ help
92138 This is the portion of low virtual memory which should be protected
92139 from userspace allocation. Keeping a user from writing to low pages
92140 can help reduce the impact of kernel NULL pointer bugs.
92141@@ -360,7 +361,7 @@ config MEMORY_FAILURE
92142
92143 config HWPOISON_INJECT
92144 tristate "HWPoison pages injector"
92145- depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS
92146+ depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS && !GRKERNSEC
92147 select PROC_PAGE_MONITOR
92148
92149 config NOMMU_INITIAL_TRIM_EXCESS
92150diff --git a/mm/backing-dev.c b/mm/backing-dev.c
92151index 09d9591..165bb75 100644
92152--- a/mm/backing-dev.c
92153+++ b/mm/backing-dev.c
92154@@ -12,7 +12,7 @@
92155 #include <linux/device.h>
92156 #include <trace/events/writeback.h>
92157
92158-static atomic_long_t bdi_seq = ATOMIC_LONG_INIT(0);
92159+static atomic_long_unchecked_t bdi_seq = ATOMIC_LONG_INIT(0);
92160
92161 struct backing_dev_info default_backing_dev_info = {
92162 .name = "default",
92163@@ -533,7 +533,7 @@ int bdi_setup_and_register(struct backing_dev_info *bdi, char *name,
92164 return err;
92165
92166 err = bdi_register(bdi, NULL, "%.28s-%ld", name,
92167- atomic_long_inc_return(&bdi_seq));
92168+ atomic_long_inc_return_unchecked(&bdi_seq));
92169 if (err) {
92170 bdi_destroy(bdi);
92171 return err;
92172diff --git a/mm/filemap.c b/mm/filemap.c
92173index 7a13f6a..e52e841 100644
92174--- a/mm/filemap.c
92175+++ b/mm/filemap.c
92176@@ -1766,7 +1766,7 @@ int generic_file_mmap(struct file * file, struct vm_area_struct * vma)
92177 struct address_space *mapping = file->f_mapping;
92178
92179 if (!mapping->a_ops->readpage)
92180- return -ENOEXEC;
92181+ return -ENODEV;
92182 file_accessed(file);
92183 vma->vm_ops = &generic_file_vm_ops;
92184 return 0;
92185@@ -1948,7 +1948,7 @@ static size_t __iovec_copy_from_user_inatomic(char *vaddr,
92186
92187 while (bytes) {
92188 char __user *buf = iov->iov_base + base;
92189- int copy = min(bytes, iov->iov_len - base);
92190+ size_t copy = min(bytes, iov->iov_len - base);
92191
92192 base = 0;
92193 left = __copy_from_user_inatomic(vaddr, buf, copy);
92194@@ -1977,7 +1977,7 @@ size_t iov_iter_copy_from_user_atomic(struct page *page,
92195 BUG_ON(!in_atomic());
92196 kaddr = kmap_atomic(page);
92197 if (likely(i->nr_segs == 1)) {
92198- int left;
92199+ size_t left;
92200 char __user *buf = i->iov->iov_base + i->iov_offset;
92201 left = __copy_from_user_inatomic(kaddr + offset, buf, bytes);
92202 copied = bytes - left;
92203@@ -2005,7 +2005,7 @@ size_t iov_iter_copy_from_user(struct page *page,
92204
92205 kaddr = kmap(page);
92206 if (likely(i->nr_segs == 1)) {
92207- int left;
92208+ size_t left;
92209 char __user *buf = i->iov->iov_base + i->iov_offset;
92210 left = __copy_from_user(kaddr + offset, buf, bytes);
92211 copied = bytes - left;
92212@@ -2035,7 +2035,7 @@ void iov_iter_advance(struct iov_iter *i, size_t bytes)
92213 * zero-length segments (without overruning the iovec).
92214 */
92215 while (bytes || unlikely(i->count && !iov->iov_len)) {
92216- int copy;
92217+ size_t copy;
92218
92219 copy = min(bytes, iov->iov_len - base);
92220 BUG_ON(!i->count || i->count < copy);
92221@@ -2106,6 +2106,7 @@ inline int generic_write_checks(struct file *file, loff_t *pos, size_t *count, i
92222 *pos = i_size_read(inode);
92223
92224 if (limit != RLIM_INFINITY) {
92225+ gr_learn_resource(current, RLIMIT_FSIZE,*pos, 0);
92226 if (*pos >= limit) {
92227 send_sig(SIGXFSZ, current, 0);
92228 return -EFBIG;
92229diff --git a/mm/fremap.c b/mm/fremap.c
92230index 34feba6..315fe78 100644
92231--- a/mm/fremap.c
92232+++ b/mm/fremap.c
92233@@ -179,6 +179,11 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
92234 retry:
92235 vma = find_vma(mm, start);
92236
92237+#ifdef CONFIG_PAX_SEGMEXEC
92238+ if (vma && (mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_MAYEXEC))
92239+ goto out;
92240+#endif
92241+
92242 /*
92243 * Make sure the vma is shared, that it supports prefaulting,
92244 * and that the remapped range is valid and fully within
92245diff --git a/mm/highmem.c b/mm/highmem.c
92246index b32b70c..e512eb0 100644
92247--- a/mm/highmem.c
92248+++ b/mm/highmem.c
92249@@ -138,8 +138,9 @@ static void flush_all_zero_pkmaps(void)
92250 * So no dangers, even with speculative execution.
92251 */
92252 page = pte_page(pkmap_page_table[i]);
92253+ pax_open_kernel();
92254 pte_clear(&init_mm, PKMAP_ADDR(i), &pkmap_page_table[i]);
92255-
92256+ pax_close_kernel();
92257 set_page_address(page, NULL);
92258 need_flush = 1;
92259 }
92260@@ -198,9 +199,11 @@ start:
92261 }
92262 }
92263 vaddr = PKMAP_ADDR(last_pkmap_nr);
92264+
92265+ pax_open_kernel();
92266 set_pte_at(&init_mm, vaddr,
92267 &(pkmap_page_table[last_pkmap_nr]), mk_pte(page, kmap_prot));
92268-
92269+ pax_close_kernel();
92270 pkmap_count[last_pkmap_nr] = 1;
92271 set_page_address(page, (void *)vaddr);
92272
92273diff --git a/mm/hugetlb.c b/mm/hugetlb.c
92274index 2de3c84..4ecaf1b 100644
92275--- a/mm/hugetlb.c
92276+++ b/mm/hugetlb.c
92277@@ -2069,15 +2069,17 @@ static int hugetlb_sysctl_handler_common(bool obey_mempolicy,
92278 struct hstate *h = &default_hstate;
92279 unsigned long tmp;
92280 int ret;
92281+ ctl_table_no_const hugetlb_table;
92282
92283 tmp = h->max_huge_pages;
92284
92285 if (write && h->order >= MAX_ORDER)
92286 return -EINVAL;
92287
92288- table->data = &tmp;
92289- table->maxlen = sizeof(unsigned long);
92290- ret = proc_doulongvec_minmax(table, write, buffer, length, ppos);
92291+ hugetlb_table = *table;
92292+ hugetlb_table.data = &tmp;
92293+ hugetlb_table.maxlen = sizeof(unsigned long);
92294+ ret = proc_doulongvec_minmax(&hugetlb_table, write, buffer, length, ppos);
92295 if (ret)
92296 goto out;
92297
92298@@ -2122,15 +2124,17 @@ int hugetlb_overcommit_handler(struct ctl_table *table, int write,
92299 struct hstate *h = &default_hstate;
92300 unsigned long tmp;
92301 int ret;
92302+ ctl_table_no_const hugetlb_table;
92303
92304 tmp = h->nr_overcommit_huge_pages;
92305
92306 if (write && h->order >= MAX_ORDER)
92307 return -EINVAL;
92308
92309- table->data = &tmp;
92310- table->maxlen = sizeof(unsigned long);
92311- ret = proc_doulongvec_minmax(table, write, buffer, length, ppos);
92312+ hugetlb_table = *table;
92313+ hugetlb_table.data = &tmp;
92314+ hugetlb_table.maxlen = sizeof(unsigned long);
92315+ ret = proc_doulongvec_minmax(&hugetlb_table, write, buffer, length, ppos);
92316 if (ret)
92317 goto out;
92318
92319@@ -2599,6 +2603,27 @@ static int unmap_ref_private(struct mm_struct *mm, struct vm_area_struct *vma,
92320 return 1;
92321 }
92322
92323+#ifdef CONFIG_PAX_SEGMEXEC
92324+static void pax_mirror_huge_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m)
92325+{
92326+ struct mm_struct *mm = vma->vm_mm;
92327+ struct vm_area_struct *vma_m;
92328+ unsigned long address_m;
92329+ pte_t *ptep_m;
92330+
92331+ vma_m = pax_find_mirror_vma(vma);
92332+ if (!vma_m)
92333+ return;
92334+
92335+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
92336+ address_m = address + SEGMEXEC_TASK_SIZE;
92337+ ptep_m = huge_pte_offset(mm, address_m & HPAGE_MASK);
92338+ get_page(page_m);
92339+ hugepage_add_anon_rmap(page_m, vma_m, address_m);
92340+ set_huge_pte_at(mm, address_m, ptep_m, make_huge_pte(vma_m, page_m, 0));
92341+}
92342+#endif
92343+
92344 /*
92345 * Hugetlb_cow() should be called with page lock of the original hugepage held.
92346 * Called with hugetlb_instantiation_mutex held and pte_page locked so we
92347@@ -2715,6 +2740,11 @@ retry_avoidcopy:
92348 make_huge_pte(vma, new_page, 1));
92349 page_remove_rmap(old_page);
92350 hugepage_add_new_anon_rmap(new_page, vma, address);
92351+
92352+#ifdef CONFIG_PAX_SEGMEXEC
92353+ pax_mirror_huge_pte(vma, address, new_page);
92354+#endif
92355+
92356 /* Make the old page be freed below */
92357 new_page = old_page;
92358 }
92359@@ -2879,6 +2909,10 @@ retry:
92360 && (vma->vm_flags & VM_SHARED)));
92361 set_huge_pte_at(mm, address, ptep, new_pte);
92362
92363+#ifdef CONFIG_PAX_SEGMEXEC
92364+ pax_mirror_huge_pte(vma, address, page);
92365+#endif
92366+
92367 if ((flags & FAULT_FLAG_WRITE) && !(vma->vm_flags & VM_SHARED)) {
92368 /* Optimization, do the COW without a second fault */
92369 ret = hugetlb_cow(mm, vma, address, ptep, new_pte, page, ptl);
92370@@ -2909,6 +2943,10 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
92371 static DEFINE_MUTEX(hugetlb_instantiation_mutex);
92372 struct hstate *h = hstate_vma(vma);
92373
92374+#ifdef CONFIG_PAX_SEGMEXEC
92375+ struct vm_area_struct *vma_m;
92376+#endif
92377+
92378 address &= huge_page_mask(h);
92379
92380 ptep = huge_pte_offset(mm, address);
92381@@ -2922,6 +2960,26 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
92382 VM_FAULT_SET_HINDEX(hstate_index(h));
92383 }
92384
92385+#ifdef CONFIG_PAX_SEGMEXEC
92386+ vma_m = pax_find_mirror_vma(vma);
92387+ if (vma_m) {
92388+ unsigned long address_m;
92389+
92390+ if (vma->vm_start > vma_m->vm_start) {
92391+ address_m = address;
92392+ address -= SEGMEXEC_TASK_SIZE;
92393+ vma = vma_m;
92394+ h = hstate_vma(vma);
92395+ } else
92396+ address_m = address + SEGMEXEC_TASK_SIZE;
92397+
92398+ if (!huge_pte_alloc(mm, address_m, huge_page_size(h)))
92399+ return VM_FAULT_OOM;
92400+ address_m &= HPAGE_MASK;
92401+ unmap_hugepage_range(vma, address_m, address_m + HPAGE_SIZE, NULL);
92402+ }
92403+#endif
92404+
92405 ptep = huge_pte_alloc(mm, address, huge_page_size(h));
92406 if (!ptep)
92407 return VM_FAULT_OOM;
92408diff --git a/mm/internal.h b/mm/internal.h
92409index 3e91000..4741a60 100644
92410--- a/mm/internal.h
92411+++ b/mm/internal.h
92412@@ -94,6 +94,7 @@ extern pmd_t *mm_find_pmd(struct mm_struct *mm, unsigned long address);
92413 * in mm/page_alloc.c
92414 */
92415 extern void __free_pages_bootmem(struct page *page, unsigned int order);
92416+extern void free_compound_page(struct page *page);
92417 extern void prep_compound_page(struct page *page, unsigned long order);
92418 #ifdef CONFIG_MEMORY_FAILURE
92419 extern bool is_free_buddy_page(struct page *page);
92420@@ -352,7 +353,7 @@ extern u32 hwpoison_filter_enable;
92421
92422 extern unsigned long vm_mmap_pgoff(struct file *, unsigned long,
92423 unsigned long, unsigned long,
92424- unsigned long, unsigned long);
92425+ unsigned long, unsigned long) __intentional_overflow(-1);
92426
92427 extern void set_pageblock_order(void);
92428 unsigned long reclaim_clean_pages_from_list(struct zone *zone,
92429diff --git a/mm/kmemleak.c b/mm/kmemleak.c
92430index 31f01c5..7015178 100644
92431--- a/mm/kmemleak.c
92432+++ b/mm/kmemleak.c
92433@@ -363,7 +363,7 @@ static void print_unreferenced(struct seq_file *seq,
92434
92435 for (i = 0; i < object->trace_len; i++) {
92436 void *ptr = (void *)object->trace[i];
92437- seq_printf(seq, " [<%p>] %pS\n", ptr, ptr);
92438+ seq_printf(seq, " [<%pP>] %pA\n", ptr, ptr);
92439 }
92440 }
92441
92442@@ -1853,7 +1853,7 @@ static int __init kmemleak_late_init(void)
92443 return -ENOMEM;
92444 }
92445
92446- dentry = debugfs_create_file("kmemleak", S_IRUGO, NULL, NULL,
92447+ dentry = debugfs_create_file("kmemleak", S_IRUSR, NULL, NULL,
92448 &kmemleak_fops);
92449 if (!dentry)
92450 pr_warning("Failed to create the debugfs kmemleak file\n");
92451diff --git a/mm/maccess.c b/mm/maccess.c
92452index d53adf9..03a24bf 100644
92453--- a/mm/maccess.c
92454+++ b/mm/maccess.c
92455@@ -26,7 +26,7 @@ long __probe_kernel_read(void *dst, const void *src, size_t size)
92456 set_fs(KERNEL_DS);
92457 pagefault_disable();
92458 ret = __copy_from_user_inatomic(dst,
92459- (__force const void __user *)src, size);
92460+ (const void __force_user *)src, size);
92461 pagefault_enable();
92462 set_fs(old_fs);
92463
92464@@ -53,7 +53,7 @@ long __probe_kernel_write(void *dst, const void *src, size_t size)
92465
92466 set_fs(KERNEL_DS);
92467 pagefault_disable();
92468- ret = __copy_to_user_inatomic((__force void __user *)dst, src, size);
92469+ ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
92470 pagefault_enable();
92471 set_fs(old_fs);
92472
92473diff --git a/mm/madvise.c b/mm/madvise.c
92474index 539eeb9..e24a987 100644
92475--- a/mm/madvise.c
92476+++ b/mm/madvise.c
92477@@ -51,6 +51,10 @@ static long madvise_behavior(struct vm_area_struct *vma,
92478 pgoff_t pgoff;
92479 unsigned long new_flags = vma->vm_flags;
92480
92481+#ifdef CONFIG_PAX_SEGMEXEC
92482+ struct vm_area_struct *vma_m;
92483+#endif
92484+
92485 switch (behavior) {
92486 case MADV_NORMAL:
92487 new_flags = new_flags & ~VM_RAND_READ & ~VM_SEQ_READ;
92488@@ -126,6 +130,13 @@ success:
92489 /*
92490 * vm_flags is protected by the mmap_sem held in write mode.
92491 */
92492+
92493+#ifdef CONFIG_PAX_SEGMEXEC
92494+ vma_m = pax_find_mirror_vma(vma);
92495+ if (vma_m)
92496+ vma_m->vm_flags = new_flags & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT);
92497+#endif
92498+
92499 vma->vm_flags = new_flags;
92500
92501 out:
92502@@ -274,6 +285,11 @@ static long madvise_dontneed(struct vm_area_struct *vma,
92503 struct vm_area_struct **prev,
92504 unsigned long start, unsigned long end)
92505 {
92506+
92507+#ifdef CONFIG_PAX_SEGMEXEC
92508+ struct vm_area_struct *vma_m;
92509+#endif
92510+
92511 *prev = vma;
92512 if (vma->vm_flags & (VM_LOCKED|VM_HUGETLB|VM_PFNMAP))
92513 return -EINVAL;
92514@@ -286,6 +302,21 @@ static long madvise_dontneed(struct vm_area_struct *vma,
92515 zap_page_range(vma, start, end - start, &details);
92516 } else
92517 zap_page_range(vma, start, end - start, NULL);
92518+
92519+#ifdef CONFIG_PAX_SEGMEXEC
92520+ vma_m = pax_find_mirror_vma(vma);
92521+ if (vma_m) {
92522+ if (unlikely(vma->vm_flags & VM_NONLINEAR)) {
92523+ struct zap_details details = {
92524+ .nonlinear_vma = vma_m,
92525+ .last_index = ULONG_MAX,
92526+ };
92527+ zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, &details);
92528+ } else
92529+ zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, NULL);
92530+ }
92531+#endif
92532+
92533 return 0;
92534 }
92535
92536@@ -491,6 +522,16 @@ SYSCALL_DEFINE3(madvise, unsigned long, start, size_t, len_in, int, behavior)
92537 if (end < start)
92538 return error;
92539
92540+#ifdef CONFIG_PAX_SEGMEXEC
92541+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
92542+ if (end > SEGMEXEC_TASK_SIZE)
92543+ return error;
92544+ } else
92545+#endif
92546+
92547+ if (end > TASK_SIZE)
92548+ return error;
92549+
92550 error = 0;
92551 if (end == start)
92552 return error;
92553diff --git a/mm/memory-failure.c b/mm/memory-failure.c
92554index 90002ea..db1452d 100644
92555--- a/mm/memory-failure.c
92556+++ b/mm/memory-failure.c
92557@@ -61,7 +61,7 @@ int sysctl_memory_failure_early_kill __read_mostly = 0;
92558
92559 int sysctl_memory_failure_recovery __read_mostly = 1;
92560
92561-atomic_long_t num_poisoned_pages __read_mostly = ATOMIC_LONG_INIT(0);
92562+atomic_long_unchecked_t num_poisoned_pages __read_mostly = ATOMIC_LONG_INIT(0);
92563
92564 #if defined(CONFIG_HWPOISON_INJECT) || defined(CONFIG_HWPOISON_INJECT_MODULE)
92565
92566@@ -202,7 +202,7 @@ static int kill_proc(struct task_struct *t, unsigned long addr, int trapno,
92567 pfn, t->comm, t->pid);
92568 si.si_signo = SIGBUS;
92569 si.si_errno = 0;
92570- si.si_addr = (void *)addr;
92571+ si.si_addr = (void __user *)addr;
92572 #ifdef __ARCH_SI_TRAPNO
92573 si.si_trapno = trapno;
92574 #endif
92575@@ -762,7 +762,7 @@ static struct page_state {
92576 unsigned long res;
92577 char *msg;
92578 int (*action)(struct page *p, unsigned long pfn);
92579-} error_states[] = {
92580+} __do_const error_states[] = {
92581 { reserved, reserved, "reserved kernel", me_kernel },
92582 /*
92583 * free pages are specially detected outside this table:
92584@@ -1062,7 +1062,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
92585 nr_pages = 1 << compound_order(hpage);
92586 else /* normal page or thp */
92587 nr_pages = 1;
92588- atomic_long_add(nr_pages, &num_poisoned_pages);
92589+ atomic_long_add_unchecked(nr_pages, &num_poisoned_pages);
92590
92591 /*
92592 * We need/can do nothing about count=0 pages.
92593@@ -1092,7 +1092,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
92594 if (!PageHWPoison(hpage)
92595 || (hwpoison_filter(p) && TestClearPageHWPoison(p))
92596 || (p != hpage && TestSetPageHWPoison(hpage))) {
92597- atomic_long_sub(nr_pages, &num_poisoned_pages);
92598+ atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
92599 return 0;
92600 }
92601 set_page_hwpoison_huge_page(hpage);
92602@@ -1161,7 +1161,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
92603 }
92604 if (hwpoison_filter(p)) {
92605 if (TestClearPageHWPoison(p))
92606- atomic_long_sub(nr_pages, &num_poisoned_pages);
92607+ atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
92608 unlock_page(hpage);
92609 put_page(hpage);
92610 return 0;
92611@@ -1383,7 +1383,7 @@ int unpoison_memory(unsigned long pfn)
92612 return 0;
92613 }
92614 if (TestClearPageHWPoison(p))
92615- atomic_long_dec(&num_poisoned_pages);
92616+ atomic_long_dec_unchecked(&num_poisoned_pages);
92617 pr_info("MCE: Software-unpoisoned free page %#lx\n", pfn);
92618 return 0;
92619 }
92620@@ -1397,7 +1397,7 @@ int unpoison_memory(unsigned long pfn)
92621 */
92622 if (TestClearPageHWPoison(page)) {
92623 pr_info("MCE: Software-unpoisoned page %#lx\n", pfn);
92624- atomic_long_sub(nr_pages, &num_poisoned_pages);
92625+ atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
92626 freeit = 1;
92627 if (PageHuge(page))
92628 clear_page_hwpoison_huge_page(page);
92629@@ -1522,11 +1522,11 @@ static int soft_offline_huge_page(struct page *page, int flags)
92630 if (PageHuge(page)) {
92631 set_page_hwpoison_huge_page(hpage);
92632 dequeue_hwpoisoned_huge_page(hpage);
92633- atomic_long_add(1 << compound_order(hpage),
92634+ atomic_long_add_unchecked(1 << compound_order(hpage),
92635 &num_poisoned_pages);
92636 } else {
92637 SetPageHWPoison(page);
92638- atomic_long_inc(&num_poisoned_pages);
92639+ atomic_long_inc_unchecked(&num_poisoned_pages);
92640 }
92641 }
92642 return ret;
92643@@ -1565,7 +1565,7 @@ static int __soft_offline_page(struct page *page, int flags)
92644 put_page(page);
92645 pr_info("soft_offline: %#lx: invalidated\n", pfn);
92646 SetPageHWPoison(page);
92647- atomic_long_inc(&num_poisoned_pages);
92648+ atomic_long_inc_unchecked(&num_poisoned_pages);
92649 return 0;
92650 }
92651
92652@@ -1616,7 +1616,7 @@ static int __soft_offline_page(struct page *page, int flags)
92653 if (!is_free_buddy_page(page))
92654 pr_info("soft offline: %#lx: page leaked\n",
92655 pfn);
92656- atomic_long_inc(&num_poisoned_pages);
92657+ atomic_long_inc_unchecked(&num_poisoned_pages);
92658 }
92659 } else {
92660 pr_info("soft offline: %#lx: isolation failed: %d, page count %d, type %lx\n",
92661@@ -1690,11 +1690,11 @@ int soft_offline_page(struct page *page, int flags)
92662 if (PageHuge(page)) {
92663 set_page_hwpoison_huge_page(hpage);
92664 dequeue_hwpoisoned_huge_page(hpage);
92665- atomic_long_add(1 << compound_order(hpage),
92666+ atomic_long_add_unchecked(1 << compound_order(hpage),
92667 &num_poisoned_pages);
92668 } else {
92669 SetPageHWPoison(page);
92670- atomic_long_inc(&num_poisoned_pages);
92671+ atomic_long_inc_unchecked(&num_poisoned_pages);
92672 }
92673 }
92674 unset_migratetype_isolate(page, MIGRATE_MOVABLE);
92675diff --git a/mm/memory.c b/mm/memory.c
92676index 22dfa61..90d7ec5 100644
92677--- a/mm/memory.c
92678+++ b/mm/memory.c
92679@@ -403,6 +403,7 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
92680 free_pte_range(tlb, pmd, addr);
92681 } while (pmd++, addr = next, addr != end);
92682
92683+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_PER_CPU_PGD)
92684 start &= PUD_MASK;
92685 if (start < floor)
92686 return;
92687@@ -417,6 +418,8 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
92688 pmd = pmd_offset(pud, start);
92689 pud_clear(pud);
92690 pmd_free_tlb(tlb, pmd, start);
92691+#endif
92692+
92693 }
92694
92695 static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
92696@@ -436,6 +439,7 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
92697 free_pmd_range(tlb, pud, addr, next, floor, ceiling);
92698 } while (pud++, addr = next, addr != end);
92699
92700+#if !defined(CONFIG_X86_64) || !defined(CONFIG_PAX_PER_CPU_PGD)
92701 start &= PGDIR_MASK;
92702 if (start < floor)
92703 return;
92704@@ -450,6 +454,8 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
92705 pud = pud_offset(pgd, start);
92706 pgd_clear(pgd);
92707 pud_free_tlb(tlb, pud, start);
92708+#endif
92709+
92710 }
92711
92712 /*
92713@@ -1636,12 +1642,6 @@ no_page_table:
92714 return page;
92715 }
92716
92717-static inline int stack_guard_page(struct vm_area_struct *vma, unsigned long addr)
92718-{
92719- return stack_guard_page_start(vma, addr) ||
92720- stack_guard_page_end(vma, addr+PAGE_SIZE);
92721-}
92722-
92723 /**
92724 * __get_user_pages() - pin user pages in memory
92725 * @tsk: task_struct of target task
92726@@ -1728,10 +1728,10 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
92727
92728 i = 0;
92729
92730- do {
92731+ while (nr_pages) {
92732 struct vm_area_struct *vma;
92733
92734- vma = find_extend_vma(mm, start);
92735+ vma = find_vma(mm, start);
92736 if (!vma && in_gate_area(mm, start)) {
92737 unsigned long pg = start & PAGE_MASK;
92738 pgd_t *pgd;
92739@@ -1780,7 +1780,7 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
92740 goto next_page;
92741 }
92742
92743- if (!vma ||
92744+ if (!vma || start < vma->vm_start ||
92745 (vma->vm_flags & (VM_IO | VM_PFNMAP)) ||
92746 !(vm_flags & vma->vm_flags))
92747 return i ? : -EFAULT;
92748@@ -1809,11 +1809,6 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
92749 int ret;
92750 unsigned int fault_flags = 0;
92751
92752- /* For mlock, just skip the stack guard page. */
92753- if (foll_flags & FOLL_MLOCK) {
92754- if (stack_guard_page(vma, start))
92755- goto next_page;
92756- }
92757 if (foll_flags & FOLL_WRITE)
92758 fault_flags |= FAULT_FLAG_WRITE;
92759 if (nonblocking)
92760@@ -1893,7 +1888,7 @@ next_page:
92761 start += page_increm * PAGE_SIZE;
92762 nr_pages -= page_increm;
92763 } while (nr_pages && start < vma->vm_end);
92764- } while (nr_pages);
92765+ }
92766 return i;
92767 }
92768 EXPORT_SYMBOL(__get_user_pages);
92769@@ -1929,12 +1924,17 @@ int fixup_user_fault(struct task_struct *tsk, struct mm_struct *mm,
92770 unsigned long address, unsigned int fault_flags)
92771 {
92772 struct vm_area_struct *vma;
92773+ vm_flags_t vm_flags;
92774 int ret;
92775
92776 vma = find_extend_vma(mm, address);
92777 if (!vma || address < vma->vm_start)
92778 return -EFAULT;
92779
92780+ vm_flags = (fault_flags & FAULT_FLAG_WRITE) ? VM_WRITE : VM_READ;
92781+ if (!(vm_flags & vma->vm_flags))
92782+ return -EFAULT;
92783+
92784 ret = handle_mm_fault(mm, vma, address, fault_flags);
92785 if (ret & VM_FAULT_ERROR) {
92786 if (ret & VM_FAULT_OOM)
92787@@ -2100,6 +2100,10 @@ static int insert_page(struct vm_area_struct *vma, unsigned long addr,
92788 page_add_file_rmap(page);
92789 set_pte_at(mm, addr, pte, mk_pte(page, prot));
92790
92791+#ifdef CONFIG_PAX_SEGMEXEC
92792+ pax_mirror_file_pte(vma, addr, page, ptl);
92793+#endif
92794+
92795 retval = 0;
92796 pte_unmap_unlock(pte, ptl);
92797 return retval;
92798@@ -2144,9 +2148,21 @@ int vm_insert_page(struct vm_area_struct *vma, unsigned long addr,
92799 if (!page_count(page))
92800 return -EINVAL;
92801 if (!(vma->vm_flags & VM_MIXEDMAP)) {
92802+
92803+#ifdef CONFIG_PAX_SEGMEXEC
92804+ struct vm_area_struct *vma_m;
92805+#endif
92806+
92807 BUG_ON(down_read_trylock(&vma->vm_mm->mmap_sem));
92808 BUG_ON(vma->vm_flags & VM_PFNMAP);
92809 vma->vm_flags |= VM_MIXEDMAP;
92810+
92811+#ifdef CONFIG_PAX_SEGMEXEC
92812+ vma_m = pax_find_mirror_vma(vma);
92813+ if (vma_m)
92814+ vma_m->vm_flags |= VM_MIXEDMAP;
92815+#endif
92816+
92817 }
92818 return insert_page(vma, addr, page, vma->vm_page_prot);
92819 }
92820@@ -2229,6 +2245,7 @@ int vm_insert_mixed(struct vm_area_struct *vma, unsigned long addr,
92821 unsigned long pfn)
92822 {
92823 BUG_ON(!(vma->vm_flags & VM_MIXEDMAP));
92824+ BUG_ON(vma->vm_mirror);
92825
92826 if (addr < vma->vm_start || addr >= vma->vm_end)
92827 return -EFAULT;
92828@@ -2476,7 +2493,9 @@ static int apply_to_pmd_range(struct mm_struct *mm, pud_t *pud,
92829
92830 BUG_ON(pud_huge(*pud));
92831
92832- pmd = pmd_alloc(mm, pud, addr);
92833+ pmd = (mm == &init_mm) ?
92834+ pmd_alloc_kernel(mm, pud, addr) :
92835+ pmd_alloc(mm, pud, addr);
92836 if (!pmd)
92837 return -ENOMEM;
92838 do {
92839@@ -2496,7 +2515,9 @@ static int apply_to_pud_range(struct mm_struct *mm, pgd_t *pgd,
92840 unsigned long next;
92841 int err;
92842
92843- pud = pud_alloc(mm, pgd, addr);
92844+ pud = (mm == &init_mm) ?
92845+ pud_alloc_kernel(mm, pgd, addr) :
92846+ pud_alloc(mm, pgd, addr);
92847 if (!pud)
92848 return -ENOMEM;
92849 do {
92850@@ -2586,6 +2607,186 @@ static inline void cow_user_page(struct page *dst, struct page *src, unsigned lo
92851 copy_user_highpage(dst, src, va, vma);
92852 }
92853
92854+#ifdef CONFIG_PAX_SEGMEXEC
92855+static void pax_unmap_mirror_pte(struct vm_area_struct *vma, unsigned long address, pmd_t *pmd)
92856+{
92857+ struct mm_struct *mm = vma->vm_mm;
92858+ spinlock_t *ptl;
92859+ pte_t *pte, entry;
92860+
92861+ pte = pte_offset_map_lock(mm, pmd, address, &ptl);
92862+ entry = *pte;
92863+ if (!pte_present(entry)) {
92864+ if (!pte_none(entry)) {
92865+ BUG_ON(pte_file(entry));
92866+ free_swap_and_cache(pte_to_swp_entry(entry));
92867+ pte_clear_not_present_full(mm, address, pte, 0);
92868+ }
92869+ } else {
92870+ struct page *page;
92871+
92872+ flush_cache_page(vma, address, pte_pfn(entry));
92873+ entry = ptep_clear_flush(vma, address, pte);
92874+ BUG_ON(pte_dirty(entry));
92875+ page = vm_normal_page(vma, address, entry);
92876+ if (page) {
92877+ update_hiwater_rss(mm);
92878+ if (PageAnon(page))
92879+ dec_mm_counter_fast(mm, MM_ANONPAGES);
92880+ else
92881+ dec_mm_counter_fast(mm, MM_FILEPAGES);
92882+ page_remove_rmap(page);
92883+ page_cache_release(page);
92884+ }
92885+ }
92886+ pte_unmap_unlock(pte, ptl);
92887+}
92888+
92889+/* PaX: if vma is mirrored, synchronize the mirror's PTE
92890+ *
92891+ * the ptl of the lower mapped page is held on entry and is not released on exit
92892+ * or inside to ensure atomic changes to the PTE states (swapout, mremap, munmap, etc)
92893+ */
92894+static void pax_mirror_anon_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
92895+{
92896+ struct mm_struct *mm = vma->vm_mm;
92897+ unsigned long address_m;
92898+ spinlock_t *ptl_m;
92899+ struct vm_area_struct *vma_m;
92900+ pmd_t *pmd_m;
92901+ pte_t *pte_m, entry_m;
92902+
92903+ BUG_ON(!page_m || !PageAnon(page_m));
92904+
92905+ vma_m = pax_find_mirror_vma(vma);
92906+ if (!vma_m)
92907+ return;
92908+
92909+ BUG_ON(!PageLocked(page_m));
92910+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
92911+ address_m = address + SEGMEXEC_TASK_SIZE;
92912+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
92913+ pte_m = pte_offset_map(pmd_m, address_m);
92914+ ptl_m = pte_lockptr(mm, pmd_m);
92915+ if (ptl != ptl_m) {
92916+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
92917+ if (!pte_none(*pte_m))
92918+ goto out;
92919+ }
92920+
92921+ entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
92922+ page_cache_get(page_m);
92923+ page_add_anon_rmap(page_m, vma_m, address_m);
92924+ inc_mm_counter_fast(mm, MM_ANONPAGES);
92925+ set_pte_at(mm, address_m, pte_m, entry_m);
92926+ update_mmu_cache(vma_m, address_m, pte_m);
92927+out:
92928+ if (ptl != ptl_m)
92929+ spin_unlock(ptl_m);
92930+ pte_unmap(pte_m);
92931+ unlock_page(page_m);
92932+}
92933+
92934+void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
92935+{
92936+ struct mm_struct *mm = vma->vm_mm;
92937+ unsigned long address_m;
92938+ spinlock_t *ptl_m;
92939+ struct vm_area_struct *vma_m;
92940+ pmd_t *pmd_m;
92941+ pte_t *pte_m, entry_m;
92942+
92943+ BUG_ON(!page_m || PageAnon(page_m));
92944+
92945+ vma_m = pax_find_mirror_vma(vma);
92946+ if (!vma_m)
92947+ return;
92948+
92949+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
92950+ address_m = address + SEGMEXEC_TASK_SIZE;
92951+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
92952+ pte_m = pte_offset_map(pmd_m, address_m);
92953+ ptl_m = pte_lockptr(mm, pmd_m);
92954+ if (ptl != ptl_m) {
92955+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
92956+ if (!pte_none(*pte_m))
92957+ goto out;
92958+ }
92959+
92960+ entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
92961+ page_cache_get(page_m);
92962+ page_add_file_rmap(page_m);
92963+ inc_mm_counter_fast(mm, MM_FILEPAGES);
92964+ set_pte_at(mm, address_m, pte_m, entry_m);
92965+ update_mmu_cache(vma_m, address_m, pte_m);
92966+out:
92967+ if (ptl != ptl_m)
92968+ spin_unlock(ptl_m);
92969+ pte_unmap(pte_m);
92970+}
92971+
92972+static void pax_mirror_pfn_pte(struct vm_area_struct *vma, unsigned long address, unsigned long pfn_m, spinlock_t *ptl)
92973+{
92974+ struct mm_struct *mm = vma->vm_mm;
92975+ unsigned long address_m;
92976+ spinlock_t *ptl_m;
92977+ struct vm_area_struct *vma_m;
92978+ pmd_t *pmd_m;
92979+ pte_t *pte_m, entry_m;
92980+
92981+ vma_m = pax_find_mirror_vma(vma);
92982+ if (!vma_m)
92983+ return;
92984+
92985+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
92986+ address_m = address + SEGMEXEC_TASK_SIZE;
92987+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
92988+ pte_m = pte_offset_map(pmd_m, address_m);
92989+ ptl_m = pte_lockptr(mm, pmd_m);
92990+ if (ptl != ptl_m) {
92991+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
92992+ if (!pte_none(*pte_m))
92993+ goto out;
92994+ }
92995+
92996+ entry_m = pfn_pte(pfn_m, vma_m->vm_page_prot);
92997+ set_pte_at(mm, address_m, pte_m, entry_m);
92998+out:
92999+ if (ptl != ptl_m)
93000+ spin_unlock(ptl_m);
93001+ pte_unmap(pte_m);
93002+}
93003+
93004+static void pax_mirror_pte(struct vm_area_struct *vma, unsigned long address, pte_t *pte, pmd_t *pmd, spinlock_t *ptl)
93005+{
93006+ struct page *page_m;
93007+ pte_t entry;
93008+
93009+ if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC))
93010+ goto out;
93011+
93012+ entry = *pte;
93013+ page_m = vm_normal_page(vma, address, entry);
93014+ if (!page_m)
93015+ pax_mirror_pfn_pte(vma, address, pte_pfn(entry), ptl);
93016+ else if (PageAnon(page_m)) {
93017+ if (pax_find_mirror_vma(vma)) {
93018+ pte_unmap_unlock(pte, ptl);
93019+ lock_page(page_m);
93020+ pte = pte_offset_map_lock(vma->vm_mm, pmd, address, &ptl);
93021+ if (pte_same(entry, *pte))
93022+ pax_mirror_anon_pte(vma, address, page_m, ptl);
93023+ else
93024+ unlock_page(page_m);
93025+ }
93026+ } else
93027+ pax_mirror_file_pte(vma, address, page_m, ptl);
93028+
93029+out:
93030+ pte_unmap_unlock(pte, ptl);
93031+}
93032+#endif
93033+
93034 /*
93035 * This routine handles present pages, when users try to write
93036 * to a shared page. It is done by copying the page to a new address
93037@@ -2810,6 +3011,12 @@ gotten:
93038 */
93039 page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
93040 if (likely(pte_same(*page_table, orig_pte))) {
93041+
93042+#ifdef CONFIG_PAX_SEGMEXEC
93043+ if (pax_find_mirror_vma(vma))
93044+ BUG_ON(!trylock_page(new_page));
93045+#endif
93046+
93047 if (old_page) {
93048 if (!PageAnon(old_page)) {
93049 dec_mm_counter_fast(mm, MM_FILEPAGES);
93050@@ -2861,6 +3068,10 @@ gotten:
93051 page_remove_rmap(old_page);
93052 }
93053
93054+#ifdef CONFIG_PAX_SEGMEXEC
93055+ pax_mirror_anon_pte(vma, address, new_page, ptl);
93056+#endif
93057+
93058 /* Free the old page.. */
93059 new_page = old_page;
93060 ret |= VM_FAULT_WRITE;
93061@@ -3138,6 +3349,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
93062 swap_free(entry);
93063 if (vm_swap_full() || (vma->vm_flags & VM_LOCKED) || PageMlocked(page))
93064 try_to_free_swap(page);
93065+
93066+#ifdef CONFIG_PAX_SEGMEXEC
93067+ if ((flags & FAULT_FLAG_WRITE) || !pax_find_mirror_vma(vma))
93068+#endif
93069+
93070 unlock_page(page);
93071 if (page != swapcache) {
93072 /*
93073@@ -3161,6 +3377,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
93074
93075 /* No need to invalidate - it was non-present before */
93076 update_mmu_cache(vma, address, page_table);
93077+
93078+#ifdef CONFIG_PAX_SEGMEXEC
93079+ pax_mirror_anon_pte(vma, address, page, ptl);
93080+#endif
93081+
93082 unlock:
93083 pte_unmap_unlock(page_table, ptl);
93084 out:
93085@@ -3180,40 +3401,6 @@ out_release:
93086 }
93087
93088 /*
93089- * This is like a special single-page "expand_{down|up}wards()",
93090- * except we must first make sure that 'address{-|+}PAGE_SIZE'
93091- * doesn't hit another vma.
93092- */
93093-static inline int check_stack_guard_page(struct vm_area_struct *vma, unsigned long address)
93094-{
93095- address &= PAGE_MASK;
93096- if ((vma->vm_flags & VM_GROWSDOWN) && address == vma->vm_start) {
93097- struct vm_area_struct *prev = vma->vm_prev;
93098-
93099- /*
93100- * Is there a mapping abutting this one below?
93101- *
93102- * That's only ok if it's the same stack mapping
93103- * that has gotten split..
93104- */
93105- if (prev && prev->vm_end == address)
93106- return prev->vm_flags & VM_GROWSDOWN ? 0 : -ENOMEM;
93107-
93108- expand_downwards(vma, address - PAGE_SIZE);
93109- }
93110- if ((vma->vm_flags & VM_GROWSUP) && address + PAGE_SIZE == vma->vm_end) {
93111- struct vm_area_struct *next = vma->vm_next;
93112-
93113- /* As VM_GROWSDOWN but s/below/above/ */
93114- if (next && next->vm_start == address + PAGE_SIZE)
93115- return next->vm_flags & VM_GROWSUP ? 0 : -ENOMEM;
93116-
93117- expand_upwards(vma, address + PAGE_SIZE);
93118- }
93119- return 0;
93120-}
93121-
93122-/*
93123 * We enter with non-exclusive mmap_sem (to exclude vma changes,
93124 * but allow concurrent faults), and pte mapped but not yet locked.
93125 * We return with mmap_sem still held, but pte unmapped and unlocked.
93126@@ -3222,27 +3409,23 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
93127 unsigned long address, pte_t *page_table, pmd_t *pmd,
93128 unsigned int flags)
93129 {
93130- struct page *page;
93131+ struct page *page = NULL;
93132 spinlock_t *ptl;
93133 pte_t entry;
93134
93135- pte_unmap(page_table);
93136-
93137- /* Check if we need to add a guard page to the stack */
93138- if (check_stack_guard_page(vma, address) < 0)
93139- return VM_FAULT_SIGBUS;
93140-
93141- /* Use the zero-page for reads */
93142 if (!(flags & FAULT_FLAG_WRITE)) {
93143 entry = pte_mkspecial(pfn_pte(my_zero_pfn(address),
93144 vma->vm_page_prot));
93145- page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
93146+ ptl = pte_lockptr(mm, pmd);
93147+ spin_lock(ptl);
93148 if (!pte_none(*page_table))
93149 goto unlock;
93150 goto setpte;
93151 }
93152
93153 /* Allocate our own private page. */
93154+ pte_unmap(page_table);
93155+
93156 if (unlikely(anon_vma_prepare(vma)))
93157 goto oom;
93158 page = alloc_zeroed_user_highpage_movable(vma, address);
93159@@ -3266,6 +3449,11 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
93160 if (!pte_none(*page_table))
93161 goto release;
93162
93163+#ifdef CONFIG_PAX_SEGMEXEC
93164+ if (pax_find_mirror_vma(vma))
93165+ BUG_ON(!trylock_page(page));
93166+#endif
93167+
93168 inc_mm_counter_fast(mm, MM_ANONPAGES);
93169 page_add_new_anon_rmap(page, vma, address);
93170 setpte:
93171@@ -3273,6 +3461,12 @@ setpte:
93172
93173 /* No need to invalidate - it was non-present before */
93174 update_mmu_cache(vma, address, page_table);
93175+
93176+#ifdef CONFIG_PAX_SEGMEXEC
93177+ if (page)
93178+ pax_mirror_anon_pte(vma, address, page, ptl);
93179+#endif
93180+
93181 unlock:
93182 pte_unmap_unlock(page_table, ptl);
93183 return 0;
93184@@ -3417,6 +3611,12 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
93185 */
93186 /* Only go through if we didn't race with anybody else... */
93187 if (likely(pte_same(*page_table, orig_pte))) {
93188+
93189+#ifdef CONFIG_PAX_SEGMEXEC
93190+ if (anon && pax_find_mirror_vma(vma))
93191+ BUG_ON(!trylock_page(page));
93192+#endif
93193+
93194 flush_icache_page(vma, page);
93195 entry = mk_pte(page, vma->vm_page_prot);
93196 if (flags & FAULT_FLAG_WRITE)
93197@@ -3438,6 +3638,14 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
93198
93199 /* no need to invalidate: a not-present page won't be cached */
93200 update_mmu_cache(vma, address, page_table);
93201+
93202+#ifdef CONFIG_PAX_SEGMEXEC
93203+ if (anon)
93204+ pax_mirror_anon_pte(vma, address, page, ptl);
93205+ else
93206+ pax_mirror_file_pte(vma, address, page, ptl);
93207+#endif
93208+
93209 } else {
93210 if (cow_page)
93211 mem_cgroup_uncharge_page(cow_page);
93212@@ -3685,6 +3893,12 @@ static int handle_pte_fault(struct mm_struct *mm,
93213 if (flags & FAULT_FLAG_WRITE)
93214 flush_tlb_fix_spurious_fault(vma, address);
93215 }
93216+
93217+#ifdef CONFIG_PAX_SEGMEXEC
93218+ pax_mirror_pte(vma, address, pte, pmd, ptl);
93219+ return 0;
93220+#endif
93221+
93222 unlock:
93223 pte_unmap_unlock(pte, ptl);
93224 return 0;
93225@@ -3701,9 +3915,41 @@ static int __handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
93226 pmd_t *pmd;
93227 pte_t *pte;
93228
93229+#ifdef CONFIG_PAX_SEGMEXEC
93230+ struct vm_area_struct *vma_m;
93231+#endif
93232+
93233 if (unlikely(is_vm_hugetlb_page(vma)))
93234 return hugetlb_fault(mm, vma, address, flags);
93235
93236+#ifdef CONFIG_PAX_SEGMEXEC
93237+ vma_m = pax_find_mirror_vma(vma);
93238+ if (vma_m) {
93239+ unsigned long address_m;
93240+ pgd_t *pgd_m;
93241+ pud_t *pud_m;
93242+ pmd_t *pmd_m;
93243+
93244+ if (vma->vm_start > vma_m->vm_start) {
93245+ address_m = address;
93246+ address -= SEGMEXEC_TASK_SIZE;
93247+ vma = vma_m;
93248+ } else
93249+ address_m = address + SEGMEXEC_TASK_SIZE;
93250+
93251+ pgd_m = pgd_offset(mm, address_m);
93252+ pud_m = pud_alloc(mm, pgd_m, address_m);
93253+ if (!pud_m)
93254+ return VM_FAULT_OOM;
93255+ pmd_m = pmd_alloc(mm, pud_m, address_m);
93256+ if (!pmd_m)
93257+ return VM_FAULT_OOM;
93258+ if (!pmd_present(*pmd_m) && __pte_alloc(mm, vma_m, pmd_m, address_m))
93259+ return VM_FAULT_OOM;
93260+ pax_unmap_mirror_pte(vma_m, address_m, pmd_m);
93261+ }
93262+#endif
93263+
93264 pgd = pgd_offset(mm, address);
93265 pud = pud_alloc(mm, pgd, address);
93266 if (!pud)
93267@@ -3834,6 +4080,23 @@ int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
93268 spin_unlock(&mm->page_table_lock);
93269 return 0;
93270 }
93271+
93272+int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
93273+{
93274+ pud_t *new = pud_alloc_one(mm, address);
93275+ if (!new)
93276+ return -ENOMEM;
93277+
93278+ smp_wmb(); /* See comment in __pte_alloc */
93279+
93280+ spin_lock(&mm->page_table_lock);
93281+ if (pgd_present(*pgd)) /* Another has populated it */
93282+ pud_free(mm, new);
93283+ else
93284+ pgd_populate_kernel(mm, pgd, new);
93285+ spin_unlock(&mm->page_table_lock);
93286+ return 0;
93287+}
93288 #endif /* __PAGETABLE_PUD_FOLDED */
93289
93290 #ifndef __PAGETABLE_PMD_FOLDED
93291@@ -3864,6 +4127,30 @@ int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
93292 spin_unlock(&mm->page_table_lock);
93293 return 0;
93294 }
93295+
93296+int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
93297+{
93298+ pmd_t *new = pmd_alloc_one(mm, address);
93299+ if (!new)
93300+ return -ENOMEM;
93301+
93302+ smp_wmb(); /* See comment in __pte_alloc */
93303+
93304+ spin_lock(&mm->page_table_lock);
93305+#ifndef __ARCH_HAS_4LEVEL_HACK
93306+ if (pud_present(*pud)) /* Another has populated it */
93307+ pmd_free(mm, new);
93308+ else
93309+ pud_populate_kernel(mm, pud, new);
93310+#else
93311+ if (pgd_present(*pud)) /* Another has populated it */
93312+ pmd_free(mm, new);
93313+ else
93314+ pgd_populate_kernel(mm, pud, new);
93315+#endif /* __ARCH_HAS_4LEVEL_HACK */
93316+ spin_unlock(&mm->page_table_lock);
93317+ return 0;
93318+}
93319 #endif /* __PAGETABLE_PMD_FOLDED */
93320
93321 #if !defined(__HAVE_ARCH_GATE_AREA)
93322@@ -3877,7 +4164,7 @@ static int __init gate_vma_init(void)
93323 gate_vma.vm_start = FIXADDR_USER_START;
93324 gate_vma.vm_end = FIXADDR_USER_END;
93325 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
93326- gate_vma.vm_page_prot = __P101;
93327+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
93328
93329 return 0;
93330 }
93331@@ -4011,8 +4298,8 @@ out:
93332 return ret;
93333 }
93334
93335-int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
93336- void *buf, int len, int write)
93337+ssize_t generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
93338+ void *buf, size_t len, int write)
93339 {
93340 resource_size_t phys_addr;
93341 unsigned long prot = 0;
93342@@ -4038,8 +4325,8 @@ EXPORT_SYMBOL_GPL(generic_access_phys);
93343 * Access another process' address space as given in mm. If non-NULL, use the
93344 * given task for page fault accounting.
93345 */
93346-static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
93347- unsigned long addr, void *buf, int len, int write)
93348+static ssize_t __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
93349+ unsigned long addr, void *buf, size_t len, int write)
93350 {
93351 struct vm_area_struct *vma;
93352 void *old_buf = buf;
93353@@ -4047,7 +4334,7 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
93354 down_read(&mm->mmap_sem);
93355 /* ignore errors, just check how much was successfully transferred */
93356 while (len) {
93357- int bytes, ret, offset;
93358+ ssize_t bytes, ret, offset;
93359 void *maddr;
93360 struct page *page = NULL;
93361
93362@@ -4106,8 +4393,8 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
93363 *
93364 * The caller must hold a reference on @mm.
93365 */
93366-int access_remote_vm(struct mm_struct *mm, unsigned long addr,
93367- void *buf, int len, int write)
93368+ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
93369+ void *buf, size_t len, int write)
93370 {
93371 return __access_remote_vm(NULL, mm, addr, buf, len, write);
93372 }
93373@@ -4117,11 +4404,11 @@ int access_remote_vm(struct mm_struct *mm, unsigned long addr,
93374 * Source/target buffer must be kernel space,
93375 * Do not walk the page table directly, use get_user_pages
93376 */
93377-int access_process_vm(struct task_struct *tsk, unsigned long addr,
93378- void *buf, int len, int write)
93379+ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr,
93380+ void *buf, size_t len, int write)
93381 {
93382 struct mm_struct *mm;
93383- int ret;
93384+ ssize_t ret;
93385
93386 mm = get_task_mm(tsk);
93387 if (!mm)
93388diff --git a/mm/mempolicy.c b/mm/mempolicy.c
93389index ae3c8f3..fa4ee8e 100644
93390--- a/mm/mempolicy.c
93391+++ b/mm/mempolicy.c
93392@@ -746,6 +746,10 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
93393 unsigned long vmstart;
93394 unsigned long vmend;
93395
93396+#ifdef CONFIG_PAX_SEGMEXEC
93397+ struct vm_area_struct *vma_m;
93398+#endif
93399+
93400 vma = find_vma(mm, start);
93401 if (!vma || vma->vm_start > start)
93402 return -EFAULT;
93403@@ -789,6 +793,16 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
93404 err = vma_replace_policy(vma, new_pol);
93405 if (err)
93406 goto out;
93407+
93408+#ifdef CONFIG_PAX_SEGMEXEC
93409+ vma_m = pax_find_mirror_vma(vma);
93410+ if (vma_m) {
93411+ err = vma_replace_policy(vma_m, new_pol);
93412+ if (err)
93413+ goto out;
93414+ }
93415+#endif
93416+
93417 }
93418
93419 out:
93420@@ -1252,6 +1266,17 @@ static long do_mbind(unsigned long start, unsigned long len,
93421
93422 if (end < start)
93423 return -EINVAL;
93424+
93425+#ifdef CONFIG_PAX_SEGMEXEC
93426+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
93427+ if (end > SEGMEXEC_TASK_SIZE)
93428+ return -EINVAL;
93429+ } else
93430+#endif
93431+
93432+ if (end > TASK_SIZE)
93433+ return -EINVAL;
93434+
93435 if (end == start)
93436 return 0;
93437
93438@@ -1480,8 +1505,7 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
93439 */
93440 tcred = __task_cred(task);
93441 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
93442- !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
93443- !capable(CAP_SYS_NICE)) {
93444+ !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
93445 rcu_read_unlock();
93446 err = -EPERM;
93447 goto out_put;
93448@@ -1512,6 +1536,15 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
93449 goto out;
93450 }
93451
93452+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
93453+ if (mm != current->mm &&
93454+ (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
93455+ mmput(mm);
93456+ err = -EPERM;
93457+ goto out;
93458+ }
93459+#endif
93460+
93461 err = do_migrate_pages(mm, old, new,
93462 capable(CAP_SYS_NICE) ? MPOL_MF_MOVE_ALL : MPOL_MF_MOVE);
93463
93464diff --git a/mm/migrate.c b/mm/migrate.c
93465index bed4880..a493f67 100644
93466--- a/mm/migrate.c
93467+++ b/mm/migrate.c
93468@@ -1485,8 +1485,7 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid, unsigned long, nr_pages,
93469 */
93470 tcred = __task_cred(task);
93471 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
93472- !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
93473- !capable(CAP_SYS_NICE)) {
93474+ !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
93475 rcu_read_unlock();
93476 err = -EPERM;
93477 goto out;
93478diff --git a/mm/mlock.c b/mm/mlock.c
93479index b1eb536..091d154 100644
93480--- a/mm/mlock.c
93481+++ b/mm/mlock.c
93482@@ -14,6 +14,7 @@
93483 #include <linux/pagevec.h>
93484 #include <linux/mempolicy.h>
93485 #include <linux/syscalls.h>
93486+#include <linux/security.h>
93487 #include <linux/sched.h>
93488 #include <linux/export.h>
93489 #include <linux/rmap.h>
93490@@ -606,7 +607,7 @@ static int do_mlock(unsigned long start, size_t len, int on)
93491 {
93492 unsigned long nstart, end, tmp;
93493 struct vm_area_struct * vma, * prev;
93494- int error;
93495+ int error = 0;
93496
93497 VM_BUG_ON(start & ~PAGE_MASK);
93498 VM_BUG_ON(len != PAGE_ALIGN(len));
93499@@ -615,6 +616,9 @@ static int do_mlock(unsigned long start, size_t len, int on)
93500 return -EINVAL;
93501 if (end == start)
93502 return 0;
93503+ if (end > TASK_SIZE)
93504+ return -EINVAL;
93505+
93506 vma = find_vma(current->mm, start);
93507 if (!vma || vma->vm_start > start)
93508 return -ENOMEM;
93509@@ -626,6 +630,11 @@ static int do_mlock(unsigned long start, size_t len, int on)
93510 for (nstart = start ; ; ) {
93511 vm_flags_t newflags;
93512
93513+#ifdef CONFIG_PAX_SEGMEXEC
93514+ if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
93515+ break;
93516+#endif
93517+
93518 /* Here we know that vma->vm_start <= nstart < vma->vm_end. */
93519
93520 newflags = vma->vm_flags & ~VM_LOCKED;
93521@@ -739,6 +748,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, start, size_t, len)
93522 locked += current->mm->locked_vm;
93523
93524 /* check against resource limits */
93525+ gr_learn_resource(current, RLIMIT_MEMLOCK, (current->mm->locked_vm << PAGE_SHIFT) + len, 1);
93526 if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
93527 error = do_mlock(start, len, 1);
93528
93529@@ -776,6 +786,11 @@ static int do_mlockall(int flags)
93530 for (vma = current->mm->mmap; vma ; vma = prev->vm_next) {
93531 vm_flags_t newflags;
93532
93533+#ifdef CONFIG_PAX_SEGMEXEC
93534+ if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
93535+ break;
93536+#endif
93537+
93538 newflags = vma->vm_flags & ~VM_LOCKED;
93539 if (flags & MCL_CURRENT)
93540 newflags |= VM_LOCKED;
93541@@ -807,8 +822,10 @@ SYSCALL_DEFINE1(mlockall, int, flags)
93542 lock_limit >>= PAGE_SHIFT;
93543
93544 ret = -ENOMEM;
93545+
93546+ gr_learn_resource(current, RLIMIT_MEMLOCK, current->mm->total_vm << PAGE_SHIFT, 1);
93547+
93548 down_write(&current->mm->mmap_sem);
93549-
93550 if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
93551 capable(CAP_IPC_LOCK))
93552 ret = do_mlockall(flags);
93553diff --git a/mm/mmap.c b/mm/mmap.c
93554index 20ff0c3..a9eda98 100644
93555--- a/mm/mmap.c
93556+++ b/mm/mmap.c
93557@@ -36,6 +36,7 @@
93558 #include <linux/sched/sysctl.h>
93559 #include <linux/notifier.h>
93560 #include <linux/memory.h>
93561+#include <linux/random.h>
93562
93563 #include <asm/uaccess.h>
93564 #include <asm/cacheflush.h>
93565@@ -52,6 +53,16 @@
93566 #define arch_rebalance_pgtables(addr, len) (addr)
93567 #endif
93568
93569+static inline void verify_mm_writelocked(struct mm_struct *mm)
93570+{
93571+#if defined(CONFIG_DEBUG_VM) || defined(CONFIG_PAX)
93572+ if (unlikely(down_read_trylock(&mm->mmap_sem))) {
93573+ up_read(&mm->mmap_sem);
93574+ BUG();
93575+ }
93576+#endif
93577+}
93578+
93579 static void unmap_region(struct mm_struct *mm,
93580 struct vm_area_struct *vma, struct vm_area_struct *prev,
93581 unsigned long start, unsigned long end);
93582@@ -71,16 +82,25 @@ static void unmap_region(struct mm_struct *mm,
93583 * x: (no) no x: (no) yes x: (no) yes x: (yes) yes
93584 *
93585 */
93586-pgprot_t protection_map[16] = {
93587+pgprot_t protection_map[16] __read_only = {
93588 __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,
93589 __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111
93590 };
93591
93592-pgprot_t vm_get_page_prot(unsigned long vm_flags)
93593+pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
93594 {
93595- return __pgprot(pgprot_val(protection_map[vm_flags &
93596+ pgprot_t prot = __pgprot(pgprot_val(protection_map[vm_flags &
93597 (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]) |
93598 pgprot_val(arch_vm_get_page_prot(vm_flags)));
93599+
93600+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
93601+ if (!(__supported_pte_mask & _PAGE_NX) &&
93602+ (vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC &&
93603+ (vm_flags & (VM_READ | VM_WRITE)))
93604+ prot = __pgprot(pte_val(pte_exprotect(__pte(pgprot_val(prot)))));
93605+#endif
93606+
93607+ return prot;
93608 }
93609 EXPORT_SYMBOL(vm_get_page_prot);
93610
93611@@ -90,6 +110,7 @@ unsigned long sysctl_overcommit_kbytes __read_mostly;
93612 int sysctl_max_map_count __read_mostly = DEFAULT_MAX_MAP_COUNT;
93613 unsigned long sysctl_user_reserve_kbytes __read_mostly = 1UL << 17; /* 128MB */
93614 unsigned long sysctl_admin_reserve_kbytes __read_mostly = 1UL << 13; /* 8MB */
93615+unsigned long sysctl_heap_stack_gap __read_mostly = 64*1024;
93616 /*
93617 * Make sure vm_committed_as in one cacheline and not cacheline shared with
93618 * other variables. It can be updated by several CPUs frequently.
93619@@ -246,6 +267,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
93620 struct vm_area_struct *next = vma->vm_next;
93621
93622 might_sleep();
93623+ BUG_ON(vma->vm_mirror);
93624 if (vma->vm_ops && vma->vm_ops->close)
93625 vma->vm_ops->close(vma);
93626 if (vma->vm_file)
93627@@ -290,6 +312,7 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
93628 * not page aligned -Ram Gupta
93629 */
93630 rlim = rlimit(RLIMIT_DATA);
93631+ gr_learn_resource(current, RLIMIT_DATA, (brk - mm->start_brk) + (mm->end_data - mm->start_data), 1);
93632 if (rlim < RLIM_INFINITY && (brk - mm->start_brk) +
93633 (mm->end_data - mm->start_data) > rlim)
93634 goto out;
93635@@ -940,6 +963,12 @@ static int
93636 can_vma_merge_before(struct vm_area_struct *vma, unsigned long vm_flags,
93637 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
93638 {
93639+
93640+#ifdef CONFIG_PAX_SEGMEXEC
93641+ if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_start == SEGMEXEC_TASK_SIZE)
93642+ return 0;
93643+#endif
93644+
93645 if (is_mergeable_vma(vma, file, vm_flags) &&
93646 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
93647 if (vma->vm_pgoff == vm_pgoff)
93648@@ -959,6 +988,12 @@ static int
93649 can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
93650 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
93651 {
93652+
93653+#ifdef CONFIG_PAX_SEGMEXEC
93654+ if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end == SEGMEXEC_TASK_SIZE)
93655+ return 0;
93656+#endif
93657+
93658 if (is_mergeable_vma(vma, file, vm_flags) &&
93659 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
93660 pgoff_t vm_pglen;
93661@@ -1001,13 +1036,20 @@ can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
93662 struct vm_area_struct *vma_merge(struct mm_struct *mm,
93663 struct vm_area_struct *prev, unsigned long addr,
93664 unsigned long end, unsigned long vm_flags,
93665- struct anon_vma *anon_vma, struct file *file,
93666+ struct anon_vma *anon_vma, struct file *file,
93667 pgoff_t pgoff, struct mempolicy *policy)
93668 {
93669 pgoff_t pglen = (end - addr) >> PAGE_SHIFT;
93670 struct vm_area_struct *area, *next;
93671 int err;
93672
93673+#ifdef CONFIG_PAX_SEGMEXEC
93674+ unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE, end_m = end + SEGMEXEC_TASK_SIZE;
93675+ struct vm_area_struct *area_m = NULL, *next_m = NULL, *prev_m = NULL;
93676+
93677+ BUG_ON((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE < end);
93678+#endif
93679+
93680 /*
93681 * We later require that vma->vm_flags == vm_flags,
93682 * so this tests vma->vm_flags & VM_SPECIAL, too.
93683@@ -1023,6 +1065,15 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
93684 if (next && next->vm_end == end) /* cases 6, 7, 8 */
93685 next = next->vm_next;
93686
93687+#ifdef CONFIG_PAX_SEGMEXEC
93688+ if (prev)
93689+ prev_m = pax_find_mirror_vma(prev);
93690+ if (area)
93691+ area_m = pax_find_mirror_vma(area);
93692+ if (next)
93693+ next_m = pax_find_mirror_vma(next);
93694+#endif
93695+
93696 /*
93697 * Can it merge with the predecessor?
93698 */
93699@@ -1042,9 +1093,24 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
93700 /* cases 1, 6 */
93701 err = vma_adjust(prev, prev->vm_start,
93702 next->vm_end, prev->vm_pgoff, NULL);
93703- } else /* cases 2, 5, 7 */
93704+
93705+#ifdef CONFIG_PAX_SEGMEXEC
93706+ if (!err && prev_m)
93707+ err = vma_adjust(prev_m, prev_m->vm_start,
93708+ next_m->vm_end, prev_m->vm_pgoff, NULL);
93709+#endif
93710+
93711+ } else { /* cases 2, 5, 7 */
93712 err = vma_adjust(prev, prev->vm_start,
93713 end, prev->vm_pgoff, NULL);
93714+
93715+#ifdef CONFIG_PAX_SEGMEXEC
93716+ if (!err && prev_m)
93717+ err = vma_adjust(prev_m, prev_m->vm_start,
93718+ end_m, prev_m->vm_pgoff, NULL);
93719+#endif
93720+
93721+ }
93722 if (err)
93723 return NULL;
93724 khugepaged_enter_vma_merge(prev);
93725@@ -1058,12 +1124,27 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
93726 mpol_equal(policy, vma_policy(next)) &&
93727 can_vma_merge_before(next, vm_flags,
93728 anon_vma, file, pgoff+pglen)) {
93729- if (prev && addr < prev->vm_end) /* case 4 */
93730+ if (prev && addr < prev->vm_end) { /* case 4 */
93731 err = vma_adjust(prev, prev->vm_start,
93732 addr, prev->vm_pgoff, NULL);
93733- else /* cases 3, 8 */
93734+
93735+#ifdef CONFIG_PAX_SEGMEXEC
93736+ if (!err && prev_m)
93737+ err = vma_adjust(prev_m, prev_m->vm_start,
93738+ addr_m, prev_m->vm_pgoff, NULL);
93739+#endif
93740+
93741+ } else { /* cases 3, 8 */
93742 err = vma_adjust(area, addr, next->vm_end,
93743 next->vm_pgoff - pglen, NULL);
93744+
93745+#ifdef CONFIG_PAX_SEGMEXEC
93746+ if (!err && area_m)
93747+ err = vma_adjust(area_m, addr_m, next_m->vm_end,
93748+ next_m->vm_pgoff - pglen, NULL);
93749+#endif
93750+
93751+ }
93752 if (err)
93753 return NULL;
93754 khugepaged_enter_vma_merge(area);
93755@@ -1172,8 +1253,10 @@ none:
93756 void vm_stat_account(struct mm_struct *mm, unsigned long flags,
93757 struct file *file, long pages)
93758 {
93759- const unsigned long stack_flags
93760- = VM_STACK_FLAGS & (VM_GROWSUP|VM_GROWSDOWN);
93761+
93762+#ifdef CONFIG_PAX_RANDMMAP
93763+ if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
93764+#endif
93765
93766 mm->total_vm += pages;
93767
93768@@ -1181,7 +1264,7 @@ void vm_stat_account(struct mm_struct *mm, unsigned long flags,
93769 mm->shared_vm += pages;
93770 if ((flags & (VM_EXEC|VM_WRITE)) == VM_EXEC)
93771 mm->exec_vm += pages;
93772- } else if (flags & stack_flags)
93773+ } else if (flags & (VM_GROWSUP|VM_GROWSDOWN))
93774 mm->stack_vm += pages;
93775 }
93776 #endif /* CONFIG_PROC_FS */
93777@@ -1211,6 +1294,7 @@ static inline int mlock_future_check(struct mm_struct *mm,
93778 locked += mm->locked_vm;
93779 lock_limit = rlimit(RLIMIT_MEMLOCK);
93780 lock_limit >>= PAGE_SHIFT;
93781+ gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
93782 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
93783 return -EAGAIN;
93784 }
93785@@ -1237,7 +1321,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
93786 * (the exception is when the underlying filesystem is noexec
93787 * mounted, in which case we dont add PROT_EXEC.)
93788 */
93789- if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
93790+ if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
93791 if (!(file && (file->f_path.mnt->mnt_flags & MNT_NOEXEC)))
93792 prot |= PROT_EXEC;
93793
93794@@ -1263,7 +1347,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
93795 /* Obtain the address to map to. we verify (or select) it and ensure
93796 * that it represents a valid section of the address space.
93797 */
93798- addr = get_unmapped_area(file, addr, len, pgoff, flags);
93799+ addr = get_unmapped_area(file, addr, len, pgoff, flags | ((prot & PROT_EXEC) ? MAP_EXECUTABLE : 0));
93800 if (addr & ~PAGE_MASK)
93801 return addr;
93802
93803@@ -1274,6 +1358,43 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
93804 vm_flags = calc_vm_prot_bits(prot) | calc_vm_flag_bits(flags) |
93805 mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
93806
93807+#ifdef CONFIG_PAX_MPROTECT
93808+ if (mm->pax_flags & MF_PAX_MPROTECT) {
93809+
93810+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
93811+ if (file && !pgoff && (vm_flags & VM_EXEC) && mm->binfmt &&
93812+ mm->binfmt->handle_mmap)
93813+ mm->binfmt->handle_mmap(file);
93814+#endif
93815+
93816+#ifndef CONFIG_PAX_MPROTECT_COMPAT
93817+ if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC)) {
93818+ gr_log_rwxmmap(file);
93819+
93820+#ifdef CONFIG_PAX_EMUPLT
93821+ vm_flags &= ~VM_EXEC;
93822+#else
93823+ return -EPERM;
93824+#endif
93825+
93826+ }
93827+
93828+ if (!(vm_flags & VM_EXEC))
93829+ vm_flags &= ~VM_MAYEXEC;
93830+#else
93831+ if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
93832+ vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
93833+#endif
93834+ else
93835+ vm_flags &= ~VM_MAYWRITE;
93836+ }
93837+#endif
93838+
93839+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
93840+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && file)
93841+ vm_flags &= ~VM_PAGEEXEC;
93842+#endif
93843+
93844 if (flags & MAP_LOCKED)
93845 if (!can_do_mlock())
93846 return -EPERM;
93847@@ -1361,6 +1482,9 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
93848 vm_flags |= VM_NORESERVE;
93849 }
93850
93851+ if (!gr_acl_handle_mmap(file, prot))
93852+ return -EACCES;
93853+
93854 addr = mmap_region(file, addr, len, vm_flags, pgoff);
93855 if (!IS_ERR_VALUE(addr) &&
93856 ((vm_flags & VM_LOCKED) ||
93857@@ -1454,7 +1578,7 @@ int vma_wants_writenotify(struct vm_area_struct *vma)
93858 vm_flags_t vm_flags = vma->vm_flags;
93859
93860 /* If it was private or non-writable, the write bit is already clear */
93861- if ((vm_flags & (VM_WRITE|VM_SHARED)) != ((VM_WRITE|VM_SHARED)))
93862+ if ((vm_flags & (VM_WRITE|VM_SHARED)) != (VM_WRITE|VM_SHARED))
93863 return 0;
93864
93865 /* The backer wishes to know when pages are first written to? */
93866@@ -1500,7 +1624,22 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
93867 struct rb_node **rb_link, *rb_parent;
93868 unsigned long charged = 0;
93869
93870+#ifdef CONFIG_PAX_SEGMEXEC
93871+ struct vm_area_struct *vma_m = NULL;
93872+#endif
93873+
93874+ /*
93875+ * mm->mmap_sem is required to protect against another thread
93876+ * changing the mappings in case we sleep.
93877+ */
93878+ verify_mm_writelocked(mm);
93879+
93880 /* Check against address space limit. */
93881+
93882+#ifdef CONFIG_PAX_RANDMMAP
93883+ if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (vm_flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
93884+#endif
93885+
93886 if (!may_expand_vm(mm, len >> PAGE_SHIFT)) {
93887 unsigned long nr_pages;
93888
93889@@ -1519,11 +1658,10 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
93890
93891 /* Clear old maps */
93892 error = -ENOMEM;
93893-munmap_back:
93894 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
93895 if (do_munmap(mm, addr, len))
93896 return -ENOMEM;
93897- goto munmap_back;
93898+ BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
93899 }
93900
93901 /*
93902@@ -1554,6 +1692,16 @@ munmap_back:
93903 goto unacct_error;
93904 }
93905
93906+#ifdef CONFIG_PAX_SEGMEXEC
93907+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vm_flags & VM_EXEC)) {
93908+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
93909+ if (!vma_m) {
93910+ error = -ENOMEM;
93911+ goto free_vma;
93912+ }
93913+ }
93914+#endif
93915+
93916 vma->vm_mm = mm;
93917 vma->vm_start = addr;
93918 vma->vm_end = addr + len;
93919@@ -1573,6 +1721,13 @@ munmap_back:
93920 if (error)
93921 goto unmap_and_free_vma;
93922
93923+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
93924+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && !(vma->vm_flags & VM_SPECIAL)) {
93925+ vma->vm_flags |= VM_PAGEEXEC;
93926+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
93927+ }
93928+#endif
93929+
93930 /* Can addr have changed??
93931 *
93932 * Answer: Yes, several device drivers can do it in their
93933@@ -1606,6 +1761,12 @@ munmap_back:
93934 }
93935
93936 vma_link(mm, vma, prev, rb_link, rb_parent);
93937+
93938+#ifdef CONFIG_PAX_SEGMEXEC
93939+ if (vma_m)
93940+ BUG_ON(pax_mirror_vma(vma_m, vma));
93941+#endif
93942+
93943 /* Once vma denies write, undo our temporary denial count */
93944 if (vm_flags & VM_DENYWRITE)
93945 allow_write_access(file);
93946@@ -1614,6 +1775,7 @@ out:
93947 perf_event_mmap(vma);
93948
93949 vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
93950+ track_exec_limit(mm, addr, addr + len, vm_flags);
93951 if (vm_flags & VM_LOCKED) {
93952 if (!((vm_flags & VM_SPECIAL) || is_vm_hugetlb_page(vma) ||
93953 vma == get_gate_vma(current->mm)))
93954@@ -1646,6 +1808,12 @@ unmap_and_free_vma:
93955 unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
93956 charged = 0;
93957 free_vma:
93958+
93959+#ifdef CONFIG_PAX_SEGMEXEC
93960+ if (vma_m)
93961+ kmem_cache_free(vm_area_cachep, vma_m);
93962+#endif
93963+
93964 kmem_cache_free(vm_area_cachep, vma);
93965 unacct_error:
93966 if (charged)
93967@@ -1653,7 +1821,63 @@ unacct_error:
93968 return error;
93969 }
93970
93971-unsigned long unmapped_area(struct vm_unmapped_area_info *info)
93972+#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
93973+unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
93974+{
93975+ if ((mm->pax_flags & MF_PAX_RANDMMAP) && !filp && (flags & MAP_STACK))
93976+ return ((prandom_u32() & 0xFF) + 1) << PAGE_SHIFT;
93977+
93978+ return 0;
93979+}
93980+#endif
93981+
93982+bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset)
93983+{
93984+ if (!vma) {
93985+#ifdef CONFIG_STACK_GROWSUP
93986+ if (addr > sysctl_heap_stack_gap)
93987+ vma = find_vma(current->mm, addr - sysctl_heap_stack_gap);
93988+ else
93989+ vma = find_vma(current->mm, 0);
93990+ if (vma && (vma->vm_flags & VM_GROWSUP))
93991+ return false;
93992+#endif
93993+ return true;
93994+ }
93995+
93996+ if (addr + len > vma->vm_start)
93997+ return false;
93998+
93999+ if (vma->vm_flags & VM_GROWSDOWN)
94000+ return sysctl_heap_stack_gap <= vma->vm_start - addr - len;
94001+#ifdef CONFIG_STACK_GROWSUP
94002+ else if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP))
94003+ return addr - vma->vm_prev->vm_end >= sysctl_heap_stack_gap;
94004+#endif
94005+ else if (offset)
94006+ return offset <= vma->vm_start - addr - len;
94007+
94008+ return true;
94009+}
94010+
94011+unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset)
94012+{
94013+ if (vma->vm_start < len)
94014+ return -ENOMEM;
94015+
94016+ if (!(vma->vm_flags & VM_GROWSDOWN)) {
94017+ if (offset <= vma->vm_start - len)
94018+ return vma->vm_start - len - offset;
94019+ else
94020+ return -ENOMEM;
94021+ }
94022+
94023+ if (sysctl_heap_stack_gap <= vma->vm_start - len)
94024+ return vma->vm_start - len - sysctl_heap_stack_gap;
94025+ return -ENOMEM;
94026+}
94027+
94028+unsigned long unmapped_area(const struct vm_unmapped_area_info *info)
94029 {
94030 /*
94031 * We implement the search by looking for an rbtree node that
94032@@ -1701,11 +1925,29 @@ unsigned long unmapped_area(struct vm_unmapped_area_info *info)
94033 }
94034 }
94035
94036- gap_start = vma->vm_prev ? vma->vm_prev->vm_end : 0;
94037+ gap_start = vma->vm_prev ? vma->vm_prev->vm_end: 0;
94038 check_current:
94039 /* Check if current node has a suitable gap */
94040 if (gap_start > high_limit)
94041 return -ENOMEM;
94042+
94043+ if (gap_end - gap_start > info->threadstack_offset)
94044+ gap_start += info->threadstack_offset;
94045+ else
94046+ gap_start = gap_end;
94047+
94048+ if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP)) {
94049+ if (gap_end - gap_start > sysctl_heap_stack_gap)
94050+ gap_start += sysctl_heap_stack_gap;
94051+ else
94052+ gap_start = gap_end;
94053+ }
94054+ if (vma->vm_flags & VM_GROWSDOWN) {
94055+ if (gap_end - gap_start > sysctl_heap_stack_gap)
94056+ gap_end -= sysctl_heap_stack_gap;
94057+ else
94058+ gap_end = gap_start;
94059+ }
94060 if (gap_end >= low_limit && gap_end - gap_start >= length)
94061 goto found;
94062
94063@@ -1755,7 +1997,7 @@ found:
94064 return gap_start;
94065 }
94066
94067-unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info)
94068+unsigned long unmapped_area_topdown(const struct vm_unmapped_area_info *info)
94069 {
94070 struct mm_struct *mm = current->mm;
94071 struct vm_area_struct *vma;
94072@@ -1809,6 +2051,24 @@ check_current:
94073 gap_end = vma->vm_start;
94074 if (gap_end < low_limit)
94075 return -ENOMEM;
94076+
94077+ if (gap_end - gap_start > info->threadstack_offset)
94078+ gap_end -= info->threadstack_offset;
94079+ else
94080+ gap_end = gap_start;
94081+
94082+ if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP)) {
94083+ if (gap_end - gap_start > sysctl_heap_stack_gap)
94084+ gap_start += sysctl_heap_stack_gap;
94085+ else
94086+ gap_start = gap_end;
94087+ }
94088+ if (vma->vm_flags & VM_GROWSDOWN) {
94089+ if (gap_end - gap_start > sysctl_heap_stack_gap)
94090+ gap_end -= sysctl_heap_stack_gap;
94091+ else
94092+ gap_end = gap_start;
94093+ }
94094 if (gap_start <= high_limit && gap_end - gap_start >= length)
94095 goto found;
94096
94097@@ -1872,6 +2132,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
94098 struct mm_struct *mm = current->mm;
94099 struct vm_area_struct *vma;
94100 struct vm_unmapped_area_info info;
94101+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
94102
94103 if (len > TASK_SIZE - mmap_min_addr)
94104 return -ENOMEM;
94105@@ -1879,11 +2140,15 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
94106 if (flags & MAP_FIXED)
94107 return addr;
94108
94109+#ifdef CONFIG_PAX_RANDMMAP
94110+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
94111+#endif
94112+
94113 if (addr) {
94114 addr = PAGE_ALIGN(addr);
94115 vma = find_vma(mm, addr);
94116 if (TASK_SIZE - len >= addr && addr >= mmap_min_addr &&
94117- (!vma || addr + len <= vma->vm_start))
94118+ check_heap_stack_gap(vma, addr, len, offset))
94119 return addr;
94120 }
94121
94122@@ -1892,6 +2157,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
94123 info.low_limit = mm->mmap_base;
94124 info.high_limit = TASK_SIZE;
94125 info.align_mask = 0;
94126+ info.threadstack_offset = offset;
94127 return vm_unmapped_area(&info);
94128 }
94129 #endif
94130@@ -1910,6 +2176,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
94131 struct mm_struct *mm = current->mm;
94132 unsigned long addr = addr0;
94133 struct vm_unmapped_area_info info;
94134+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
94135
94136 /* requested length too big for entire address space */
94137 if (len > TASK_SIZE - mmap_min_addr)
94138@@ -1918,12 +2185,16 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
94139 if (flags & MAP_FIXED)
94140 return addr;
94141
94142+#ifdef CONFIG_PAX_RANDMMAP
94143+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
94144+#endif
94145+
94146 /* requesting a specific address */
94147 if (addr) {
94148 addr = PAGE_ALIGN(addr);
94149 vma = find_vma(mm, addr);
94150 if (TASK_SIZE - len >= addr && addr >= mmap_min_addr &&
94151- (!vma || addr + len <= vma->vm_start))
94152+ check_heap_stack_gap(vma, addr, len, offset))
94153 return addr;
94154 }
94155
94156@@ -1932,6 +2203,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
94157 info.low_limit = max(PAGE_SIZE, mmap_min_addr);
94158 info.high_limit = mm->mmap_base;
94159 info.align_mask = 0;
94160+ info.threadstack_offset = offset;
94161 addr = vm_unmapped_area(&info);
94162
94163 /*
94164@@ -1944,6 +2216,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
94165 VM_BUG_ON(addr != -ENOMEM);
94166 info.flags = 0;
94167 info.low_limit = TASK_UNMAPPED_BASE;
94168+
94169+#ifdef CONFIG_PAX_RANDMMAP
94170+ if (mm->pax_flags & MF_PAX_RANDMMAP)
94171+ info.low_limit += mm->delta_mmap;
94172+#endif
94173+
94174 info.high_limit = TASK_SIZE;
94175 addr = vm_unmapped_area(&info);
94176 }
94177@@ -2045,6 +2323,28 @@ find_vma_prev(struct mm_struct *mm, unsigned long addr,
94178 return vma;
94179 }
94180
94181+#ifdef CONFIG_PAX_SEGMEXEC
94182+struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma)
94183+{
94184+ struct vm_area_struct *vma_m;
94185+
94186+ BUG_ON(!vma || vma->vm_start >= vma->vm_end);
94187+ if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC)) {
94188+ BUG_ON(vma->vm_mirror);
94189+ return NULL;
94190+ }
94191+ BUG_ON(vma->vm_start < SEGMEXEC_TASK_SIZE && SEGMEXEC_TASK_SIZE < vma->vm_end);
94192+ vma_m = vma->vm_mirror;
94193+ BUG_ON(!vma_m || vma_m->vm_mirror != vma);
94194+ BUG_ON(vma->vm_file != vma_m->vm_file);
94195+ BUG_ON(vma->vm_end - vma->vm_start != vma_m->vm_end - vma_m->vm_start);
94196+ BUG_ON(vma->vm_pgoff != vma_m->vm_pgoff);
94197+ BUG_ON(vma->anon_vma != vma_m->anon_vma && vma->anon_vma->root != vma_m->anon_vma->root);
94198+ BUG_ON((vma->vm_flags ^ vma_m->vm_flags) & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED));
94199+ return vma_m;
94200+}
94201+#endif
94202+
94203 /*
94204 * Verify that the stack growth is acceptable and
94205 * update accounting. This is shared with both the
94206@@ -2061,6 +2361,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
94207 return -ENOMEM;
94208
94209 /* Stack limit test */
94210+ gr_learn_resource(current, RLIMIT_STACK, size, 1);
94211 if (size > ACCESS_ONCE(rlim[RLIMIT_STACK].rlim_cur))
94212 return -ENOMEM;
94213
94214@@ -2071,6 +2372,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
94215 locked = mm->locked_vm + grow;
94216 limit = ACCESS_ONCE(rlim[RLIMIT_MEMLOCK].rlim_cur);
94217 limit >>= PAGE_SHIFT;
94218+ gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
94219 if (locked > limit && !capable(CAP_IPC_LOCK))
94220 return -ENOMEM;
94221 }
94222@@ -2100,37 +2402,48 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
94223 * PA-RISC uses this for its stack; IA64 for its Register Backing Store.
94224 * vma is the last one with address > vma->vm_end. Have to extend vma.
94225 */
94226+#ifndef CONFIG_IA64
94227+static
94228+#endif
94229 int expand_upwards(struct vm_area_struct *vma, unsigned long address)
94230 {
94231 int error;
94232+ bool locknext;
94233
94234 if (!(vma->vm_flags & VM_GROWSUP))
94235 return -EFAULT;
94236
94237+ /* Also guard against wrapping around to address 0. */
94238+ if (address < PAGE_ALIGN(address+1))
94239+ address = PAGE_ALIGN(address+1);
94240+ else
94241+ return -ENOMEM;
94242+
94243 /*
94244 * We must make sure the anon_vma is allocated
94245 * so that the anon_vma locking is not a noop.
94246 */
94247 if (unlikely(anon_vma_prepare(vma)))
94248 return -ENOMEM;
94249+ locknext = vma->vm_next && (vma->vm_next->vm_flags & VM_GROWSDOWN);
94250+ if (locknext && anon_vma_prepare(vma->vm_next))
94251+ return -ENOMEM;
94252 vma_lock_anon_vma(vma);
94253+ if (locknext)
94254+ vma_lock_anon_vma(vma->vm_next);
94255
94256 /*
94257 * vma->vm_start/vm_end cannot change under us because the caller
94258 * is required to hold the mmap_sem in read mode. We need the
94259- * anon_vma lock to serialize against concurrent expand_stacks.
94260- * Also guard against wrapping around to address 0.
94261+ * anon_vma locks to serialize against concurrent expand_stacks
94262+ * and expand_upwards.
94263 */
94264- if (address < PAGE_ALIGN(address+4))
94265- address = PAGE_ALIGN(address+4);
94266- else {
94267- vma_unlock_anon_vma(vma);
94268- return -ENOMEM;
94269- }
94270 error = 0;
94271
94272 /* Somebody else might have raced and expanded it already */
94273- if (address > vma->vm_end) {
94274+ 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)
94275+ error = -ENOMEM;
94276+ else if (address > vma->vm_end && (!locknext || vma->vm_next->vm_start >= address)) {
94277 unsigned long size, grow;
94278
94279 size = address - vma->vm_start;
94280@@ -2165,6 +2478,8 @@ int expand_upwards(struct vm_area_struct *vma, unsigned long address)
94281 }
94282 }
94283 }
94284+ if (locknext)
94285+ vma_unlock_anon_vma(vma->vm_next);
94286 vma_unlock_anon_vma(vma);
94287 khugepaged_enter_vma_merge(vma);
94288 validate_mm(vma->vm_mm);
94289@@ -2179,6 +2494,8 @@ int expand_downwards(struct vm_area_struct *vma,
94290 unsigned long address)
94291 {
94292 int error;
94293+ bool lockprev = false;
94294+ struct vm_area_struct *prev;
94295
94296 /*
94297 * We must make sure the anon_vma is allocated
94298@@ -2192,6 +2509,15 @@ int expand_downwards(struct vm_area_struct *vma,
94299 if (error)
94300 return error;
94301
94302+ prev = vma->vm_prev;
94303+#if defined(CONFIG_STACK_GROWSUP) || defined(CONFIG_IA64)
94304+ lockprev = prev && (prev->vm_flags & VM_GROWSUP);
94305+#endif
94306+ if (lockprev && anon_vma_prepare(prev))
94307+ return -ENOMEM;
94308+ if (lockprev)
94309+ vma_lock_anon_vma(prev);
94310+
94311 vma_lock_anon_vma(vma);
94312
94313 /*
94314@@ -2201,9 +2527,17 @@ int expand_downwards(struct vm_area_struct *vma,
94315 */
94316
94317 /* Somebody else might have raced and expanded it already */
94318- if (address < vma->vm_start) {
94319+ if (prev && (prev->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)) && address - prev->vm_end < sysctl_heap_stack_gap)
94320+ error = -ENOMEM;
94321+ else if (address < vma->vm_start && (!lockprev || prev->vm_end <= address)) {
94322 unsigned long size, grow;
94323
94324+#ifdef CONFIG_PAX_SEGMEXEC
94325+ struct vm_area_struct *vma_m;
94326+
94327+ vma_m = pax_find_mirror_vma(vma);
94328+#endif
94329+
94330 size = vma->vm_end - address;
94331 grow = (vma->vm_start - address) >> PAGE_SHIFT;
94332
94333@@ -2228,13 +2562,27 @@ int expand_downwards(struct vm_area_struct *vma,
94334 vma->vm_pgoff -= grow;
94335 anon_vma_interval_tree_post_update_vma(vma);
94336 vma_gap_update(vma);
94337+
94338+#ifdef CONFIG_PAX_SEGMEXEC
94339+ if (vma_m) {
94340+ anon_vma_interval_tree_pre_update_vma(vma_m);
94341+ vma_m->vm_start -= grow << PAGE_SHIFT;
94342+ vma_m->vm_pgoff -= grow;
94343+ anon_vma_interval_tree_post_update_vma(vma_m);
94344+ vma_gap_update(vma_m);
94345+ }
94346+#endif
94347+
94348 spin_unlock(&vma->vm_mm->page_table_lock);
94349
94350+ track_exec_limit(vma->vm_mm, vma->vm_start, vma->vm_end, vma->vm_flags);
94351 perf_event_mmap(vma);
94352 }
94353 }
94354 }
94355 vma_unlock_anon_vma(vma);
94356+ if (lockprev)
94357+ vma_unlock_anon_vma(prev);
94358 khugepaged_enter_vma_merge(vma);
94359 validate_mm(vma->vm_mm);
94360 return error;
94361@@ -2332,6 +2680,13 @@ static void remove_vma_list(struct mm_struct *mm, struct vm_area_struct *vma)
94362 do {
94363 long nrpages = vma_pages(vma);
94364
94365+#ifdef CONFIG_PAX_SEGMEXEC
94366+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE)) {
94367+ vma = remove_vma(vma);
94368+ continue;
94369+ }
94370+#endif
94371+
94372 if (vma->vm_flags & VM_ACCOUNT)
94373 nr_accounted += nrpages;
94374 vm_stat_account(mm, vma->vm_flags, vma->vm_file, -nrpages);
94375@@ -2376,6 +2731,16 @@ detach_vmas_to_be_unmapped(struct mm_struct *mm, struct vm_area_struct *vma,
94376 insertion_point = (prev ? &prev->vm_next : &mm->mmap);
94377 vma->vm_prev = NULL;
94378 do {
94379+
94380+#ifdef CONFIG_PAX_SEGMEXEC
94381+ if (vma->vm_mirror) {
94382+ BUG_ON(!vma->vm_mirror->vm_mirror || vma->vm_mirror->vm_mirror != vma);
94383+ vma->vm_mirror->vm_mirror = NULL;
94384+ vma->vm_mirror->vm_flags &= ~VM_EXEC;
94385+ vma->vm_mirror = NULL;
94386+ }
94387+#endif
94388+
94389 vma_rb_erase(vma, &mm->mm_rb);
94390 mm->map_count--;
94391 tail_vma = vma;
94392@@ -2401,14 +2766,33 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
94393 struct vm_area_struct *new;
94394 int err = -ENOMEM;
94395
94396+#ifdef CONFIG_PAX_SEGMEXEC
94397+ struct vm_area_struct *vma_m, *new_m = NULL;
94398+ unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE;
94399+#endif
94400+
94401 if (is_vm_hugetlb_page(vma) && (addr &
94402 ~(huge_page_mask(hstate_vma(vma)))))
94403 return -EINVAL;
94404
94405+#ifdef CONFIG_PAX_SEGMEXEC
94406+ vma_m = pax_find_mirror_vma(vma);
94407+#endif
94408+
94409 new = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
94410 if (!new)
94411 goto out_err;
94412
94413+#ifdef CONFIG_PAX_SEGMEXEC
94414+ if (vma_m) {
94415+ new_m = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
94416+ if (!new_m) {
94417+ kmem_cache_free(vm_area_cachep, new);
94418+ goto out_err;
94419+ }
94420+ }
94421+#endif
94422+
94423 /* most fields are the same, copy all, and then fixup */
94424 *new = *vma;
94425
94426@@ -2421,6 +2805,22 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
94427 new->vm_pgoff += ((addr - vma->vm_start) >> PAGE_SHIFT);
94428 }
94429
94430+#ifdef CONFIG_PAX_SEGMEXEC
94431+ if (vma_m) {
94432+ *new_m = *vma_m;
94433+ INIT_LIST_HEAD(&new_m->anon_vma_chain);
94434+ new_m->vm_mirror = new;
94435+ new->vm_mirror = new_m;
94436+
94437+ if (new_below)
94438+ new_m->vm_end = addr_m;
94439+ else {
94440+ new_m->vm_start = addr_m;
94441+ new_m->vm_pgoff += ((addr_m - vma_m->vm_start) >> PAGE_SHIFT);
94442+ }
94443+ }
94444+#endif
94445+
94446 err = vma_dup_policy(vma, new);
94447 if (err)
94448 goto out_free_vma;
94449@@ -2440,6 +2840,38 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
94450 else
94451 err = vma_adjust(vma, vma->vm_start, addr, vma->vm_pgoff, new);
94452
94453+#ifdef CONFIG_PAX_SEGMEXEC
94454+ if (!err && vma_m) {
94455+ struct mempolicy *pol = vma_policy(new);
94456+
94457+ if (anon_vma_clone(new_m, vma_m))
94458+ goto out_free_mpol;
94459+
94460+ mpol_get(pol);
94461+ set_vma_policy(new_m, pol);
94462+
94463+ if (new_m->vm_file)
94464+ get_file(new_m->vm_file);
94465+
94466+ if (new_m->vm_ops && new_m->vm_ops->open)
94467+ new_m->vm_ops->open(new_m);
94468+
94469+ if (new_below)
94470+ err = vma_adjust(vma_m, addr_m, vma_m->vm_end, vma_m->vm_pgoff +
94471+ ((addr_m - new_m->vm_start) >> PAGE_SHIFT), new_m);
94472+ else
94473+ err = vma_adjust(vma_m, vma_m->vm_start, addr_m, vma_m->vm_pgoff, new_m);
94474+
94475+ if (err) {
94476+ if (new_m->vm_ops && new_m->vm_ops->close)
94477+ new_m->vm_ops->close(new_m);
94478+ if (new_m->vm_file)
94479+ fput(new_m->vm_file);
94480+ mpol_put(pol);
94481+ }
94482+ }
94483+#endif
94484+
94485 /* Success. */
94486 if (!err)
94487 return 0;
94488@@ -2449,10 +2881,18 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
94489 new->vm_ops->close(new);
94490 if (new->vm_file)
94491 fput(new->vm_file);
94492- unlink_anon_vmas(new);
94493 out_free_mpol:
94494 mpol_put(vma_policy(new));
94495 out_free_vma:
94496+
94497+#ifdef CONFIG_PAX_SEGMEXEC
94498+ if (new_m) {
94499+ unlink_anon_vmas(new_m);
94500+ kmem_cache_free(vm_area_cachep, new_m);
94501+ }
94502+#endif
94503+
94504+ unlink_anon_vmas(new);
94505 kmem_cache_free(vm_area_cachep, new);
94506 out_err:
94507 return err;
94508@@ -2465,6 +2905,15 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
94509 int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
94510 unsigned long addr, int new_below)
94511 {
94512+
94513+#ifdef CONFIG_PAX_SEGMEXEC
94514+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
94515+ BUG_ON(vma->vm_end > SEGMEXEC_TASK_SIZE);
94516+ if (mm->map_count >= sysctl_max_map_count-1)
94517+ return -ENOMEM;
94518+ } else
94519+#endif
94520+
94521 if (mm->map_count >= sysctl_max_map_count)
94522 return -ENOMEM;
94523
94524@@ -2476,11 +2925,30 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
94525 * work. This now handles partial unmappings.
94526 * Jeremy Fitzhardinge <jeremy@goop.org>
94527 */
94528+#ifdef CONFIG_PAX_SEGMEXEC
94529 int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
94530 {
94531+ int ret = __do_munmap(mm, start, len);
94532+ if (ret || !(mm->pax_flags & MF_PAX_SEGMEXEC))
94533+ return ret;
94534+
94535+ return __do_munmap(mm, start + SEGMEXEC_TASK_SIZE, len);
94536+}
94537+
94538+int __do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
94539+#else
94540+int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
94541+#endif
94542+{
94543 unsigned long end;
94544 struct vm_area_struct *vma, *prev, *last;
94545
94546+ /*
94547+ * mm->mmap_sem is required to protect against another thread
94548+ * changing the mappings in case we sleep.
94549+ */
94550+ verify_mm_writelocked(mm);
94551+
94552 if ((start & ~PAGE_MASK) || start > TASK_SIZE || len > TASK_SIZE-start)
94553 return -EINVAL;
94554
94555@@ -2555,6 +3023,8 @@ int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
94556 /* Fix up all other VM information */
94557 remove_vma_list(mm, vma);
94558
94559+ track_exec_limit(mm, start, end, 0UL);
94560+
94561 return 0;
94562 }
94563
94564@@ -2563,6 +3033,13 @@ int vm_munmap(unsigned long start, size_t len)
94565 int ret;
94566 struct mm_struct *mm = current->mm;
94567
94568+
94569+#ifdef CONFIG_PAX_SEGMEXEC
94570+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) &&
94571+ (len > SEGMEXEC_TASK_SIZE || start > SEGMEXEC_TASK_SIZE-len))
94572+ return -EINVAL;
94573+#endif
94574+
94575 down_write(&mm->mmap_sem);
94576 ret = do_munmap(mm, start, len);
94577 up_write(&mm->mmap_sem);
94578@@ -2576,16 +3053,6 @@ SYSCALL_DEFINE2(munmap, unsigned long, addr, size_t, len)
94579 return vm_munmap(addr, len);
94580 }
94581
94582-static inline void verify_mm_writelocked(struct mm_struct *mm)
94583-{
94584-#ifdef CONFIG_DEBUG_VM
94585- if (unlikely(down_read_trylock(&mm->mmap_sem))) {
94586- WARN_ON(1);
94587- up_read(&mm->mmap_sem);
94588- }
94589-#endif
94590-}
94591-
94592 /*
94593 * this is really a simplified "do_mmap". it only handles
94594 * anonymous maps. eventually we may be able to do some
94595@@ -2599,6 +3066,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
94596 struct rb_node ** rb_link, * rb_parent;
94597 pgoff_t pgoff = addr >> PAGE_SHIFT;
94598 int error;
94599+ unsigned long charged;
94600
94601 len = PAGE_ALIGN(len);
94602 if (!len)
94603@@ -2606,10 +3074,24 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
94604
94605 flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags;
94606
94607+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
94608+ if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
94609+ flags &= ~VM_EXEC;
94610+
94611+#ifdef CONFIG_PAX_MPROTECT
94612+ if (mm->pax_flags & MF_PAX_MPROTECT)
94613+ flags &= ~VM_MAYEXEC;
94614+#endif
94615+
94616+ }
94617+#endif
94618+
94619 error = get_unmapped_area(NULL, addr, len, 0, MAP_FIXED);
94620 if (error & ~PAGE_MASK)
94621 return error;
94622
94623+ charged = len >> PAGE_SHIFT;
94624+
94625 error = mlock_future_check(mm, mm->def_flags, len);
94626 if (error)
94627 return error;
94628@@ -2623,21 +3105,20 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
94629 /*
94630 * Clear old maps. this also does some error checking for us
94631 */
94632- munmap_back:
94633 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
94634 if (do_munmap(mm, addr, len))
94635 return -ENOMEM;
94636- goto munmap_back;
94637+ BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
94638 }
94639
94640 /* Check against address space limits *after* clearing old maps... */
94641- if (!may_expand_vm(mm, len >> PAGE_SHIFT))
94642+ if (!may_expand_vm(mm, charged))
94643 return -ENOMEM;
94644
94645 if (mm->map_count > sysctl_max_map_count)
94646 return -ENOMEM;
94647
94648- if (security_vm_enough_memory_mm(mm, len >> PAGE_SHIFT))
94649+ if (security_vm_enough_memory_mm(mm, charged))
94650 return -ENOMEM;
94651
94652 /* Can we just expand an old private anonymous mapping? */
94653@@ -2651,7 +3132,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
94654 */
94655 vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
94656 if (!vma) {
94657- vm_unacct_memory(len >> PAGE_SHIFT);
94658+ vm_unacct_memory(charged);
94659 return -ENOMEM;
94660 }
94661
94662@@ -2665,10 +3146,11 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
94663 vma_link(mm, vma, prev, rb_link, rb_parent);
94664 out:
94665 perf_event_mmap(vma);
94666- mm->total_vm += len >> PAGE_SHIFT;
94667+ mm->total_vm += charged;
94668 if (flags & VM_LOCKED)
94669- mm->locked_vm += (len >> PAGE_SHIFT);
94670+ mm->locked_vm += charged;
94671 vma->vm_flags |= VM_SOFTDIRTY;
94672+ track_exec_limit(mm, addr, addr + len, flags);
94673 return addr;
94674 }
94675
94676@@ -2730,6 +3212,7 @@ void exit_mmap(struct mm_struct *mm)
94677 while (vma) {
94678 if (vma->vm_flags & VM_ACCOUNT)
94679 nr_accounted += vma_pages(vma);
94680+ vma->vm_mirror = NULL;
94681 vma = remove_vma(vma);
94682 }
94683 vm_unacct_memory(nr_accounted);
94684@@ -2747,6 +3230,13 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
94685 struct vm_area_struct *prev;
94686 struct rb_node **rb_link, *rb_parent;
94687
94688+#ifdef CONFIG_PAX_SEGMEXEC
94689+ struct vm_area_struct *vma_m = NULL;
94690+#endif
94691+
94692+ if (security_mmap_addr(vma->vm_start))
94693+ return -EPERM;
94694+
94695 /*
94696 * The vm_pgoff of a purely anonymous vma should be irrelevant
94697 * until its first write fault, when page's anon_vma and index
94698@@ -2770,7 +3260,21 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
94699 security_vm_enough_memory_mm(mm, vma_pages(vma)))
94700 return -ENOMEM;
94701
94702+#ifdef CONFIG_PAX_SEGMEXEC
94703+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_EXEC)) {
94704+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
94705+ if (!vma_m)
94706+ return -ENOMEM;
94707+ }
94708+#endif
94709+
94710 vma_link(mm, vma, prev, rb_link, rb_parent);
94711+
94712+#ifdef CONFIG_PAX_SEGMEXEC
94713+ if (vma_m)
94714+ BUG_ON(pax_mirror_vma(vma_m, vma));
94715+#endif
94716+
94717 return 0;
94718 }
94719
94720@@ -2789,6 +3293,8 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
94721 struct rb_node **rb_link, *rb_parent;
94722 bool faulted_in_anon_vma = true;
94723
94724+ BUG_ON(vma->vm_mirror);
94725+
94726 /*
94727 * If anonymous vma has not yet been faulted, update new pgoff
94728 * to match new location, to increase its chance of merging.
94729@@ -2853,6 +3359,39 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
94730 return NULL;
94731 }
94732
94733+#ifdef CONFIG_PAX_SEGMEXEC
94734+long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma)
94735+{
94736+ struct vm_area_struct *prev_m;
94737+ struct rb_node **rb_link_m, *rb_parent_m;
94738+ struct mempolicy *pol_m;
94739+
94740+ BUG_ON(!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC));
94741+ BUG_ON(vma->vm_mirror || vma_m->vm_mirror);
94742+ BUG_ON(!mpol_equal(vma_policy(vma), vma_policy(vma_m)));
94743+ *vma_m = *vma;
94744+ INIT_LIST_HEAD(&vma_m->anon_vma_chain);
94745+ if (anon_vma_clone(vma_m, vma))
94746+ return -ENOMEM;
94747+ pol_m = vma_policy(vma_m);
94748+ mpol_get(pol_m);
94749+ set_vma_policy(vma_m, pol_m);
94750+ vma_m->vm_start += SEGMEXEC_TASK_SIZE;
94751+ vma_m->vm_end += SEGMEXEC_TASK_SIZE;
94752+ vma_m->vm_flags &= ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED);
94753+ vma_m->vm_page_prot = vm_get_page_prot(vma_m->vm_flags);
94754+ if (vma_m->vm_file)
94755+ get_file(vma_m->vm_file);
94756+ if (vma_m->vm_ops && vma_m->vm_ops->open)
94757+ vma_m->vm_ops->open(vma_m);
94758+ BUG_ON(find_vma_links(vma->vm_mm, vma_m->vm_start, vma_m->vm_end, &prev_m, &rb_link_m, &rb_parent_m));
94759+ vma_link(vma->vm_mm, vma_m, prev_m, rb_link_m, rb_parent_m);
94760+ vma_m->vm_mirror = vma;
94761+ vma->vm_mirror = vma_m;
94762+ return 0;
94763+}
94764+#endif
94765+
94766 /*
94767 * Return true if the calling process may expand its vm space by the passed
94768 * number of pages
94769@@ -2864,6 +3403,7 @@ int may_expand_vm(struct mm_struct *mm, unsigned long npages)
94770
94771 lim = rlimit(RLIMIT_AS) >> PAGE_SHIFT;
94772
94773+ gr_learn_resource(current, RLIMIT_AS, (cur + npages) << PAGE_SHIFT, 1);
94774 if (cur + npages > lim)
94775 return 0;
94776 return 1;
94777@@ -2934,6 +3474,22 @@ int install_special_mapping(struct mm_struct *mm,
94778 vma->vm_start = addr;
94779 vma->vm_end = addr + len;
94780
94781+#ifdef CONFIG_PAX_MPROTECT
94782+ if (mm->pax_flags & MF_PAX_MPROTECT) {
94783+#ifndef CONFIG_PAX_MPROTECT_COMPAT
94784+ if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC))
94785+ return -EPERM;
94786+ if (!(vm_flags & VM_EXEC))
94787+ vm_flags &= ~VM_MAYEXEC;
94788+#else
94789+ if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
94790+ vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
94791+#endif
94792+ else
94793+ vm_flags &= ~VM_MAYWRITE;
94794+ }
94795+#endif
94796+
94797 vma->vm_flags = vm_flags | mm->def_flags | VM_DONTEXPAND | VM_SOFTDIRTY;
94798 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
94799
94800diff --git a/mm/mprotect.c b/mm/mprotect.c
94801index 769a67a..414d24f 100644
94802--- a/mm/mprotect.c
94803+++ b/mm/mprotect.c
94804@@ -24,10 +24,18 @@
94805 #include <linux/migrate.h>
94806 #include <linux/perf_event.h>
94807 #include <linux/ksm.h>
94808+#include <linux/sched/sysctl.h>
94809+
94810+#ifdef CONFIG_PAX_MPROTECT
94811+#include <linux/elf.h>
94812+#include <linux/binfmts.h>
94813+#endif
94814+
94815 #include <asm/uaccess.h>
94816 #include <asm/pgtable.h>
94817 #include <asm/cacheflush.h>
94818 #include <asm/tlbflush.h>
94819+#include <asm/mmu_context.h>
94820
94821 #ifndef pgprot_modify
94822 static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot)
94823@@ -214,6 +222,48 @@ unsigned long change_protection(struct vm_area_struct *vma, unsigned long start,
94824 return pages;
94825 }
94826
94827+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
94828+/* called while holding the mmap semaphor for writing except stack expansion */
94829+void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot)
94830+{
94831+ unsigned long oldlimit, newlimit = 0UL;
94832+
94833+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || (__supported_pte_mask & _PAGE_NX))
94834+ return;
94835+
94836+ spin_lock(&mm->page_table_lock);
94837+ oldlimit = mm->context.user_cs_limit;
94838+ if ((prot & VM_EXEC) && oldlimit < end)
94839+ /* USER_CS limit moved up */
94840+ newlimit = end;
94841+ else if (!(prot & VM_EXEC) && start < oldlimit && oldlimit <= end)
94842+ /* USER_CS limit moved down */
94843+ newlimit = start;
94844+
94845+ if (newlimit) {
94846+ mm->context.user_cs_limit = newlimit;
94847+
94848+#ifdef CONFIG_SMP
94849+ wmb();
94850+ cpus_clear(mm->context.cpu_user_cs_mask);
94851+ cpu_set(smp_processor_id(), mm->context.cpu_user_cs_mask);
94852+#endif
94853+
94854+ set_user_cs(mm->context.user_cs_base, mm->context.user_cs_limit, smp_processor_id());
94855+ }
94856+ spin_unlock(&mm->page_table_lock);
94857+ if (newlimit == end) {
94858+ struct vm_area_struct *vma = find_vma(mm, oldlimit);
94859+
94860+ for (; vma && vma->vm_start < end; vma = vma->vm_next)
94861+ if (is_vm_hugetlb_page(vma))
94862+ hugetlb_change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot);
94863+ else
94864+ change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot, vma_wants_writenotify(vma), 0);
94865+ }
94866+}
94867+#endif
94868+
94869 int
94870 mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
94871 unsigned long start, unsigned long end, unsigned long newflags)
94872@@ -226,11 +276,29 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
94873 int error;
94874 int dirty_accountable = 0;
94875
94876+#ifdef CONFIG_PAX_SEGMEXEC
94877+ struct vm_area_struct *vma_m = NULL;
94878+ unsigned long start_m, end_m;
94879+
94880+ start_m = start + SEGMEXEC_TASK_SIZE;
94881+ end_m = end + SEGMEXEC_TASK_SIZE;
94882+#endif
94883+
94884 if (newflags == oldflags) {
94885 *pprev = vma;
94886 return 0;
94887 }
94888
94889+ if (newflags & (VM_READ | VM_WRITE | VM_EXEC)) {
94890+ struct vm_area_struct *prev = vma->vm_prev, *next = vma->vm_next;
94891+
94892+ if (next && (next->vm_flags & VM_GROWSDOWN) && sysctl_heap_stack_gap > next->vm_start - end)
94893+ return -ENOMEM;
94894+
94895+ if (prev && (prev->vm_flags & VM_GROWSUP) && sysctl_heap_stack_gap > start - prev->vm_end)
94896+ return -ENOMEM;
94897+ }
94898+
94899 /*
94900 * If we make a private mapping writable we increase our commit;
94901 * but (without finer accounting) cannot reduce our commit if we
94902@@ -247,6 +315,42 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
94903 }
94904 }
94905
94906+#ifdef CONFIG_PAX_SEGMEXEC
94907+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && ((oldflags ^ newflags) & VM_EXEC)) {
94908+ if (start != vma->vm_start) {
94909+ error = split_vma(mm, vma, start, 1);
94910+ if (error)
94911+ goto fail;
94912+ BUG_ON(!*pprev || (*pprev)->vm_next == vma);
94913+ *pprev = (*pprev)->vm_next;
94914+ }
94915+
94916+ if (end != vma->vm_end) {
94917+ error = split_vma(mm, vma, end, 0);
94918+ if (error)
94919+ goto fail;
94920+ }
94921+
94922+ if (pax_find_mirror_vma(vma)) {
94923+ error = __do_munmap(mm, start_m, end_m - start_m);
94924+ if (error)
94925+ goto fail;
94926+ } else {
94927+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
94928+ if (!vma_m) {
94929+ error = -ENOMEM;
94930+ goto fail;
94931+ }
94932+ vma->vm_flags = newflags;
94933+ error = pax_mirror_vma(vma_m, vma);
94934+ if (error) {
94935+ vma->vm_flags = oldflags;
94936+ goto fail;
94937+ }
94938+ }
94939+ }
94940+#endif
94941+
94942 /*
94943 * First try to merge with previous and/or next vma.
94944 */
94945@@ -277,9 +381,21 @@ success:
94946 * vm_flags and vm_page_prot are protected by the mmap_sem
94947 * held in write mode.
94948 */
94949+
94950+#ifdef CONFIG_PAX_SEGMEXEC
94951+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (newflags & VM_EXEC) && ((vma->vm_flags ^ newflags) & VM_READ))
94952+ pax_find_mirror_vma(vma)->vm_flags ^= VM_READ;
94953+#endif
94954+
94955 vma->vm_flags = newflags;
94956+
94957+#ifdef CONFIG_PAX_MPROTECT
94958+ if (mm->binfmt && mm->binfmt->handle_mprotect)
94959+ mm->binfmt->handle_mprotect(vma, newflags);
94960+#endif
94961+
94962 vma->vm_page_prot = pgprot_modify(vma->vm_page_prot,
94963- vm_get_page_prot(newflags));
94964+ vm_get_page_prot(vma->vm_flags));
94965
94966 if (vma_wants_writenotify(vma)) {
94967 vma->vm_page_prot = vm_get_page_prot(newflags & ~VM_SHARED);
94968@@ -318,6 +434,17 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
94969 end = start + len;
94970 if (end <= start)
94971 return -ENOMEM;
94972+
94973+#ifdef CONFIG_PAX_SEGMEXEC
94974+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
94975+ if (end > SEGMEXEC_TASK_SIZE)
94976+ return -EINVAL;
94977+ } else
94978+#endif
94979+
94980+ if (end > TASK_SIZE)
94981+ return -EINVAL;
94982+
94983 if (!arch_validate_prot(prot))
94984 return -EINVAL;
94985
94986@@ -325,7 +452,7 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
94987 /*
94988 * Does the application expect PROT_READ to imply PROT_EXEC:
94989 */
94990- if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
94991+ if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
94992 prot |= PROT_EXEC;
94993
94994 vm_flags = calc_vm_prot_bits(prot);
94995@@ -357,6 +484,11 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
94996 if (start > vma->vm_start)
94997 prev = vma;
94998
94999+#ifdef CONFIG_PAX_MPROTECT
95000+ if (current->mm->binfmt && current->mm->binfmt->handle_mprotect)
95001+ current->mm->binfmt->handle_mprotect(vma, vm_flags);
95002+#endif
95003+
95004 for (nstart = start ; ; ) {
95005 unsigned long newflags;
95006
95007@@ -367,6 +499,14 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
95008
95009 /* newflags >> 4 shift VM_MAY% in place of VM_% */
95010 if ((newflags & ~(newflags >> 4)) & (VM_READ | VM_WRITE | VM_EXEC)) {
95011+ if (prot & (PROT_WRITE | PROT_EXEC))
95012+ gr_log_rwxmprotect(vma);
95013+
95014+ error = -EACCES;
95015+ goto out;
95016+ }
95017+
95018+ if (!gr_acl_handle_mprotect(vma->vm_file, prot)) {
95019 error = -EACCES;
95020 goto out;
95021 }
95022@@ -381,6 +521,9 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
95023 error = mprotect_fixup(vma, &prev, nstart, tmp, newflags);
95024 if (error)
95025 goto out;
95026+
95027+ track_exec_limit(current->mm, nstart, tmp, vm_flags);
95028+
95029 nstart = tmp;
95030
95031 if (nstart < prev->vm_end)
95032diff --git a/mm/mremap.c b/mm/mremap.c
95033index 0843feb..c3cde48 100644
95034--- a/mm/mremap.c
95035+++ b/mm/mremap.c
95036@@ -144,6 +144,12 @@ static void move_ptes(struct vm_area_struct *vma, pmd_t *old_pmd,
95037 continue;
95038 pte = ptep_get_and_clear(mm, old_addr, old_pte);
95039 pte = move_pte(pte, new_vma->vm_page_prot, old_addr, new_addr);
95040+
95041+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
95042+ if (!(__supported_pte_mask & _PAGE_NX) && pte_present(pte) && (new_vma->vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC)
95043+ pte = pte_exprotect(pte);
95044+#endif
95045+
95046 pte = move_soft_dirty_pte(pte);
95047 set_pte_at(mm, new_addr, new_pte, pte);
95048 }
95049@@ -194,10 +200,17 @@ unsigned long move_page_tables(struct vm_area_struct *vma,
95050 break;
95051 if (pmd_trans_huge(*old_pmd)) {
95052 int err = 0;
95053- if (extent == HPAGE_PMD_SIZE)
95054+ if (extent == HPAGE_PMD_SIZE) {
95055+ VM_BUG_ON(vma->vm_file || !vma->anon_vma);
95056+ /* See comment in move_ptes() */
95057+ if (need_rmap_locks)
95058+ anon_vma_lock_write(vma->anon_vma);
95059 err = move_huge_pmd(vma, new_vma, old_addr,
95060 new_addr, old_end,
95061 old_pmd, new_pmd);
95062+ if (need_rmap_locks)
95063+ anon_vma_unlock_write(vma->anon_vma);
95064+ }
95065 if (err > 0) {
95066 need_flush = true;
95067 continue;
95068@@ -337,6 +350,11 @@ static struct vm_area_struct *vma_to_resize(unsigned long addr,
95069 if (is_vm_hugetlb_page(vma))
95070 goto Einval;
95071
95072+#ifdef CONFIG_PAX_SEGMEXEC
95073+ if (pax_find_mirror_vma(vma))
95074+ goto Einval;
95075+#endif
95076+
95077 /* We can't remap across vm area boundaries */
95078 if (old_len > vma->vm_end - addr)
95079 goto Efault;
95080@@ -392,20 +410,25 @@ static unsigned long mremap_to(unsigned long addr, unsigned long old_len,
95081 unsigned long ret = -EINVAL;
95082 unsigned long charged = 0;
95083 unsigned long map_flags;
95084+ unsigned long pax_task_size = TASK_SIZE;
95085
95086 if (new_addr & ~PAGE_MASK)
95087 goto out;
95088
95089- if (new_len > TASK_SIZE || new_addr > TASK_SIZE - new_len)
95090+#ifdef CONFIG_PAX_SEGMEXEC
95091+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
95092+ pax_task_size = SEGMEXEC_TASK_SIZE;
95093+#endif
95094+
95095+ pax_task_size -= PAGE_SIZE;
95096+
95097+ if (new_len > TASK_SIZE || new_addr > pax_task_size - new_len)
95098 goto out;
95099
95100 /* Check if the location we're moving into overlaps the
95101 * old location at all, and fail if it does.
95102 */
95103- if ((new_addr <= addr) && (new_addr+new_len) > addr)
95104- goto out;
95105-
95106- if ((addr <= new_addr) && (addr+old_len) > new_addr)
95107+ if (addr + old_len > new_addr && new_addr + new_len > addr)
95108 goto out;
95109
95110 ret = do_munmap(mm, new_addr, new_len);
95111@@ -474,6 +497,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
95112 unsigned long ret = -EINVAL;
95113 unsigned long charged = 0;
95114 bool locked = false;
95115+ unsigned long pax_task_size = TASK_SIZE;
95116
95117 if (flags & ~(MREMAP_FIXED | MREMAP_MAYMOVE))
95118 return ret;
95119@@ -495,6 +519,17 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
95120 if (!new_len)
95121 return ret;
95122
95123+#ifdef CONFIG_PAX_SEGMEXEC
95124+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
95125+ pax_task_size = SEGMEXEC_TASK_SIZE;
95126+#endif
95127+
95128+ pax_task_size -= PAGE_SIZE;
95129+
95130+ if (new_len > pax_task_size || addr > pax_task_size-new_len ||
95131+ old_len > pax_task_size || addr > pax_task_size-old_len)
95132+ return ret;
95133+
95134 down_write(&current->mm->mmap_sem);
95135
95136 if (flags & MREMAP_FIXED) {
95137@@ -545,6 +580,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
95138 new_addr = addr;
95139 }
95140 ret = addr;
95141+ track_exec_limit(vma->vm_mm, vma->vm_start, addr + new_len, vma->vm_flags);
95142 goto out;
95143 }
95144 }
95145@@ -568,7 +604,12 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
95146 goto out;
95147 }
95148
95149+ map_flags = vma->vm_flags;
95150 ret = move_vma(vma, addr, old_len, new_len, new_addr, &locked);
95151+ if (!(ret & ~PAGE_MASK)) {
95152+ track_exec_limit(current->mm, addr, addr + old_len, 0UL);
95153+ track_exec_limit(current->mm, new_addr, new_addr + new_len, map_flags);
95154+ }
95155 }
95156 out:
95157 if (ret & ~PAGE_MASK)
95158diff --git a/mm/nommu.c b/mm/nommu.c
95159index 8740213..f87e25b 100644
95160--- a/mm/nommu.c
95161+++ b/mm/nommu.c
95162@@ -65,7 +65,6 @@ int sysctl_max_map_count = DEFAULT_MAX_MAP_COUNT;
95163 int sysctl_nr_trim_pages = CONFIG_NOMMU_INITIAL_TRIM_EXCESS;
95164 unsigned long sysctl_user_reserve_kbytes __read_mostly = 1UL << 17; /* 128MB */
95165 unsigned long sysctl_admin_reserve_kbytes __read_mostly = 1UL << 13; /* 8MB */
95166-int heap_stack_gap = 0;
95167
95168 atomic_long_t mmap_pages_allocated;
95169
95170@@ -845,15 +844,6 @@ struct vm_area_struct *find_vma(struct mm_struct *mm, unsigned long addr)
95171 EXPORT_SYMBOL(find_vma);
95172
95173 /*
95174- * find a VMA
95175- * - we don't extend stack VMAs under NOMMU conditions
95176- */
95177-struct vm_area_struct *find_extend_vma(struct mm_struct *mm, unsigned long addr)
95178-{
95179- return find_vma(mm, addr);
95180-}
95181-
95182-/*
95183 * expand a stack to a given address
95184 * - not supported under NOMMU conditions
95185 */
95186@@ -1564,6 +1554,7 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
95187
95188 /* most fields are the same, copy all, and then fixup */
95189 *new = *vma;
95190+ INIT_LIST_HEAD(&new->anon_vma_chain);
95191 *region = *vma->vm_region;
95192 new->vm_region = region;
95193
95194@@ -1993,8 +1984,8 @@ int generic_file_remap_pages(struct vm_area_struct *vma, unsigned long addr,
95195 }
95196 EXPORT_SYMBOL(generic_file_remap_pages);
95197
95198-static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
95199- unsigned long addr, void *buf, int len, int write)
95200+static ssize_t __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
95201+ unsigned long addr, void *buf, size_t len, int write)
95202 {
95203 struct vm_area_struct *vma;
95204
95205@@ -2035,8 +2026,8 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
95206 *
95207 * The caller must hold a reference on @mm.
95208 */
95209-int access_remote_vm(struct mm_struct *mm, unsigned long addr,
95210- void *buf, int len, int write)
95211+ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
95212+ void *buf, size_t len, int write)
95213 {
95214 return __access_remote_vm(NULL, mm, addr, buf, len, write);
95215 }
95216@@ -2045,7 +2036,7 @@ int access_remote_vm(struct mm_struct *mm, unsigned long addr,
95217 * Access another process' address space.
95218 * - source/target buffer must be kernel space
95219 */
95220-int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write)
95221+ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, size_t len, int write)
95222 {
95223 struct mm_struct *mm;
95224
95225diff --git a/mm/page-writeback.c b/mm/page-writeback.c
95226index 7106cb1..0805f48 100644
95227--- a/mm/page-writeback.c
95228+++ b/mm/page-writeback.c
95229@@ -685,7 +685,7 @@ static inline long long pos_ratio_polynom(unsigned long setpoint,
95230 * card's bdi_dirty may rush to many times higher than bdi_setpoint.
95231 * - the bdi dirty thresh drops quickly due to change of JBOD workload
95232 */
95233-static unsigned long bdi_position_ratio(struct backing_dev_info *bdi,
95234+static unsigned long __intentional_overflow(-1) bdi_position_ratio(struct backing_dev_info *bdi,
95235 unsigned long thresh,
95236 unsigned long bg_thresh,
95237 unsigned long dirty,
95238diff --git a/mm/page_alloc.c b/mm/page_alloc.c
95239index 7387a67..67105e4 100644
95240--- a/mm/page_alloc.c
95241+++ b/mm/page_alloc.c
95242@@ -61,6 +61,7 @@
95243 #include <linux/page-debug-flags.h>
95244 #include <linux/hugetlb.h>
95245 #include <linux/sched/rt.h>
95246+#include <linux/random.h>
95247
95248 #include <asm/sections.h>
95249 #include <asm/tlbflush.h>
95250@@ -354,7 +355,7 @@ out:
95251 * This usage means that zero-order pages may not be compound.
95252 */
95253
95254-static void free_compound_page(struct page *page)
95255+void free_compound_page(struct page *page)
95256 {
95257 __free_pages_ok(page, compound_order(page));
95258 }
95259@@ -728,6 +729,10 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
95260 int i;
95261 int bad = 0;
95262
95263+#ifdef CONFIG_PAX_MEMORY_SANITIZE
95264+ unsigned long index = 1UL << order;
95265+#endif
95266+
95267 trace_mm_page_free(page, order);
95268 kmemcheck_free_shadow(page, order);
95269
95270@@ -744,6 +749,12 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
95271 debug_check_no_obj_freed(page_address(page),
95272 PAGE_SIZE << order);
95273 }
95274+
95275+#ifdef CONFIG_PAX_MEMORY_SANITIZE
95276+ for (; index; --index)
95277+ sanitize_highpage(page + index - 1);
95278+#endif
95279+
95280 arch_free_page(page, order);
95281 kernel_map_pages(page, 1 << order, 0);
95282
95283@@ -766,6 +777,20 @@ static void __free_pages_ok(struct page *page, unsigned int order)
95284 local_irq_restore(flags);
95285 }
95286
95287+#ifdef CONFIG_PAX_LATENT_ENTROPY
95288+bool __meminitdata extra_latent_entropy;
95289+
95290+static int __init setup_pax_extra_latent_entropy(char *str)
95291+{
95292+ extra_latent_entropy = true;
95293+ return 0;
95294+}
95295+early_param("pax_extra_latent_entropy", setup_pax_extra_latent_entropy);
95296+
95297+volatile u64 latent_entropy __latent_entropy;
95298+EXPORT_SYMBOL(latent_entropy);
95299+#endif
95300+
95301 void __init __free_pages_bootmem(struct page *page, unsigned int order)
95302 {
95303 unsigned int nr_pages = 1 << order;
95304@@ -781,6 +806,19 @@ void __init __free_pages_bootmem(struct page *page, unsigned int order)
95305 __ClearPageReserved(p);
95306 set_page_count(p, 0);
95307
95308+#ifdef CONFIG_PAX_LATENT_ENTROPY
95309+ if (extra_latent_entropy && !PageHighMem(page) && page_to_pfn(page) < 0x100000) {
95310+ u64 hash = 0;
95311+ size_t index, end = PAGE_SIZE * nr_pages / sizeof hash;
95312+ const u64 *data = lowmem_page_address(page);
95313+
95314+ for (index = 0; index < end; index++)
95315+ hash ^= hash + data[index];
95316+ latent_entropy ^= hash;
95317+ add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
95318+ }
95319+#endif
95320+
95321 page_zone(page)->managed_pages += nr_pages;
95322 set_page_refcounted(page);
95323 __free_pages(page, order);
95324@@ -897,8 +935,10 @@ static int prep_new_page(struct page *page, int order, gfp_t gfp_flags)
95325 arch_alloc_page(page, order);
95326 kernel_map_pages(page, 1 << order, 1);
95327
95328+#ifndef CONFIG_PAX_MEMORY_SANITIZE
95329 if (gfp_flags & __GFP_ZERO)
95330 prep_zero_page(page, order, gfp_flags);
95331+#endif
95332
95333 if (order && (gfp_flags & __GFP_COMP))
95334 prep_compound_page(page, order);
95335@@ -2401,7 +2441,7 @@ static void reset_alloc_batches(struct zonelist *zonelist,
95336 continue;
95337 mod_zone_page_state(zone, NR_ALLOC_BATCH,
95338 high_wmark_pages(zone) - low_wmark_pages(zone) -
95339- atomic_long_read(&zone->vm_stat[NR_ALLOC_BATCH]));
95340+ atomic_long_read_unchecked(&zone->vm_stat[NR_ALLOC_BATCH]));
95341 }
95342 }
95343
95344@@ -6565,4 +6605,4 @@ void dump_page(struct page *page, char *reason)
95345 {
95346 dump_page_badflags(page, reason, 0);
95347 }
95348-EXPORT_SYMBOL_GPL(dump_page);
95349+EXPORT_SYMBOL(dump_page);
95350diff --git a/mm/page_io.c b/mm/page_io.c
95351index 7c59ef6..1358905 100644
95352--- a/mm/page_io.c
95353+++ b/mm/page_io.c
95354@@ -260,7 +260,7 @@ int __swap_writepage(struct page *page, struct writeback_control *wbc,
95355 struct file *swap_file = sis->swap_file;
95356 struct address_space *mapping = swap_file->f_mapping;
95357 struct iovec iov = {
95358- .iov_base = kmap(page),
95359+ .iov_base = (void __force_user *)kmap(page),
95360 .iov_len = PAGE_SIZE,
95361 };
95362
95363diff --git a/mm/percpu.c b/mm/percpu.c
95364index 036cfe0..980d0fa 100644
95365--- a/mm/percpu.c
95366+++ b/mm/percpu.c
95367@@ -122,7 +122,7 @@ static unsigned int pcpu_low_unit_cpu __read_mostly;
95368 static unsigned int pcpu_high_unit_cpu __read_mostly;
95369
95370 /* the address of the first chunk which starts with the kernel static area */
95371-void *pcpu_base_addr __read_mostly;
95372+void *pcpu_base_addr __read_only;
95373 EXPORT_SYMBOL_GPL(pcpu_base_addr);
95374
95375 static const int *pcpu_unit_map __read_mostly; /* cpu -> unit */
95376diff --git a/mm/process_vm_access.c b/mm/process_vm_access.c
95377index fd26d04..0cea1b0 100644
95378--- a/mm/process_vm_access.c
95379+++ b/mm/process_vm_access.c
95380@@ -13,6 +13,7 @@
95381 #include <linux/uio.h>
95382 #include <linux/sched.h>
95383 #include <linux/highmem.h>
95384+#include <linux/security.h>
95385 #include <linux/ptrace.h>
95386 #include <linux/slab.h>
95387 #include <linux/syscalls.h>
95388@@ -258,19 +259,19 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
95389 size_t iov_l_curr_offset = 0;
95390 ssize_t iov_len;
95391
95392+ return -ENOSYS; // PaX: until properly audited
95393+
95394 /*
95395 * Work out how many pages of struct pages we're going to need
95396 * when eventually calling get_user_pages
95397 */
95398 for (i = 0; i < riovcnt; i++) {
95399 iov_len = rvec[i].iov_len;
95400- if (iov_len > 0) {
95401- nr_pages_iov = ((unsigned long)rvec[i].iov_base
95402- + iov_len)
95403- / PAGE_SIZE - (unsigned long)rvec[i].iov_base
95404- / PAGE_SIZE + 1;
95405- nr_pages = max(nr_pages, nr_pages_iov);
95406- }
95407+ if (iov_len <= 0)
95408+ continue;
95409+ nr_pages_iov = ((unsigned long)rvec[i].iov_base + iov_len) / PAGE_SIZE -
95410+ (unsigned long)rvec[i].iov_base / PAGE_SIZE + 1;
95411+ nr_pages = max(nr_pages, nr_pages_iov);
95412 }
95413
95414 if (nr_pages == 0)
95415@@ -298,6 +299,11 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
95416 goto free_proc_pages;
95417 }
95418
95419+ if (gr_handle_ptrace(task, vm_write ? PTRACE_POKETEXT : PTRACE_ATTACH)) {
95420+ rc = -EPERM;
95421+ goto put_task_struct;
95422+ }
95423+
95424 mm = mm_access(task, PTRACE_MODE_ATTACH);
95425 if (!mm || IS_ERR(mm)) {
95426 rc = IS_ERR(mm) ? PTR_ERR(mm) : -ESRCH;
95427diff --git a/mm/rmap.c b/mm/rmap.c
95428index d3cbac5..0788da4 100644
95429--- a/mm/rmap.c
95430+++ b/mm/rmap.c
95431@@ -163,6 +163,10 @@ int anon_vma_prepare(struct vm_area_struct *vma)
95432 struct anon_vma *anon_vma = vma->anon_vma;
95433 struct anon_vma_chain *avc;
95434
95435+#ifdef CONFIG_PAX_SEGMEXEC
95436+ struct anon_vma_chain *avc_m = NULL;
95437+#endif
95438+
95439 might_sleep();
95440 if (unlikely(!anon_vma)) {
95441 struct mm_struct *mm = vma->vm_mm;
95442@@ -172,6 +176,12 @@ int anon_vma_prepare(struct vm_area_struct *vma)
95443 if (!avc)
95444 goto out_enomem;
95445
95446+#ifdef CONFIG_PAX_SEGMEXEC
95447+ avc_m = anon_vma_chain_alloc(GFP_KERNEL);
95448+ if (!avc_m)
95449+ goto out_enomem_free_avc;
95450+#endif
95451+
95452 anon_vma = find_mergeable_anon_vma(vma);
95453 allocated = NULL;
95454 if (!anon_vma) {
95455@@ -185,6 +195,18 @@ int anon_vma_prepare(struct vm_area_struct *vma)
95456 /* page_table_lock to protect against threads */
95457 spin_lock(&mm->page_table_lock);
95458 if (likely(!vma->anon_vma)) {
95459+
95460+#ifdef CONFIG_PAX_SEGMEXEC
95461+ struct vm_area_struct *vma_m = pax_find_mirror_vma(vma);
95462+
95463+ if (vma_m) {
95464+ BUG_ON(vma_m->anon_vma);
95465+ vma_m->anon_vma = anon_vma;
95466+ anon_vma_chain_link(vma_m, avc_m, anon_vma);
95467+ avc_m = NULL;
95468+ }
95469+#endif
95470+
95471 vma->anon_vma = anon_vma;
95472 anon_vma_chain_link(vma, avc, anon_vma);
95473 allocated = NULL;
95474@@ -195,12 +217,24 @@ int anon_vma_prepare(struct vm_area_struct *vma)
95475
95476 if (unlikely(allocated))
95477 put_anon_vma(allocated);
95478+
95479+#ifdef CONFIG_PAX_SEGMEXEC
95480+ if (unlikely(avc_m))
95481+ anon_vma_chain_free(avc_m);
95482+#endif
95483+
95484 if (unlikely(avc))
95485 anon_vma_chain_free(avc);
95486 }
95487 return 0;
95488
95489 out_enomem_free_avc:
95490+
95491+#ifdef CONFIG_PAX_SEGMEXEC
95492+ if (avc_m)
95493+ anon_vma_chain_free(avc_m);
95494+#endif
95495+
95496 anon_vma_chain_free(avc);
95497 out_enomem:
95498 return -ENOMEM;
95499@@ -236,7 +270,7 @@ static inline void unlock_anon_vma_root(struct anon_vma *root)
95500 * Attach the anon_vmas from src to dst.
95501 * Returns 0 on success, -ENOMEM on failure.
95502 */
95503-int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
95504+int anon_vma_clone(struct vm_area_struct *dst, const struct vm_area_struct *src)
95505 {
95506 struct anon_vma_chain *avc, *pavc;
95507 struct anon_vma *root = NULL;
95508@@ -269,7 +303,7 @@ int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
95509 * the corresponding VMA in the parent process is attached to.
95510 * Returns 0 on success, non-zero on failure.
95511 */
95512-int anon_vma_fork(struct vm_area_struct *vma, struct vm_area_struct *pvma)
95513+int anon_vma_fork(struct vm_area_struct *vma, const struct vm_area_struct *pvma)
95514 {
95515 struct anon_vma_chain *avc;
95516 struct anon_vma *anon_vma;
95517@@ -373,8 +407,10 @@ static void anon_vma_ctor(void *data)
95518 void __init anon_vma_init(void)
95519 {
95520 anon_vma_cachep = kmem_cache_create("anon_vma", sizeof(struct anon_vma),
95521- 0, SLAB_DESTROY_BY_RCU|SLAB_PANIC, anon_vma_ctor);
95522- anon_vma_chain_cachep = KMEM_CACHE(anon_vma_chain, SLAB_PANIC);
95523+ 0, SLAB_DESTROY_BY_RCU|SLAB_PANIC|SLAB_NO_SANITIZE,
95524+ anon_vma_ctor);
95525+ anon_vma_chain_cachep = KMEM_CACHE(anon_vma_chain,
95526+ SLAB_PANIC|SLAB_NO_SANITIZE);
95527 }
95528
95529 /*
95530diff --git a/mm/shmem.c b/mm/shmem.c
95531index 1f18c9d..3e03d33 100644
95532--- a/mm/shmem.c
95533+++ b/mm/shmem.c
95534@@ -33,7 +33,7 @@
95535 #include <linux/swap.h>
95536 #include <linux/aio.h>
95537
95538-static struct vfsmount *shm_mnt;
95539+struct vfsmount *shm_mnt;
95540
95541 #ifdef CONFIG_SHMEM
95542 /*
95543@@ -77,7 +77,7 @@ static struct vfsmount *shm_mnt;
95544 #define BOGO_DIRENT_SIZE 20
95545
95546 /* Symlink up to this size is kmalloc'ed instead of using a swappable page */
95547-#define SHORT_SYMLINK_LEN 128
95548+#define SHORT_SYMLINK_LEN 64
95549
95550 /*
95551 * shmem_fallocate and shmem_writepage communicate via inode->i_private
95552@@ -2218,6 +2218,11 @@ static const struct xattr_handler *shmem_xattr_handlers[] = {
95553 static int shmem_xattr_validate(const char *name)
95554 {
95555 struct { const char *prefix; size_t len; } arr[] = {
95556+
95557+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
95558+ { XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN},
95559+#endif
95560+
95561 { XATTR_SECURITY_PREFIX, XATTR_SECURITY_PREFIX_LEN },
95562 { XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN }
95563 };
95564@@ -2273,6 +2278,15 @@ static int shmem_setxattr(struct dentry *dentry, const char *name,
95565 if (err)
95566 return err;
95567
95568+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
95569+ if (!strncmp(name, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN)) {
95570+ if (strcmp(name, XATTR_NAME_PAX_FLAGS))
95571+ return -EOPNOTSUPP;
95572+ if (size > 8)
95573+ return -EINVAL;
95574+ }
95575+#endif
95576+
95577 return simple_xattr_set(&info->xattrs, name, value, size, flags);
95578 }
95579
95580@@ -2585,8 +2599,7 @@ int shmem_fill_super(struct super_block *sb, void *data, int silent)
95581 int err = -ENOMEM;
95582
95583 /* Round up to L1_CACHE_BYTES to resist false sharing */
95584- sbinfo = kzalloc(max((int)sizeof(struct shmem_sb_info),
95585- L1_CACHE_BYTES), GFP_KERNEL);
95586+ sbinfo = kzalloc(max(sizeof(struct shmem_sb_info), L1_CACHE_BYTES), GFP_KERNEL);
95587 if (!sbinfo)
95588 return -ENOMEM;
95589
95590diff --git a/mm/slab.c b/mm/slab.c
95591index b264214..83872cd 100644
95592--- a/mm/slab.c
95593+++ b/mm/slab.c
95594@@ -300,10 +300,12 @@ static void kmem_cache_node_init(struct kmem_cache_node *parent)
95595 if ((x)->max_freeable < i) \
95596 (x)->max_freeable = i; \
95597 } while (0)
95598-#define STATS_INC_ALLOCHIT(x) atomic_inc(&(x)->allochit)
95599-#define STATS_INC_ALLOCMISS(x) atomic_inc(&(x)->allocmiss)
95600-#define STATS_INC_FREEHIT(x) atomic_inc(&(x)->freehit)
95601-#define STATS_INC_FREEMISS(x) atomic_inc(&(x)->freemiss)
95602+#define STATS_INC_ALLOCHIT(x) atomic_inc_unchecked(&(x)->allochit)
95603+#define STATS_INC_ALLOCMISS(x) atomic_inc_unchecked(&(x)->allocmiss)
95604+#define STATS_INC_FREEHIT(x) atomic_inc_unchecked(&(x)->freehit)
95605+#define STATS_INC_FREEMISS(x) atomic_inc_unchecked(&(x)->freemiss)
95606+#define STATS_INC_SANITIZED(x) atomic_inc_unchecked(&(x)->sanitized)
95607+#define STATS_INC_NOT_SANITIZED(x) atomic_inc_unchecked(&(x)->not_sanitized)
95608 #else
95609 #define STATS_INC_ACTIVE(x) do { } while (0)
95610 #define STATS_DEC_ACTIVE(x) do { } while (0)
95611@@ -320,6 +322,8 @@ static void kmem_cache_node_init(struct kmem_cache_node *parent)
95612 #define STATS_INC_ALLOCMISS(x) do { } while (0)
95613 #define STATS_INC_FREEHIT(x) do { } while (0)
95614 #define STATS_INC_FREEMISS(x) do { } while (0)
95615+#define STATS_INC_SANITIZED(x) do { } while (0)
95616+#define STATS_INC_NOT_SANITIZED(x) do { } while (0)
95617 #endif
95618
95619 #if DEBUG
95620@@ -403,7 +407,7 @@ static inline void *index_to_obj(struct kmem_cache *cache, struct page *page,
95621 * reciprocal_divide(offset, cache->reciprocal_buffer_size)
95622 */
95623 static inline unsigned int obj_to_index(const struct kmem_cache *cache,
95624- const struct page *page, void *obj)
95625+ const struct page *page, const void *obj)
95626 {
95627 u32 offset = (obj - page->s_mem);
95628 return reciprocal_divide(offset, cache->reciprocal_buffer_size);
95629@@ -1489,12 +1493,12 @@ void __init kmem_cache_init(void)
95630 */
95631
95632 kmalloc_caches[INDEX_AC] = create_kmalloc_cache("kmalloc-ac",
95633- kmalloc_size(INDEX_AC), ARCH_KMALLOC_FLAGS);
95634+ kmalloc_size(INDEX_AC), SLAB_USERCOPY | ARCH_KMALLOC_FLAGS);
95635
95636 if (INDEX_AC != INDEX_NODE)
95637 kmalloc_caches[INDEX_NODE] =
95638 create_kmalloc_cache("kmalloc-node",
95639- kmalloc_size(INDEX_NODE), ARCH_KMALLOC_FLAGS);
95640+ kmalloc_size(INDEX_NODE), SLAB_USERCOPY | ARCH_KMALLOC_FLAGS);
95641
95642 slab_early_init = 0;
95643
95644@@ -3428,6 +3432,21 @@ static inline void __cache_free(struct kmem_cache *cachep, void *objp,
95645 struct array_cache *ac = cpu_cache_get(cachep);
95646
95647 check_irq_off();
95648+
95649+#ifdef CONFIG_PAX_MEMORY_SANITIZE
95650+ if (pax_sanitize_slab) {
95651+ if (!(cachep->flags & (SLAB_POISON | SLAB_NO_SANITIZE))) {
95652+ memset(objp, PAX_MEMORY_SANITIZE_VALUE, cachep->object_size);
95653+
95654+ if (cachep->ctor)
95655+ cachep->ctor(objp);
95656+
95657+ STATS_INC_SANITIZED(cachep);
95658+ } else
95659+ STATS_INC_NOT_SANITIZED(cachep);
95660+ }
95661+#endif
95662+
95663 kmemleak_free_recursive(objp, cachep->flags);
95664 objp = cache_free_debugcheck(cachep, objp, caller);
95665
95666@@ -3656,6 +3675,7 @@ void kfree(const void *objp)
95667
95668 if (unlikely(ZERO_OR_NULL_PTR(objp)))
95669 return;
95670+ VM_BUG_ON(!virt_addr_valid(objp));
95671 local_irq_save(flags);
95672 kfree_debugcheck(objp);
95673 c = virt_to_cache(objp);
95674@@ -4097,14 +4117,22 @@ void slabinfo_show_stats(struct seq_file *m, struct kmem_cache *cachep)
95675 }
95676 /* cpu stats */
95677 {
95678- unsigned long allochit = atomic_read(&cachep->allochit);
95679- unsigned long allocmiss = atomic_read(&cachep->allocmiss);
95680- unsigned long freehit = atomic_read(&cachep->freehit);
95681- unsigned long freemiss = atomic_read(&cachep->freemiss);
95682+ unsigned long allochit = atomic_read_unchecked(&cachep->allochit);
95683+ unsigned long allocmiss = atomic_read_unchecked(&cachep->allocmiss);
95684+ unsigned long freehit = atomic_read_unchecked(&cachep->freehit);
95685+ unsigned long freemiss = atomic_read_unchecked(&cachep->freemiss);
95686
95687 seq_printf(m, " : cpustat %6lu %6lu %6lu %6lu",
95688 allochit, allocmiss, freehit, freemiss);
95689 }
95690+#ifdef CONFIG_PAX_MEMORY_SANITIZE
95691+ {
95692+ unsigned long sanitized = atomic_read_unchecked(&cachep->sanitized);
95693+ unsigned long not_sanitized = atomic_read_unchecked(&cachep->not_sanitized);
95694+
95695+ seq_printf(m, " : pax %6lu %6lu", sanitized, not_sanitized);
95696+ }
95697+#endif
95698 #endif
95699 }
95700
95701@@ -4334,13 +4362,69 @@ static const struct file_operations proc_slabstats_operations = {
95702 static int __init slab_proc_init(void)
95703 {
95704 #ifdef CONFIG_DEBUG_SLAB_LEAK
95705- proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations);
95706+ proc_create("slab_allocators", S_IRUSR, NULL, &proc_slabstats_operations);
95707 #endif
95708 return 0;
95709 }
95710 module_init(slab_proc_init);
95711 #endif
95712
95713+bool is_usercopy_object(const void *ptr)
95714+{
95715+ struct page *page;
95716+ struct kmem_cache *cachep;
95717+
95718+ if (ZERO_OR_NULL_PTR(ptr))
95719+ return false;
95720+
95721+ if (!slab_is_available())
95722+ return false;
95723+
95724+ if (!virt_addr_valid(ptr))
95725+ return false;
95726+
95727+ page = virt_to_head_page(ptr);
95728+
95729+ if (!PageSlab(page))
95730+ return false;
95731+
95732+ cachep = page->slab_cache;
95733+ return cachep->flags & SLAB_USERCOPY;
95734+}
95735+
95736+#ifdef CONFIG_PAX_USERCOPY
95737+const char *check_heap_object(const void *ptr, unsigned long n)
95738+{
95739+ struct page *page;
95740+ struct kmem_cache *cachep;
95741+ unsigned int objnr;
95742+ unsigned long offset;
95743+
95744+ if (ZERO_OR_NULL_PTR(ptr))
95745+ return "<null>";
95746+
95747+ if (!virt_addr_valid(ptr))
95748+ return NULL;
95749+
95750+ page = virt_to_head_page(ptr);
95751+
95752+ if (!PageSlab(page))
95753+ return NULL;
95754+
95755+ cachep = page->slab_cache;
95756+ if (!(cachep->flags & SLAB_USERCOPY))
95757+ return cachep->name;
95758+
95759+ objnr = obj_to_index(cachep, page, ptr);
95760+ BUG_ON(objnr >= cachep->num);
95761+ offset = ptr - index_to_obj(cachep, page, objnr) - obj_offset(cachep);
95762+ if (offset <= cachep->object_size && n <= cachep->object_size - offset)
95763+ return NULL;
95764+
95765+ return cachep->name;
95766+}
95767+#endif
95768+
95769 /**
95770 * ksize - get the actual amount of memory allocated for a given object
95771 * @objp: Pointer to the object
95772diff --git a/mm/slab.h b/mm/slab.h
95773index 8184a7c..ab27737 100644
95774--- a/mm/slab.h
95775+++ b/mm/slab.h
95776@@ -32,6 +32,15 @@ extern struct list_head slab_caches;
95777 /* The slab cache that manages slab cache information */
95778 extern struct kmem_cache *kmem_cache;
95779
95780+#ifdef CONFIG_PAX_MEMORY_SANITIZE
95781+#ifdef CONFIG_X86_64
95782+#define PAX_MEMORY_SANITIZE_VALUE '\xfe'
95783+#else
95784+#define PAX_MEMORY_SANITIZE_VALUE '\xff'
95785+#endif
95786+extern bool pax_sanitize_slab;
95787+#endif
95788+
95789 unsigned long calculate_alignment(unsigned long flags,
95790 unsigned long align, unsigned long size);
95791
95792@@ -67,7 +76,8 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
95793
95794 /* Legal flag mask for kmem_cache_create(), for various configurations */
95795 #define SLAB_CORE_FLAGS (SLAB_HWCACHE_ALIGN | SLAB_CACHE_DMA | SLAB_PANIC | \
95796- SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS )
95797+ SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS | \
95798+ SLAB_USERCOPY | SLAB_NO_SANITIZE)
95799
95800 #if defined(CONFIG_DEBUG_SLAB)
95801 #define SLAB_DEBUG_FLAGS (SLAB_RED_ZONE | SLAB_POISON | SLAB_STORE_USER)
95802@@ -257,6 +267,9 @@ static inline struct kmem_cache *cache_from_obj(struct kmem_cache *s, void *x)
95803 return s;
95804
95805 page = virt_to_head_page(x);
95806+
95807+ BUG_ON(!PageSlab(page));
95808+
95809 cachep = page->slab_cache;
95810 if (slab_equal_or_root(cachep, s))
95811 return cachep;
95812diff --git a/mm/slab_common.c b/mm/slab_common.c
95813index 1ec3c61..2067c11 100644
95814--- a/mm/slab_common.c
95815+++ b/mm/slab_common.c
95816@@ -23,11 +23,22 @@
95817
95818 #include "slab.h"
95819
95820-enum slab_state slab_state;
95821+enum slab_state slab_state __read_only;
95822 LIST_HEAD(slab_caches);
95823 DEFINE_MUTEX(slab_mutex);
95824 struct kmem_cache *kmem_cache;
95825
95826+#ifdef CONFIG_PAX_MEMORY_SANITIZE
95827+bool pax_sanitize_slab __read_only = true;
95828+static int __init pax_sanitize_slab_setup(char *str)
95829+{
95830+ pax_sanitize_slab = !!simple_strtol(str, NULL, 0);
95831+ printk("%sabled PaX slab sanitization\n", pax_sanitize_slab ? "En" : "Dis");
95832+ return 1;
95833+}
95834+__setup("pax_sanitize_slab=", pax_sanitize_slab_setup);
95835+#endif
95836+
95837 #ifdef CONFIG_DEBUG_VM
95838 static int kmem_cache_sanity_check(struct mem_cgroup *memcg, const char *name,
95839 size_t size)
95840@@ -225,7 +236,7 @@ kmem_cache_create_memcg(struct mem_cgroup *memcg, const char *name, size_t size,
95841 if (err)
95842 goto out_free_cache;
95843
95844- s->refcount = 1;
95845+ atomic_set(&s->refcount, 1);
95846 list_add(&s->list, &slab_caches);
95847 memcg_register_cache(s);
95848
95849@@ -278,8 +289,7 @@ void kmem_cache_destroy(struct kmem_cache *s)
95850
95851 get_online_cpus();
95852 mutex_lock(&slab_mutex);
95853- s->refcount--;
95854- if (!s->refcount) {
95855+ if (atomic_dec_and_test(&s->refcount)) {
95856 list_del(&s->list);
95857
95858 if (!__kmem_cache_shutdown(s)) {
95859@@ -326,7 +336,7 @@ void __init create_boot_cache(struct kmem_cache *s, const char *name, size_t siz
95860 panic("Creation of kmalloc slab %s size=%zu failed. Reason %d\n",
95861 name, size, err);
95862
95863- s->refcount = -1; /* Exempt from merging for now */
95864+ atomic_set(&s->refcount, -1); /* Exempt from merging for now */
95865 }
95866
95867 struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
95868@@ -339,7 +349,7 @@ struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
95869
95870 create_boot_cache(s, name, size, flags);
95871 list_add(&s->list, &slab_caches);
95872- s->refcount = 1;
95873+ atomic_set(&s->refcount, 1);
95874 return s;
95875 }
95876
95877@@ -351,6 +361,11 @@ struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
95878 EXPORT_SYMBOL(kmalloc_dma_caches);
95879 #endif
95880
95881+#ifdef CONFIG_PAX_USERCOPY_SLABS
95882+struct kmem_cache *kmalloc_usercopy_caches[KMALLOC_SHIFT_HIGH + 1];
95883+EXPORT_SYMBOL(kmalloc_usercopy_caches);
95884+#endif
95885+
95886 /*
95887 * Conversion table for small slabs sizes / 8 to the index in the
95888 * kmalloc array. This is necessary for slabs < 192 since we have non power
95889@@ -415,6 +430,13 @@ struct kmem_cache *kmalloc_slab(size_t size, gfp_t flags)
95890 return kmalloc_dma_caches[index];
95891
95892 #endif
95893+
95894+#ifdef CONFIG_PAX_USERCOPY_SLABS
95895+ if (unlikely((flags & GFP_USERCOPY)))
95896+ return kmalloc_usercopy_caches[index];
95897+
95898+#endif
95899+
95900 return kmalloc_caches[index];
95901 }
95902
95903@@ -471,7 +493,7 @@ void __init create_kmalloc_caches(unsigned long flags)
95904 for (i = KMALLOC_SHIFT_LOW; i <= KMALLOC_SHIFT_HIGH; i++) {
95905 if (!kmalloc_caches[i]) {
95906 kmalloc_caches[i] = create_kmalloc_cache(NULL,
95907- 1 << i, flags);
95908+ 1 << i, SLAB_USERCOPY | flags);
95909 }
95910
95911 /*
95912@@ -480,10 +502,10 @@ void __init create_kmalloc_caches(unsigned long flags)
95913 * earlier power of two caches
95914 */
95915 if (KMALLOC_MIN_SIZE <= 32 && !kmalloc_caches[1] && i == 6)
95916- kmalloc_caches[1] = create_kmalloc_cache(NULL, 96, flags);
95917+ kmalloc_caches[1] = create_kmalloc_cache(NULL, 96, SLAB_USERCOPY | flags);
95918
95919 if (KMALLOC_MIN_SIZE <= 64 && !kmalloc_caches[2] && i == 7)
95920- kmalloc_caches[2] = create_kmalloc_cache(NULL, 192, flags);
95921+ kmalloc_caches[2] = create_kmalloc_cache(NULL, 192, SLAB_USERCOPY | flags);
95922 }
95923
95924 /* Kmalloc array is now usable */
95925@@ -516,6 +538,23 @@ void __init create_kmalloc_caches(unsigned long flags)
95926 }
95927 }
95928 #endif
95929+
95930+#ifdef CONFIG_PAX_USERCOPY_SLABS
95931+ for (i = 0; i <= KMALLOC_SHIFT_HIGH; i++) {
95932+ struct kmem_cache *s = kmalloc_caches[i];
95933+
95934+ if (s) {
95935+ int size = kmalloc_size(i);
95936+ char *n = kasprintf(GFP_NOWAIT,
95937+ "usercopy-kmalloc-%d", size);
95938+
95939+ BUG_ON(!n);
95940+ kmalloc_usercopy_caches[i] = create_kmalloc_cache(n,
95941+ size, SLAB_USERCOPY | flags);
95942+ }
95943+ }
95944+#endif
95945+
95946 }
95947 #endif /* !CONFIG_SLOB */
95948
95949@@ -556,6 +595,9 @@ void print_slabinfo_header(struct seq_file *m)
95950 seq_puts(m, " : globalstat <listallocs> <maxobjs> <grown> <reaped> "
95951 "<error> <maxfreeable> <nodeallocs> <remotefrees> <alienoverflow>");
95952 seq_puts(m, " : cpustat <allochit> <allocmiss> <freehit> <freemiss>");
95953+#ifdef CONFIG_PAX_MEMORY_SANITIZE
95954+ seq_puts(m, " : pax <sanitized> <not_sanitized>");
95955+#endif
95956 #endif
95957 seq_putc(m, '\n');
95958 }
95959diff --git a/mm/slob.c b/mm/slob.c
95960index 4bf8809..98a6914 100644
95961--- a/mm/slob.c
95962+++ b/mm/slob.c
95963@@ -157,7 +157,7 @@ static void set_slob(slob_t *s, slobidx_t size, slob_t *next)
95964 /*
95965 * Return the size of a slob block.
95966 */
95967-static slobidx_t slob_units(slob_t *s)
95968+static slobidx_t slob_units(const slob_t *s)
95969 {
95970 if (s->units > 0)
95971 return s->units;
95972@@ -167,7 +167,7 @@ static slobidx_t slob_units(slob_t *s)
95973 /*
95974 * Return the next free slob block pointer after this one.
95975 */
95976-static slob_t *slob_next(slob_t *s)
95977+static slob_t *slob_next(const slob_t *s)
95978 {
95979 slob_t *base = (slob_t *)((unsigned long)s & PAGE_MASK);
95980 slobidx_t next;
95981@@ -182,14 +182,14 @@ static slob_t *slob_next(slob_t *s)
95982 /*
95983 * Returns true if s is the last free block in its page.
95984 */
95985-static int slob_last(slob_t *s)
95986+static int slob_last(const slob_t *s)
95987 {
95988 return !((unsigned long)slob_next(s) & ~PAGE_MASK);
95989 }
95990
95991-static void *slob_new_pages(gfp_t gfp, int order, int node)
95992+static struct page *slob_new_pages(gfp_t gfp, unsigned int order, int node)
95993 {
95994- void *page;
95995+ struct page *page;
95996
95997 #ifdef CONFIG_NUMA
95998 if (node != NUMA_NO_NODE)
95999@@ -201,14 +201,18 @@ static void *slob_new_pages(gfp_t gfp, int order, int node)
96000 if (!page)
96001 return NULL;
96002
96003- return page_address(page);
96004+ __SetPageSlab(page);
96005+ return page;
96006 }
96007
96008-static void slob_free_pages(void *b, int order)
96009+static void slob_free_pages(struct page *sp, int order)
96010 {
96011 if (current->reclaim_state)
96012 current->reclaim_state->reclaimed_slab += 1 << order;
96013- free_pages((unsigned long)b, order);
96014+ __ClearPageSlab(sp);
96015+ page_mapcount_reset(sp);
96016+ sp->private = 0;
96017+ __free_pages(sp, order);
96018 }
96019
96020 /*
96021@@ -313,15 +317,15 @@ static void *slob_alloc(size_t size, gfp_t gfp, int align, int node)
96022
96023 /* Not enough space: must allocate a new page */
96024 if (!b) {
96025- b = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
96026- if (!b)
96027+ sp = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
96028+ if (!sp)
96029 return NULL;
96030- sp = virt_to_page(b);
96031- __SetPageSlab(sp);
96032+ b = page_address(sp);
96033
96034 spin_lock_irqsave(&slob_lock, flags);
96035 sp->units = SLOB_UNITS(PAGE_SIZE);
96036 sp->freelist = b;
96037+ sp->private = 0;
96038 INIT_LIST_HEAD(&sp->list);
96039 set_slob(b, SLOB_UNITS(PAGE_SIZE), b + SLOB_UNITS(PAGE_SIZE));
96040 set_slob_page_free(sp, slob_list);
96041@@ -359,12 +363,15 @@ static void slob_free(void *block, int size)
96042 if (slob_page_free(sp))
96043 clear_slob_page_free(sp);
96044 spin_unlock_irqrestore(&slob_lock, flags);
96045- __ClearPageSlab(sp);
96046- page_mapcount_reset(sp);
96047- slob_free_pages(b, 0);
96048+ slob_free_pages(sp, 0);
96049 return;
96050 }
96051
96052+#ifdef CONFIG_PAX_MEMORY_SANITIZE
96053+ if (pax_sanitize_slab)
96054+ memset(block, PAX_MEMORY_SANITIZE_VALUE, size);
96055+#endif
96056+
96057 if (!slob_page_free(sp)) {
96058 /* This slob page is about to become partially free. Easy! */
96059 sp->units = units;
96060@@ -424,11 +431,10 @@ out:
96061 */
96062
96063 static __always_inline void *
96064-__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
96065+__do_kmalloc_node_align(size_t size, gfp_t gfp, int node, unsigned long caller, int align)
96066 {
96067- unsigned int *m;
96068- int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
96069- void *ret;
96070+ slob_t *m;
96071+ void *ret = NULL;
96072
96073 gfp &= gfp_allowed_mask;
96074
96075@@ -442,23 +448,41 @@ __do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
96076
96077 if (!m)
96078 return NULL;
96079- *m = size;
96080+ BUILD_BUG_ON(ARCH_KMALLOC_MINALIGN < 2 * SLOB_UNIT);
96081+ BUILD_BUG_ON(ARCH_SLAB_MINALIGN < 2 * SLOB_UNIT);
96082+ m[0].units = size;
96083+ m[1].units = align;
96084 ret = (void *)m + align;
96085
96086 trace_kmalloc_node(caller, ret,
96087 size, size + align, gfp, node);
96088 } else {
96089 unsigned int order = get_order(size);
96090+ struct page *page;
96091
96092 if (likely(order))
96093 gfp |= __GFP_COMP;
96094- ret = slob_new_pages(gfp, order, node);
96095+ page = slob_new_pages(gfp, order, node);
96096+ if (page) {
96097+ ret = page_address(page);
96098+ page->private = size;
96099+ }
96100
96101 trace_kmalloc_node(caller, ret,
96102 size, PAGE_SIZE << order, gfp, node);
96103 }
96104
96105- kmemleak_alloc(ret, size, 1, gfp);
96106+ return ret;
96107+}
96108+
96109+static __always_inline void *
96110+__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
96111+{
96112+ int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
96113+ void *ret = __do_kmalloc_node_align(size, gfp, node, caller, align);
96114+
96115+ if (!ZERO_OR_NULL_PTR(ret))
96116+ kmemleak_alloc(ret, size, 1, gfp);
96117 return ret;
96118 }
96119
96120@@ -493,34 +517,112 @@ void kfree(const void *block)
96121 return;
96122 kmemleak_free(block);
96123
96124+ VM_BUG_ON(!virt_addr_valid(block));
96125 sp = virt_to_page(block);
96126- if (PageSlab(sp)) {
96127+ VM_BUG_ON(!PageSlab(sp));
96128+ if (!sp->private) {
96129 int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
96130- unsigned int *m = (unsigned int *)(block - align);
96131- slob_free(m, *m + align);
96132- } else
96133+ slob_t *m = (slob_t *)(block - align);
96134+ slob_free(m, m[0].units + align);
96135+ } else {
96136+ __ClearPageSlab(sp);
96137+ page_mapcount_reset(sp);
96138+ sp->private = 0;
96139 __free_pages(sp, compound_order(sp));
96140+ }
96141 }
96142 EXPORT_SYMBOL(kfree);
96143
96144+bool is_usercopy_object(const void *ptr)
96145+{
96146+ if (!slab_is_available())
96147+ return false;
96148+
96149+ // PAX: TODO
96150+
96151+ return false;
96152+}
96153+
96154+#ifdef CONFIG_PAX_USERCOPY
96155+const char *check_heap_object(const void *ptr, unsigned long n)
96156+{
96157+ struct page *page;
96158+ const slob_t *free;
96159+ const void *base;
96160+ unsigned long flags;
96161+
96162+ if (ZERO_OR_NULL_PTR(ptr))
96163+ return "<null>";
96164+
96165+ if (!virt_addr_valid(ptr))
96166+ return NULL;
96167+
96168+ page = virt_to_head_page(ptr);
96169+ if (!PageSlab(page))
96170+ return NULL;
96171+
96172+ if (page->private) {
96173+ base = page;
96174+ if (base <= ptr && n <= page->private - (ptr - base))
96175+ return NULL;
96176+ return "<slob>";
96177+ }
96178+
96179+ /* some tricky double walking to find the chunk */
96180+ spin_lock_irqsave(&slob_lock, flags);
96181+ base = (void *)((unsigned long)ptr & PAGE_MASK);
96182+ free = page->freelist;
96183+
96184+ while (!slob_last(free) && (void *)free <= ptr) {
96185+ base = free + slob_units(free);
96186+ free = slob_next(free);
96187+ }
96188+
96189+ while (base < (void *)free) {
96190+ slobidx_t m = ((slob_t *)base)[0].units, align = ((slob_t *)base)[1].units;
96191+ int size = SLOB_UNIT * SLOB_UNITS(m + align);
96192+ int offset;
96193+
96194+ if (ptr < base + align)
96195+ break;
96196+
96197+ offset = ptr - base - align;
96198+ if (offset >= m) {
96199+ base += size;
96200+ continue;
96201+ }
96202+
96203+ if (n > m - offset)
96204+ break;
96205+
96206+ spin_unlock_irqrestore(&slob_lock, flags);
96207+ return NULL;
96208+ }
96209+
96210+ spin_unlock_irqrestore(&slob_lock, flags);
96211+ return "<slob>";
96212+}
96213+#endif
96214+
96215 /* can't use ksize for kmem_cache_alloc memory, only kmalloc */
96216 size_t ksize(const void *block)
96217 {
96218 struct page *sp;
96219 int align;
96220- unsigned int *m;
96221+ slob_t *m;
96222
96223 BUG_ON(!block);
96224 if (unlikely(block == ZERO_SIZE_PTR))
96225 return 0;
96226
96227 sp = virt_to_page(block);
96228- if (unlikely(!PageSlab(sp)))
96229- return PAGE_SIZE << compound_order(sp);
96230+ VM_BUG_ON(!PageSlab(sp));
96231+ if (sp->private)
96232+ return sp->private;
96233
96234 align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
96235- m = (unsigned int *)(block - align);
96236- return SLOB_UNITS(*m) * SLOB_UNIT;
96237+ m = (slob_t *)(block - align);
96238+ return SLOB_UNITS(m[0].units) * SLOB_UNIT;
96239 }
96240 EXPORT_SYMBOL(ksize);
96241
96242@@ -536,23 +638,33 @@ int __kmem_cache_create(struct kmem_cache *c, unsigned long flags)
96243
96244 void *slob_alloc_node(struct kmem_cache *c, gfp_t flags, int node)
96245 {
96246- void *b;
96247+ void *b = NULL;
96248
96249 flags &= gfp_allowed_mask;
96250
96251 lockdep_trace_alloc(flags);
96252
96253+#ifdef CONFIG_PAX_USERCOPY_SLABS
96254+ b = __do_kmalloc_node_align(c->size, flags, node, _RET_IP_, c->align);
96255+#else
96256 if (c->size < PAGE_SIZE) {
96257 b = slob_alloc(c->size, flags, c->align, node);
96258 trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size,
96259 SLOB_UNITS(c->size) * SLOB_UNIT,
96260 flags, node);
96261 } else {
96262- b = slob_new_pages(flags, get_order(c->size), node);
96263+ struct page *sp;
96264+
96265+ sp = slob_new_pages(flags, get_order(c->size), node);
96266+ if (sp) {
96267+ b = page_address(sp);
96268+ sp->private = c->size;
96269+ }
96270 trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size,
96271 PAGE_SIZE << get_order(c->size),
96272 flags, node);
96273 }
96274+#endif
96275
96276 if (b && c->ctor)
96277 c->ctor(b);
96278@@ -584,10 +696,14 @@ EXPORT_SYMBOL(kmem_cache_alloc_node);
96279
96280 static void __kmem_cache_free(void *b, int size)
96281 {
96282- if (size < PAGE_SIZE)
96283+ struct page *sp;
96284+
96285+ sp = virt_to_page(b);
96286+ BUG_ON(!PageSlab(sp));
96287+ if (!sp->private)
96288 slob_free(b, size);
96289 else
96290- slob_free_pages(b, get_order(size));
96291+ slob_free_pages(sp, get_order(size));
96292 }
96293
96294 static void kmem_rcu_free(struct rcu_head *head)
96295@@ -600,17 +716,31 @@ static void kmem_rcu_free(struct rcu_head *head)
96296
96297 void kmem_cache_free(struct kmem_cache *c, void *b)
96298 {
96299+ int size = c->size;
96300+
96301+#ifdef CONFIG_PAX_USERCOPY_SLABS
96302+ if (size + c->align < PAGE_SIZE) {
96303+ size += c->align;
96304+ b -= c->align;
96305+ }
96306+#endif
96307+
96308 kmemleak_free_recursive(b, c->flags);
96309 if (unlikely(c->flags & SLAB_DESTROY_BY_RCU)) {
96310 struct slob_rcu *slob_rcu;
96311- slob_rcu = b + (c->size - sizeof(struct slob_rcu));
96312- slob_rcu->size = c->size;
96313+ slob_rcu = b + (size - sizeof(struct slob_rcu));
96314+ slob_rcu->size = size;
96315 call_rcu(&slob_rcu->head, kmem_rcu_free);
96316 } else {
96317- __kmem_cache_free(b, c->size);
96318+ __kmem_cache_free(b, size);
96319 }
96320
96321+#ifdef CONFIG_PAX_USERCOPY_SLABS
96322+ trace_kfree(_RET_IP_, b);
96323+#else
96324 trace_kmem_cache_free(_RET_IP_, b);
96325+#endif
96326+
96327 }
96328 EXPORT_SYMBOL(kmem_cache_free);
96329
96330diff --git a/mm/slub.c b/mm/slub.c
96331index 25f14ad..ff4d0b7 100644
96332--- a/mm/slub.c
96333+++ b/mm/slub.c
96334@@ -207,7 +207,7 @@ struct track {
96335
96336 enum track_item { TRACK_ALLOC, TRACK_FREE };
96337
96338-#ifdef CONFIG_SYSFS
96339+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
96340 static int sysfs_slab_add(struct kmem_cache *);
96341 static int sysfs_slab_alias(struct kmem_cache *, const char *);
96342 static void sysfs_slab_remove(struct kmem_cache *);
96343@@ -545,7 +545,7 @@ static void print_track(const char *s, struct track *t)
96344 if (!t->addr)
96345 return;
96346
96347- printk(KERN_ERR "INFO: %s in %pS age=%lu cpu=%u pid=%d\n",
96348+ printk(KERN_ERR "INFO: %s in %pA age=%lu cpu=%u pid=%d\n",
96349 s, (void *)t->addr, jiffies - t->when, t->cpu, t->pid);
96350 #ifdef CONFIG_STACKTRACE
96351 {
96352@@ -2666,6 +2666,14 @@ static __always_inline void slab_free(struct kmem_cache *s,
96353
96354 slab_free_hook(s, x);
96355
96356+#ifdef CONFIG_PAX_MEMORY_SANITIZE
96357+ if (pax_sanitize_slab && !(s->flags & SLAB_NO_SANITIZE)) {
96358+ memset(x, PAX_MEMORY_SANITIZE_VALUE, s->object_size);
96359+ if (s->ctor)
96360+ s->ctor(x);
96361+ }
96362+#endif
96363+
96364 redo:
96365 /*
96366 * Determine the currently cpus per cpu slab.
96367@@ -2733,7 +2741,7 @@ static int slub_min_objects;
96368 * Merge control. If this is set then no merging of slab caches will occur.
96369 * (Could be removed. This was introduced to pacify the merge skeptics.)
96370 */
96371-static int slub_nomerge;
96372+static int slub_nomerge = 1;
96373
96374 /*
96375 * Calculate the order of allocation given an slab object size.
96376@@ -3014,6 +3022,9 @@ static int calculate_sizes(struct kmem_cache *s, int forced_order)
96377 s->inuse = size;
96378
96379 if (((flags & (SLAB_DESTROY_BY_RCU | SLAB_POISON)) ||
96380+#ifdef CONFIG_PAX_MEMORY_SANITIZE
96381+ (pax_sanitize_slab && !(flags & SLAB_NO_SANITIZE)) ||
96382+#endif
96383 s->ctor)) {
96384 /*
96385 * Relocate free pointer after the object if it is not
96386@@ -3359,6 +3370,59 @@ void *__kmalloc_node(size_t size, gfp_t flags, int node)
96387 EXPORT_SYMBOL(__kmalloc_node);
96388 #endif
96389
96390+bool is_usercopy_object(const void *ptr)
96391+{
96392+ struct page *page;
96393+ struct kmem_cache *s;
96394+
96395+ if (ZERO_OR_NULL_PTR(ptr))
96396+ return false;
96397+
96398+ if (!slab_is_available())
96399+ return false;
96400+
96401+ if (!virt_addr_valid(ptr))
96402+ return false;
96403+
96404+ page = virt_to_head_page(ptr);
96405+
96406+ if (!PageSlab(page))
96407+ return false;
96408+
96409+ s = page->slab_cache;
96410+ return s->flags & SLAB_USERCOPY;
96411+}
96412+
96413+#ifdef CONFIG_PAX_USERCOPY
96414+const char *check_heap_object(const void *ptr, unsigned long n)
96415+{
96416+ struct page *page;
96417+ struct kmem_cache *s;
96418+ unsigned long offset;
96419+
96420+ if (ZERO_OR_NULL_PTR(ptr))
96421+ return "<null>";
96422+
96423+ if (!virt_addr_valid(ptr))
96424+ return NULL;
96425+
96426+ page = virt_to_head_page(ptr);
96427+
96428+ if (!PageSlab(page))
96429+ return NULL;
96430+
96431+ s = page->slab_cache;
96432+ if (!(s->flags & SLAB_USERCOPY))
96433+ return s->name;
96434+
96435+ offset = (ptr - page_address(page)) % s->size;
96436+ if (offset <= s->object_size && n <= s->object_size - offset)
96437+ return NULL;
96438+
96439+ return s->name;
96440+}
96441+#endif
96442+
96443 size_t ksize(const void *object)
96444 {
96445 struct page *page;
96446@@ -3387,6 +3451,7 @@ void kfree(const void *x)
96447 if (unlikely(ZERO_OR_NULL_PTR(x)))
96448 return;
96449
96450+ VM_BUG_ON(!virt_addr_valid(x));
96451 page = virt_to_head_page(x);
96452 if (unlikely(!PageSlab(page))) {
96453 BUG_ON(!PageCompound(page));
96454@@ -3692,7 +3757,7 @@ static int slab_unmergeable(struct kmem_cache *s)
96455 /*
96456 * We may have set a slab to be unmergeable during bootstrap.
96457 */
96458- if (s->refcount < 0)
96459+ if (atomic_read(&s->refcount) < 0)
96460 return 1;
96461
96462 return 0;
96463@@ -3750,7 +3815,7 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
96464
96465 s = find_mergeable(memcg, size, align, flags, name, ctor);
96466 if (s) {
96467- s->refcount++;
96468+ atomic_inc(&s->refcount);
96469 /*
96470 * Adjust the object sizes so that we clear
96471 * the complete object on kzalloc.
96472@@ -3759,7 +3824,7 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
96473 s->inuse = max_t(int, s->inuse, ALIGN(size, sizeof(void *)));
96474
96475 if (sysfs_slab_alias(s, name)) {
96476- s->refcount--;
96477+ atomic_dec(&s->refcount);
96478 s = NULL;
96479 }
96480 }
96481@@ -3879,7 +3944,7 @@ void *__kmalloc_node_track_caller(size_t size, gfp_t gfpflags,
96482 }
96483 #endif
96484
96485-#ifdef CONFIG_SYSFS
96486+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
96487 static int count_inuse(struct page *page)
96488 {
96489 return page->inuse;
96490@@ -4268,12 +4333,12 @@ static void resiliency_test(void)
96491 validate_slab_cache(kmalloc_caches[9]);
96492 }
96493 #else
96494-#ifdef CONFIG_SYSFS
96495+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
96496 static void resiliency_test(void) {};
96497 #endif
96498 #endif
96499
96500-#ifdef CONFIG_SYSFS
96501+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
96502 enum slab_stat_type {
96503 SL_ALL, /* All slabs */
96504 SL_PARTIAL, /* Only partially allocated slabs */
96505@@ -4519,7 +4584,7 @@ SLAB_ATTR_RO(ctor);
96506
96507 static ssize_t aliases_show(struct kmem_cache *s, char *buf)
96508 {
96509- return sprintf(buf, "%d\n", s->refcount - 1);
96510+ return sprintf(buf, "%d\n", atomic_read(&s->refcount) - 1);
96511 }
96512 SLAB_ATTR_RO(aliases);
96513
96514@@ -4607,6 +4672,14 @@ static ssize_t cache_dma_show(struct kmem_cache *s, char *buf)
96515 SLAB_ATTR_RO(cache_dma);
96516 #endif
96517
96518+#ifdef CONFIG_PAX_USERCOPY_SLABS
96519+static ssize_t usercopy_show(struct kmem_cache *s, char *buf)
96520+{
96521+ return sprintf(buf, "%d\n", !!(s->flags & SLAB_USERCOPY));
96522+}
96523+SLAB_ATTR_RO(usercopy);
96524+#endif
96525+
96526 static ssize_t destroy_by_rcu_show(struct kmem_cache *s, char *buf)
96527 {
96528 return sprintf(buf, "%d\n", !!(s->flags & SLAB_DESTROY_BY_RCU));
96529@@ -4941,6 +5014,9 @@ static struct attribute *slab_attrs[] = {
96530 #ifdef CONFIG_ZONE_DMA
96531 &cache_dma_attr.attr,
96532 #endif
96533+#ifdef CONFIG_PAX_USERCOPY_SLABS
96534+ &usercopy_attr.attr,
96535+#endif
96536 #ifdef CONFIG_NUMA
96537 &remote_node_defrag_ratio_attr.attr,
96538 #endif
96539@@ -5173,6 +5249,7 @@ static char *create_unique_id(struct kmem_cache *s)
96540 return name;
96541 }
96542
96543+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
96544 static int sysfs_slab_add(struct kmem_cache *s)
96545 {
96546 int err;
96547@@ -5230,6 +5307,7 @@ static void sysfs_slab_remove(struct kmem_cache *s)
96548 kobject_del(&s->kobj);
96549 kobject_put(&s->kobj);
96550 }
96551+#endif
96552
96553 /*
96554 * Need to buffer aliases during bootup until sysfs becomes
96555@@ -5243,6 +5321,7 @@ struct saved_alias {
96556
96557 static struct saved_alias *alias_list;
96558
96559+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
96560 static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
96561 {
96562 struct saved_alias *al;
96563@@ -5265,6 +5344,7 @@ static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
96564 alias_list = al;
96565 return 0;
96566 }
96567+#endif
96568
96569 static int __init slab_sysfs_init(void)
96570 {
96571diff --git a/mm/sparse-vmemmap.c b/mm/sparse-vmemmap.c
96572index 4cba9c2..b4f9fcc 100644
96573--- a/mm/sparse-vmemmap.c
96574+++ b/mm/sparse-vmemmap.c
96575@@ -131,7 +131,7 @@ pud_t * __meminit vmemmap_pud_populate(pgd_t *pgd, unsigned long addr, int node)
96576 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
96577 if (!p)
96578 return NULL;
96579- pud_populate(&init_mm, pud, p);
96580+ pud_populate_kernel(&init_mm, pud, p);
96581 }
96582 return pud;
96583 }
96584@@ -143,7 +143,7 @@ pgd_t * __meminit vmemmap_pgd_populate(unsigned long addr, int node)
96585 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
96586 if (!p)
96587 return NULL;
96588- pgd_populate(&init_mm, pgd, p);
96589+ pgd_populate_kernel(&init_mm, pgd, p);
96590 }
96591 return pgd;
96592 }
96593diff --git a/mm/sparse.c b/mm/sparse.c
96594index 63c3ea5..95c0858 100644
96595--- a/mm/sparse.c
96596+++ b/mm/sparse.c
96597@@ -748,7 +748,7 @@ static void clear_hwpoisoned_pages(struct page *memmap, int nr_pages)
96598
96599 for (i = 0; i < PAGES_PER_SECTION; i++) {
96600 if (PageHWPoison(&memmap[i])) {
96601- atomic_long_sub(1, &num_poisoned_pages);
96602+ atomic_long_sub_unchecked(1, &num_poisoned_pages);
96603 ClearPageHWPoison(&memmap[i]);
96604 }
96605 }
96606diff --git a/mm/swap.c b/mm/swap.c
96607index 0092097..33361ff 100644
96608--- a/mm/swap.c
96609+++ b/mm/swap.c
96610@@ -31,6 +31,7 @@
96611 #include <linux/memcontrol.h>
96612 #include <linux/gfp.h>
96613 #include <linux/uio.h>
96614+#include <linux/hugetlb.h>
96615
96616 #include "internal.h"
96617
96618@@ -76,6 +77,8 @@ static void __put_compound_page(struct page *page)
96619
96620 __page_cache_release(page);
96621 dtor = get_compound_page_dtor(page);
96622+ if (!PageHuge(page))
96623+ BUG_ON(dtor != free_compound_page);
96624 (*dtor)(page);
96625 }
96626
96627diff --git a/mm/swapfile.c b/mm/swapfile.c
96628index 4a7f7e6..22cddf5 100644
96629--- a/mm/swapfile.c
96630+++ b/mm/swapfile.c
96631@@ -66,7 +66,7 @@ static DEFINE_MUTEX(swapon_mutex);
96632
96633 static DECLARE_WAIT_QUEUE_HEAD(proc_poll_wait);
96634 /* Activity counter to indicate that a swapon or swapoff has occurred */
96635-static atomic_t proc_poll_event = ATOMIC_INIT(0);
96636+static atomic_unchecked_t proc_poll_event = ATOMIC_INIT(0);
96637
96638 static inline unsigned char swap_count(unsigned char ent)
96639 {
96640@@ -1959,7 +1959,7 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
96641 spin_unlock(&swap_lock);
96642
96643 err = 0;
96644- atomic_inc(&proc_poll_event);
96645+ atomic_inc_unchecked(&proc_poll_event);
96646 wake_up_interruptible(&proc_poll_wait);
96647
96648 out_dput:
96649@@ -1976,8 +1976,8 @@ static unsigned swaps_poll(struct file *file, poll_table *wait)
96650
96651 poll_wait(file, &proc_poll_wait, wait);
96652
96653- if (seq->poll_event != atomic_read(&proc_poll_event)) {
96654- seq->poll_event = atomic_read(&proc_poll_event);
96655+ if (seq->poll_event != atomic_read_unchecked(&proc_poll_event)) {
96656+ seq->poll_event = atomic_read_unchecked(&proc_poll_event);
96657 return POLLIN | POLLRDNORM | POLLERR | POLLPRI;
96658 }
96659
96660@@ -2075,7 +2075,7 @@ static int swaps_open(struct inode *inode, struct file *file)
96661 return ret;
96662
96663 seq = file->private_data;
96664- seq->poll_event = atomic_read(&proc_poll_event);
96665+ seq->poll_event = atomic_read_unchecked(&proc_poll_event);
96666 return 0;
96667 }
96668
96669@@ -2534,7 +2534,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
96670 (frontswap_map) ? "FS" : "");
96671
96672 mutex_unlock(&swapon_mutex);
96673- atomic_inc(&proc_poll_event);
96674+ atomic_inc_unchecked(&proc_poll_event);
96675 wake_up_interruptible(&proc_poll_wait);
96676
96677 if (S_ISREG(inode->i_mode))
96678diff --git a/mm/util.c b/mm/util.c
96679index a24aa22..a0d41ae 100644
96680--- a/mm/util.c
96681+++ b/mm/util.c
96682@@ -297,6 +297,12 @@ done:
96683 void arch_pick_mmap_layout(struct mm_struct *mm)
96684 {
96685 mm->mmap_base = TASK_UNMAPPED_BASE;
96686+
96687+#ifdef CONFIG_PAX_RANDMMAP
96688+ if (mm->pax_flags & MF_PAX_RANDMMAP)
96689+ mm->mmap_base += mm->delta_mmap;
96690+#endif
96691+
96692 mm->get_unmapped_area = arch_get_unmapped_area;
96693 }
96694 #endif
96695diff --git a/mm/vmalloc.c b/mm/vmalloc.c
96696index 0fdf968..d6686e8 100644
96697--- a/mm/vmalloc.c
96698+++ b/mm/vmalloc.c
96699@@ -59,8 +59,19 @@ static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
96700
96701 pte = pte_offset_kernel(pmd, addr);
96702 do {
96703- pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
96704- WARN_ON(!pte_none(ptent) && !pte_present(ptent));
96705+
96706+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
96707+ if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr < (unsigned long)MODULES_EXEC_END) {
96708+ BUG_ON(!pte_exec(*pte));
96709+ set_pte_at(&init_mm, addr, pte, pfn_pte(__pa(addr) >> PAGE_SHIFT, PAGE_KERNEL_EXEC));
96710+ continue;
96711+ }
96712+#endif
96713+
96714+ {
96715+ pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
96716+ WARN_ON(!pte_none(ptent) && !pte_present(ptent));
96717+ }
96718 } while (pte++, addr += PAGE_SIZE, addr != end);
96719 }
96720
96721@@ -120,16 +131,29 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
96722 pte = pte_alloc_kernel(pmd, addr);
96723 if (!pte)
96724 return -ENOMEM;
96725+
96726+ pax_open_kernel();
96727 do {
96728 struct page *page = pages[*nr];
96729
96730- if (WARN_ON(!pte_none(*pte)))
96731+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
96732+ if (pgprot_val(prot) & _PAGE_NX)
96733+#endif
96734+
96735+ if (!pte_none(*pte)) {
96736+ pax_close_kernel();
96737+ WARN_ON(1);
96738 return -EBUSY;
96739- if (WARN_ON(!page))
96740+ }
96741+ if (!page) {
96742+ pax_close_kernel();
96743+ WARN_ON(1);
96744 return -ENOMEM;
96745+ }
96746 set_pte_at(&init_mm, addr, pte, mk_pte(page, prot));
96747 (*nr)++;
96748 } while (pte++, addr += PAGE_SIZE, addr != end);
96749+ pax_close_kernel();
96750 return 0;
96751 }
96752
96753@@ -139,7 +163,7 @@ static int vmap_pmd_range(pud_t *pud, unsigned long addr,
96754 pmd_t *pmd;
96755 unsigned long next;
96756
96757- pmd = pmd_alloc(&init_mm, pud, addr);
96758+ pmd = pmd_alloc_kernel(&init_mm, pud, addr);
96759 if (!pmd)
96760 return -ENOMEM;
96761 do {
96762@@ -156,7 +180,7 @@ static int vmap_pud_range(pgd_t *pgd, unsigned long addr,
96763 pud_t *pud;
96764 unsigned long next;
96765
96766- pud = pud_alloc(&init_mm, pgd, addr);
96767+ pud = pud_alloc_kernel(&init_mm, pgd, addr);
96768 if (!pud)
96769 return -ENOMEM;
96770 do {
96771@@ -216,6 +240,12 @@ int is_vmalloc_or_module_addr(const void *x)
96772 if (addr >= MODULES_VADDR && addr < MODULES_END)
96773 return 1;
96774 #endif
96775+
96776+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
96777+ if (x >= (const void *)MODULES_EXEC_VADDR && x < (const void *)MODULES_EXEC_END)
96778+ return 1;
96779+#endif
96780+
96781 return is_vmalloc_addr(x);
96782 }
96783
96784@@ -236,8 +266,14 @@ struct page *vmalloc_to_page(const void *vmalloc_addr)
96785
96786 if (!pgd_none(*pgd)) {
96787 pud_t *pud = pud_offset(pgd, addr);
96788+#ifdef CONFIG_X86
96789+ if (!pud_large(*pud))
96790+#endif
96791 if (!pud_none(*pud)) {
96792 pmd_t *pmd = pmd_offset(pud, addr);
96793+#ifdef CONFIG_X86
96794+ if (!pmd_large(*pmd))
96795+#endif
96796 if (!pmd_none(*pmd)) {
96797 pte_t *ptep, pte;
96798
96799@@ -1309,6 +1345,16 @@ static struct vm_struct *__get_vm_area_node(unsigned long size,
96800 struct vm_struct *area;
96801
96802 BUG_ON(in_interrupt());
96803+
96804+#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
96805+ if (flags & VM_KERNEXEC) {
96806+ if (start != VMALLOC_START || end != VMALLOC_END)
96807+ return NULL;
96808+ start = (unsigned long)MODULES_EXEC_VADDR;
96809+ end = (unsigned long)MODULES_EXEC_END;
96810+ }
96811+#endif
96812+
96813 if (flags & VM_IOREMAP)
96814 align = 1ul << clamp(fls(size), PAGE_SHIFT, IOREMAP_MAX_ORDER);
96815
96816@@ -1534,6 +1580,11 @@ void *vmap(struct page **pages, unsigned int count,
96817 if (count > totalram_pages)
96818 return NULL;
96819
96820+#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
96821+ if (!(pgprot_val(prot) & _PAGE_NX))
96822+ flags |= VM_KERNEXEC;
96823+#endif
96824+
96825 area = get_vm_area_caller((count << PAGE_SHIFT), flags,
96826 __builtin_return_address(0));
96827 if (!area)
96828@@ -1634,6 +1685,13 @@ void *__vmalloc_node_range(unsigned long size, unsigned long align,
96829 if (!size || (size >> PAGE_SHIFT) > totalram_pages)
96830 goto fail;
96831
96832+#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
96833+ if (!(pgprot_val(prot) & _PAGE_NX))
96834+ area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNINITIALIZED | VM_KERNEXEC,
96835+ VMALLOC_START, VMALLOC_END, node, gfp_mask, caller);
96836+ else
96837+#endif
96838+
96839 area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNINITIALIZED,
96840 start, end, node, gfp_mask, caller);
96841 if (!area)
96842@@ -1810,10 +1868,9 @@ EXPORT_SYMBOL(vzalloc_node);
96843 * For tight control over page level allocator and protection flags
96844 * use __vmalloc() instead.
96845 */
96846-
96847 void *vmalloc_exec(unsigned long size)
96848 {
96849- return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
96850+ return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL_EXEC,
96851 NUMA_NO_NODE, __builtin_return_address(0));
96852 }
96853
96854@@ -2120,6 +2177,8 @@ int remap_vmalloc_range_partial(struct vm_area_struct *vma, unsigned long uaddr,
96855 {
96856 struct vm_struct *area;
96857
96858+ BUG_ON(vma->vm_mirror);
96859+
96860 size = PAGE_ALIGN(size);
96861
96862 if (!PAGE_ALIGNED(uaddr) || !PAGE_ALIGNED(kaddr))
96863@@ -2602,7 +2661,11 @@ static int s_show(struct seq_file *m, void *p)
96864 v->addr, v->addr + v->size, v->size);
96865
96866 if (v->caller)
96867+#ifdef CONFIG_GRKERNSEC_HIDESYM
96868+ seq_printf(m, " %pK", v->caller);
96869+#else
96870 seq_printf(m, " %pS", v->caller);
96871+#endif
96872
96873 if (v->nr_pages)
96874 seq_printf(m, " pages=%d", v->nr_pages);
96875diff --git a/mm/vmstat.c b/mm/vmstat.c
96876index def5dd2..4ce55cec 100644
96877--- a/mm/vmstat.c
96878+++ b/mm/vmstat.c
96879@@ -20,6 +20,7 @@
96880 #include <linux/writeback.h>
96881 #include <linux/compaction.h>
96882 #include <linux/mm_inline.h>
96883+#include <linux/grsecurity.h>
96884
96885 #include "internal.h"
96886
96887@@ -79,7 +80,7 @@ void vm_events_fold_cpu(int cpu)
96888 *
96889 * vm_stat contains the global counters
96890 */
96891-atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
96892+atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
96893 EXPORT_SYMBOL(vm_stat);
96894
96895 #ifdef CONFIG_SMP
96896@@ -423,7 +424,7 @@ static inline void fold_diff(int *diff)
96897
96898 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
96899 if (diff[i])
96900- atomic_long_add(diff[i], &vm_stat[i]);
96901+ atomic_long_add_unchecked(diff[i], &vm_stat[i]);
96902 }
96903
96904 /*
96905@@ -455,7 +456,7 @@ static void refresh_cpu_vm_stats(void)
96906 v = this_cpu_xchg(p->vm_stat_diff[i], 0);
96907 if (v) {
96908
96909- atomic_long_add(v, &zone->vm_stat[i]);
96910+ atomic_long_add_unchecked(v, &zone->vm_stat[i]);
96911 global_diff[i] += v;
96912 #ifdef CONFIG_NUMA
96913 /* 3 seconds idle till flush */
96914@@ -517,7 +518,7 @@ void cpu_vm_stats_fold(int cpu)
96915
96916 v = p->vm_stat_diff[i];
96917 p->vm_stat_diff[i] = 0;
96918- atomic_long_add(v, &zone->vm_stat[i]);
96919+ atomic_long_add_unchecked(v, &zone->vm_stat[i]);
96920 global_diff[i] += v;
96921 }
96922 }
96923@@ -537,8 +538,8 @@ void drain_zonestat(struct zone *zone, struct per_cpu_pageset *pset)
96924 if (pset->vm_stat_diff[i]) {
96925 int v = pset->vm_stat_diff[i];
96926 pset->vm_stat_diff[i] = 0;
96927- atomic_long_add(v, &zone->vm_stat[i]);
96928- atomic_long_add(v, &vm_stat[i]);
96929+ atomic_long_add_unchecked(v, &zone->vm_stat[i]);
96930+ atomic_long_add_unchecked(v, &vm_stat[i]);
96931 }
96932 }
96933 #endif
96934@@ -1150,10 +1151,22 @@ static void *vmstat_start(struct seq_file *m, loff_t *pos)
96935 stat_items_size += sizeof(struct vm_event_state);
96936 #endif
96937
96938- v = kmalloc(stat_items_size, GFP_KERNEL);
96939+ v = kzalloc(stat_items_size, GFP_KERNEL);
96940 m->private = v;
96941 if (!v)
96942 return ERR_PTR(-ENOMEM);
96943+
96944+#ifdef CONFIG_GRKERNSEC_PROC_ADD
96945+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
96946+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)
96947+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
96948+ && !in_group_p(grsec_proc_gid)
96949+#endif
96950+ )
96951+ return (unsigned long *)m->private + *pos;
96952+#endif
96953+#endif
96954+
96955 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
96956 v[i] = global_page_state(i);
96957 v += NR_VM_ZONE_STAT_ITEMS;
96958@@ -1302,10 +1315,16 @@ static int __init setup_vmstat(void)
96959 put_online_cpus();
96960 #endif
96961 #ifdef CONFIG_PROC_FS
96962- proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations);
96963- proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops);
96964- proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
96965- proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations);
96966+ {
96967+ mode_t gr_mode = S_IRUGO;
96968+#ifdef CONFIG_GRKERNSEC_PROC_ADD
96969+ gr_mode = S_IRUSR;
96970+#endif
96971+ proc_create("buddyinfo", gr_mode, NULL, &fragmentation_file_operations);
96972+ proc_create("pagetypeinfo", gr_mode, NULL, &pagetypeinfo_file_ops);
96973+ proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
96974+ proc_create("zoneinfo", gr_mode, NULL, &proc_zoneinfo_file_operations);
96975+ }
96976 #endif
96977 return 0;
96978 }
96979diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
96980index 175273f..1c63e05 100644
96981--- a/net/8021q/vlan.c
96982+++ b/net/8021q/vlan.c
96983@@ -474,7 +474,7 @@ out:
96984 return NOTIFY_DONE;
96985 }
96986
96987-static struct notifier_block vlan_notifier_block __read_mostly = {
96988+static struct notifier_block vlan_notifier_block = {
96989 .notifier_call = vlan_device_event,
96990 };
96991
96992@@ -549,8 +549,7 @@ static int vlan_ioctl_handler(struct net *net, void __user *arg)
96993 err = -EPERM;
96994 if (!ns_capable(net->user_ns, CAP_NET_ADMIN))
96995 break;
96996- if ((args.u.name_type >= 0) &&
96997- (args.u.name_type < VLAN_NAME_TYPE_HIGHEST)) {
96998+ if (args.u.name_type < VLAN_NAME_TYPE_HIGHEST) {
96999 struct vlan_net *vn;
97000
97001 vn = net_generic(net, vlan_net_id);
97002diff --git a/net/9p/client.c b/net/9p/client.c
97003index 9186550..e604a2f 100644
97004--- a/net/9p/client.c
97005+++ b/net/9p/client.c
97006@@ -588,7 +588,7 @@ static int p9_check_zc_errors(struct p9_client *c, struct p9_req_t *req,
97007 len - inline_len);
97008 } else {
97009 err = copy_from_user(ename + inline_len,
97010- uidata, len - inline_len);
97011+ (char __force_user *)uidata, len - inline_len);
97012 if (err) {
97013 err = -EFAULT;
97014 goto out_err;
97015@@ -1560,7 +1560,7 @@ p9_client_read(struct p9_fid *fid, char *data, char __user *udata, u64 offset,
97016 kernel_buf = 1;
97017 indata = data;
97018 } else
97019- indata = (__force char *)udata;
97020+ indata = (__force_kernel char *)udata;
97021 /*
97022 * response header len is 11
97023 * PDU Header(7) + IO Size (4)
97024@@ -1635,7 +1635,7 @@ p9_client_write(struct p9_fid *fid, char *data, const char __user *udata,
97025 kernel_buf = 1;
97026 odata = data;
97027 } else
97028- odata = (char *)udata;
97029+ odata = (char __force_kernel *)udata;
97030 req = p9_client_zc_rpc(clnt, P9_TWRITE, NULL, odata, 0, rsize,
97031 P9_ZC_HDR_SZ, kernel_buf, "dqd",
97032 fid->fid, offset, rsize);
97033diff --git a/net/9p/mod.c b/net/9p/mod.c
97034index 6ab36ae..6f1841b 100644
97035--- a/net/9p/mod.c
97036+++ b/net/9p/mod.c
97037@@ -84,7 +84,7 @@ static LIST_HEAD(v9fs_trans_list);
97038 void v9fs_register_trans(struct p9_trans_module *m)
97039 {
97040 spin_lock(&v9fs_trans_lock);
97041- list_add_tail(&m->list, &v9fs_trans_list);
97042+ pax_list_add_tail((struct list_head *)&m->list, &v9fs_trans_list);
97043 spin_unlock(&v9fs_trans_lock);
97044 }
97045 EXPORT_SYMBOL(v9fs_register_trans);
97046@@ -97,7 +97,7 @@ EXPORT_SYMBOL(v9fs_register_trans);
97047 void v9fs_unregister_trans(struct p9_trans_module *m)
97048 {
97049 spin_lock(&v9fs_trans_lock);
97050- list_del_init(&m->list);
97051+ pax_list_del_init((struct list_head *)&m->list);
97052 spin_unlock(&v9fs_trans_lock);
97053 }
97054 EXPORT_SYMBOL(v9fs_unregister_trans);
97055diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c
97056index b7bd7f2..2498bf7 100644
97057--- a/net/9p/trans_fd.c
97058+++ b/net/9p/trans_fd.c
97059@@ -432,7 +432,7 @@ static int p9_fd_write(struct p9_client *client, void *v, int len)
97060 oldfs = get_fs();
97061 set_fs(get_ds());
97062 /* The cast to a user pointer is valid due to the set_fs() */
97063- ret = vfs_write(ts->wr, (__force void __user *)v, len, &ts->wr->f_pos);
97064+ ret = vfs_write(ts->wr, (void __force_user *)v, len, &ts->wr->f_pos);
97065 set_fs(oldfs);
97066
97067 if (ret <= 0 && ret != -ERESTARTSYS && ret != -EAGAIN)
97068diff --git a/net/appletalk/atalk_proc.c b/net/appletalk/atalk_proc.c
97069index af46bc4..f9adfcd 100644
97070--- a/net/appletalk/atalk_proc.c
97071+++ b/net/appletalk/atalk_proc.c
97072@@ -256,7 +256,7 @@ int __init atalk_proc_init(void)
97073 struct proc_dir_entry *p;
97074 int rc = -ENOMEM;
97075
97076- atalk_proc_dir = proc_mkdir("atalk", init_net.proc_net);
97077+ atalk_proc_dir = proc_mkdir_restrict("atalk", init_net.proc_net);
97078 if (!atalk_proc_dir)
97079 goto out;
97080
97081diff --git a/net/atm/atm_misc.c b/net/atm/atm_misc.c
97082index 876fbe8..8bbea9f 100644
97083--- a/net/atm/atm_misc.c
97084+++ b/net/atm/atm_misc.c
97085@@ -17,7 +17,7 @@ int atm_charge(struct atm_vcc *vcc, int truesize)
97086 if (atomic_read(&sk_atm(vcc)->sk_rmem_alloc) <= sk_atm(vcc)->sk_rcvbuf)
97087 return 1;
97088 atm_return(vcc, truesize);
97089- atomic_inc(&vcc->stats->rx_drop);
97090+ atomic_inc_unchecked(&vcc->stats->rx_drop);
97091 return 0;
97092 }
97093 EXPORT_SYMBOL(atm_charge);
97094@@ -39,7 +39,7 @@ struct sk_buff *atm_alloc_charge(struct atm_vcc *vcc, int pdu_size,
97095 }
97096 }
97097 atm_return(vcc, guess);
97098- atomic_inc(&vcc->stats->rx_drop);
97099+ atomic_inc_unchecked(&vcc->stats->rx_drop);
97100 return NULL;
97101 }
97102 EXPORT_SYMBOL(atm_alloc_charge);
97103@@ -86,7 +86,7 @@ EXPORT_SYMBOL(atm_pcr_goal);
97104
97105 void sonet_copy_stats(struct k_sonet_stats *from, struct sonet_stats *to)
97106 {
97107-#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
97108+#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
97109 __SONET_ITEMS
97110 #undef __HANDLE_ITEM
97111 }
97112@@ -94,7 +94,7 @@ EXPORT_SYMBOL(sonet_copy_stats);
97113
97114 void sonet_subtract_stats(struct k_sonet_stats *from, struct sonet_stats *to)
97115 {
97116-#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
97117+#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i,&from->i)
97118 __SONET_ITEMS
97119 #undef __HANDLE_ITEM
97120 }
97121diff --git a/net/atm/lec.c b/net/atm/lec.c
97122index 5a2f602..9396143 100644
97123--- a/net/atm/lec.c
97124+++ b/net/atm/lec.c
97125@@ -111,9 +111,9 @@ static inline void lec_arp_put(struct lec_arp_table *entry)
97126 }
97127
97128 static struct lane2_ops lane2_ops = {
97129- lane2_resolve, /* resolve, spec 3.1.3 */
97130- lane2_associate_req, /* associate_req, spec 3.1.4 */
97131- NULL /* associate indicator, spec 3.1.5 */
97132+ .resolve = lane2_resolve,
97133+ .associate_req = lane2_associate_req,
97134+ .associate_indicator = NULL
97135 };
97136
97137 static unsigned char bus_mac[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
97138diff --git a/net/atm/lec.h b/net/atm/lec.h
97139index 4149db1..f2ab682 100644
97140--- a/net/atm/lec.h
97141+++ b/net/atm/lec.h
97142@@ -48,7 +48,7 @@ struct lane2_ops {
97143 const u8 *tlvs, u32 sizeoftlvs);
97144 void (*associate_indicator) (struct net_device *dev, const u8 *mac_addr,
97145 const u8 *tlvs, u32 sizeoftlvs);
97146-};
97147+} __no_const;
97148
97149 /*
97150 * ATM LAN Emulation supports both LLC & Dix Ethernet EtherType
97151diff --git a/net/atm/mpoa_caches.c b/net/atm/mpoa_caches.c
97152index d1b2d9a..d549f7f 100644
97153--- a/net/atm/mpoa_caches.c
97154+++ b/net/atm/mpoa_caches.c
97155@@ -535,30 +535,30 @@ static void eg_destroy_cache(struct mpoa_client *mpc)
97156
97157
97158 static struct in_cache_ops ingress_ops = {
97159- in_cache_add_entry, /* add_entry */
97160- in_cache_get, /* get */
97161- in_cache_get_with_mask, /* get_with_mask */
97162- in_cache_get_by_vcc, /* get_by_vcc */
97163- in_cache_put, /* put */
97164- in_cache_remove_entry, /* remove_entry */
97165- cache_hit, /* cache_hit */
97166- clear_count_and_expired, /* clear_count */
97167- check_resolving_entries, /* check_resolving */
97168- refresh_entries, /* refresh */
97169- in_destroy_cache /* destroy_cache */
97170+ .add_entry = in_cache_add_entry,
97171+ .get = in_cache_get,
97172+ .get_with_mask = in_cache_get_with_mask,
97173+ .get_by_vcc = in_cache_get_by_vcc,
97174+ .put = in_cache_put,
97175+ .remove_entry = in_cache_remove_entry,
97176+ .cache_hit = cache_hit,
97177+ .clear_count = clear_count_and_expired,
97178+ .check_resolving = check_resolving_entries,
97179+ .refresh = refresh_entries,
97180+ .destroy_cache = in_destroy_cache
97181 };
97182
97183 static struct eg_cache_ops egress_ops = {
97184- eg_cache_add_entry, /* add_entry */
97185- eg_cache_get_by_cache_id, /* get_by_cache_id */
97186- eg_cache_get_by_tag, /* get_by_tag */
97187- eg_cache_get_by_vcc, /* get_by_vcc */
97188- eg_cache_get_by_src_ip, /* get_by_src_ip */
97189- eg_cache_put, /* put */
97190- eg_cache_remove_entry, /* remove_entry */
97191- update_eg_cache_entry, /* update */
97192- clear_expired, /* clear_expired */
97193- eg_destroy_cache /* destroy_cache */
97194+ .add_entry = eg_cache_add_entry,
97195+ .get_by_cache_id = eg_cache_get_by_cache_id,
97196+ .get_by_tag = eg_cache_get_by_tag,
97197+ .get_by_vcc = eg_cache_get_by_vcc,
97198+ .get_by_src_ip = eg_cache_get_by_src_ip,
97199+ .put = eg_cache_put,
97200+ .remove_entry = eg_cache_remove_entry,
97201+ .update = update_eg_cache_entry,
97202+ .clear_expired = clear_expired,
97203+ .destroy_cache = eg_destroy_cache
97204 };
97205
97206
97207diff --git a/net/atm/proc.c b/net/atm/proc.c
97208index bbb6461..cf04016 100644
97209--- a/net/atm/proc.c
97210+++ b/net/atm/proc.c
97211@@ -45,9 +45,9 @@ static void add_stats(struct seq_file *seq, const char *aal,
97212 const struct k_atm_aal_stats *stats)
97213 {
97214 seq_printf(seq, "%s ( %d %d %d %d %d )", aal,
97215- atomic_read(&stats->tx), atomic_read(&stats->tx_err),
97216- atomic_read(&stats->rx), atomic_read(&stats->rx_err),
97217- atomic_read(&stats->rx_drop));
97218+ atomic_read_unchecked(&stats->tx),atomic_read_unchecked(&stats->tx_err),
97219+ atomic_read_unchecked(&stats->rx),atomic_read_unchecked(&stats->rx_err),
97220+ atomic_read_unchecked(&stats->rx_drop));
97221 }
97222
97223 static void atm_dev_info(struct seq_file *seq, const struct atm_dev *dev)
97224diff --git a/net/atm/resources.c b/net/atm/resources.c
97225index 0447d5d..3cf4728 100644
97226--- a/net/atm/resources.c
97227+++ b/net/atm/resources.c
97228@@ -160,7 +160,7 @@ EXPORT_SYMBOL(atm_dev_deregister);
97229 static void copy_aal_stats(struct k_atm_aal_stats *from,
97230 struct atm_aal_stats *to)
97231 {
97232-#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
97233+#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
97234 __AAL_STAT_ITEMS
97235 #undef __HANDLE_ITEM
97236 }
97237@@ -168,7 +168,7 @@ static void copy_aal_stats(struct k_atm_aal_stats *from,
97238 static void subtract_aal_stats(struct k_atm_aal_stats *from,
97239 struct atm_aal_stats *to)
97240 {
97241-#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
97242+#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i, &from->i)
97243 __AAL_STAT_ITEMS
97244 #undef __HANDLE_ITEM
97245 }
97246diff --git a/net/ax25/sysctl_net_ax25.c b/net/ax25/sysctl_net_ax25.c
97247index 919a5ce..cc6b444 100644
97248--- a/net/ax25/sysctl_net_ax25.c
97249+++ b/net/ax25/sysctl_net_ax25.c
97250@@ -152,7 +152,7 @@ int ax25_register_dev_sysctl(ax25_dev *ax25_dev)
97251 {
97252 char path[sizeof("net/ax25/") + IFNAMSIZ];
97253 int k;
97254- struct ctl_table *table;
97255+ ctl_table_no_const *table;
97256
97257 table = kmemdup(ax25_param_table, sizeof(ax25_param_table), GFP_KERNEL);
97258 if (!table)
97259diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
97260index 8323bce..a03130d 100644
97261--- a/net/batman-adv/bat_iv_ogm.c
97262+++ b/net/batman-adv/bat_iv_ogm.c
97263@@ -312,7 +312,7 @@ static int batadv_iv_ogm_iface_enable(struct batadv_hard_iface *hard_iface)
97264
97265 /* randomize initial seqno to avoid collision */
97266 get_random_bytes(&random_seqno, sizeof(random_seqno));
97267- atomic_set(&hard_iface->bat_iv.ogm_seqno, random_seqno);
97268+ atomic_set_unchecked(&hard_iface->bat_iv.ogm_seqno, random_seqno);
97269
97270 hard_iface->bat_iv.ogm_buff_len = BATADV_OGM_HLEN;
97271 ogm_buff = kmalloc(hard_iface->bat_iv.ogm_buff_len, GFP_ATOMIC);
97272@@ -917,9 +917,9 @@ static void batadv_iv_ogm_schedule(struct batadv_hard_iface *hard_iface)
97273 batadv_ogm_packet->tvlv_len = htons(tvlv_len);
97274
97275 /* change sequence number to network order */
97276- seqno = (uint32_t)atomic_read(&hard_iface->bat_iv.ogm_seqno);
97277+ seqno = (uint32_t)atomic_read_unchecked(&hard_iface->bat_iv.ogm_seqno);
97278 batadv_ogm_packet->seqno = htonl(seqno);
97279- atomic_inc(&hard_iface->bat_iv.ogm_seqno);
97280+ atomic_inc_unchecked(&hard_iface->bat_iv.ogm_seqno);
97281
97282 batadv_iv_ogm_slide_own_bcast_window(hard_iface);
97283
97284@@ -1594,7 +1594,7 @@ static void batadv_iv_ogm_process(const struct sk_buff *skb, int ogm_offset,
97285 return;
97286
97287 /* could be changed by schedule_own_packet() */
97288- if_incoming_seqno = atomic_read(&if_incoming->bat_iv.ogm_seqno);
97289+ if_incoming_seqno = atomic_read_unchecked(&if_incoming->bat_iv.ogm_seqno);
97290
97291 if (ogm_packet->flags & BATADV_DIRECTLINK)
97292 has_directlink_flag = true;
97293diff --git a/net/batman-adv/fragmentation.c b/net/batman-adv/fragmentation.c
97294index 88df9b1..69cf7c0 100644
97295--- a/net/batman-adv/fragmentation.c
97296+++ b/net/batman-adv/fragmentation.c
97297@@ -445,7 +445,7 @@ bool batadv_frag_send_packet(struct sk_buff *skb,
97298 frag_header.packet_type = BATADV_UNICAST_FRAG;
97299 frag_header.version = BATADV_COMPAT_VERSION;
97300 frag_header.ttl = BATADV_TTL;
97301- frag_header.seqno = htons(atomic_inc_return(&bat_priv->frag_seqno));
97302+ frag_header.seqno = htons(atomic_inc_return_unchecked(&bat_priv->frag_seqno));
97303 frag_header.reserved = 0;
97304 frag_header.no = 0;
97305 frag_header.total_size = htons(skb->len);
97306diff --git a/net/batman-adv/soft-interface.c b/net/batman-adv/soft-interface.c
97307index f82c267..0e56d32 100644
97308--- a/net/batman-adv/soft-interface.c
97309+++ b/net/batman-adv/soft-interface.c
97310@@ -283,7 +283,7 @@ send:
97311 primary_if->net_dev->dev_addr, ETH_ALEN);
97312
97313 /* set broadcast sequence number */
97314- seqno = atomic_inc_return(&bat_priv->bcast_seqno);
97315+ seqno = atomic_inc_return_unchecked(&bat_priv->bcast_seqno);
97316 bcast_packet->seqno = htonl(seqno);
97317
97318 batadv_add_bcast_packet_to_list(bat_priv, skb, brd_delay);
97319@@ -707,7 +707,7 @@ static int batadv_softif_init_late(struct net_device *dev)
97320 atomic_set(&bat_priv->batman_queue_left, BATADV_BATMAN_QUEUE_LEN);
97321
97322 atomic_set(&bat_priv->mesh_state, BATADV_MESH_INACTIVE);
97323- atomic_set(&bat_priv->bcast_seqno, 1);
97324+ atomic_set_unchecked(&bat_priv->bcast_seqno, 1);
97325 atomic_set(&bat_priv->tt.vn, 0);
97326 atomic_set(&bat_priv->tt.local_changes, 0);
97327 atomic_set(&bat_priv->tt.ogm_append_cnt, 0);
97328@@ -721,7 +721,7 @@ static int batadv_softif_init_late(struct net_device *dev)
97329
97330 /* randomize initial seqno to avoid collision */
97331 get_random_bytes(&random_seqno, sizeof(random_seqno));
97332- atomic_set(&bat_priv->frag_seqno, random_seqno);
97333+ atomic_set_unchecked(&bat_priv->frag_seqno, random_seqno);
97334
97335 bat_priv->primary_if = NULL;
97336 bat_priv->num_ifaces = 0;
97337diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
97338index 78370ab..1cb3614 100644
97339--- a/net/batman-adv/types.h
97340+++ b/net/batman-adv/types.h
97341@@ -66,7 +66,7 @@ enum batadv_dhcp_recipient {
97342 struct batadv_hard_iface_bat_iv {
97343 unsigned char *ogm_buff;
97344 int ogm_buff_len;
97345- atomic_t ogm_seqno;
97346+ atomic_unchecked_t ogm_seqno;
97347 };
97348
97349 /**
97350@@ -714,7 +714,7 @@ struct batadv_priv {
97351 atomic_t bonding;
97352 atomic_t fragmentation;
97353 atomic_t packet_size_max;
97354- atomic_t frag_seqno;
97355+ atomic_unchecked_t frag_seqno;
97356 #ifdef CONFIG_BATMAN_ADV_BLA
97357 atomic_t bridge_loop_avoidance;
97358 #endif
97359@@ -730,7 +730,7 @@ struct batadv_priv {
97360 #endif
97361 uint32_t isolation_mark;
97362 uint32_t isolation_mark_mask;
97363- atomic_t bcast_seqno;
97364+ atomic_unchecked_t bcast_seqno;
97365 atomic_t bcast_queue_left;
97366 atomic_t batman_queue_left;
97367 char num_ifaces;
97368diff --git a/net/bluetooth/hci_sock.c b/net/bluetooth/hci_sock.c
97369index 7552f9e..074ce29 100644
97370--- a/net/bluetooth/hci_sock.c
97371+++ b/net/bluetooth/hci_sock.c
97372@@ -1052,7 +1052,7 @@ static int hci_sock_setsockopt(struct socket *sock, int level, int optname,
97373 uf.event_mask[1] = *((u32 *) f->event_mask + 1);
97374 }
97375
97376- len = min_t(unsigned int, len, sizeof(uf));
97377+ len = min((size_t)len, sizeof(uf));
97378 if (copy_from_user(&uf, optval, len)) {
97379 err = -EFAULT;
97380 break;
97381diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
97382index b0ad2c7..96f6a5e 100644
97383--- a/net/bluetooth/l2cap_core.c
97384+++ b/net/bluetooth/l2cap_core.c
97385@@ -3740,8 +3740,10 @@ static int l2cap_parse_conf_rsp(struct l2cap_chan *chan, void *rsp, int len,
97386 break;
97387
97388 case L2CAP_CONF_RFC:
97389- if (olen == sizeof(rfc))
97390- memcpy(&rfc, (void *)val, olen);
97391+ if (olen != sizeof(rfc))
97392+ break;
97393+
97394+ memcpy(&rfc, (void *)val, olen);
97395
97396 if (test_bit(CONF_STATE2_DEVICE, &chan->conf_state) &&
97397 rfc.mode != chan->mode)
97398diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c
97399index d58f76b..b69600a 100644
97400--- a/net/bluetooth/l2cap_sock.c
97401+++ b/net/bluetooth/l2cap_sock.c
97402@@ -625,7 +625,8 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
97403 struct sock *sk = sock->sk;
97404 struct l2cap_chan *chan = l2cap_pi(sk)->chan;
97405 struct l2cap_options opts;
97406- int len, err = 0;
97407+ int err = 0;
97408+ size_t len = optlen;
97409 u32 opt;
97410
97411 BT_DBG("sk %p", sk);
97412@@ -652,7 +653,7 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
97413 opts.max_tx = chan->max_tx;
97414 opts.txwin_size = chan->tx_win;
97415
97416- len = min_t(unsigned int, sizeof(opts), optlen);
97417+ len = min(sizeof(opts), len);
97418 if (copy_from_user((char *) &opts, optval, len)) {
97419 err = -EFAULT;
97420 break;
97421@@ -734,7 +735,8 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
97422 struct bt_security sec;
97423 struct bt_power pwr;
97424 struct l2cap_conn *conn;
97425- int len, err = 0;
97426+ int err = 0;
97427+ size_t len = optlen;
97428 u32 opt;
97429
97430 BT_DBG("sk %p", sk);
97431@@ -757,7 +759,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
97432
97433 sec.level = BT_SECURITY_LOW;
97434
97435- len = min_t(unsigned int, sizeof(sec), optlen);
97436+ len = min(sizeof(sec), len);
97437 if (copy_from_user((char *) &sec, optval, len)) {
97438 err = -EFAULT;
97439 break;
97440@@ -857,7 +859,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
97441
97442 pwr.force_active = BT_POWER_FORCE_ACTIVE_ON;
97443
97444- len = min_t(unsigned int, sizeof(pwr), optlen);
97445+ len = min(sizeof(pwr), len);
97446 if (copy_from_user((char *) &pwr, optval, len)) {
97447 err = -EFAULT;
97448 break;
97449diff --git a/net/bluetooth/rfcomm/sock.c b/net/bluetooth/rfcomm/sock.c
97450index 3c2d3e4..884855a 100644
97451--- a/net/bluetooth/rfcomm/sock.c
97452+++ b/net/bluetooth/rfcomm/sock.c
97453@@ -672,7 +672,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
97454 struct sock *sk = sock->sk;
97455 struct bt_security sec;
97456 int err = 0;
97457- size_t len;
97458+ size_t len = optlen;
97459 u32 opt;
97460
97461 BT_DBG("sk %p", sk);
97462@@ -694,7 +694,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
97463
97464 sec.level = BT_SECURITY_LOW;
97465
97466- len = min_t(unsigned int, sizeof(sec), optlen);
97467+ len = min(sizeof(sec), len);
97468 if (copy_from_user((char *) &sec, optval, len)) {
97469 err = -EFAULT;
97470 break;
97471diff --git a/net/bluetooth/rfcomm/tty.c b/net/bluetooth/rfcomm/tty.c
97472index f9c0980a..fcbbfeb 100644
97473--- a/net/bluetooth/rfcomm/tty.c
97474+++ b/net/bluetooth/rfcomm/tty.c
97475@@ -717,7 +717,7 @@ static int rfcomm_tty_open(struct tty_struct *tty, struct file *filp)
97476 BT_DBG("tty %p id %d", tty, tty->index);
97477
97478 BT_DBG("dev %p dst %pMR channel %d opened %d", dev, &dev->dst,
97479- dev->channel, dev->port.count);
97480+ dev->channel, atomic_read(&dev->port.count));
97481
97482 err = tty_port_open(&dev->port, tty, filp);
97483 if (err)
97484@@ -740,7 +740,7 @@ static void rfcomm_tty_close(struct tty_struct *tty, struct file *filp)
97485 struct rfcomm_dev *dev = (struct rfcomm_dev *) tty->driver_data;
97486
97487 BT_DBG("tty %p dev %p dlc %p opened %d", tty, dev, dev->dlc,
97488- dev->port.count);
97489+ atomic_read(&dev->port.count));
97490
97491 tty_port_close(&dev->port, tty, filp);
97492 }
97493diff --git a/net/bridge/netfilter/ebtables.c b/net/bridge/netfilter/ebtables.c
97494index 0e474b1..fb7109c 100644
97495--- a/net/bridge/netfilter/ebtables.c
97496+++ b/net/bridge/netfilter/ebtables.c
97497@@ -1525,7 +1525,7 @@ static int do_ebt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
97498 tmp.valid_hooks = t->table->valid_hooks;
97499 }
97500 mutex_unlock(&ebt_mutex);
97501- if (copy_to_user(user, &tmp, *len) != 0) {
97502+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
97503 BUGPRINT("c2u Didn't work\n");
97504 ret = -EFAULT;
97505 break;
97506@@ -2331,7 +2331,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
97507 goto out;
97508 tmp.valid_hooks = t->valid_hooks;
97509
97510- if (copy_to_user(user, &tmp, *len) != 0) {
97511+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
97512 ret = -EFAULT;
97513 break;
97514 }
97515@@ -2342,7 +2342,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
97516 tmp.entries_size = t->table->entries_size;
97517 tmp.valid_hooks = t->table->valid_hooks;
97518
97519- if (copy_to_user(user, &tmp, *len) != 0) {
97520+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
97521 ret = -EFAULT;
97522 break;
97523 }
97524diff --git a/net/caif/cfctrl.c b/net/caif/cfctrl.c
97525index 0f45522..dab651f 100644
97526--- a/net/caif/cfctrl.c
97527+++ b/net/caif/cfctrl.c
97528@@ -10,6 +10,7 @@
97529 #include <linux/spinlock.h>
97530 #include <linux/slab.h>
97531 #include <linux/pkt_sched.h>
97532+#include <linux/sched.h>
97533 #include <net/caif/caif_layer.h>
97534 #include <net/caif/cfpkt.h>
97535 #include <net/caif/cfctrl.h>
97536@@ -43,8 +44,8 @@ struct cflayer *cfctrl_create(void)
97537 memset(&dev_info, 0, sizeof(dev_info));
97538 dev_info.id = 0xff;
97539 cfsrvl_init(&this->serv, 0, &dev_info, false);
97540- atomic_set(&this->req_seq_no, 1);
97541- atomic_set(&this->rsp_seq_no, 1);
97542+ atomic_set_unchecked(&this->req_seq_no, 1);
97543+ atomic_set_unchecked(&this->rsp_seq_no, 1);
97544 this->serv.layer.receive = cfctrl_recv;
97545 sprintf(this->serv.layer.name, "ctrl");
97546 this->serv.layer.ctrlcmd = cfctrl_ctrlcmd;
97547@@ -130,8 +131,8 @@ static void cfctrl_insert_req(struct cfctrl *ctrl,
97548 struct cfctrl_request_info *req)
97549 {
97550 spin_lock_bh(&ctrl->info_list_lock);
97551- atomic_inc(&ctrl->req_seq_no);
97552- req->sequence_no = atomic_read(&ctrl->req_seq_no);
97553+ atomic_inc_unchecked(&ctrl->req_seq_no);
97554+ req->sequence_no = atomic_read_unchecked(&ctrl->req_seq_no);
97555 list_add_tail(&req->list, &ctrl->list);
97556 spin_unlock_bh(&ctrl->info_list_lock);
97557 }
97558@@ -149,7 +150,7 @@ static struct cfctrl_request_info *cfctrl_remove_req(struct cfctrl *ctrl,
97559 if (p != first)
97560 pr_warn("Requests are not received in order\n");
97561
97562- atomic_set(&ctrl->rsp_seq_no,
97563+ atomic_set_unchecked(&ctrl->rsp_seq_no,
97564 p->sequence_no);
97565 list_del(&p->list);
97566 goto out;
97567diff --git a/net/can/af_can.c b/net/can/af_can.c
97568index a27f8aa..67174a3 100644
97569--- a/net/can/af_can.c
97570+++ b/net/can/af_can.c
97571@@ -863,7 +863,7 @@ static const struct net_proto_family can_family_ops = {
97572 };
97573
97574 /* notifier block for netdevice event */
97575-static struct notifier_block can_netdev_notifier __read_mostly = {
97576+static struct notifier_block can_netdev_notifier = {
97577 .notifier_call = can_notifier,
97578 };
97579
97580diff --git a/net/can/bcm.c b/net/can/bcm.c
97581index dcb75c0..24b1b43 100644
97582--- a/net/can/bcm.c
97583+++ b/net/can/bcm.c
97584@@ -1624,7 +1624,7 @@ static int __init bcm_module_init(void)
97585 }
97586
97587 /* create /proc/net/can-bcm directory */
97588- proc_dir = proc_mkdir("can-bcm", init_net.proc_net);
97589+ proc_dir = proc_mkdir_restrict("can-bcm", init_net.proc_net);
97590 return 0;
97591 }
97592
97593diff --git a/net/can/gw.c b/net/can/gw.c
97594index ac31891..4799c17 100644
97595--- a/net/can/gw.c
97596+++ b/net/can/gw.c
97597@@ -80,7 +80,6 @@ MODULE_PARM_DESC(max_hops,
97598 "default: " __stringify(CGW_DEFAULT_HOPS) ")");
97599
97600 static HLIST_HEAD(cgw_list);
97601-static struct notifier_block notifier;
97602
97603 static struct kmem_cache *cgw_cache __read_mostly;
97604
97605@@ -947,6 +946,10 @@ static int cgw_remove_job(struct sk_buff *skb, struct nlmsghdr *nlh)
97606 return err;
97607 }
97608
97609+static struct notifier_block notifier = {
97610+ .notifier_call = cgw_notifier
97611+};
97612+
97613 static __init int cgw_module_init(void)
97614 {
97615 /* sanitize given module parameter */
97616@@ -962,7 +965,6 @@ static __init int cgw_module_init(void)
97617 return -ENOMEM;
97618
97619 /* set notifier */
97620- notifier.notifier_call = cgw_notifier;
97621 register_netdevice_notifier(&notifier);
97622
97623 if (__rtnl_register(PF_CAN, RTM_GETROUTE, NULL, cgw_dump_jobs, NULL)) {
97624diff --git a/net/can/proc.c b/net/can/proc.c
97625index b543470..d2ddae2 100644
97626--- a/net/can/proc.c
97627+++ b/net/can/proc.c
97628@@ -468,7 +468,7 @@ static void can_remove_proc_readentry(const char *name)
97629 void can_init_proc(void)
97630 {
97631 /* create /proc/net/can directory */
97632- can_dir = proc_mkdir("can", init_net.proc_net);
97633+ can_dir = proc_mkdir_restrict("can", init_net.proc_net);
97634
97635 if (!can_dir) {
97636 printk(KERN_INFO "can: failed to create /proc/net/can . "
97637diff --git a/net/ceph/messenger.c b/net/ceph/messenger.c
97638index 30efc5c..cfa1bbc 100644
97639--- a/net/ceph/messenger.c
97640+++ b/net/ceph/messenger.c
97641@@ -187,7 +187,7 @@ static void con_fault(struct ceph_connection *con);
97642 #define MAX_ADDR_STR_LEN 64 /* 54 is enough */
97643
97644 static char addr_str[ADDR_STR_COUNT][MAX_ADDR_STR_LEN];
97645-static atomic_t addr_str_seq = ATOMIC_INIT(0);
97646+static atomic_unchecked_t addr_str_seq = ATOMIC_INIT(0);
97647
97648 static struct page *zero_page; /* used in certain error cases */
97649
97650@@ -198,7 +198,7 @@ const char *ceph_pr_addr(const struct sockaddr_storage *ss)
97651 struct sockaddr_in *in4 = (struct sockaddr_in *) ss;
97652 struct sockaddr_in6 *in6 = (struct sockaddr_in6 *) ss;
97653
97654- i = atomic_inc_return(&addr_str_seq) & ADDR_STR_COUNT_MASK;
97655+ i = atomic_inc_return_unchecked(&addr_str_seq) & ADDR_STR_COUNT_MASK;
97656 s = addr_str[i];
97657
97658 switch (ss->ss_family) {
97659diff --git a/net/compat.c b/net/compat.c
97660index f50161f..94fa415 100644
97661--- a/net/compat.c
97662+++ b/net/compat.c
97663@@ -73,9 +73,9 @@ int get_compat_msghdr(struct msghdr *kmsg, struct compat_msghdr __user *umsg)
97664 return -EFAULT;
97665 if (kmsg->msg_namelen > sizeof(struct sockaddr_storage))
97666 kmsg->msg_namelen = sizeof(struct sockaddr_storage);
97667- kmsg->msg_name = compat_ptr(tmp1);
97668- kmsg->msg_iov = compat_ptr(tmp2);
97669- kmsg->msg_control = compat_ptr(tmp3);
97670+ kmsg->msg_name = (void __force_kernel *)compat_ptr(tmp1);
97671+ kmsg->msg_iov = (void __force_kernel *)compat_ptr(tmp2);
97672+ kmsg->msg_control = (void __force_kernel *)compat_ptr(tmp3);
97673 return 0;
97674 }
97675
97676@@ -87,7 +87,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
97677
97678 if (kern_msg->msg_namelen) {
97679 if (mode == VERIFY_READ) {
97680- int err = move_addr_to_kernel(kern_msg->msg_name,
97681+ int err = move_addr_to_kernel((void __force_user *)kern_msg->msg_name,
97682 kern_msg->msg_namelen,
97683 kern_address);
97684 if (err < 0)
97685@@ -99,7 +99,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
97686 kern_msg->msg_name = NULL;
97687
97688 tot_len = iov_from_user_compat_to_kern(kern_iov,
97689- (struct compat_iovec __user *)kern_msg->msg_iov,
97690+ (struct compat_iovec __force_user *)kern_msg->msg_iov,
97691 kern_msg->msg_iovlen);
97692 if (tot_len >= 0)
97693 kern_msg->msg_iov = kern_iov;
97694@@ -119,20 +119,20 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
97695
97696 #define CMSG_COMPAT_FIRSTHDR(msg) \
97697 (((msg)->msg_controllen) >= sizeof(struct compat_cmsghdr) ? \
97698- (struct compat_cmsghdr __user *)((msg)->msg_control) : \
97699+ (struct compat_cmsghdr __force_user *)((msg)->msg_control) : \
97700 (struct compat_cmsghdr __user *)NULL)
97701
97702 #define CMSG_COMPAT_OK(ucmlen, ucmsg, mhdr) \
97703 ((ucmlen) >= sizeof(struct compat_cmsghdr) && \
97704 (ucmlen) <= (unsigned long) \
97705 ((mhdr)->msg_controllen - \
97706- ((char *)(ucmsg) - (char *)(mhdr)->msg_control)))
97707+ ((char __force_kernel *)(ucmsg) - (char *)(mhdr)->msg_control)))
97708
97709 static inline struct compat_cmsghdr __user *cmsg_compat_nxthdr(struct msghdr *msg,
97710 struct compat_cmsghdr __user *cmsg, int cmsg_len)
97711 {
97712 char __user *ptr = (char __user *)cmsg + CMSG_COMPAT_ALIGN(cmsg_len);
97713- if ((unsigned long)(ptr + 1 - (char __user *)msg->msg_control) >
97714+ if ((unsigned long)(ptr + 1 - (char __force_user *)msg->msg_control) >
97715 msg->msg_controllen)
97716 return NULL;
97717 return (struct compat_cmsghdr __user *)ptr;
97718@@ -222,7 +222,7 @@ Efault:
97719
97720 int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *data)
97721 {
97722- struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
97723+ struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
97724 struct compat_cmsghdr cmhdr;
97725 struct compat_timeval ctv;
97726 struct compat_timespec cts[3];
97727@@ -278,7 +278,7 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat
97728
97729 void scm_detach_fds_compat(struct msghdr *kmsg, struct scm_cookie *scm)
97730 {
97731- struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
97732+ struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
97733 int fdmax = (kmsg->msg_controllen - sizeof(struct compat_cmsghdr)) / sizeof(int);
97734 int fdnum = scm->fp->count;
97735 struct file **fp = scm->fp->fp;
97736@@ -366,7 +366,7 @@ static int do_set_sock_timeout(struct socket *sock, int level,
97737 return -EFAULT;
97738 old_fs = get_fs();
97739 set_fs(KERNEL_DS);
97740- err = sock_setsockopt(sock, level, optname, (char *)&ktime, sizeof(ktime));
97741+ err = sock_setsockopt(sock, level, optname, (char __force_user *)&ktime, sizeof(ktime));
97742 set_fs(old_fs);
97743
97744 return err;
97745@@ -427,7 +427,7 @@ static int do_get_sock_timeout(struct socket *sock, int level, int optname,
97746 len = sizeof(ktime);
97747 old_fs = get_fs();
97748 set_fs(KERNEL_DS);
97749- err = sock_getsockopt(sock, level, optname, (char *) &ktime, &len);
97750+ err = sock_getsockopt(sock, level, optname, (char __force_user *) &ktime, (int __force_user *)&len);
97751 set_fs(old_fs);
97752
97753 if (!err) {
97754@@ -570,7 +570,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
97755 case MCAST_JOIN_GROUP:
97756 case MCAST_LEAVE_GROUP:
97757 {
97758- struct compat_group_req __user *gr32 = (void *)optval;
97759+ struct compat_group_req __user *gr32 = (void __user *)optval;
97760 struct group_req __user *kgr =
97761 compat_alloc_user_space(sizeof(struct group_req));
97762 u32 interface;
97763@@ -591,7 +591,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
97764 case MCAST_BLOCK_SOURCE:
97765 case MCAST_UNBLOCK_SOURCE:
97766 {
97767- struct compat_group_source_req __user *gsr32 = (void *)optval;
97768+ struct compat_group_source_req __user *gsr32 = (void __user *)optval;
97769 struct group_source_req __user *kgsr = compat_alloc_user_space(
97770 sizeof(struct group_source_req));
97771 u32 interface;
97772@@ -612,7 +612,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
97773 }
97774 case MCAST_MSFILTER:
97775 {
97776- struct compat_group_filter __user *gf32 = (void *)optval;
97777+ struct compat_group_filter __user *gf32 = (void __user *)optval;
97778 struct group_filter __user *kgf;
97779 u32 interface, fmode, numsrc;
97780
97781@@ -650,7 +650,7 @@ int compat_mc_getsockopt(struct sock *sock, int level, int optname,
97782 char __user *optval, int __user *optlen,
97783 int (*getsockopt)(struct sock *, int, int, char __user *, int __user *))
97784 {
97785- struct compat_group_filter __user *gf32 = (void *)optval;
97786+ struct compat_group_filter __user *gf32 = (void __user *)optval;
97787 struct group_filter __user *kgf;
97788 int __user *koptlen;
97789 u32 interface, fmode, numsrc;
97790@@ -803,7 +803,7 @@ asmlinkage long compat_sys_socketcall(int call, u32 __user *args)
97791
97792 if (call < SYS_SOCKET || call > SYS_SENDMMSG)
97793 return -EINVAL;
97794- if (copy_from_user(a, args, nas[call]))
97795+ if (nas[call] > sizeof a || copy_from_user(a, args, nas[call]))
97796 return -EFAULT;
97797 a0 = a[0];
97798 a1 = a[1];
97799diff --git a/net/core/datagram.c b/net/core/datagram.c
97800index a16ed7b..eb44d17 100644
97801--- a/net/core/datagram.c
97802+++ b/net/core/datagram.c
97803@@ -301,7 +301,7 @@ int skb_kill_datagram(struct sock *sk, struct sk_buff *skb, unsigned int flags)
97804 }
97805
97806 kfree_skb(skb);
97807- atomic_inc(&sk->sk_drops);
97808+ atomic_inc_unchecked(&sk->sk_drops);
97809 sk_mem_reclaim_partial(sk);
97810
97811 return err;
97812diff --git a/net/core/dev.c b/net/core/dev.c
97813index 45fa2f1..f3e28ec 100644
97814--- a/net/core/dev.c
97815+++ b/net/core/dev.c
97816@@ -1688,14 +1688,14 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
97817 {
97818 if (skb_shinfo(skb)->tx_flags & SKBTX_DEV_ZEROCOPY) {
97819 if (skb_copy_ubufs(skb, GFP_ATOMIC)) {
97820- atomic_long_inc(&dev->rx_dropped);
97821+ atomic_long_inc_unchecked(&dev->rx_dropped);
97822 kfree_skb(skb);
97823 return NET_RX_DROP;
97824 }
97825 }
97826
97827 if (unlikely(!is_skb_forwardable(dev, skb))) {
97828- atomic_long_inc(&dev->rx_dropped);
97829+ atomic_long_inc_unchecked(&dev->rx_dropped);
97830 kfree_skb(skb);
97831 return NET_RX_DROP;
97832 }
97833@@ -2453,7 +2453,7 @@ static int illegal_highdma(const struct net_device *dev, struct sk_buff *skb)
97834
97835 struct dev_gso_cb {
97836 void (*destructor)(struct sk_buff *skb);
97837-};
97838+} __no_const;
97839
97840 #define DEV_GSO_CB(skb) ((struct dev_gso_cb *)(skb)->cb)
97841
97842@@ -3227,7 +3227,7 @@ enqueue:
97843
97844 local_irq_restore(flags);
97845
97846- atomic_long_inc(&skb->dev->rx_dropped);
97847+ atomic_long_inc_unchecked(&skb->dev->rx_dropped);
97848 kfree_skb(skb);
97849 return NET_RX_DROP;
97850 }
97851@@ -3308,7 +3308,7 @@ int netif_rx_ni(struct sk_buff *skb)
97852 }
97853 EXPORT_SYMBOL(netif_rx_ni);
97854
97855-static void net_tx_action(struct softirq_action *h)
97856+static __latent_entropy void net_tx_action(void)
97857 {
97858 struct softnet_data *sd = &__get_cpu_var(softnet_data);
97859
97860@@ -3645,7 +3645,7 @@ ncls:
97861 ret = pt_prev->func(skb, skb->dev, pt_prev, orig_dev);
97862 } else {
97863 drop:
97864- atomic_long_inc(&skb->dev->rx_dropped);
97865+ atomic_long_inc_unchecked(&skb->dev->rx_dropped);
97866 kfree_skb(skb);
97867 /* Jamal, now you will not able to escape explaining
97868 * me how you were going to use this. :-)
97869@@ -4331,7 +4331,7 @@ void netif_napi_del(struct napi_struct *napi)
97870 }
97871 EXPORT_SYMBOL(netif_napi_del);
97872
97873-static void net_rx_action(struct softirq_action *h)
97874+static __latent_entropy void net_rx_action(void)
97875 {
97876 struct softnet_data *sd = &__get_cpu_var(softnet_data);
97877 unsigned long time_limit = jiffies + 2;
97878@@ -6250,7 +6250,7 @@ struct rtnl_link_stats64 *dev_get_stats(struct net_device *dev,
97879 } else {
97880 netdev_stats_to_stats64(storage, &dev->stats);
97881 }
97882- storage->rx_dropped += atomic_long_read(&dev->rx_dropped);
97883+ storage->rx_dropped += atomic_long_read_unchecked(&dev->rx_dropped);
97884 return storage;
97885 }
97886 EXPORT_SYMBOL(dev_get_stats);
97887diff --git a/net/core/dev_ioctl.c b/net/core/dev_ioctl.c
97888index cf999e0..c59a975 100644
97889--- a/net/core/dev_ioctl.c
97890+++ b/net/core/dev_ioctl.c
97891@@ -366,9 +366,13 @@ void dev_load(struct net *net, const char *name)
97892 if (no_module && capable(CAP_NET_ADMIN))
97893 no_module = request_module("netdev-%s", name);
97894 if (no_module && capable(CAP_SYS_MODULE)) {
97895+#ifdef CONFIG_GRKERNSEC_MODHARDEN
97896+ ___request_module(true, "grsec_modharden_netdev", "%s", name);
97897+#else
97898 if (!request_module("%s", name))
97899 pr_warn("Loading kernel module for a network device with CAP_SYS_MODULE (deprecated). Use CAP_NET_ADMIN and alias netdev-%s instead.\n",
97900 name);
97901+#endif
97902 }
97903 }
97904 EXPORT_SYMBOL(dev_load);
97905diff --git a/net/core/filter.c b/net/core/filter.c
97906index ad30d62..21c0743 100644
97907--- a/net/core/filter.c
97908+++ b/net/core/filter.c
97909@@ -126,7 +126,7 @@ unsigned int sk_run_filter(const struct sk_buff *skb,
97910 void *ptr;
97911 u32 A = 0; /* Accumulator */
97912 u32 X = 0; /* Index Register */
97913- u32 mem[BPF_MEMWORDS]; /* Scratch Memory Store */
97914+ u32 mem[BPF_MEMWORDS] = {}; /* Scratch Memory Store */
97915 u32 tmp;
97916 int k;
97917
97918@@ -292,10 +292,10 @@ load_b:
97919 X = K;
97920 continue;
97921 case BPF_S_LD_MEM:
97922- A = mem[K];
97923+ A = mem[K&15];
97924 continue;
97925 case BPF_S_LDX_MEM:
97926- X = mem[K];
97927+ X = mem[K&15];
97928 continue;
97929 case BPF_S_MISC_TAX:
97930 X = A;
97931@@ -308,10 +308,10 @@ load_b:
97932 case BPF_S_RET_A:
97933 return A;
97934 case BPF_S_ST:
97935- mem[K] = A;
97936+ mem[K&15] = A;
97937 continue;
97938 case BPF_S_STX:
97939- mem[K] = X;
97940+ mem[K&15] = X;
97941 continue;
97942 case BPF_S_ANC_PROTOCOL:
97943 A = ntohs(skb->protocol);
97944@@ -355,6 +355,10 @@ load_b:
97945
97946 if (skb_is_nonlinear(skb))
97947 return 0;
97948+
97949+ if (skb->len < sizeof(struct nlattr))
97950+ return 0;
97951+
97952 if (A > skb->len - sizeof(struct nlattr))
97953 return 0;
97954
97955@@ -371,11 +375,15 @@ load_b:
97956
97957 if (skb_is_nonlinear(skb))
97958 return 0;
97959+
97960+ if (skb->len < sizeof(struct nlattr))
97961+ return 0;
97962+
97963 if (A > skb->len - sizeof(struct nlattr))
97964 return 0;
97965
97966 nla = (struct nlattr *)&skb->data[A];
97967- if (nla->nla_len > A - skb->len)
97968+ if (nla->nla_len > skb->len - A)
97969 return 0;
97970
97971 nla = nla_find_nested(nla, X);
97972@@ -391,9 +399,10 @@ load_b:
97973 continue;
97974 #endif
97975 default:
97976- WARN_RATELIMIT(1, "Unknown code:%u jt:%u tf:%u k:%u\n",
97977+ WARN(1, KERN_ALERT "Unknown sock filter code:%u jt:%u tf:%u k:%u\n",
97978 fentry->code, fentry->jt,
97979 fentry->jf, fentry->k);
97980+ BUG();
97981 return 0;
97982 }
97983 }
97984@@ -416,7 +425,7 @@ static int check_load_and_stores(struct sock_filter *filter, int flen)
97985 u16 *masks, memvalid = 0; /* one bit per cell, 16 cells */
97986 int pc, ret = 0;
97987
97988- BUILD_BUG_ON(BPF_MEMWORDS > 16);
97989+ BUILD_BUG_ON(BPF_MEMWORDS != 16);
97990 masks = kmalloc(flen * sizeof(*masks), GFP_KERNEL);
97991 if (!masks)
97992 return -ENOMEM;
97993@@ -679,7 +688,7 @@ int sk_unattached_filter_create(struct sk_filter **pfp,
97994 fp = kmalloc(sk_filter_size(fprog->len), GFP_KERNEL);
97995 if (!fp)
97996 return -ENOMEM;
97997- memcpy(fp->insns, fprog->filter, fsize);
97998+ memcpy(fp->insns, (void __force_kernel *)fprog->filter, fsize);
97999
98000 atomic_set(&fp->refcnt, 1);
98001 fp->len = fprog->len;
98002diff --git a/net/core/flow.c b/net/core/flow.c
98003index dfa602c..3103d88 100644
98004--- a/net/core/flow.c
98005+++ b/net/core/flow.c
98006@@ -61,7 +61,7 @@ struct flow_cache {
98007 struct timer_list rnd_timer;
98008 };
98009
98010-atomic_t flow_cache_genid = ATOMIC_INIT(0);
98011+atomic_unchecked_t flow_cache_genid = ATOMIC_INIT(0);
98012 EXPORT_SYMBOL(flow_cache_genid);
98013 static struct flow_cache flow_cache_global;
98014 static struct kmem_cache *flow_cachep __read_mostly;
98015@@ -86,7 +86,7 @@ static void flow_cache_new_hashrnd(unsigned long arg)
98016
98017 static int flow_entry_valid(struct flow_cache_entry *fle)
98018 {
98019- if (atomic_read(&flow_cache_genid) != fle->genid)
98020+ if (atomic_read_unchecked(&flow_cache_genid) != fle->genid)
98021 return 0;
98022 if (fle->object && !fle->object->ops->check(fle->object))
98023 return 0;
98024@@ -258,7 +258,7 @@ flow_cache_lookup(struct net *net, const struct flowi *key, u16 family, u8 dir,
98025 hlist_add_head(&fle->u.hlist, &fcp->hash_table[hash]);
98026 fcp->hash_count++;
98027 }
98028- } else if (likely(fle->genid == atomic_read(&flow_cache_genid))) {
98029+ } else if (likely(fle->genid == atomic_read_unchecked(&flow_cache_genid))) {
98030 flo = fle->object;
98031 if (!flo)
98032 goto ret_object;
98033@@ -279,7 +279,7 @@ nocache:
98034 }
98035 flo = resolver(net, key, family, dir, flo, ctx);
98036 if (fle) {
98037- fle->genid = atomic_read(&flow_cache_genid);
98038+ fle->genid = atomic_read_unchecked(&flow_cache_genid);
98039 if (!IS_ERR(flo))
98040 fle->object = flo;
98041 else
98042diff --git a/net/core/iovec.c b/net/core/iovec.c
98043index b618694..192bbba 100644
98044--- a/net/core/iovec.c
98045+++ b/net/core/iovec.c
98046@@ -42,7 +42,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
98047 if (m->msg_namelen) {
98048 if (mode == VERIFY_READ) {
98049 void __user *namep;
98050- namep = (void __user __force *) m->msg_name;
98051+ namep = (void __force_user *) m->msg_name;
98052 err = move_addr_to_kernel(namep, m->msg_namelen,
98053 address);
98054 if (err < 0)
98055@@ -55,7 +55,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
98056 }
98057
98058 size = m->msg_iovlen * sizeof(struct iovec);
98059- if (copy_from_user(iov, (void __user __force *) m->msg_iov, size))
98060+ if (copy_from_user(iov, (void __force_user *) m->msg_iov, size))
98061 return -EFAULT;
98062
98063 m->msg_iov = iov;
98064diff --git a/net/core/neighbour.c b/net/core/neighbour.c
98065index e161290..8149aea 100644
98066--- a/net/core/neighbour.c
98067+++ b/net/core/neighbour.c
98068@@ -2824,7 +2824,7 @@ static int proc_unres_qlen(struct ctl_table *ctl, int write,
98069 void __user *buffer, size_t *lenp, loff_t *ppos)
98070 {
98071 int size, ret;
98072- struct ctl_table tmp = *ctl;
98073+ ctl_table_no_const tmp = *ctl;
98074
98075 tmp.extra1 = &zero;
98076 tmp.extra2 = &unres_qlen_max;
98077@@ -2886,7 +2886,7 @@ static int neigh_proc_dointvec_zero_intmax(struct ctl_table *ctl, int write,
98078 void __user *buffer,
98079 size_t *lenp, loff_t *ppos)
98080 {
98081- struct ctl_table tmp = *ctl;
98082+ ctl_table_no_const tmp = *ctl;
98083 int ret;
98084
98085 tmp.extra1 = &zero;
98086@@ -3058,11 +3058,12 @@ int neigh_sysctl_register(struct net_device *dev, struct neigh_parms *p,
98087 memset(&t->neigh_vars[NEIGH_VAR_GC_INTERVAL], 0,
98088 sizeof(t->neigh_vars[NEIGH_VAR_GC_INTERVAL]));
98089 } else {
98090+ struct neigh_table *ntable = container_of(p, struct neigh_table, parms);
98091 dev_name_source = "default";
98092- t->neigh_vars[NEIGH_VAR_GC_INTERVAL].data = (int *)(p + 1);
98093- t->neigh_vars[NEIGH_VAR_GC_THRESH1].data = (int *)(p + 1) + 1;
98094- t->neigh_vars[NEIGH_VAR_GC_THRESH2].data = (int *)(p + 1) + 2;
98095- t->neigh_vars[NEIGH_VAR_GC_THRESH3].data = (int *)(p + 1) + 3;
98096+ t->neigh_vars[NEIGH_VAR_GC_INTERVAL].data = &ntable->gc_interval;
98097+ t->neigh_vars[NEIGH_VAR_GC_THRESH1].data = &ntable->gc_thresh1;
98098+ t->neigh_vars[NEIGH_VAR_GC_THRESH2].data = &ntable->gc_thresh2;
98099+ t->neigh_vars[NEIGH_VAR_GC_THRESH3].data = &ntable->gc_thresh3;
98100 }
98101
98102 if (handler) {
98103diff --git a/net/core/net-procfs.c b/net/core/net-procfs.c
98104index 2bf8329..2eb1423 100644
98105--- a/net/core/net-procfs.c
98106+++ b/net/core/net-procfs.c
98107@@ -79,7 +79,13 @@ static void dev_seq_printf_stats(struct seq_file *seq, struct net_device *dev)
98108 struct rtnl_link_stats64 temp;
98109 const struct rtnl_link_stats64 *stats = dev_get_stats(dev, &temp);
98110
98111- seq_printf(seq, "%6s: %7llu %7llu %4llu %4llu %4llu %5llu %10llu %9llu "
98112+ if (gr_proc_is_restricted())
98113+ seq_printf(seq, "%6s: %7llu %7llu %4llu %4llu %4llu %5llu %10llu %9llu "
98114+ "%8llu %7llu %4llu %4llu %4llu %5llu %7llu %10llu\n",
98115+ dev->name, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL,
98116+ 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL);
98117+ else
98118+ seq_printf(seq, "%6s: %7llu %7llu %4llu %4llu %4llu %5llu %10llu %9llu "
98119 "%8llu %7llu %4llu %4llu %4llu %5llu %7llu %10llu\n",
98120 dev->name, stats->rx_bytes, stats->rx_packets,
98121 stats->rx_errors,
98122@@ -166,7 +172,7 @@ static int softnet_seq_show(struct seq_file *seq, void *v)
98123 return 0;
98124 }
98125
98126-static const struct seq_operations dev_seq_ops = {
98127+const struct seq_operations dev_seq_ops = {
98128 .start = dev_seq_start,
98129 .next = dev_seq_next,
98130 .stop = dev_seq_stop,
98131@@ -196,7 +202,7 @@ static const struct seq_operations softnet_seq_ops = {
98132
98133 static int softnet_seq_open(struct inode *inode, struct file *file)
98134 {
98135- return seq_open(file, &softnet_seq_ops);
98136+ return seq_open_restrict(file, &softnet_seq_ops);
98137 }
98138
98139 static const struct file_operations softnet_seq_fops = {
98140@@ -283,8 +289,13 @@ static int ptype_seq_show(struct seq_file *seq, void *v)
98141 else
98142 seq_printf(seq, "%04x", ntohs(pt->type));
98143
98144+#ifdef CONFIG_GRKERNSEC_HIDESYM
98145+ seq_printf(seq, " %-8s %pf\n",
98146+ pt->dev ? pt->dev->name : "", NULL);
98147+#else
98148 seq_printf(seq, " %-8s %pf\n",
98149 pt->dev ? pt->dev->name : "", pt->func);
98150+#endif
98151 }
98152
98153 return 0;
98154diff --git a/net/core/net_namespace.c b/net/core/net_namespace.c
98155index 81d3a9a..a0bd7a8 100644
98156--- a/net/core/net_namespace.c
98157+++ b/net/core/net_namespace.c
98158@@ -443,7 +443,7 @@ static int __register_pernet_operations(struct list_head *list,
98159 int error;
98160 LIST_HEAD(net_exit_list);
98161
98162- list_add_tail(&ops->list, list);
98163+ pax_list_add_tail((struct list_head *)&ops->list, list);
98164 if (ops->init || (ops->id && ops->size)) {
98165 for_each_net(net) {
98166 error = ops_init(ops, net);
98167@@ -456,7 +456,7 @@ static int __register_pernet_operations(struct list_head *list,
98168
98169 out_undo:
98170 /* If I have an error cleanup all namespaces I initialized */
98171- list_del(&ops->list);
98172+ pax_list_del((struct list_head *)&ops->list);
98173 ops_exit_list(ops, &net_exit_list);
98174 ops_free_list(ops, &net_exit_list);
98175 return error;
98176@@ -467,7 +467,7 @@ static void __unregister_pernet_operations(struct pernet_operations *ops)
98177 struct net *net;
98178 LIST_HEAD(net_exit_list);
98179
98180- list_del(&ops->list);
98181+ pax_list_del((struct list_head *)&ops->list);
98182 for_each_net(net)
98183 list_add_tail(&net->exit_list, &net_exit_list);
98184 ops_exit_list(ops, &net_exit_list);
98185@@ -601,7 +601,7 @@ int register_pernet_device(struct pernet_operations *ops)
98186 mutex_lock(&net_mutex);
98187 error = register_pernet_operations(&pernet_list, ops);
98188 if (!error && (first_device == &pernet_list))
98189- first_device = &ops->list;
98190+ first_device = (struct list_head *)&ops->list;
98191 mutex_unlock(&net_mutex);
98192 return error;
98193 }
98194diff --git a/net/core/netpoll.c b/net/core/netpoll.c
98195index df9e6b1..6e68e4e 100644
98196--- a/net/core/netpoll.c
98197+++ b/net/core/netpoll.c
98198@@ -435,7 +435,7 @@ void netpoll_send_udp(struct netpoll *np, const char *msg, int len)
98199 struct udphdr *udph;
98200 struct iphdr *iph;
98201 struct ethhdr *eth;
98202- static atomic_t ip_ident;
98203+ static atomic_unchecked_t ip_ident;
98204 struct ipv6hdr *ip6h;
98205
98206 udp_len = len + sizeof(*udph);
98207@@ -506,7 +506,7 @@ void netpoll_send_udp(struct netpoll *np, const char *msg, int len)
98208 put_unaligned(0x45, (unsigned char *)iph);
98209 iph->tos = 0;
98210 put_unaligned(htons(ip_len), &(iph->tot_len));
98211- iph->id = htons(atomic_inc_return(&ip_ident));
98212+ iph->id = htons(atomic_inc_return_unchecked(&ip_ident));
98213 iph->frag_off = 0;
98214 iph->ttl = 64;
98215 iph->protocol = IPPROTO_UDP;
98216diff --git a/net/core/pktgen.c b/net/core/pktgen.c
98217index fdac61c..e5e5b46 100644
98218--- a/net/core/pktgen.c
98219+++ b/net/core/pktgen.c
98220@@ -3719,7 +3719,7 @@ static int __net_init pg_net_init(struct net *net)
98221 pn->net = net;
98222 INIT_LIST_HEAD(&pn->pktgen_threads);
98223 pn->pktgen_exiting = false;
98224- pn->proc_dir = proc_mkdir(PG_PROC_DIR, pn->net->proc_net);
98225+ pn->proc_dir = proc_mkdir_restrict(PG_PROC_DIR, pn->net->proc_net);
98226 if (!pn->proc_dir) {
98227 pr_warn("cannot create /proc/net/%s\n", PG_PROC_DIR);
98228 return -ENODEV;
98229diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
98230index 120eecc..cd1ec44 100644
98231--- a/net/core/rtnetlink.c
98232+++ b/net/core/rtnetlink.c
98233@@ -58,7 +58,7 @@ struct rtnl_link {
98234 rtnl_doit_func doit;
98235 rtnl_dumpit_func dumpit;
98236 rtnl_calcit_func calcit;
98237-};
98238+} __no_const;
98239
98240 static DEFINE_MUTEX(rtnl_mutex);
98241
98242@@ -299,10 +299,13 @@ int __rtnl_link_register(struct rtnl_link_ops *ops)
98243 if (rtnl_link_ops_get(ops->kind))
98244 return -EEXIST;
98245
98246- if (!ops->dellink)
98247- ops->dellink = unregister_netdevice_queue;
98248+ if (!ops->dellink) {
98249+ pax_open_kernel();
98250+ *(void **)&ops->dellink = unregister_netdevice_queue;
98251+ pax_close_kernel();
98252+ }
98253
98254- list_add_tail(&ops->list, &link_ops);
98255+ pax_list_add_tail((struct list_head *)&ops->list, &link_ops);
98256 return 0;
98257 }
98258 EXPORT_SYMBOL_GPL(__rtnl_link_register);
98259@@ -349,7 +352,7 @@ void __rtnl_link_unregister(struct rtnl_link_ops *ops)
98260 for_each_net(net) {
98261 __rtnl_kill_links(net, ops);
98262 }
98263- list_del(&ops->list);
98264+ pax_list_del((struct list_head *)&ops->list);
98265 }
98266 EXPORT_SYMBOL_GPL(__rtnl_link_unregister);
98267
98268diff --git a/net/core/scm.c b/net/core/scm.c
98269index b442e7e..6f5b5a2 100644
98270--- a/net/core/scm.c
98271+++ b/net/core/scm.c
98272@@ -210,7 +210,7 @@ EXPORT_SYMBOL(__scm_send);
98273 int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
98274 {
98275 struct cmsghdr __user *cm
98276- = (__force struct cmsghdr __user *)msg->msg_control;
98277+ = (struct cmsghdr __force_user *)msg->msg_control;
98278 struct cmsghdr cmhdr;
98279 int cmlen = CMSG_LEN(len);
98280 int err;
98281@@ -233,7 +233,7 @@ int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
98282 err = -EFAULT;
98283 if (copy_to_user(cm, &cmhdr, sizeof cmhdr))
98284 goto out;
98285- if (copy_to_user(CMSG_DATA(cm), data, cmlen - sizeof(struct cmsghdr)))
98286+ if (copy_to_user((void __force_user *)CMSG_DATA((void __force_kernel *)cm), data, cmlen - sizeof(struct cmsghdr)))
98287 goto out;
98288 cmlen = CMSG_SPACE(len);
98289 if (msg->msg_controllen < cmlen)
98290@@ -249,7 +249,7 @@ EXPORT_SYMBOL(put_cmsg);
98291 void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
98292 {
98293 struct cmsghdr __user *cm
98294- = (__force struct cmsghdr __user*)msg->msg_control;
98295+ = (struct cmsghdr __force_user *)msg->msg_control;
98296
98297 int fdmax = 0;
98298 int fdnum = scm->fp->count;
98299@@ -269,7 +269,7 @@ void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
98300 if (fdnum < fdmax)
98301 fdmax = fdnum;
98302
98303- for (i=0, cmfptr=(__force int __user *)CMSG_DATA(cm); i<fdmax;
98304+ for (i=0, cmfptr=(int __force_user *)CMSG_DATA((void __force_kernel *)cm); i<fdmax;
98305 i++, cmfptr++)
98306 {
98307 struct socket *sock;
98308diff --git a/net/core/skbuff.c b/net/core/skbuff.c
98309index 90b96a1..cd18f16d 100644
98310--- a/net/core/skbuff.c
98311+++ b/net/core/skbuff.c
98312@@ -2003,7 +2003,7 @@ EXPORT_SYMBOL(__skb_checksum);
98313 __wsum skb_checksum(const struct sk_buff *skb, int offset,
98314 int len, __wsum csum)
98315 {
98316- const struct skb_checksum_ops ops = {
98317+ static const struct skb_checksum_ops ops = {
98318 .update = csum_partial_ext,
98319 .combine = csum_block_add_ext,
98320 };
98321@@ -3220,13 +3220,15 @@ void __init skb_init(void)
98322 skbuff_head_cache = kmem_cache_create("skbuff_head_cache",
98323 sizeof(struct sk_buff),
98324 0,
98325- SLAB_HWCACHE_ALIGN|SLAB_PANIC,
98326+ SLAB_HWCACHE_ALIGN|SLAB_PANIC|
98327+ SLAB_NO_SANITIZE,
98328 NULL);
98329 skbuff_fclone_cache = kmem_cache_create("skbuff_fclone_cache",
98330 (2*sizeof(struct sk_buff)) +
98331 sizeof(atomic_t),
98332 0,
98333- SLAB_HWCACHE_ALIGN|SLAB_PANIC,
98334+ SLAB_HWCACHE_ALIGN|SLAB_PANIC|
98335+ SLAB_NO_SANITIZE,
98336 NULL);
98337 }
98338
98339diff --git a/net/core/sock.c b/net/core/sock.c
98340index c0fc6bd..51d8326 100644
98341--- a/net/core/sock.c
98342+++ b/net/core/sock.c
98343@@ -393,7 +393,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
98344 struct sk_buff_head *list = &sk->sk_receive_queue;
98345
98346 if (atomic_read(&sk->sk_rmem_alloc) >= sk->sk_rcvbuf) {
98347- atomic_inc(&sk->sk_drops);
98348+ atomic_inc_unchecked(&sk->sk_drops);
98349 trace_sock_rcvqueue_full(sk, skb);
98350 return -ENOMEM;
98351 }
98352@@ -403,7 +403,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
98353 return err;
98354
98355 if (!sk_rmem_schedule(sk, skb, skb->truesize)) {
98356- atomic_inc(&sk->sk_drops);
98357+ atomic_inc_unchecked(&sk->sk_drops);
98358 return -ENOBUFS;
98359 }
98360
98361@@ -423,7 +423,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
98362 skb_dst_force(skb);
98363
98364 spin_lock_irqsave(&list->lock, flags);
98365- skb->dropcount = atomic_read(&sk->sk_drops);
98366+ skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
98367 __skb_queue_tail(list, skb);
98368 spin_unlock_irqrestore(&list->lock, flags);
98369
98370@@ -443,7 +443,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
98371 skb->dev = NULL;
98372
98373 if (sk_rcvqueues_full(sk, skb, sk->sk_rcvbuf)) {
98374- atomic_inc(&sk->sk_drops);
98375+ atomic_inc_unchecked(&sk->sk_drops);
98376 goto discard_and_relse;
98377 }
98378 if (nested)
98379@@ -461,7 +461,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
98380 mutex_release(&sk->sk_lock.dep_map, 1, _RET_IP_);
98381 } else if (sk_add_backlog(sk, skb, sk->sk_rcvbuf)) {
98382 bh_unlock_sock(sk);
98383- atomic_inc(&sk->sk_drops);
98384+ atomic_inc_unchecked(&sk->sk_drops);
98385 goto discard_and_relse;
98386 }
98387
98388@@ -949,12 +949,12 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
98389 struct timeval tm;
98390 } v;
98391
98392- int lv = sizeof(int);
98393- int len;
98394+ unsigned int lv = sizeof(int);
98395+ unsigned int len;
98396
98397 if (get_user(len, optlen))
98398 return -EFAULT;
98399- if (len < 0)
98400+ if (len > INT_MAX)
98401 return -EINVAL;
98402
98403 memset(&v, 0, sizeof(v));
98404@@ -1106,11 +1106,11 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
98405
98406 case SO_PEERNAME:
98407 {
98408- char address[128];
98409+ char address[_K_SS_MAXSIZE];
98410
98411 if (sock->ops->getname(sock, (struct sockaddr *)address, &lv, 2))
98412 return -ENOTCONN;
98413- if (lv < len)
98414+ if (lv < len || sizeof address < len)
98415 return -EINVAL;
98416 if (copy_to_user(optval, address, len))
98417 return -EFAULT;
98418@@ -1191,7 +1191,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
98419
98420 if (len > lv)
98421 len = lv;
98422- if (copy_to_user(optval, &v, len))
98423+ if (len > sizeof(v) || copy_to_user(optval, &v, len))
98424 return -EFAULT;
98425 lenout:
98426 if (put_user(len, optlen))
98427@@ -2326,7 +2326,7 @@ void sock_init_data(struct socket *sock, struct sock *sk)
98428 */
98429 smp_wmb();
98430 atomic_set(&sk->sk_refcnt, 1);
98431- atomic_set(&sk->sk_drops, 0);
98432+ atomic_set_unchecked(&sk->sk_drops, 0);
98433 }
98434 EXPORT_SYMBOL(sock_init_data);
98435
98436@@ -2454,6 +2454,7 @@ void sock_enable_timestamp(struct sock *sk, int flag)
98437 int sock_recv_errqueue(struct sock *sk, struct msghdr *msg, int len,
98438 int level, int type)
98439 {
98440+ struct sock_extended_err ee;
98441 struct sock_exterr_skb *serr;
98442 struct sk_buff *skb, *skb2;
98443 int copied, err;
98444@@ -2475,7 +2476,8 @@ int sock_recv_errqueue(struct sock *sk, struct msghdr *msg, int len,
98445 sock_recv_timestamp(msg, sk, skb);
98446
98447 serr = SKB_EXT_ERR(skb);
98448- put_cmsg(msg, level, type, sizeof(serr->ee), &serr->ee);
98449+ ee = serr->ee;
98450+ put_cmsg(msg, level, type, sizeof ee, &ee);
98451
98452 msg->msg_flags |= MSG_ERRQUEUE;
98453 err = copied;
98454diff --git a/net/core/sock_diag.c b/net/core/sock_diag.c
98455index a0e9cf6..ef7f9ed 100644
98456--- a/net/core/sock_diag.c
98457+++ b/net/core/sock_diag.c
98458@@ -9,26 +9,33 @@
98459 #include <linux/inet_diag.h>
98460 #include <linux/sock_diag.h>
98461
98462-static const struct sock_diag_handler *sock_diag_handlers[AF_MAX];
98463+static const struct sock_diag_handler *sock_diag_handlers[AF_MAX] __read_only;
98464 static int (*inet_rcv_compat)(struct sk_buff *skb, struct nlmsghdr *nlh);
98465 static DEFINE_MUTEX(sock_diag_table_mutex);
98466
98467 int sock_diag_check_cookie(void *sk, __u32 *cookie)
98468 {
98469+#ifndef CONFIG_GRKERNSEC_HIDESYM
98470 if ((cookie[0] != INET_DIAG_NOCOOKIE ||
98471 cookie[1] != INET_DIAG_NOCOOKIE) &&
98472 ((u32)(unsigned long)sk != cookie[0] ||
98473 (u32)((((unsigned long)sk) >> 31) >> 1) != cookie[1]))
98474 return -ESTALE;
98475 else
98476+#endif
98477 return 0;
98478 }
98479 EXPORT_SYMBOL_GPL(sock_diag_check_cookie);
98480
98481 void sock_diag_save_cookie(void *sk, __u32 *cookie)
98482 {
98483+#ifdef CONFIG_GRKERNSEC_HIDESYM
98484+ cookie[0] = 0;
98485+ cookie[1] = 0;
98486+#else
98487 cookie[0] = (u32)(unsigned long)sk;
98488 cookie[1] = (u32)(((unsigned long)sk >> 31) >> 1);
98489+#endif
98490 }
98491 EXPORT_SYMBOL_GPL(sock_diag_save_cookie);
98492
98493@@ -113,8 +120,11 @@ int sock_diag_register(const struct sock_diag_handler *hndl)
98494 mutex_lock(&sock_diag_table_mutex);
98495 if (sock_diag_handlers[hndl->family])
98496 err = -EBUSY;
98497- else
98498+ else {
98499+ pax_open_kernel();
98500 sock_diag_handlers[hndl->family] = hndl;
98501+ pax_close_kernel();
98502+ }
98503 mutex_unlock(&sock_diag_table_mutex);
98504
98505 return err;
98506@@ -130,7 +140,9 @@ void sock_diag_unregister(const struct sock_diag_handler *hnld)
98507
98508 mutex_lock(&sock_diag_table_mutex);
98509 BUG_ON(sock_diag_handlers[family] != hnld);
98510+ pax_open_kernel();
98511 sock_diag_handlers[family] = NULL;
98512+ pax_close_kernel();
98513 mutex_unlock(&sock_diag_table_mutex);
98514 }
98515 EXPORT_SYMBOL_GPL(sock_diag_unregister);
98516diff --git a/net/core/sysctl_net_core.c b/net/core/sysctl_net_core.c
98517index cf9cd13..8b56af3 100644
98518--- a/net/core/sysctl_net_core.c
98519+++ b/net/core/sysctl_net_core.c
98520@@ -32,7 +32,7 @@ static int rps_sock_flow_sysctl(struct ctl_table *table, int write,
98521 {
98522 unsigned int orig_size, size;
98523 int ret, i;
98524- struct ctl_table tmp = {
98525+ ctl_table_no_const tmp = {
98526 .data = &size,
98527 .maxlen = sizeof(size),
98528 .mode = table->mode
98529@@ -200,7 +200,7 @@ static int set_default_qdisc(struct ctl_table *table, int write,
98530 void __user *buffer, size_t *lenp, loff_t *ppos)
98531 {
98532 char id[IFNAMSIZ];
98533- struct ctl_table tbl = {
98534+ ctl_table_no_const tbl = {
98535 .data = id,
98536 .maxlen = IFNAMSIZ,
98537 };
98538@@ -379,13 +379,12 @@ static struct ctl_table netns_core_table[] = {
98539
98540 static __net_init int sysctl_core_net_init(struct net *net)
98541 {
98542- struct ctl_table *tbl;
98543+ ctl_table_no_const *tbl = NULL;
98544
98545 net->core.sysctl_somaxconn = SOMAXCONN;
98546
98547- tbl = netns_core_table;
98548 if (!net_eq(net, &init_net)) {
98549- tbl = kmemdup(tbl, sizeof(netns_core_table), GFP_KERNEL);
98550+ tbl = kmemdup(netns_core_table, sizeof(netns_core_table), GFP_KERNEL);
98551 if (tbl == NULL)
98552 goto err_dup;
98553
98554@@ -395,17 +394,16 @@ static __net_init int sysctl_core_net_init(struct net *net)
98555 if (net->user_ns != &init_user_ns) {
98556 tbl[0].procname = NULL;
98557 }
98558- }
98559-
98560- net->core.sysctl_hdr = register_net_sysctl(net, "net/core", tbl);
98561+ net->core.sysctl_hdr = register_net_sysctl(net, "net/core", tbl);
98562+ } else
98563+ net->core.sysctl_hdr = register_net_sysctl(net, "net/core", netns_core_table);
98564 if (net->core.sysctl_hdr == NULL)
98565 goto err_reg;
98566
98567 return 0;
98568
98569 err_reg:
98570- if (tbl != netns_core_table)
98571- kfree(tbl);
98572+ kfree(tbl);
98573 err_dup:
98574 return -ENOMEM;
98575 }
98576@@ -420,7 +418,7 @@ static __net_exit void sysctl_core_net_exit(struct net *net)
98577 kfree(tbl);
98578 }
98579
98580-static __net_initdata struct pernet_operations sysctl_core_ops = {
98581+static __net_initconst struct pernet_operations sysctl_core_ops = {
98582 .init = sysctl_core_net_init,
98583 .exit = sysctl_core_net_exit,
98584 };
98585diff --git a/net/decnet/af_decnet.c b/net/decnet/af_decnet.c
98586index 4c04848..f575934 100644
98587--- a/net/decnet/af_decnet.c
98588+++ b/net/decnet/af_decnet.c
98589@@ -465,6 +465,7 @@ static struct proto dn_proto = {
98590 .sysctl_rmem = sysctl_decnet_rmem,
98591 .max_header = DN_MAX_NSP_DATA_HEADER + 64,
98592 .obj_size = sizeof(struct dn_sock),
98593+ .slab_flags = SLAB_USERCOPY,
98594 };
98595
98596 static struct sock *dn_alloc_sock(struct net *net, struct socket *sock, gfp_t gfp)
98597diff --git a/net/decnet/dn_dev.c b/net/decnet/dn_dev.c
98598index a603823..a36ee0b 100644
98599--- a/net/decnet/dn_dev.c
98600+++ b/net/decnet/dn_dev.c
98601@@ -200,7 +200,7 @@ static struct dn_dev_sysctl_table {
98602 .extra1 = &min_t3,
98603 .extra2 = &max_t3
98604 },
98605- {0}
98606+ { }
98607 },
98608 };
98609
98610diff --git a/net/decnet/sysctl_net_decnet.c b/net/decnet/sysctl_net_decnet.c
98611index 5325b54..a0d4d69 100644
98612--- a/net/decnet/sysctl_net_decnet.c
98613+++ b/net/decnet/sysctl_net_decnet.c
98614@@ -174,7 +174,7 @@ static int dn_node_address_handler(struct ctl_table *table, int write,
98615
98616 if (len > *lenp) len = *lenp;
98617
98618- if (copy_to_user(buffer, addr, len))
98619+ if (len > sizeof addr || copy_to_user(buffer, addr, len))
98620 return -EFAULT;
98621
98622 *lenp = len;
98623@@ -237,7 +237,7 @@ static int dn_def_dev_handler(struct ctl_table *table, int write,
98624
98625 if (len > *lenp) len = *lenp;
98626
98627- if (copy_to_user(buffer, devname, len))
98628+ if (len > sizeof devname || copy_to_user(buffer, devname, len))
98629 return -EFAULT;
98630
98631 *lenp = len;
98632diff --git a/net/ieee802154/dgram.c b/net/ieee802154/dgram.c
98633index 1846c1f..96d4a9f 100644
98634--- a/net/ieee802154/dgram.c
98635+++ b/net/ieee802154/dgram.c
98636@@ -313,8 +313,9 @@ static int dgram_recvmsg(struct kiocb *iocb, struct sock *sk,
98637 if (saddr) {
98638 saddr->family = AF_IEEE802154;
98639 saddr->addr = mac_cb(skb)->sa;
98640+ }
98641+ if (addr_len)
98642 *addr_len = sizeof(*saddr);
98643- }
98644
98645 if (flags & MSG_TRUNC)
98646 copied = skb->len;
98647diff --git a/net/ipv4/af_inet.c b/net/ipv4/af_inet.c
98648index 19ab78a..bf575c9 100644
98649--- a/net/ipv4/af_inet.c
98650+++ b/net/ipv4/af_inet.c
98651@@ -1703,13 +1703,9 @@ static int __init inet_init(void)
98652
98653 BUILD_BUG_ON(sizeof(struct inet_skb_parm) > FIELD_SIZEOF(struct sk_buff, cb));
98654
98655- sysctl_local_reserved_ports = kzalloc(65536 / 8, GFP_KERNEL);
98656- if (!sysctl_local_reserved_ports)
98657- goto out;
98658-
98659 rc = proto_register(&tcp_prot, 1);
98660 if (rc)
98661- goto out_free_reserved_ports;
98662+ goto out;
98663
98664 rc = proto_register(&udp_prot, 1);
98665 if (rc)
98666@@ -1816,8 +1812,6 @@ out_unregister_udp_proto:
98667 proto_unregister(&udp_prot);
98668 out_unregister_tcp_proto:
98669 proto_unregister(&tcp_prot);
98670-out_free_reserved_ports:
98671- kfree(sysctl_local_reserved_ports);
98672 goto out;
98673 }
98674
98675diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c
98676index bdbf68b..deb4759 100644
98677--- a/net/ipv4/devinet.c
98678+++ b/net/ipv4/devinet.c
98679@@ -1543,7 +1543,7 @@ static int inet_dump_ifaddr(struct sk_buff *skb, struct netlink_callback *cb)
98680 idx = 0;
98681 head = &net->dev_index_head[h];
98682 rcu_read_lock();
98683- cb->seq = atomic_read(&net->ipv4.dev_addr_genid) ^
98684+ cb->seq = atomic_read_unchecked(&net->ipv4.dev_addr_genid) ^
98685 net->dev_base_seq;
98686 hlist_for_each_entry_rcu(dev, head, index_hlist) {
98687 if (idx < s_idx)
98688@@ -1861,7 +1861,7 @@ static int inet_netconf_dump_devconf(struct sk_buff *skb,
98689 idx = 0;
98690 head = &net->dev_index_head[h];
98691 rcu_read_lock();
98692- cb->seq = atomic_read(&net->ipv4.dev_addr_genid) ^
98693+ cb->seq = atomic_read_unchecked(&net->ipv4.dev_addr_genid) ^
98694 net->dev_base_seq;
98695 hlist_for_each_entry_rcu(dev, head, index_hlist) {
98696 if (idx < s_idx)
98697@@ -2096,7 +2096,7 @@ static int ipv4_doint_and_flush(struct ctl_table *ctl, int write,
98698 #define DEVINET_SYSCTL_FLUSHING_ENTRY(attr, name) \
98699 DEVINET_SYSCTL_COMPLEX_ENTRY(attr, name, ipv4_doint_and_flush)
98700
98701-static struct devinet_sysctl_table {
98702+static const struct devinet_sysctl_table {
98703 struct ctl_table_header *sysctl_header;
98704 struct ctl_table devinet_vars[__IPV4_DEVCONF_MAX];
98705 } devinet_sysctl = {
98706@@ -2218,7 +2218,7 @@ static __net_init int devinet_init_net(struct net *net)
98707 int err;
98708 struct ipv4_devconf *all, *dflt;
98709 #ifdef CONFIG_SYSCTL
98710- struct ctl_table *tbl = ctl_forward_entry;
98711+ ctl_table_no_const *tbl = NULL;
98712 struct ctl_table_header *forw_hdr;
98713 #endif
98714
98715@@ -2236,7 +2236,7 @@ static __net_init int devinet_init_net(struct net *net)
98716 goto err_alloc_dflt;
98717
98718 #ifdef CONFIG_SYSCTL
98719- tbl = kmemdup(tbl, sizeof(ctl_forward_entry), GFP_KERNEL);
98720+ tbl = kmemdup(ctl_forward_entry, sizeof(ctl_forward_entry), GFP_KERNEL);
98721 if (tbl == NULL)
98722 goto err_alloc_ctl;
98723
98724@@ -2256,7 +2256,10 @@ static __net_init int devinet_init_net(struct net *net)
98725 goto err_reg_dflt;
98726
98727 err = -ENOMEM;
98728- forw_hdr = register_net_sysctl(net, "net/ipv4", tbl);
98729+ if (!net_eq(net, &init_net))
98730+ forw_hdr = register_net_sysctl(net, "net/ipv4", tbl);
98731+ else
98732+ forw_hdr = register_net_sysctl(net, "net/ipv4", ctl_forward_entry);
98733 if (forw_hdr == NULL)
98734 goto err_reg_ctl;
98735 net->ipv4.forw_hdr = forw_hdr;
98736@@ -2272,8 +2275,7 @@ err_reg_ctl:
98737 err_reg_dflt:
98738 __devinet_sysctl_unregister(all);
98739 err_reg_all:
98740- if (tbl != ctl_forward_entry)
98741- kfree(tbl);
98742+ kfree(tbl);
98743 err_alloc_ctl:
98744 #endif
98745 if (dflt != &ipv4_devconf_dflt)
98746diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
98747index c7539e2..b455e51 100644
98748--- a/net/ipv4/fib_frontend.c
98749+++ b/net/ipv4/fib_frontend.c
98750@@ -1015,12 +1015,12 @@ static int fib_inetaddr_event(struct notifier_block *this, unsigned long event,
98751 #ifdef CONFIG_IP_ROUTE_MULTIPATH
98752 fib_sync_up(dev);
98753 #endif
98754- atomic_inc(&net->ipv4.dev_addr_genid);
98755+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
98756 rt_cache_flush(dev_net(dev));
98757 break;
98758 case NETDEV_DOWN:
98759 fib_del_ifaddr(ifa, NULL);
98760- atomic_inc(&net->ipv4.dev_addr_genid);
98761+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
98762 if (ifa->ifa_dev->ifa_list == NULL) {
98763 /* Last address was deleted from this interface.
98764 * Disable IP.
98765@@ -1058,7 +1058,7 @@ static int fib_netdev_event(struct notifier_block *this, unsigned long event, vo
98766 #ifdef CONFIG_IP_ROUTE_MULTIPATH
98767 fib_sync_up(dev);
98768 #endif
98769- atomic_inc(&net->ipv4.dev_addr_genid);
98770+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
98771 rt_cache_flush(net);
98772 break;
98773 case NETDEV_DOWN:
98774diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c
98775index b53f0bf..3585b33 100644
98776--- a/net/ipv4/fib_semantics.c
98777+++ b/net/ipv4/fib_semantics.c
98778@@ -767,7 +767,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh)
98779 nh->nh_saddr = inet_select_addr(nh->nh_dev,
98780 nh->nh_gw,
98781 nh->nh_parent->fib_scope);
98782- nh->nh_saddr_genid = atomic_read(&net->ipv4.dev_addr_genid);
98783+ nh->nh_saddr_genid = atomic_read_unchecked(&net->ipv4.dev_addr_genid);
98784
98785 return nh->nh_saddr;
98786 }
98787diff --git a/net/ipv4/inet_connection_sock.c b/net/ipv4/inet_connection_sock.c
98788index 0d1e2cb..4501a2c 100644
98789--- a/net/ipv4/inet_connection_sock.c
98790+++ b/net/ipv4/inet_connection_sock.c
98791@@ -29,7 +29,7 @@ const char inet_csk_timer_bug_msg[] = "inet_csk BUG: unknown timer value\n";
98792 EXPORT_SYMBOL(inet_csk_timer_bug_msg);
98793 #endif
98794
98795-unsigned long *sysctl_local_reserved_ports;
98796+unsigned long sysctl_local_reserved_ports[65536 / 8 / sizeof(unsigned long)];
98797 EXPORT_SYMBOL(sysctl_local_reserved_ports);
98798
98799 void inet_get_local_port_range(struct net *net, int *low, int *high)
98800diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c
98801index 8b9cf27..0d8d592 100644
98802--- a/net/ipv4/inet_hashtables.c
98803+++ b/net/ipv4/inet_hashtables.c
98804@@ -18,6 +18,7 @@
98805 #include <linux/sched.h>
98806 #include <linux/slab.h>
98807 #include <linux/wait.h>
98808+#include <linux/security.h>
98809
98810 #include <net/inet_connection_sock.h>
98811 #include <net/inet_hashtables.h>
98812@@ -49,6 +50,8 @@ static unsigned int inet_sk_ehashfn(const struct sock *sk)
98813 return inet_ehashfn(net, laddr, lport, faddr, fport);
98814 }
98815
98816+extern void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet);
98817+
98818 /*
98819 * Allocate and initialize a new local port bind bucket.
98820 * The bindhash mutex for snum's hash chain must be held here.
98821@@ -554,6 +557,8 @@ ok:
98822 twrefcnt += inet_twsk_bind_unhash(tw, hinfo);
98823 spin_unlock(&head->lock);
98824
98825+ gr_update_task_in_ip_table(current, inet_sk(sk));
98826+
98827 if (tw) {
98828 inet_twsk_deschedule(tw, death_row);
98829 while (twrefcnt) {
98830diff --git a/net/ipv4/inetpeer.c b/net/ipv4/inetpeer.c
98831index 48f4244..f56d83a 100644
98832--- a/net/ipv4/inetpeer.c
98833+++ b/net/ipv4/inetpeer.c
98834@@ -496,8 +496,8 @@ relookup:
98835 if (p) {
98836 p->daddr = *daddr;
98837 atomic_set(&p->refcnt, 1);
98838- atomic_set(&p->rid, 0);
98839- atomic_set(&p->ip_id_count,
98840+ atomic_set_unchecked(&p->rid, 0);
98841+ atomic_set_unchecked(&p->ip_id_count,
98842 (daddr->family == AF_INET) ?
98843 secure_ip_id(daddr->addr.a4) :
98844 secure_ipv6_id(daddr->addr.a6));
98845diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c
98846index c10a3ce..dd71f84 100644
98847--- a/net/ipv4/ip_fragment.c
98848+++ b/net/ipv4/ip_fragment.c
98849@@ -283,7 +283,7 @@ static inline int ip_frag_too_far(struct ipq *qp)
98850 return 0;
98851
98852 start = qp->rid;
98853- end = atomic_inc_return(&peer->rid);
98854+ end = atomic_inc_return_unchecked(&peer->rid);
98855 qp->rid = end;
98856
98857 rc = qp->q.fragments && (end - start) > max;
98858@@ -760,12 +760,11 @@ static struct ctl_table ip4_frags_ctl_table[] = {
98859
98860 static int __net_init ip4_frags_ns_ctl_register(struct net *net)
98861 {
98862- struct ctl_table *table;
98863+ ctl_table_no_const *table = NULL;
98864 struct ctl_table_header *hdr;
98865
98866- table = ip4_frags_ns_ctl_table;
98867 if (!net_eq(net, &init_net)) {
98868- table = kmemdup(table, sizeof(ip4_frags_ns_ctl_table), GFP_KERNEL);
98869+ table = kmemdup(ip4_frags_ns_ctl_table, sizeof(ip4_frags_ns_ctl_table), GFP_KERNEL);
98870 if (table == NULL)
98871 goto err_alloc;
98872
98873@@ -776,9 +775,10 @@ static int __net_init ip4_frags_ns_ctl_register(struct net *net)
98874 /* Don't export sysctls to unprivileged users */
98875 if (net->user_ns != &init_user_ns)
98876 table[0].procname = NULL;
98877- }
98878+ hdr = register_net_sysctl(net, "net/ipv4", table);
98879+ } else
98880+ hdr = register_net_sysctl(net, "net/ipv4", ip4_frags_ns_ctl_table);
98881
98882- hdr = register_net_sysctl(net, "net/ipv4", table);
98883 if (hdr == NULL)
98884 goto err_reg;
98885
98886@@ -786,8 +786,7 @@ static int __net_init ip4_frags_ns_ctl_register(struct net *net)
98887 return 0;
98888
98889 err_reg:
98890- if (!net_eq(net, &init_net))
98891- kfree(table);
98892+ kfree(table);
98893 err_alloc:
98894 return -ENOMEM;
98895 }
98896diff --git a/net/ipv4/ip_gre.c b/net/ipv4/ip_gre.c
98897index ec4f762..4ce3645 100644
98898--- a/net/ipv4/ip_gre.c
98899+++ b/net/ipv4/ip_gre.c
98900@@ -115,7 +115,7 @@ static bool log_ecn_error = true;
98901 module_param(log_ecn_error, bool, 0644);
98902 MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN");
98903
98904-static struct rtnl_link_ops ipgre_link_ops __read_mostly;
98905+static struct rtnl_link_ops ipgre_link_ops;
98906 static int ipgre_tunnel_init(struct net_device *dev);
98907
98908 static int ipgre_net_id __read_mostly;
98909@@ -732,7 +732,7 @@ static const struct nla_policy ipgre_policy[IFLA_GRE_MAX + 1] = {
98910 [IFLA_GRE_PMTUDISC] = { .type = NLA_U8 },
98911 };
98912
98913-static struct rtnl_link_ops ipgre_link_ops __read_mostly = {
98914+static struct rtnl_link_ops ipgre_link_ops = {
98915 .kind = "gre",
98916 .maxtype = IFLA_GRE_MAX,
98917 .policy = ipgre_policy,
98918@@ -746,7 +746,7 @@ static struct rtnl_link_ops ipgre_link_ops __read_mostly = {
98919 .fill_info = ipgre_fill_info,
98920 };
98921
98922-static struct rtnl_link_ops ipgre_tap_ops __read_mostly = {
98923+static struct rtnl_link_ops ipgre_tap_ops = {
98924 .kind = "gretap",
98925 .maxtype = IFLA_GRE_MAX,
98926 .policy = ipgre_policy,
98927diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
98928index 580dd96..9fcef7e 100644
98929--- a/net/ipv4/ip_sockglue.c
98930+++ b/net/ipv4/ip_sockglue.c
98931@@ -1171,7 +1171,8 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
98932 len = min_t(unsigned int, len, opt->optlen);
98933 if (put_user(len, optlen))
98934 return -EFAULT;
98935- if (copy_to_user(optval, opt->__data, len))
98936+ if ((len > (sizeof(optbuf) - sizeof(struct ip_options))) ||
98937+ copy_to_user(optval, opt->__data, len))
98938 return -EFAULT;
98939 return 0;
98940 }
98941@@ -1302,7 +1303,7 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
98942 if (sk->sk_type != SOCK_STREAM)
98943 return -ENOPROTOOPT;
98944
98945- msg.msg_control = optval;
98946+ msg.msg_control = (void __force_kernel *)optval;
98947 msg.msg_controllen = len;
98948 msg.msg_flags = flags;
98949
98950diff --git a/net/ipv4/ip_vti.c b/net/ipv4/ip_vti.c
98951index 48eafae..defff53 100644
98952--- a/net/ipv4/ip_vti.c
98953+++ b/net/ipv4/ip_vti.c
98954@@ -44,7 +44,7 @@
98955 #include <net/net_namespace.h>
98956 #include <net/netns/generic.h>
98957
98958-static struct rtnl_link_ops vti_link_ops __read_mostly;
98959+static struct rtnl_link_ops vti_link_ops;
98960
98961 static int vti_net_id __read_mostly;
98962 static int vti_tunnel_init(struct net_device *dev);
98963@@ -360,7 +360,7 @@ static const struct nla_policy vti_policy[IFLA_VTI_MAX + 1] = {
98964 [IFLA_VTI_REMOTE] = { .len = FIELD_SIZEOF(struct iphdr, daddr) },
98965 };
98966
98967-static struct rtnl_link_ops vti_link_ops __read_mostly = {
98968+static struct rtnl_link_ops vti_link_ops = {
98969 .kind = "vti",
98970 .maxtype = IFLA_VTI_MAX,
98971 .policy = vti_policy,
98972diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c
98973index b3e86ea..18ce98c 100644
98974--- a/net/ipv4/ipconfig.c
98975+++ b/net/ipv4/ipconfig.c
98976@@ -334,7 +334,7 @@ static int __init ic_devinet_ioctl(unsigned int cmd, struct ifreq *arg)
98977
98978 mm_segment_t oldfs = get_fs();
98979 set_fs(get_ds());
98980- res = devinet_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
98981+ res = devinet_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
98982 set_fs(oldfs);
98983 return res;
98984 }
98985@@ -345,7 +345,7 @@ static int __init ic_dev_ioctl(unsigned int cmd, struct ifreq *arg)
98986
98987 mm_segment_t oldfs = get_fs();
98988 set_fs(get_ds());
98989- res = dev_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
98990+ res = dev_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
98991 set_fs(oldfs);
98992 return res;
98993 }
98994@@ -356,7 +356,7 @@ static int __init ic_route_ioctl(unsigned int cmd, struct rtentry *arg)
98995
98996 mm_segment_t oldfs = get_fs();
98997 set_fs(get_ds());
98998- res = ip_rt_ioctl(&init_net, cmd, (void __user *) arg);
98999+ res = ip_rt_ioctl(&init_net, cmd, (void __force_user *) arg);
99000 set_fs(oldfs);
99001 return res;
99002 }
99003diff --git a/net/ipv4/ipip.c b/net/ipv4/ipip.c
99004index 812b183..56cbe9c 100644
99005--- a/net/ipv4/ipip.c
99006+++ b/net/ipv4/ipip.c
99007@@ -124,7 +124,7 @@ MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN");
99008 static int ipip_net_id __read_mostly;
99009
99010 static int ipip_tunnel_init(struct net_device *dev);
99011-static struct rtnl_link_ops ipip_link_ops __read_mostly;
99012+static struct rtnl_link_ops ipip_link_ops;
99013
99014 static int ipip_err(struct sk_buff *skb, u32 info)
99015 {
99016@@ -409,7 +409,7 @@ static const struct nla_policy ipip_policy[IFLA_IPTUN_MAX + 1] = {
99017 [IFLA_IPTUN_PMTUDISC] = { .type = NLA_U8 },
99018 };
99019
99020-static struct rtnl_link_ops ipip_link_ops __read_mostly = {
99021+static struct rtnl_link_ops ipip_link_ops = {
99022 .kind = "ipip",
99023 .maxtype = IFLA_IPTUN_MAX,
99024 .policy = ipip_policy,
99025diff --git a/net/ipv4/netfilter/arp_tables.c b/net/ipv4/netfilter/arp_tables.c
99026index 59da7cd..e318de1 100644
99027--- a/net/ipv4/netfilter/arp_tables.c
99028+++ b/net/ipv4/netfilter/arp_tables.c
99029@@ -885,14 +885,14 @@ static int compat_table_info(const struct xt_table_info *info,
99030 #endif
99031
99032 static int get_info(struct net *net, void __user *user,
99033- const int *len, int compat)
99034+ int len, int compat)
99035 {
99036 char name[XT_TABLE_MAXNAMELEN];
99037 struct xt_table *t;
99038 int ret;
99039
99040- if (*len != sizeof(struct arpt_getinfo)) {
99041- duprintf("length %u != %Zu\n", *len,
99042+ if (len != sizeof(struct arpt_getinfo)) {
99043+ duprintf("length %u != %Zu\n", len,
99044 sizeof(struct arpt_getinfo));
99045 return -EINVAL;
99046 }
99047@@ -929,7 +929,7 @@ static int get_info(struct net *net, void __user *user,
99048 info.size = private->size;
99049 strcpy(info.name, name);
99050
99051- if (copy_to_user(user, &info, *len) != 0)
99052+ if (copy_to_user(user, &info, len) != 0)
99053 ret = -EFAULT;
99054 else
99055 ret = 0;
99056@@ -1688,7 +1688,7 @@ static int compat_do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user,
99057
99058 switch (cmd) {
99059 case ARPT_SO_GET_INFO:
99060- ret = get_info(sock_net(sk), user, len, 1);
99061+ ret = get_info(sock_net(sk), user, *len, 1);
99062 break;
99063 case ARPT_SO_GET_ENTRIES:
99064 ret = compat_get_entries(sock_net(sk), user, len);
99065@@ -1733,7 +1733,7 @@ static int do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len
99066
99067 switch (cmd) {
99068 case ARPT_SO_GET_INFO:
99069- ret = get_info(sock_net(sk), user, len, 0);
99070+ ret = get_info(sock_net(sk), user, *len, 0);
99071 break;
99072
99073 case ARPT_SO_GET_ENTRIES:
99074diff --git a/net/ipv4/netfilter/ip_tables.c b/net/ipv4/netfilter/ip_tables.c
99075index 718dfbd..cef4152 100644
99076--- a/net/ipv4/netfilter/ip_tables.c
99077+++ b/net/ipv4/netfilter/ip_tables.c
99078@@ -1073,14 +1073,14 @@ static int compat_table_info(const struct xt_table_info *info,
99079 #endif
99080
99081 static int get_info(struct net *net, void __user *user,
99082- const int *len, int compat)
99083+ int len, int compat)
99084 {
99085 char name[XT_TABLE_MAXNAMELEN];
99086 struct xt_table *t;
99087 int ret;
99088
99089- if (*len != sizeof(struct ipt_getinfo)) {
99090- duprintf("length %u != %zu\n", *len,
99091+ if (len != sizeof(struct ipt_getinfo)) {
99092+ duprintf("length %u != %zu\n", len,
99093 sizeof(struct ipt_getinfo));
99094 return -EINVAL;
99095 }
99096@@ -1117,7 +1117,7 @@ static int get_info(struct net *net, void __user *user,
99097 info.size = private->size;
99098 strcpy(info.name, name);
99099
99100- if (copy_to_user(user, &info, *len) != 0)
99101+ if (copy_to_user(user, &info, len) != 0)
99102 ret = -EFAULT;
99103 else
99104 ret = 0;
99105@@ -1971,7 +1971,7 @@ compat_do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
99106
99107 switch (cmd) {
99108 case IPT_SO_GET_INFO:
99109- ret = get_info(sock_net(sk), user, len, 1);
99110+ ret = get_info(sock_net(sk), user, *len, 1);
99111 break;
99112 case IPT_SO_GET_ENTRIES:
99113 ret = compat_get_entries(sock_net(sk), user, len);
99114@@ -2018,7 +2018,7 @@ do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
99115
99116 switch (cmd) {
99117 case IPT_SO_GET_INFO:
99118- ret = get_info(sock_net(sk), user, len, 0);
99119+ ret = get_info(sock_net(sk), user, *len, 0);
99120 break;
99121
99122 case IPT_SO_GET_ENTRIES:
99123diff --git a/net/ipv4/netfilter/ipt_CLUSTERIP.c b/net/ipv4/netfilter/ipt_CLUSTERIP.c
99124index 2510c02..cfb34fa 100644
99125--- a/net/ipv4/netfilter/ipt_CLUSTERIP.c
99126+++ b/net/ipv4/netfilter/ipt_CLUSTERIP.c
99127@@ -720,7 +720,7 @@ static int clusterip_net_init(struct net *net)
99128 spin_lock_init(&cn->lock);
99129
99130 #ifdef CONFIG_PROC_FS
99131- cn->procdir = proc_mkdir("ipt_CLUSTERIP", net->proc_net);
99132+ cn->procdir = proc_mkdir_restrict("ipt_CLUSTERIP", net->proc_net);
99133 if (!cn->procdir) {
99134 pr_err("Unable to proc dir entry\n");
99135 return -ENOMEM;
99136diff --git a/net/ipv4/ping.c b/net/ipv4/ping.c
99137index 2d11c09..3f153f8 100644
99138--- a/net/ipv4/ping.c
99139+++ b/net/ipv4/ping.c
99140@@ -59,7 +59,7 @@ struct ping_table {
99141 };
99142
99143 static struct ping_table ping_table;
99144-struct pingv6_ops pingv6_ops;
99145+struct pingv6_ops *pingv6_ops;
99146 EXPORT_SYMBOL_GPL(pingv6_ops);
99147
99148 static u16 ping_port_rover;
99149@@ -255,23 +255,28 @@ int ping_init_sock(struct sock *sk)
99150 struct group_info *group_info = get_current_groups();
99151 int i, j, count = group_info->ngroups;
99152 kgid_t low, high;
99153+ int ret = 0;
99154
99155 inet_get_ping_group_range_net(net, &low, &high);
99156 if (gid_lte(low, group) && gid_lte(group, high))
99157- return 0;
99158+ goto out_release_group;
99159
99160 for (i = 0; i < group_info->nblocks; i++) {
99161 int cp_count = min_t(int, NGROUPS_PER_BLOCK, count);
99162 for (j = 0; j < cp_count; j++) {
99163 kgid_t gid = group_info->blocks[i][j];
99164 if (gid_lte(low, gid) && gid_lte(gid, high))
99165- return 0;
99166+ goto out_release_group;
99167 }
99168
99169 count -= cp_count;
99170 }
99171
99172- return -EACCES;
99173+ ret = -EACCES;
99174+
99175+out_release_group:
99176+ put_group_info(group_info);
99177+ return ret;
99178 }
99179 EXPORT_SYMBOL_GPL(ping_init_sock);
99180
99181@@ -341,7 +346,7 @@ static int ping_check_bind_addr(struct sock *sk, struct inet_sock *isk,
99182 return -ENODEV;
99183 }
99184 }
99185- has_addr = pingv6_ops.ipv6_chk_addr(net, &addr->sin6_addr, dev,
99186+ has_addr = pingv6_ops->ipv6_chk_addr(net, &addr->sin6_addr, dev,
99187 scoped);
99188 rcu_read_unlock();
99189
99190@@ -549,7 +554,7 @@ void ping_err(struct sk_buff *skb, int offset, u32 info)
99191 }
99192 #if IS_ENABLED(CONFIG_IPV6)
99193 } else if (skb->protocol == htons(ETH_P_IPV6)) {
99194- harderr = pingv6_ops.icmpv6_err_convert(type, code, &err);
99195+ harderr = pingv6_ops->icmpv6_err_convert(type, code, &err);
99196 #endif
99197 }
99198
99199@@ -567,7 +572,7 @@ void ping_err(struct sk_buff *skb, int offset, u32 info)
99200 info, (u8 *)icmph);
99201 #if IS_ENABLED(CONFIG_IPV6)
99202 } else if (family == AF_INET6) {
99203- pingv6_ops.ipv6_icmp_error(sk, skb, err, 0,
99204+ pingv6_ops->ipv6_icmp_error(sk, skb, err, 0,
99205 info, (u8 *)icmph);
99206 #endif
99207 }
99208@@ -837,6 +842,8 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
99209 {
99210 struct inet_sock *isk = inet_sk(sk);
99211 int family = sk->sk_family;
99212+ struct sockaddr_in *sin;
99213+ struct sockaddr_in6 *sin6;
99214 struct sk_buff *skb;
99215 int copied, err;
99216
99217@@ -846,12 +853,19 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
99218 if (flags & MSG_OOB)
99219 goto out;
99220
99221+ if (addr_len) {
99222+ if (family == AF_INET)
99223+ *addr_len = sizeof(*sin);
99224+ else if (family == AF_INET6 && addr_len)
99225+ *addr_len = sizeof(*sin6);
99226+ }
99227+
99228 if (flags & MSG_ERRQUEUE) {
99229 if (family == AF_INET) {
99230 return ip_recv_error(sk, msg, len, addr_len);
99231 #if IS_ENABLED(CONFIG_IPV6)
99232 } else if (family == AF_INET6) {
99233- return pingv6_ops.ipv6_recv_error(sk, msg, len,
99234+ return pingv6_ops->ipv6_recv_error(sk, msg, len,
99235 addr_len);
99236 #endif
99237 }
99238@@ -883,7 +897,6 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
99239 sin->sin_port = 0 /* skb->h.uh->source */;
99240 sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
99241 memset(sin->sin_zero, 0, sizeof(sin->sin_zero));
99242- *addr_len = sizeof(*sin);
99243 }
99244
99245 if (isk->cmsg_flags)
99246@@ -905,14 +918,13 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
99247 sin6->sin6_scope_id =
99248 ipv6_iface_scope_id(&sin6->sin6_addr,
99249 IP6CB(skb)->iif);
99250- *addr_len = sizeof(*sin6);
99251 }
99252
99253 if (inet6_sk(sk)->rxopt.all)
99254- pingv6_ops.ip6_datagram_recv_common_ctl(sk, msg, skb);
99255+ pingv6_ops->ip6_datagram_recv_common_ctl(sk, msg, skb);
99256 if (skb->protocol == htons(ETH_P_IPV6) &&
99257 inet6_sk(sk)->rxopt.all)
99258- pingv6_ops.ip6_datagram_recv_specific_ctl(sk, msg, skb);
99259+ pingv6_ops->ip6_datagram_recv_specific_ctl(sk, msg, skb);
99260 else if (skb->protocol == htons(ETH_P_IP) && isk->cmsg_flags)
99261 ip_cmsg_recv(msg, skb);
99262 #endif
99263@@ -1104,7 +1116,7 @@ static void ping_v4_format_sock(struct sock *sp, struct seq_file *f,
99264 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
99265 0, sock_i_ino(sp),
99266 atomic_read(&sp->sk_refcnt), sp,
99267- atomic_read(&sp->sk_drops));
99268+ atomic_read_unchecked(&sp->sk_drops));
99269 }
99270
99271 static int ping_v4_seq_show(struct seq_file *seq, void *v)
99272diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c
99273index c04518f..824ebe5 100644
99274--- a/net/ipv4/raw.c
99275+++ b/net/ipv4/raw.c
99276@@ -311,7 +311,7 @@ static int raw_rcv_skb(struct sock *sk, struct sk_buff *skb)
99277 int raw_rcv(struct sock *sk, struct sk_buff *skb)
99278 {
99279 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) {
99280- atomic_inc(&sk->sk_drops);
99281+ atomic_inc_unchecked(&sk->sk_drops);
99282 kfree_skb(skb);
99283 return NET_RX_DROP;
99284 }
99285@@ -696,6 +696,9 @@ static int raw_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
99286 if (flags & MSG_OOB)
99287 goto out;
99288
99289+ if (addr_len)
99290+ *addr_len = sizeof(*sin);
99291+
99292 if (flags & MSG_ERRQUEUE) {
99293 err = ip_recv_error(sk, msg, len, addr_len);
99294 goto out;
99295@@ -723,7 +726,6 @@ static int raw_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
99296 sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
99297 sin->sin_port = 0;
99298 memset(&sin->sin_zero, 0, sizeof(sin->sin_zero));
99299- *addr_len = sizeof(*sin);
99300 }
99301 if (inet->cmsg_flags)
99302 ip_cmsg_recv(msg, skb);
99303@@ -748,16 +750,20 @@ static int raw_init(struct sock *sk)
99304
99305 static int raw_seticmpfilter(struct sock *sk, char __user *optval, int optlen)
99306 {
99307+ struct icmp_filter filter;
99308+
99309 if (optlen > sizeof(struct icmp_filter))
99310 optlen = sizeof(struct icmp_filter);
99311- if (copy_from_user(&raw_sk(sk)->filter, optval, optlen))
99312+ if (copy_from_user(&filter, optval, optlen))
99313 return -EFAULT;
99314+ raw_sk(sk)->filter = filter;
99315 return 0;
99316 }
99317
99318 static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *optlen)
99319 {
99320 int len, ret = -EFAULT;
99321+ struct icmp_filter filter;
99322
99323 if (get_user(len, optlen))
99324 goto out;
99325@@ -767,8 +773,8 @@ static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *o
99326 if (len > sizeof(struct icmp_filter))
99327 len = sizeof(struct icmp_filter);
99328 ret = -EFAULT;
99329- if (put_user(len, optlen) ||
99330- copy_to_user(optval, &raw_sk(sk)->filter, len))
99331+ filter = raw_sk(sk)->filter;
99332+ if (put_user(len, optlen) || len > sizeof filter || copy_to_user(optval, &filter, len))
99333 goto out;
99334 ret = 0;
99335 out: return ret;
99336@@ -997,7 +1003,7 @@ static void raw_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
99337 0, 0L, 0,
99338 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sp)),
99339 0, sock_i_ino(sp),
99340- atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
99341+ atomic_read(&sp->sk_refcnt), sp, atomic_read_unchecked(&sp->sk_drops));
99342 }
99343
99344 static int raw_seq_show(struct seq_file *seq, void *v)
99345diff --git a/net/ipv4/route.c b/net/ipv4/route.c
99346index 4c011ec..8fae66b 100644
99347--- a/net/ipv4/route.c
99348+++ b/net/ipv4/route.c
99349@@ -233,7 +233,7 @@ static const struct seq_operations rt_cache_seq_ops = {
99350
99351 static int rt_cache_seq_open(struct inode *inode, struct file *file)
99352 {
99353- return seq_open(file, &rt_cache_seq_ops);
99354+ return seq_open_restrict(file, &rt_cache_seq_ops);
99355 }
99356
99357 static const struct file_operations rt_cache_seq_fops = {
99358@@ -324,7 +324,7 @@ static const struct seq_operations rt_cpu_seq_ops = {
99359
99360 static int rt_cpu_seq_open(struct inode *inode, struct file *file)
99361 {
99362- return seq_open(file, &rt_cpu_seq_ops);
99363+ return seq_open_restrict(file, &rt_cpu_seq_ops);
99364 }
99365
99366 static const struct file_operations rt_cpu_seq_fops = {
99367@@ -362,7 +362,7 @@ static int rt_acct_proc_show(struct seq_file *m, void *v)
99368
99369 static int rt_acct_proc_open(struct inode *inode, struct file *file)
99370 {
99371- return single_open(file, rt_acct_proc_show, NULL);
99372+ return single_open_restrict(file, rt_acct_proc_show, NULL);
99373 }
99374
99375 static const struct file_operations rt_acct_proc_fops = {
99376@@ -2623,34 +2623,34 @@ static struct ctl_table ipv4_route_flush_table[] = {
99377 .maxlen = sizeof(int),
99378 .mode = 0200,
99379 .proc_handler = ipv4_sysctl_rtcache_flush,
99380+ .extra1 = &init_net,
99381 },
99382 { },
99383 };
99384
99385 static __net_init int sysctl_route_net_init(struct net *net)
99386 {
99387- struct ctl_table *tbl;
99388+ ctl_table_no_const *tbl = NULL;
99389
99390- tbl = ipv4_route_flush_table;
99391 if (!net_eq(net, &init_net)) {
99392- tbl = kmemdup(tbl, sizeof(ipv4_route_flush_table), GFP_KERNEL);
99393+ tbl = kmemdup(ipv4_route_flush_table, sizeof(ipv4_route_flush_table), GFP_KERNEL);
99394 if (tbl == NULL)
99395 goto err_dup;
99396
99397 /* Don't export sysctls to unprivileged users */
99398 if (net->user_ns != &init_user_ns)
99399 tbl[0].procname = NULL;
99400- }
99401- tbl[0].extra1 = net;
99402+ tbl[0].extra1 = net;
99403+ net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", tbl);
99404+ } else
99405+ net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", ipv4_route_flush_table);
99406
99407- net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", tbl);
99408 if (net->ipv4.route_hdr == NULL)
99409 goto err_reg;
99410 return 0;
99411
99412 err_reg:
99413- if (tbl != ipv4_route_flush_table)
99414- kfree(tbl);
99415+ kfree(tbl);
99416 err_dup:
99417 return -ENOMEM;
99418 }
99419@@ -2673,8 +2673,8 @@ static __net_initdata struct pernet_operations sysctl_route_ops = {
99420
99421 static __net_init int rt_genid_init(struct net *net)
99422 {
99423- atomic_set(&net->ipv4.rt_genid, 0);
99424- atomic_set(&net->fnhe_genid, 0);
99425+ atomic_set_unchecked(&net->ipv4.rt_genid, 0);
99426+ atomic_set_unchecked(&net->fnhe_genid, 0);
99427 get_random_bytes(&net->ipv4.dev_addr_genid,
99428 sizeof(net->ipv4.dev_addr_genid));
99429 return 0;
99430diff --git a/net/ipv4/sysctl_net_ipv4.c b/net/ipv4/sysctl_net_ipv4.c
99431index 44eba05..b36864b 100644
99432--- a/net/ipv4/sysctl_net_ipv4.c
99433+++ b/net/ipv4/sysctl_net_ipv4.c
99434@@ -60,7 +60,7 @@ static int ipv4_local_port_range(struct ctl_table *table, int write,
99435 container_of(table->data, struct net, ipv4.sysctl_local_ports.range);
99436 int ret;
99437 int range[2];
99438- struct ctl_table tmp = {
99439+ ctl_table_no_const tmp = {
99440 .data = &range,
99441 .maxlen = sizeof(range),
99442 .mode = table->mode,
99443@@ -118,7 +118,7 @@ static int ipv4_ping_group_range(struct ctl_table *table, int write,
99444 int ret;
99445 gid_t urange[2];
99446 kgid_t low, high;
99447- struct ctl_table tmp = {
99448+ ctl_table_no_const tmp = {
99449 .data = &urange,
99450 .maxlen = sizeof(urange),
99451 .mode = table->mode,
99452@@ -149,7 +149,7 @@ static int proc_tcp_congestion_control(struct ctl_table *ctl, int write,
99453 void __user *buffer, size_t *lenp, loff_t *ppos)
99454 {
99455 char val[TCP_CA_NAME_MAX];
99456- struct ctl_table tbl = {
99457+ ctl_table_no_const tbl = {
99458 .data = val,
99459 .maxlen = TCP_CA_NAME_MAX,
99460 };
99461@@ -168,7 +168,7 @@ static int proc_tcp_available_congestion_control(struct ctl_table *ctl,
99462 void __user *buffer, size_t *lenp,
99463 loff_t *ppos)
99464 {
99465- struct ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX, };
99466+ ctl_table_no_const tbl = { .maxlen = TCP_CA_BUF_MAX, };
99467 int ret;
99468
99469 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
99470@@ -185,7 +185,7 @@ static int proc_allowed_congestion_control(struct ctl_table *ctl,
99471 void __user *buffer, size_t *lenp,
99472 loff_t *ppos)
99473 {
99474- struct ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX };
99475+ ctl_table_no_const tbl = { .maxlen = TCP_CA_BUF_MAX };
99476 int ret;
99477
99478 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
99479@@ -204,7 +204,7 @@ static int proc_tcp_fastopen_key(struct ctl_table *ctl, int write,
99480 void __user *buffer, size_t *lenp,
99481 loff_t *ppos)
99482 {
99483- struct ctl_table tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
99484+ ctl_table_no_const tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
99485 struct tcp_fastopen_context *ctxt;
99486 int ret;
99487 u32 user_key[4]; /* 16 bytes, matching TCP_FASTOPEN_KEY_LENGTH */
99488@@ -438,7 +438,7 @@ static struct ctl_table ipv4_table[] = {
99489 },
99490 {
99491 .procname = "ip_local_reserved_ports",
99492- .data = NULL, /* initialized in sysctl_ipv4_init */
99493+ .data = sysctl_local_reserved_ports,
99494 .maxlen = 65536,
99495 .mode = 0644,
99496 .proc_handler = proc_do_large_bitmap,
99497@@ -843,13 +843,12 @@ static struct ctl_table ipv4_net_table[] = {
99498
99499 static __net_init int ipv4_sysctl_init_net(struct net *net)
99500 {
99501- struct ctl_table *table;
99502+ ctl_table_no_const *table = NULL;
99503
99504- table = ipv4_net_table;
99505 if (!net_eq(net, &init_net)) {
99506 int i;
99507
99508- table = kmemdup(table, sizeof(ipv4_net_table), GFP_KERNEL);
99509+ table = kmemdup(ipv4_net_table, sizeof(ipv4_net_table), GFP_KERNEL);
99510 if (table == NULL)
99511 goto err_alloc;
99512
99513@@ -872,15 +871,17 @@ static __net_init int ipv4_sysctl_init_net(struct net *net)
99514 net->ipv4.sysctl_local_ports.range[0] = 32768;
99515 net->ipv4.sysctl_local_ports.range[1] = 61000;
99516
99517- net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
99518+ if (!net_eq(net, &init_net))
99519+ net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
99520+ else
99521+ net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", ipv4_net_table);
99522 if (net->ipv4.ipv4_hdr == NULL)
99523 goto err_reg;
99524
99525 return 0;
99526
99527 err_reg:
99528- if (!net_eq(net, &init_net))
99529- kfree(table);
99530+ kfree(table);
99531 err_alloc:
99532 return -ENOMEM;
99533 }
99534@@ -902,16 +903,6 @@ static __net_initdata struct pernet_operations ipv4_sysctl_ops = {
99535 static __init int sysctl_ipv4_init(void)
99536 {
99537 struct ctl_table_header *hdr;
99538- struct ctl_table *i;
99539-
99540- for (i = ipv4_table; i->procname; i++) {
99541- if (strcmp(i->procname, "ip_local_reserved_ports") == 0) {
99542- i->data = sysctl_local_reserved_ports;
99543- break;
99544- }
99545- }
99546- if (!i->procname)
99547- return -EINVAL;
99548
99549 hdr = register_net_sysctl(&init_net, "net/ipv4", ipv4_table);
99550 if (hdr == NULL)
99551diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
99552index eeaac39..dc29942 100644
99553--- a/net/ipv4/tcp_input.c
99554+++ b/net/ipv4/tcp_input.c
99555@@ -761,7 +761,7 @@ static void tcp_update_pacing_rate(struct sock *sk)
99556 * without any lock. We want to make sure compiler wont store
99557 * intermediate values in this location.
99558 */
99559- ACCESS_ONCE(sk->sk_pacing_rate) = min_t(u64, rate,
99560+ ACCESS_ONCE_RW(sk->sk_pacing_rate) = min_t(u64, rate,
99561 sk->sk_max_pacing_rate);
99562 }
99563
99564@@ -4485,7 +4485,7 @@ static struct sk_buff *tcp_collapse_one(struct sock *sk, struct sk_buff *skb,
99565 * simplifies code)
99566 */
99567 static void
99568-tcp_collapse(struct sock *sk, struct sk_buff_head *list,
99569+__intentional_overflow(5,6) tcp_collapse(struct sock *sk, struct sk_buff_head *list,
99570 struct sk_buff *head, struct sk_buff *tail,
99571 u32 start, u32 end)
99572 {
99573@@ -5562,6 +5562,7 @@ discard:
99574 tcp_paws_reject(&tp->rx_opt, 0))
99575 goto discard_and_undo;
99576
99577+#ifndef CONFIG_GRKERNSEC_NO_SIMULT_CONNECT
99578 if (th->syn) {
99579 /* We see SYN without ACK. It is attempt of
99580 * simultaneous connect with crossed SYNs.
99581@@ -5612,6 +5613,7 @@ discard:
99582 goto discard;
99583 #endif
99584 }
99585+#endif
99586 /* "fifth, if neither of the SYN or RST bits is set then
99587 * drop the segment and return."
99588 */
99589@@ -5658,7 +5660,7 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb,
99590 goto discard;
99591
99592 if (th->syn) {
99593- if (th->fin)
99594+ if (th->fin || th->urg || th->psh)
99595 goto discard;
99596 if (icsk->icsk_af_ops->conn_request(sk, skb) < 0)
99597 return 1;
99598diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
99599index 1e4eac7..a66fa4a 100644
99600--- a/net/ipv4/tcp_ipv4.c
99601+++ b/net/ipv4/tcp_ipv4.c
99602@@ -91,6 +91,10 @@ int sysctl_tcp_low_latency __read_mostly;
99603 EXPORT_SYMBOL(sysctl_tcp_low_latency);
99604
99605
99606+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
99607+extern int grsec_enable_blackhole;
99608+#endif
99609+
99610 #ifdef CONFIG_TCP_MD5SIG
99611 static int tcp_v4_md5_hash_hdr(char *md5_hash, const struct tcp_md5sig_key *key,
99612 __be32 daddr, __be32 saddr, const struct tcphdr *th);
99613@@ -1829,6 +1833,9 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb)
99614 return 0;
99615
99616 reset:
99617+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
99618+ if (!grsec_enable_blackhole)
99619+#endif
99620 tcp_v4_send_reset(rsk, skb);
99621 discard:
99622 kfree_skb(skb);
99623@@ -1974,12 +1981,19 @@ int tcp_v4_rcv(struct sk_buff *skb)
99624 TCP_SKB_CB(skb)->sacked = 0;
99625
99626 sk = __inet_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
99627- if (!sk)
99628+ if (!sk) {
99629+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
99630+ ret = 1;
99631+#endif
99632 goto no_tcp_socket;
99633-
99634+ }
99635 process:
99636- if (sk->sk_state == TCP_TIME_WAIT)
99637+ if (sk->sk_state == TCP_TIME_WAIT) {
99638+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
99639+ ret = 2;
99640+#endif
99641 goto do_time_wait;
99642+ }
99643
99644 if (unlikely(iph->ttl < inet_sk(sk)->min_ttl)) {
99645 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
99646@@ -2033,6 +2047,10 @@ csum_error:
99647 bad_packet:
99648 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
99649 } else {
99650+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
99651+ if (!grsec_enable_blackhole || (ret == 1 &&
99652+ (skb->dev->flags & IFF_LOOPBACK)))
99653+#endif
99654 tcp_v4_send_reset(NULL, skb);
99655 }
99656
99657diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c
99658index 7a436c5..1b05c59 100644
99659--- a/net/ipv4/tcp_minisocks.c
99660+++ b/net/ipv4/tcp_minisocks.c
99661@@ -27,6 +27,10 @@
99662 #include <net/inet_common.h>
99663 #include <net/xfrm.h>
99664
99665+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
99666+extern int grsec_enable_blackhole;
99667+#endif
99668+
99669 int sysctl_tcp_syncookies __read_mostly = 1;
99670 EXPORT_SYMBOL(sysctl_tcp_syncookies);
99671
99672@@ -709,7 +713,10 @@ embryonic_reset:
99673 * avoid becoming vulnerable to outside attack aiming at
99674 * resetting legit local connections.
99675 */
99676- req->rsk_ops->send_reset(sk, skb);
99677+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
99678+ if (!grsec_enable_blackhole)
99679+#endif
99680+ req->rsk_ops->send_reset(sk, skb);
99681 } else if (fastopen) { /* received a valid RST pkt */
99682 reqsk_fastopen_remove(sk, req, true);
99683 tcp_reset(sk);
99684diff --git a/net/ipv4/tcp_probe.c b/net/ipv4/tcp_probe.c
99685index 1f2d376..01d18c4 100644
99686--- a/net/ipv4/tcp_probe.c
99687+++ b/net/ipv4/tcp_probe.c
99688@@ -238,7 +238,7 @@ static ssize_t tcpprobe_read(struct file *file, char __user *buf,
99689 if (cnt + width >= len)
99690 break;
99691
99692- if (copy_to_user(buf + cnt, tbuf, width))
99693+ if (width > sizeof tbuf || copy_to_user(buf + cnt, tbuf, width))
99694 return -EFAULT;
99695 cnt += width;
99696 }
99697diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c
99698index 64f0354..a81b39d 100644
99699--- a/net/ipv4/tcp_timer.c
99700+++ b/net/ipv4/tcp_timer.c
99701@@ -22,6 +22,10 @@
99702 #include <linux/gfp.h>
99703 #include <net/tcp.h>
99704
99705+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
99706+extern int grsec_lastack_retries;
99707+#endif
99708+
99709 int sysctl_tcp_syn_retries __read_mostly = TCP_SYN_RETRIES;
99710 int sysctl_tcp_synack_retries __read_mostly = TCP_SYNACK_RETRIES;
99711 int sysctl_tcp_keepalive_time __read_mostly = TCP_KEEPALIVE_TIME;
99712@@ -189,6 +193,13 @@ static int tcp_write_timeout(struct sock *sk)
99713 }
99714 }
99715
99716+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
99717+ if ((sk->sk_state == TCP_LAST_ACK) &&
99718+ (grsec_lastack_retries > 0) &&
99719+ (grsec_lastack_retries < retry_until))
99720+ retry_until = grsec_lastack_retries;
99721+#endif
99722+
99723 if (retransmits_timed_out(sk, retry_until,
99724 syn_set ? 0 : icsk->icsk_user_timeout, syn_set)) {
99725 /* Has it gone just too far? */
99726diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
99727index 77bd16f..5f7174a 100644
99728--- a/net/ipv4/udp.c
99729+++ b/net/ipv4/udp.c
99730@@ -87,6 +87,7 @@
99731 #include <linux/types.h>
99732 #include <linux/fcntl.h>
99733 #include <linux/module.h>
99734+#include <linux/security.h>
99735 #include <linux/socket.h>
99736 #include <linux/sockios.h>
99737 #include <linux/igmp.h>
99738@@ -113,6 +114,10 @@
99739 #include <net/busy_poll.h>
99740 #include "udp_impl.h"
99741
99742+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
99743+extern int grsec_enable_blackhole;
99744+#endif
99745+
99746 struct udp_table udp_table __read_mostly;
99747 EXPORT_SYMBOL(udp_table);
99748
99749@@ -615,6 +620,9 @@ found:
99750 return s;
99751 }
99752
99753+extern int gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb);
99754+extern int gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr);
99755+
99756 /*
99757 * This routine is called by the ICMP module when it gets some
99758 * sort of error condition. If err < 0 then the socket should
99759@@ -914,9 +922,18 @@ int udp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
99760 dport = usin->sin_port;
99761 if (dport == 0)
99762 return -EINVAL;
99763+
99764+ err = gr_search_udp_sendmsg(sk, usin);
99765+ if (err)
99766+ return err;
99767 } else {
99768 if (sk->sk_state != TCP_ESTABLISHED)
99769 return -EDESTADDRREQ;
99770+
99771+ err = gr_search_udp_sendmsg(sk, NULL);
99772+ if (err)
99773+ return err;
99774+
99775 daddr = inet->inet_daddr;
99776 dport = inet->inet_dport;
99777 /* Open fast path for connected socket.
99778@@ -1163,7 +1180,7 @@ static unsigned int first_packet_length(struct sock *sk)
99779 IS_UDPLITE(sk));
99780 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
99781 IS_UDPLITE(sk));
99782- atomic_inc(&sk->sk_drops);
99783+ atomic_inc_unchecked(&sk->sk_drops);
99784 __skb_unlink(skb, rcvq);
99785 __skb_queue_tail(&list_kill, skb);
99786 }
99787@@ -1234,6 +1251,12 @@ int udp_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
99788 int is_udplite = IS_UDPLITE(sk);
99789 bool slow;
99790
99791+ /*
99792+ * Check any passed addresses
99793+ */
99794+ if (addr_len)
99795+ *addr_len = sizeof(*sin);
99796+
99797 if (flags & MSG_ERRQUEUE)
99798 return ip_recv_error(sk, msg, len, addr_len);
99799
99800@@ -1243,6 +1266,10 @@ try_again:
99801 if (!skb)
99802 goto out;
99803
99804+ err = gr_search_udp_recvmsg(sk, skb);
99805+ if (err)
99806+ goto out_free;
99807+
99808 ulen = skb->len - sizeof(struct udphdr);
99809 copied = len;
99810 if (copied > ulen)
99811@@ -1276,7 +1303,7 @@ try_again:
99812 if (unlikely(err)) {
99813 trace_kfree_skb(skb, udp_recvmsg);
99814 if (!peeked) {
99815- atomic_inc(&sk->sk_drops);
99816+ atomic_inc_unchecked(&sk->sk_drops);
99817 UDP_INC_STATS_USER(sock_net(sk),
99818 UDP_MIB_INERRORS, is_udplite);
99819 }
99820@@ -1295,7 +1322,6 @@ try_again:
99821 sin->sin_port = udp_hdr(skb)->source;
99822 sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
99823 memset(sin->sin_zero, 0, sizeof(sin->sin_zero));
99824- *addr_len = sizeof(*sin);
99825 }
99826 if (inet->cmsg_flags)
99827 ip_cmsg_recv(msg, skb);
99828@@ -1566,7 +1592,7 @@ csum_error:
99829 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_CSUMERRORS, is_udplite);
99830 drop:
99831 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
99832- atomic_inc(&sk->sk_drops);
99833+ atomic_inc_unchecked(&sk->sk_drops);
99834 kfree_skb(skb);
99835 return -1;
99836 }
99837@@ -1585,7 +1611,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
99838 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
99839
99840 if (!skb1) {
99841- atomic_inc(&sk->sk_drops);
99842+ atomic_inc_unchecked(&sk->sk_drops);
99843 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
99844 IS_UDPLITE(sk));
99845 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
99846@@ -1786,6 +1812,9 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
99847 goto csum_error;
99848
99849 UDP_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
99850+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
99851+ if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
99852+#endif
99853 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0);
99854
99855 /*
99856@@ -2350,7 +2379,7 @@ static void udp4_format_sock(struct sock *sp, struct seq_file *f,
99857 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
99858 0, sock_i_ino(sp),
99859 atomic_read(&sp->sk_refcnt), sp,
99860- atomic_read(&sp->sk_drops));
99861+ atomic_read_unchecked(&sp->sk_drops));
99862 }
99863
99864 int udp4_seq_show(struct seq_file *seq, void *v)
99865diff --git a/net/ipv4/xfrm4_policy.c b/net/ipv4/xfrm4_policy.c
99866index e1a6393..f634ce5 100644
99867--- a/net/ipv4/xfrm4_policy.c
99868+++ b/net/ipv4/xfrm4_policy.c
99869@@ -186,11 +186,11 @@ _decode_session4(struct sk_buff *skb, struct flowi *fl, int reverse)
99870 fl4->flowi4_tos = iph->tos;
99871 }
99872
99873-static inline int xfrm4_garbage_collect(struct dst_ops *ops)
99874+static int xfrm4_garbage_collect(struct dst_ops *ops)
99875 {
99876 struct net *net = container_of(ops, struct net, xfrm.xfrm4_dst_ops);
99877
99878- xfrm4_policy_afinfo.garbage_collect(net);
99879+ xfrm_garbage_collect_deferred(net);
99880 return (dst_entries_get_slow(ops) > ops->gc_thresh * 2);
99881 }
99882
99883@@ -269,19 +269,18 @@ static struct ctl_table xfrm4_policy_table[] = {
99884
99885 static int __net_init xfrm4_net_init(struct net *net)
99886 {
99887- struct ctl_table *table;
99888+ ctl_table_no_const *table = NULL;
99889 struct ctl_table_header *hdr;
99890
99891- table = xfrm4_policy_table;
99892 if (!net_eq(net, &init_net)) {
99893- table = kmemdup(table, sizeof(xfrm4_policy_table), GFP_KERNEL);
99894+ table = kmemdup(xfrm4_policy_table, sizeof(xfrm4_policy_table), GFP_KERNEL);
99895 if (!table)
99896 goto err_alloc;
99897
99898 table[0].data = &net->xfrm.xfrm4_dst_ops.gc_thresh;
99899- }
99900-
99901- hdr = register_net_sysctl(net, "net/ipv4", table);
99902+ hdr = register_net_sysctl(net, "net/ipv4", table);
99903+ } else
99904+ hdr = register_net_sysctl(net, "net/ipv4", xfrm4_policy_table);
99905 if (!hdr)
99906 goto err_reg;
99907
99908@@ -289,8 +288,7 @@ static int __net_init xfrm4_net_init(struct net *net)
99909 return 0;
99910
99911 err_reg:
99912- if (!net_eq(net, &init_net))
99913- kfree(table);
99914+ kfree(table);
99915 err_alloc:
99916 return -ENOMEM;
99917 }
99918diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
99919index 6c7fa08..285086c 100644
99920--- a/net/ipv6/addrconf.c
99921+++ b/net/ipv6/addrconf.c
99922@@ -598,7 +598,7 @@ static int inet6_netconf_dump_devconf(struct sk_buff *skb,
99923 idx = 0;
99924 head = &net->dev_index_head[h];
99925 rcu_read_lock();
99926- cb->seq = atomic_read(&net->ipv6.dev_addr_genid) ^
99927+ cb->seq = atomic_read_unchecked(&net->ipv6.dev_addr_genid) ^
99928 net->dev_base_seq;
99929 hlist_for_each_entry_rcu(dev, head, index_hlist) {
99930 if (idx < s_idx)
99931@@ -2395,7 +2395,7 @@ int addrconf_set_dstaddr(struct net *net, void __user *arg)
99932 p.iph.ihl = 5;
99933 p.iph.protocol = IPPROTO_IPV6;
99934 p.iph.ttl = 64;
99935- ifr.ifr_ifru.ifru_data = (__force void __user *)&p;
99936+ ifr.ifr_ifru.ifru_data = (void __force_user *)&p;
99937
99938 if (ops->ndo_do_ioctl) {
99939 mm_segment_t oldfs = get_fs();
99940@@ -4146,7 +4146,7 @@ static int inet6_dump_addr(struct sk_buff *skb, struct netlink_callback *cb,
99941 s_ip_idx = ip_idx = cb->args[2];
99942
99943 rcu_read_lock();
99944- cb->seq = atomic_read(&net->ipv6.dev_addr_genid) ^ net->dev_base_seq;
99945+ cb->seq = atomic_read_unchecked(&net->ipv6.dev_addr_genid) ^ net->dev_base_seq;
99946 for (h = s_h; h < NETDEV_HASHENTRIES; h++, s_idx = 0) {
99947 idx = 0;
99948 head = &net->dev_index_head[h];
99949@@ -4758,7 +4758,7 @@ static void __ipv6_ifa_notify(int event, struct inet6_ifaddr *ifp)
99950 dst_free(&ifp->rt->dst);
99951 break;
99952 }
99953- atomic_inc(&net->ipv6.dev_addr_genid);
99954+ atomic_inc_unchecked(&net->ipv6.dev_addr_genid);
99955 rt_genid_bump_ipv6(net);
99956 }
99957
99958@@ -4779,7 +4779,7 @@ int addrconf_sysctl_forward(struct ctl_table *ctl, int write,
99959 int *valp = ctl->data;
99960 int val = *valp;
99961 loff_t pos = *ppos;
99962- struct ctl_table lctl;
99963+ ctl_table_no_const lctl;
99964 int ret;
99965
99966 /*
99967@@ -4864,7 +4864,7 @@ int addrconf_sysctl_disable(struct ctl_table *ctl, int write,
99968 int *valp = ctl->data;
99969 int val = *valp;
99970 loff_t pos = *ppos;
99971- struct ctl_table lctl;
99972+ ctl_table_no_const lctl;
99973 int ret;
99974
99975 /*
99976diff --git a/net/ipv6/af_inet6.c b/net/ipv6/af_inet6.c
99977index d935889..2f64330 100644
99978--- a/net/ipv6/af_inet6.c
99979+++ b/net/ipv6/af_inet6.c
99980@@ -776,7 +776,7 @@ static int __net_init inet6_net_init(struct net *net)
99981 net->ipv6.sysctl.bindv6only = 0;
99982 net->ipv6.sysctl.icmpv6_time = 1*HZ;
99983 net->ipv6.sysctl.flowlabel_consistency = 1;
99984- atomic_set(&net->ipv6.rt_genid, 0);
99985+ atomic_set_unchecked(&net->ipv6.rt_genid, 0);
99986
99987 err = ipv6_init_mibs(net);
99988 if (err)
99989diff --git a/net/ipv6/datagram.c b/net/ipv6/datagram.c
99990index c3bf2d2..1f00573 100644
99991--- a/net/ipv6/datagram.c
99992+++ b/net/ipv6/datagram.c
99993@@ -938,5 +938,5 @@ void ip6_dgram_sock_seq_show(struct seq_file *seq, struct sock *sp,
99994 0,
99995 sock_i_ino(sp),
99996 atomic_read(&sp->sk_refcnt), sp,
99997- atomic_read(&sp->sk_drops));
99998+ atomic_read_unchecked(&sp->sk_drops));
99999 }
100000diff --git a/net/ipv6/icmp.c b/net/ipv6/icmp.c
100001index 7b32652..0bc348b 100644
100002--- a/net/ipv6/icmp.c
100003+++ b/net/ipv6/icmp.c
100004@@ -1005,7 +1005,7 @@ static struct ctl_table ipv6_icmp_table_template[] = {
100005
100006 struct ctl_table * __net_init ipv6_icmp_sysctl_init(struct net *net)
100007 {
100008- struct ctl_table *table;
100009+ ctl_table_no_const *table;
100010
100011 table = kmemdup(ipv6_icmp_table_template,
100012 sizeof(ipv6_icmp_table_template),
100013diff --git a/net/ipv6/ip6_gre.c b/net/ipv6/ip6_gre.c
100014index f3ffb43..1172ba7 100644
100015--- a/net/ipv6/ip6_gre.c
100016+++ b/net/ipv6/ip6_gre.c
100017@@ -71,7 +71,7 @@ struct ip6gre_net {
100018 struct net_device *fb_tunnel_dev;
100019 };
100020
100021-static struct rtnl_link_ops ip6gre_link_ops __read_mostly;
100022+static struct rtnl_link_ops ip6gre_link_ops;
100023 static int ip6gre_tunnel_init(struct net_device *dev);
100024 static void ip6gre_tunnel_setup(struct net_device *dev);
100025 static void ip6gre_tunnel_link(struct ip6gre_net *ign, struct ip6_tnl *t);
100026@@ -1291,7 +1291,7 @@ static void ip6gre_fb_tunnel_init(struct net_device *dev)
100027 }
100028
100029
100030-static struct inet6_protocol ip6gre_protocol __read_mostly = {
100031+static struct inet6_protocol ip6gre_protocol = {
100032 .handler = ip6gre_rcv,
100033 .err_handler = ip6gre_err,
100034 .flags = INET6_PROTO_NOPOLICY|INET6_PROTO_FINAL,
100035@@ -1634,7 +1634,7 @@ static const struct nla_policy ip6gre_policy[IFLA_GRE_MAX + 1] = {
100036 [IFLA_GRE_FLAGS] = { .type = NLA_U32 },
100037 };
100038
100039-static struct rtnl_link_ops ip6gre_link_ops __read_mostly = {
100040+static struct rtnl_link_ops ip6gre_link_ops = {
100041 .kind = "ip6gre",
100042 .maxtype = IFLA_GRE_MAX,
100043 .policy = ip6gre_policy,
100044@@ -1647,7 +1647,7 @@ static struct rtnl_link_ops ip6gre_link_ops __read_mostly = {
100045 .fill_info = ip6gre_fill_info,
100046 };
100047
100048-static struct rtnl_link_ops ip6gre_tap_ops __read_mostly = {
100049+static struct rtnl_link_ops ip6gre_tap_ops = {
100050 .kind = "ip6gretap",
100051 .maxtype = IFLA_GRE_MAX,
100052 .policy = ip6gre_policy,
100053diff --git a/net/ipv6/ip6_tunnel.c b/net/ipv6/ip6_tunnel.c
100054index 5db8d31..4a72c26 100644
100055--- a/net/ipv6/ip6_tunnel.c
100056+++ b/net/ipv6/ip6_tunnel.c
100057@@ -85,7 +85,7 @@ static u32 HASH(const struct in6_addr *addr1, const struct in6_addr *addr2)
100058
100059 static int ip6_tnl_dev_init(struct net_device *dev);
100060 static void ip6_tnl_dev_setup(struct net_device *dev);
100061-static struct rtnl_link_ops ip6_link_ops __read_mostly;
100062+static struct rtnl_link_ops ip6_link_ops;
100063
100064 static int ip6_tnl_net_id __read_mostly;
100065 struct ip6_tnl_net {
100066@@ -1714,7 +1714,7 @@ static const struct nla_policy ip6_tnl_policy[IFLA_IPTUN_MAX + 1] = {
100067 [IFLA_IPTUN_PROTO] = { .type = NLA_U8 },
100068 };
100069
100070-static struct rtnl_link_ops ip6_link_ops __read_mostly = {
100071+static struct rtnl_link_ops ip6_link_ops = {
100072 .kind = "ip6tnl",
100073 .maxtype = IFLA_IPTUN_MAX,
100074 .policy = ip6_tnl_policy,
100075diff --git a/net/ipv6/ip6_vti.c b/net/ipv6/ip6_vti.c
100076index 2d19272..3a46322 100644
100077--- a/net/ipv6/ip6_vti.c
100078+++ b/net/ipv6/ip6_vti.c
100079@@ -62,7 +62,7 @@ static u32 HASH(const struct in6_addr *addr1, const struct in6_addr *addr2)
100080
100081 static int vti6_dev_init(struct net_device *dev);
100082 static void vti6_dev_setup(struct net_device *dev);
100083-static struct rtnl_link_ops vti6_link_ops __read_mostly;
100084+static struct rtnl_link_ops vti6_link_ops;
100085
100086 static int vti6_net_id __read_mostly;
100087 struct vti6_net {
100088@@ -901,7 +901,7 @@ static const struct nla_policy vti6_policy[IFLA_VTI_MAX + 1] = {
100089 [IFLA_VTI_OKEY] = { .type = NLA_U32 },
100090 };
100091
100092-static struct rtnl_link_ops vti6_link_ops __read_mostly = {
100093+static struct rtnl_link_ops vti6_link_ops = {
100094 .kind = "vti6",
100095 .maxtype = IFLA_VTI_MAX,
100096 .policy = vti6_policy,
100097diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c
100098index 0a00f44..bec42b2 100644
100099--- a/net/ipv6/ipv6_sockglue.c
100100+++ b/net/ipv6/ipv6_sockglue.c
100101@@ -991,7 +991,7 @@ static int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
100102 if (sk->sk_type != SOCK_STREAM)
100103 return -ENOPROTOOPT;
100104
100105- msg.msg_control = optval;
100106+ msg.msg_control = (void __force_kernel *)optval;
100107 msg.msg_controllen = len;
100108 msg.msg_flags = flags;
100109
100110diff --git a/net/ipv6/netfilter/ip6_tables.c b/net/ipv6/netfilter/ip6_tables.c
100111index 710238f..0fd1816 100644
100112--- a/net/ipv6/netfilter/ip6_tables.c
100113+++ b/net/ipv6/netfilter/ip6_tables.c
100114@@ -1083,14 +1083,14 @@ static int compat_table_info(const struct xt_table_info *info,
100115 #endif
100116
100117 static int get_info(struct net *net, void __user *user,
100118- const int *len, int compat)
100119+ int len, int compat)
100120 {
100121 char name[XT_TABLE_MAXNAMELEN];
100122 struct xt_table *t;
100123 int ret;
100124
100125- if (*len != sizeof(struct ip6t_getinfo)) {
100126- duprintf("length %u != %zu\n", *len,
100127+ if (len != sizeof(struct ip6t_getinfo)) {
100128+ duprintf("length %u != %zu\n", len,
100129 sizeof(struct ip6t_getinfo));
100130 return -EINVAL;
100131 }
100132@@ -1127,7 +1127,7 @@ static int get_info(struct net *net, void __user *user,
100133 info.size = private->size;
100134 strcpy(info.name, name);
100135
100136- if (copy_to_user(user, &info, *len) != 0)
100137+ if (copy_to_user(user, &info, len) != 0)
100138 ret = -EFAULT;
100139 else
100140 ret = 0;
100141@@ -1981,7 +1981,7 @@ compat_do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
100142
100143 switch (cmd) {
100144 case IP6T_SO_GET_INFO:
100145- ret = get_info(sock_net(sk), user, len, 1);
100146+ ret = get_info(sock_net(sk), user, *len, 1);
100147 break;
100148 case IP6T_SO_GET_ENTRIES:
100149 ret = compat_get_entries(sock_net(sk), user, len);
100150@@ -2028,7 +2028,7 @@ do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
100151
100152 switch (cmd) {
100153 case IP6T_SO_GET_INFO:
100154- ret = get_info(sock_net(sk), user, len, 0);
100155+ ret = get_info(sock_net(sk), user, *len, 0);
100156 break;
100157
100158 case IP6T_SO_GET_ENTRIES:
100159diff --git a/net/ipv6/netfilter/nf_conntrack_reasm.c b/net/ipv6/netfilter/nf_conntrack_reasm.c
100160index 767ab8d..c5ec70a 100644
100161--- a/net/ipv6/netfilter/nf_conntrack_reasm.c
100162+++ b/net/ipv6/netfilter/nf_conntrack_reasm.c
100163@@ -90,12 +90,11 @@ static struct ctl_table nf_ct_frag6_sysctl_table[] = {
100164
100165 static int nf_ct_frag6_sysctl_register(struct net *net)
100166 {
100167- struct ctl_table *table;
100168+ ctl_table_no_const *table = NULL;
100169 struct ctl_table_header *hdr;
100170
100171- table = nf_ct_frag6_sysctl_table;
100172 if (!net_eq(net, &init_net)) {
100173- table = kmemdup(table, sizeof(nf_ct_frag6_sysctl_table),
100174+ table = kmemdup(nf_ct_frag6_sysctl_table, sizeof(nf_ct_frag6_sysctl_table),
100175 GFP_KERNEL);
100176 if (table == NULL)
100177 goto err_alloc;
100178@@ -103,9 +102,9 @@ static int nf_ct_frag6_sysctl_register(struct net *net)
100179 table[0].data = &net->nf_frag.frags.timeout;
100180 table[1].data = &net->nf_frag.frags.low_thresh;
100181 table[2].data = &net->nf_frag.frags.high_thresh;
100182- }
100183-
100184- hdr = register_net_sysctl(net, "net/netfilter", table);
100185+ hdr = register_net_sysctl(net, "net/netfilter", table);
100186+ } else
100187+ hdr = register_net_sysctl(net, "net/netfilter", nf_ct_frag6_sysctl_table);
100188 if (hdr == NULL)
100189 goto err_reg;
100190
100191@@ -113,8 +112,7 @@ static int nf_ct_frag6_sysctl_register(struct net *net)
100192 return 0;
100193
100194 err_reg:
100195- if (!net_eq(net, &init_net))
100196- kfree(table);
100197+ kfree(table);
100198 err_alloc:
100199 return -ENOMEM;
100200 }
100201diff --git a/net/ipv6/output_core.c b/net/ipv6/output_core.c
100202index 827f795..7e28e82 100644
100203--- a/net/ipv6/output_core.c
100204+++ b/net/ipv6/output_core.c
100205@@ -9,8 +9,8 @@
100206
100207 void ipv6_select_ident(struct frag_hdr *fhdr, struct rt6_info *rt)
100208 {
100209- static atomic_t ipv6_fragmentation_id;
100210- int old, new;
100211+ static atomic_unchecked_t ipv6_fragmentation_id;
100212+ int id;
100213
100214 #if IS_ENABLED(CONFIG_IPV6)
100215 if (rt && !(rt->dst.flags & DST_NOPEER)) {
100216@@ -26,13 +26,10 @@ void ipv6_select_ident(struct frag_hdr *fhdr, struct rt6_info *rt)
100217 }
100218 }
100219 #endif
100220- do {
100221- old = atomic_read(&ipv6_fragmentation_id);
100222- new = old + 1;
100223- if (!new)
100224- new = 1;
100225- } while (atomic_cmpxchg(&ipv6_fragmentation_id, old, new) != old);
100226- fhdr->identification = htonl(new);
100227+ id = atomic_inc_return_unchecked(&ipv6_fragmentation_id);
100228+ if (!id)
100229+ id = atomic_inc_return_unchecked(&ipv6_fragmentation_id);
100230+ fhdr->identification = htonl(id);
100231 }
100232 EXPORT_SYMBOL(ipv6_select_ident);
100233
100234diff --git a/net/ipv6/ping.c b/net/ipv6/ping.c
100235index bda7429..469b26b 100644
100236--- a/net/ipv6/ping.c
100237+++ b/net/ipv6/ping.c
100238@@ -246,6 +246,24 @@ static struct pernet_operations ping_v6_net_ops = {
100239 };
100240 #endif
100241
100242+static struct pingv6_ops real_pingv6_ops = {
100243+ .ipv6_recv_error = ipv6_recv_error,
100244+ .ip6_datagram_recv_common_ctl = ip6_datagram_recv_common_ctl,
100245+ .ip6_datagram_recv_specific_ctl = ip6_datagram_recv_specific_ctl,
100246+ .icmpv6_err_convert = icmpv6_err_convert,
100247+ .ipv6_icmp_error = ipv6_icmp_error,
100248+ .ipv6_chk_addr = ipv6_chk_addr,
100249+};
100250+
100251+static struct pingv6_ops dummy_pingv6_ops = {
100252+ .ipv6_recv_error = dummy_ipv6_recv_error,
100253+ .ip6_datagram_recv_common_ctl = dummy_ip6_datagram_recv_ctl,
100254+ .ip6_datagram_recv_specific_ctl = dummy_ip6_datagram_recv_ctl,
100255+ .icmpv6_err_convert = dummy_icmpv6_err_convert,
100256+ .ipv6_icmp_error = dummy_ipv6_icmp_error,
100257+ .ipv6_chk_addr = dummy_ipv6_chk_addr,
100258+};
100259+
100260 int __init pingv6_init(void)
100261 {
100262 #ifdef CONFIG_PROC_FS
100263@@ -253,13 +271,7 @@ int __init pingv6_init(void)
100264 if (ret)
100265 return ret;
100266 #endif
100267- pingv6_ops.ipv6_recv_error = ipv6_recv_error;
100268- pingv6_ops.ip6_datagram_recv_common_ctl = ip6_datagram_recv_common_ctl;
100269- pingv6_ops.ip6_datagram_recv_specific_ctl =
100270- ip6_datagram_recv_specific_ctl;
100271- pingv6_ops.icmpv6_err_convert = icmpv6_err_convert;
100272- pingv6_ops.ipv6_icmp_error = ipv6_icmp_error;
100273- pingv6_ops.ipv6_chk_addr = ipv6_chk_addr;
100274+ pingv6_ops = &real_pingv6_ops;
100275 return inet6_register_protosw(&pingv6_protosw);
100276 }
100277
100278@@ -268,14 +280,9 @@ int __init pingv6_init(void)
100279 */
100280 void pingv6_exit(void)
100281 {
100282- pingv6_ops.ipv6_recv_error = dummy_ipv6_recv_error;
100283- pingv6_ops.ip6_datagram_recv_common_ctl = dummy_ip6_datagram_recv_ctl;
100284- pingv6_ops.ip6_datagram_recv_specific_ctl = dummy_ip6_datagram_recv_ctl;
100285- pingv6_ops.icmpv6_err_convert = dummy_icmpv6_err_convert;
100286- pingv6_ops.ipv6_icmp_error = dummy_ipv6_icmp_error;
100287- pingv6_ops.ipv6_chk_addr = dummy_ipv6_chk_addr;
100288 #ifdef CONFIG_PROC_FS
100289 unregister_pernet_subsys(&ping_v6_net_ops);
100290 #endif
100291+ pingv6_ops = &dummy_pingv6_ops;
100292 inet6_unregister_protosw(&pingv6_protosw);
100293 }
100294diff --git a/net/ipv6/proc.c b/net/ipv6/proc.c
100295index 091d066..139d410 100644
100296--- a/net/ipv6/proc.c
100297+++ b/net/ipv6/proc.c
100298@@ -309,7 +309,7 @@ static int __net_init ipv6_proc_init_net(struct net *net)
100299 if (!proc_create("snmp6", S_IRUGO, net->proc_net, &snmp6_seq_fops))
100300 goto proc_snmp6_fail;
100301
100302- net->mib.proc_net_devsnmp6 = proc_mkdir("dev_snmp6", net->proc_net);
100303+ net->mib.proc_net_devsnmp6 = proc_mkdir_restrict("dev_snmp6", net->proc_net);
100304 if (!net->mib.proc_net_devsnmp6)
100305 goto proc_dev_snmp6_fail;
100306 return 0;
100307diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c
100308index 1f29996..46fe0c7 100644
100309--- a/net/ipv6/raw.c
100310+++ b/net/ipv6/raw.c
100311@@ -388,7 +388,7 @@ static inline int rawv6_rcv_skb(struct sock *sk, struct sk_buff *skb)
100312 {
100313 if ((raw6_sk(sk)->checksum || rcu_access_pointer(sk->sk_filter)) &&
100314 skb_checksum_complete(skb)) {
100315- atomic_inc(&sk->sk_drops);
100316+ atomic_inc_unchecked(&sk->sk_drops);
100317 kfree_skb(skb);
100318 return NET_RX_DROP;
100319 }
100320@@ -416,7 +416,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
100321 struct raw6_sock *rp = raw6_sk(sk);
100322
100323 if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb)) {
100324- atomic_inc(&sk->sk_drops);
100325+ atomic_inc_unchecked(&sk->sk_drops);
100326 kfree_skb(skb);
100327 return NET_RX_DROP;
100328 }
100329@@ -440,7 +440,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
100330
100331 if (inet->hdrincl) {
100332 if (skb_checksum_complete(skb)) {
100333- atomic_inc(&sk->sk_drops);
100334+ atomic_inc_unchecked(&sk->sk_drops);
100335 kfree_skb(skb);
100336 return NET_RX_DROP;
100337 }
100338@@ -469,6 +469,9 @@ static int rawv6_recvmsg(struct kiocb *iocb, struct sock *sk,
100339 if (flags & MSG_OOB)
100340 return -EOPNOTSUPP;
100341
100342+ if (addr_len)
100343+ *addr_len=sizeof(*sin6);
100344+
100345 if (flags & MSG_ERRQUEUE)
100346 return ipv6_recv_error(sk, msg, len, addr_len);
100347
100348@@ -507,7 +510,6 @@ static int rawv6_recvmsg(struct kiocb *iocb, struct sock *sk,
100349 sin6->sin6_flowinfo = 0;
100350 sin6->sin6_scope_id = ipv6_iface_scope_id(&sin6->sin6_addr,
100351 IP6CB(skb)->iif);
100352- *addr_len = sizeof(*sin6);
100353 }
100354
100355 sock_recv_ts_and_drops(msg, sk, skb);
100356@@ -610,7 +612,7 @@ out:
100357 return err;
100358 }
100359
100360-static int rawv6_send_hdrinc(struct sock *sk, void *from, int length,
100361+static int rawv6_send_hdrinc(struct sock *sk, void *from, unsigned int length,
100362 struct flowi6 *fl6, struct dst_entry **dstp,
100363 unsigned int flags)
100364 {
100365@@ -922,12 +924,15 @@ do_confirm:
100366 static int rawv6_seticmpfilter(struct sock *sk, int level, int optname,
100367 char __user *optval, int optlen)
100368 {
100369+ struct icmp6_filter filter;
100370+
100371 switch (optname) {
100372 case ICMPV6_FILTER:
100373 if (optlen > sizeof(struct icmp6_filter))
100374 optlen = sizeof(struct icmp6_filter);
100375- if (copy_from_user(&raw6_sk(sk)->filter, optval, optlen))
100376+ if (copy_from_user(&filter, optval, optlen))
100377 return -EFAULT;
100378+ raw6_sk(sk)->filter = filter;
100379 return 0;
100380 default:
100381 return -ENOPROTOOPT;
100382@@ -940,6 +945,7 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
100383 char __user *optval, int __user *optlen)
100384 {
100385 int len;
100386+ struct icmp6_filter filter;
100387
100388 switch (optname) {
100389 case ICMPV6_FILTER:
100390@@ -951,7 +957,8 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
100391 len = sizeof(struct icmp6_filter);
100392 if (put_user(len, optlen))
100393 return -EFAULT;
100394- if (copy_to_user(optval, &raw6_sk(sk)->filter, len))
100395+ filter = raw6_sk(sk)->filter;
100396+ if (len > sizeof filter || copy_to_user(optval, &filter, len))
100397 return -EFAULT;
100398 return 0;
100399 default:
100400diff --git a/net/ipv6/reassembly.c b/net/ipv6/reassembly.c
100401index cc85a9b..526a133 100644
100402--- a/net/ipv6/reassembly.c
100403+++ b/net/ipv6/reassembly.c
100404@@ -626,12 +626,11 @@ static struct ctl_table ip6_frags_ctl_table[] = {
100405
100406 static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
100407 {
100408- struct ctl_table *table;
100409+ ctl_table_no_const *table = NULL;
100410 struct ctl_table_header *hdr;
100411
100412- table = ip6_frags_ns_ctl_table;
100413 if (!net_eq(net, &init_net)) {
100414- table = kmemdup(table, sizeof(ip6_frags_ns_ctl_table), GFP_KERNEL);
100415+ table = kmemdup(ip6_frags_ns_ctl_table, sizeof(ip6_frags_ns_ctl_table), GFP_KERNEL);
100416 if (table == NULL)
100417 goto err_alloc;
100418
100419@@ -642,9 +641,10 @@ static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
100420 /* Don't export sysctls to unprivileged users */
100421 if (net->user_ns != &init_user_ns)
100422 table[0].procname = NULL;
100423- }
100424+ hdr = register_net_sysctl(net, "net/ipv6", table);
100425+ } else
100426+ hdr = register_net_sysctl(net, "net/ipv6", ip6_frags_ns_ctl_table);
100427
100428- hdr = register_net_sysctl(net, "net/ipv6", table);
100429 if (hdr == NULL)
100430 goto err_reg;
100431
100432@@ -652,8 +652,7 @@ static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
100433 return 0;
100434
100435 err_reg:
100436- if (!net_eq(net, &init_net))
100437- kfree(table);
100438+ kfree(table);
100439 err_alloc:
100440 return -ENOMEM;
100441 }
100442diff --git a/net/ipv6/route.c b/net/ipv6/route.c
100443index fba54a4..73e374e 100644
100444--- a/net/ipv6/route.c
100445+++ b/net/ipv6/route.c
100446@@ -2972,7 +2972,7 @@ struct ctl_table ipv6_route_table_template[] = {
100447
100448 struct ctl_table * __net_init ipv6_route_sysctl_init(struct net *net)
100449 {
100450- struct ctl_table *table;
100451+ ctl_table_no_const *table;
100452
100453 table = kmemdup(ipv6_route_table_template,
100454 sizeof(ipv6_route_table_template),
100455diff --git a/net/ipv6/sit.c b/net/ipv6/sit.c
100456index b4d74c8..b4f3fbe 100644
100457--- a/net/ipv6/sit.c
100458+++ b/net/ipv6/sit.c
100459@@ -74,7 +74,7 @@ static void ipip6_tunnel_setup(struct net_device *dev);
100460 static void ipip6_dev_free(struct net_device *dev);
100461 static bool check_6rd(struct ip_tunnel *tunnel, const struct in6_addr *v6dst,
100462 __be32 *v4dst);
100463-static struct rtnl_link_ops sit_link_ops __read_mostly;
100464+static struct rtnl_link_ops sit_link_ops;
100465
100466 static int sit_net_id __read_mostly;
100467 struct sit_net {
100468@@ -1683,7 +1683,7 @@ static void ipip6_dellink(struct net_device *dev, struct list_head *head)
100469 unregister_netdevice_queue(dev, head);
100470 }
100471
100472-static struct rtnl_link_ops sit_link_ops __read_mostly = {
100473+static struct rtnl_link_ops sit_link_ops = {
100474 .kind = "sit",
100475 .maxtype = IFLA_IPTUN_MAX,
100476 .policy = ipip6_policy,
100477diff --git a/net/ipv6/sysctl_net_ipv6.c b/net/ipv6/sysctl_net_ipv6.c
100478index 7f405a1..eabef92 100644
100479--- a/net/ipv6/sysctl_net_ipv6.c
100480+++ b/net/ipv6/sysctl_net_ipv6.c
100481@@ -54,7 +54,7 @@ static struct ctl_table ipv6_rotable[] = {
100482
100483 static int __net_init ipv6_sysctl_net_init(struct net *net)
100484 {
100485- struct ctl_table *ipv6_table;
100486+ ctl_table_no_const *ipv6_table;
100487 struct ctl_table *ipv6_route_table;
100488 struct ctl_table *ipv6_icmp_table;
100489 int err;
100490diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
100491index 889079b..a04512c 100644
100492--- a/net/ipv6/tcp_ipv6.c
100493+++ b/net/ipv6/tcp_ipv6.c
100494@@ -104,6 +104,10 @@ static void inet6_sk_rx_dst_set(struct sock *sk, const struct sk_buff *skb)
100495 inet6_sk(sk)->rx_dst_cookie = rt->rt6i_node->fn_sernum;
100496 }
100497
100498+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
100499+extern int grsec_enable_blackhole;
100500+#endif
100501+
100502 static void tcp_v6_hash(struct sock *sk)
100503 {
100504 if (sk->sk_state != TCP_CLOSE) {
100505@@ -1412,6 +1416,9 @@ static int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb)
100506 return 0;
100507
100508 reset:
100509+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
100510+ if (!grsec_enable_blackhole)
100511+#endif
100512 tcp_v6_send_reset(sk, skb);
100513 discard:
100514 if (opt_skb)
100515@@ -1496,12 +1503,20 @@ static int tcp_v6_rcv(struct sk_buff *skb)
100516 TCP_SKB_CB(skb)->sacked = 0;
100517
100518 sk = __inet6_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
100519- if (!sk)
100520+ if (!sk) {
100521+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
100522+ ret = 1;
100523+#endif
100524 goto no_tcp_socket;
100525+ }
100526
100527 process:
100528- if (sk->sk_state == TCP_TIME_WAIT)
100529+ if (sk->sk_state == TCP_TIME_WAIT) {
100530+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
100531+ ret = 2;
100532+#endif
100533 goto do_time_wait;
100534+ }
100535
100536 if (hdr->hop_limit < inet6_sk(sk)->min_hopcount) {
100537 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
100538@@ -1553,6 +1568,10 @@ csum_error:
100539 bad_packet:
100540 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
100541 } else {
100542+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
100543+ if (!grsec_enable_blackhole || (ret == 1 &&
100544+ (skb->dev->flags & IFF_LOOPBACK)))
100545+#endif
100546 tcp_v6_send_reset(NULL, skb);
100547 }
100548
100549diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
100550index 1e586d9..384a9c9 100644
100551--- a/net/ipv6/udp.c
100552+++ b/net/ipv6/udp.c
100553@@ -76,6 +76,10 @@ static unsigned int udp6_ehashfn(struct net *net,
100554 udp_ipv6_hash_secret + net_hash_mix(net));
100555 }
100556
100557+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
100558+extern int grsec_enable_blackhole;
100559+#endif
100560+
100561 int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
100562 {
100563 const struct in6_addr *sk2_rcv_saddr6 = inet6_rcv_saddr(sk2);
100564@@ -392,6 +396,9 @@ int udpv6_recvmsg(struct kiocb *iocb, struct sock *sk,
100565 int is_udp4;
100566 bool slow;
100567
100568+ if (addr_len)
100569+ *addr_len = sizeof(struct sockaddr_in6);
100570+
100571 if (flags & MSG_ERRQUEUE)
100572 return ipv6_recv_error(sk, msg, len, addr_len);
100573
100574@@ -435,7 +442,7 @@ try_again:
100575 if (unlikely(err)) {
100576 trace_kfree_skb(skb, udpv6_recvmsg);
100577 if (!peeked) {
100578- atomic_inc(&sk->sk_drops);
100579+ atomic_inc_unchecked(&sk->sk_drops);
100580 if (is_udp4)
100581 UDP_INC_STATS_USER(sock_net(sk),
100582 UDP_MIB_INERRORS,
100583@@ -475,7 +482,7 @@ try_again:
100584 ipv6_iface_scope_id(&sin6->sin6_addr,
100585 IP6CB(skb)->iif);
100586 }
100587- *addr_len = sizeof(*sin6);
100588+
100589 }
100590
100591 if (np->rxopt.all)
100592@@ -690,7 +697,7 @@ csum_error:
100593 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_CSUMERRORS, is_udplite);
100594 drop:
100595 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
100596- atomic_inc(&sk->sk_drops);
100597+ atomic_inc_unchecked(&sk->sk_drops);
100598 kfree_skb(skb);
100599 return -1;
100600 }
100601@@ -747,7 +754,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
100602 if (likely(skb1 == NULL))
100603 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
100604 if (!skb1) {
100605- atomic_inc(&sk->sk_drops);
100606+ atomic_inc_unchecked(&sk->sk_drops);
100607 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
100608 IS_UDPLITE(sk));
100609 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
100610@@ -886,6 +893,9 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
100611 goto csum_error;
100612
100613 UDP6_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
100614+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
100615+ if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
100616+#endif
100617 icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0);
100618
100619 kfree_skb(skb);
100620diff --git a/net/ipv6/xfrm6_policy.c b/net/ipv6/xfrm6_policy.c
100621index 5f8e128..865d38e 100644
100622--- a/net/ipv6/xfrm6_policy.c
100623+++ b/net/ipv6/xfrm6_policy.c
100624@@ -212,11 +212,11 @@ _decode_session6(struct sk_buff *skb, struct flowi *fl, int reverse)
100625 }
100626 }
100627
100628-static inline int xfrm6_garbage_collect(struct dst_ops *ops)
100629+static int xfrm6_garbage_collect(struct dst_ops *ops)
100630 {
100631 struct net *net = container_of(ops, struct net, xfrm.xfrm6_dst_ops);
100632
100633- xfrm6_policy_afinfo.garbage_collect(net);
100634+ xfrm_garbage_collect_deferred(net);
100635 return dst_entries_get_fast(ops) > ops->gc_thresh * 2;
100636 }
100637
100638@@ -329,19 +329,19 @@ static struct ctl_table xfrm6_policy_table[] = {
100639
100640 static int __net_init xfrm6_net_init(struct net *net)
100641 {
100642- struct ctl_table *table;
100643+ ctl_table_no_const *table = NULL;
100644 struct ctl_table_header *hdr;
100645
100646- table = xfrm6_policy_table;
100647 if (!net_eq(net, &init_net)) {
100648- table = kmemdup(table, sizeof(xfrm6_policy_table), GFP_KERNEL);
100649+ table = kmemdup(xfrm6_policy_table, sizeof(xfrm6_policy_table), GFP_KERNEL);
100650 if (!table)
100651 goto err_alloc;
100652
100653 table[0].data = &net->xfrm.xfrm6_dst_ops.gc_thresh;
100654- }
100655+ hdr = register_net_sysctl(net, "net/ipv6", table);
100656+ } else
100657+ hdr = register_net_sysctl(net, "net/ipv6", xfrm6_policy_table);
100658
100659- hdr = register_net_sysctl(net, "net/ipv6", table);
100660 if (!hdr)
100661 goto err_reg;
100662
100663@@ -349,8 +349,7 @@ static int __net_init xfrm6_net_init(struct net *net)
100664 return 0;
100665
100666 err_reg:
100667- if (!net_eq(net, &init_net))
100668- kfree(table);
100669+ kfree(table);
100670 err_alloc:
100671 return -ENOMEM;
100672 }
100673diff --git a/net/ipx/ipx_proc.c b/net/ipx/ipx_proc.c
100674index e15c16a..7cf07aa 100644
100675--- a/net/ipx/ipx_proc.c
100676+++ b/net/ipx/ipx_proc.c
100677@@ -289,7 +289,7 @@ int __init ipx_proc_init(void)
100678 struct proc_dir_entry *p;
100679 int rc = -ENOMEM;
100680
100681- ipx_proc_dir = proc_mkdir("ipx", init_net.proc_net);
100682+ ipx_proc_dir = proc_mkdir_restrict("ipx", init_net.proc_net);
100683
100684 if (!ipx_proc_dir)
100685 goto out;
100686diff --git a/net/irda/ircomm/ircomm_tty.c b/net/irda/ircomm/ircomm_tty.c
100687index 2ba8b97..6d33010 100644
100688--- a/net/irda/ircomm/ircomm_tty.c
100689+++ b/net/irda/ircomm/ircomm_tty.c
100690@@ -317,11 +317,11 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
100691 add_wait_queue(&port->open_wait, &wait);
100692
100693 IRDA_DEBUG(2, "%s(%d):block_til_ready before block on %s open_count=%d\n",
100694- __FILE__, __LINE__, tty->driver->name, port->count);
100695+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
100696
100697 spin_lock_irqsave(&port->lock, flags);
100698 if (!tty_hung_up_p(filp))
100699- port->count--;
100700+ atomic_dec(&port->count);
100701 port->blocked_open++;
100702 spin_unlock_irqrestore(&port->lock, flags);
100703
100704@@ -356,7 +356,7 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
100705 }
100706
100707 IRDA_DEBUG(1, "%s(%d):block_til_ready blocking on %s open_count=%d\n",
100708- __FILE__, __LINE__, tty->driver->name, port->count);
100709+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
100710
100711 schedule();
100712 }
100713@@ -366,12 +366,12 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
100714
100715 spin_lock_irqsave(&port->lock, flags);
100716 if (!tty_hung_up_p(filp))
100717- port->count++;
100718+ atomic_inc(&port->count);
100719 port->blocked_open--;
100720 spin_unlock_irqrestore(&port->lock, flags);
100721
100722 IRDA_DEBUG(1, "%s(%d):block_til_ready after blocking on %s open_count=%d\n",
100723- __FILE__, __LINE__, tty->driver->name, port->count);
100724+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
100725
100726 if (!retval)
100727 port->flags |= ASYNC_NORMAL_ACTIVE;
100728@@ -445,12 +445,12 @@ static int ircomm_tty_open(struct tty_struct *tty, struct file *filp)
100729
100730 /* ++ is not atomic, so this should be protected - Jean II */
100731 spin_lock_irqsave(&self->port.lock, flags);
100732- self->port.count++;
100733+ atomic_inc(&self->port.count);
100734 spin_unlock_irqrestore(&self->port.lock, flags);
100735 tty_port_tty_set(&self->port, tty);
100736
100737 IRDA_DEBUG(1, "%s(), %s%d, count = %d\n", __func__ , tty->driver->name,
100738- self->line, self->port.count);
100739+ self->line, atomic_read(&self->port.count));
100740
100741 /* Not really used by us, but lets do it anyway */
100742 self->port.low_latency = (self->port.flags & ASYNC_LOW_LATENCY) ? 1 : 0;
100743@@ -987,7 +987,7 @@ static void ircomm_tty_hangup(struct tty_struct *tty)
100744 tty_kref_put(port->tty);
100745 }
100746 port->tty = NULL;
100747- port->count = 0;
100748+ atomic_set(&port->count, 0);
100749 spin_unlock_irqrestore(&port->lock, flags);
100750
100751 wake_up_interruptible(&port->open_wait);
100752@@ -1344,7 +1344,7 @@ static void ircomm_tty_line_info(struct ircomm_tty_cb *self, struct seq_file *m)
100753 seq_putc(m, '\n');
100754
100755 seq_printf(m, "Role: %s\n", self->client ? "client" : "server");
100756- seq_printf(m, "Open count: %d\n", self->port.count);
100757+ seq_printf(m, "Open count: %d\n", atomic_read(&self->port.count));
100758 seq_printf(m, "Max data size: %d\n", self->max_data_size);
100759 seq_printf(m, "Max header size: %d\n", self->max_header_size);
100760
100761diff --git a/net/irda/irproc.c b/net/irda/irproc.c
100762index b9ac598..f88cc56 100644
100763--- a/net/irda/irproc.c
100764+++ b/net/irda/irproc.c
100765@@ -66,7 +66,7 @@ void __init irda_proc_register(void)
100766 {
100767 int i;
100768
100769- proc_irda = proc_mkdir("irda", init_net.proc_net);
100770+ proc_irda = proc_mkdir_restrict("irda", init_net.proc_net);
100771 if (proc_irda == NULL)
100772 return;
100773
100774diff --git a/net/iucv/af_iucv.c b/net/iucv/af_iucv.c
100775index c4b7218..3e83259 100644
100776--- a/net/iucv/af_iucv.c
100777+++ b/net/iucv/af_iucv.c
100778@@ -773,10 +773,10 @@ static int iucv_sock_autobind(struct sock *sk)
100779
100780 write_lock_bh(&iucv_sk_list.lock);
100781
100782- sprintf(name, "%08x", atomic_inc_return(&iucv_sk_list.autobind_name));
100783+ sprintf(name, "%08x", atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
100784 while (__iucv_get_sock_by_name(name)) {
100785 sprintf(name, "%08x",
100786- atomic_inc_return(&iucv_sk_list.autobind_name));
100787+ atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
100788 }
100789
100790 write_unlock_bh(&iucv_sk_list.lock);
100791diff --git a/net/iucv/iucv.c b/net/iucv/iucv.c
100792index cd5b8ec..f205e6b 100644
100793--- a/net/iucv/iucv.c
100794+++ b/net/iucv/iucv.c
100795@@ -690,7 +690,7 @@ static int iucv_cpu_notify(struct notifier_block *self,
100796 return NOTIFY_OK;
100797 }
100798
100799-static struct notifier_block __refdata iucv_cpu_notifier = {
100800+static struct notifier_block iucv_cpu_notifier = {
100801 .notifier_call = iucv_cpu_notify,
100802 };
100803
100804diff --git a/net/key/af_key.c b/net/key/af_key.c
100805index 7932697..a13d158 100644
100806--- a/net/key/af_key.c
100807+++ b/net/key/af_key.c
100808@@ -3052,10 +3052,10 @@ static int pfkey_send_policy_notify(struct xfrm_policy *xp, int dir, const struc
100809 static u32 get_acqseq(void)
100810 {
100811 u32 res;
100812- static atomic_t acqseq;
100813+ static atomic_unchecked_t acqseq;
100814
100815 do {
100816- res = atomic_inc_return(&acqseq);
100817+ res = atomic_inc_return_unchecked(&acqseq);
100818 } while (!res);
100819 return res;
100820 }
100821diff --git a/net/l2tp/l2tp_ip.c b/net/l2tp/l2tp_ip.c
100822index 0b44d85..1a7f88b 100644
100823--- a/net/l2tp/l2tp_ip.c
100824+++ b/net/l2tp/l2tp_ip.c
100825@@ -518,6 +518,9 @@ static int l2tp_ip_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *m
100826 if (flags & MSG_OOB)
100827 goto out;
100828
100829+ if (addr_len)
100830+ *addr_len = sizeof(*sin);
100831+
100832 skb = skb_recv_datagram(sk, flags, noblock, &err);
100833 if (!skb)
100834 goto out;
100835@@ -540,7 +543,6 @@ static int l2tp_ip_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *m
100836 sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
100837 sin->sin_port = 0;
100838 memset(&sin->sin_zero, 0, sizeof(sin->sin_zero));
100839- *addr_len = sizeof(*sin);
100840 }
100841 if (inet->cmsg_flags)
100842 ip_cmsg_recv(msg, skb);
100843diff --git a/net/llc/llc_proc.c b/net/llc/llc_proc.c
100844index 1a3c7e0..80f8b0c 100644
100845--- a/net/llc/llc_proc.c
100846+++ b/net/llc/llc_proc.c
100847@@ -247,7 +247,7 @@ int __init llc_proc_init(void)
100848 int rc = -ENOMEM;
100849 struct proc_dir_entry *p;
100850
100851- llc_proc_dir = proc_mkdir("llc", init_net.proc_net);
100852+ llc_proc_dir = proc_mkdir_restrict("llc", init_net.proc_net);
100853 if (!llc_proc_dir)
100854 goto out;
100855
100856diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c
100857index 453e974..b3a43a5 100644
100858--- a/net/mac80211/cfg.c
100859+++ b/net/mac80211/cfg.c
100860@@ -839,7 +839,7 @@ static int ieee80211_set_monitor_channel(struct wiphy *wiphy,
100861 ret = ieee80211_vif_use_channel(sdata, chandef,
100862 IEEE80211_CHANCTX_EXCLUSIVE);
100863 }
100864- } else if (local->open_count == local->monitors) {
100865+ } else if (local_read(&local->open_count) == local->monitors) {
100866 local->_oper_chandef = *chandef;
100867 ieee80211_hw_config(local, 0);
100868 }
100869@@ -3356,7 +3356,7 @@ static void ieee80211_mgmt_frame_register(struct wiphy *wiphy,
100870 else
100871 local->probe_req_reg--;
100872
100873- if (!local->open_count)
100874+ if (!local_read(&local->open_count))
100875 break;
100876
100877 ieee80211_queue_work(&local->hw, &local->reconfig_filter);
100878@@ -3819,8 +3819,8 @@ static int ieee80211_cfg_get_channel(struct wiphy *wiphy,
100879 if (chanctx_conf) {
100880 *chandef = chanctx_conf->def;
100881 ret = 0;
100882- } else if (local->open_count > 0 &&
100883- local->open_count == local->monitors &&
100884+ } else if (local_read(&local->open_count) > 0 &&
100885+ local_read(&local->open_count) == local->monitors &&
100886 sdata->vif.type == NL80211_IFTYPE_MONITOR) {
100887 if (local->use_chanctx)
100888 *chandef = local->monitor_chandef;
100889diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
100890index 6bd4984..d8805c5 100644
100891--- a/net/mac80211/ieee80211_i.h
100892+++ b/net/mac80211/ieee80211_i.h
100893@@ -28,6 +28,7 @@
100894 #include <net/ieee80211_radiotap.h>
100895 #include <net/cfg80211.h>
100896 #include <net/mac80211.h>
100897+#include <asm/local.h>
100898 #include "key.h"
100899 #include "sta_info.h"
100900 #include "debug.h"
100901@@ -994,7 +995,7 @@ struct ieee80211_local {
100902 /* also used to protect ampdu_ac_queue and amdpu_ac_stop_refcnt */
100903 spinlock_t queue_stop_reason_lock;
100904
100905- int open_count;
100906+ local_t open_count;
100907 int monitors, cooked_mntrs;
100908 /* number of interfaces with corresponding FIF_ flags */
100909 int fif_fcsfail, fif_plcpfail, fif_control, fif_other_bss, fif_pspoll,
100910diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
100911index ce1c443..6cd39e1 100644
100912--- a/net/mac80211/iface.c
100913+++ b/net/mac80211/iface.c
100914@@ -529,7 +529,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
100915 break;
100916 }
100917
100918- if (local->open_count == 0) {
100919+ if (local_read(&local->open_count) == 0) {
100920 res = drv_start(local);
100921 if (res)
100922 goto err_del_bss;
100923@@ -576,7 +576,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
100924 res = drv_add_interface(local, sdata);
100925 if (res)
100926 goto err_stop;
100927- } else if (local->monitors == 0 && local->open_count == 0) {
100928+ } else if (local->monitors == 0 && local_read(&local->open_count) == 0) {
100929 res = ieee80211_add_virtual_monitor(local);
100930 if (res)
100931 goto err_stop;
100932@@ -685,7 +685,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
100933 atomic_inc(&local->iff_promiscs);
100934
100935 if (coming_up)
100936- local->open_count++;
100937+ local_inc(&local->open_count);
100938
100939 if (hw_reconf_flags)
100940 ieee80211_hw_config(local, hw_reconf_flags);
100941@@ -723,7 +723,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
100942 err_del_interface:
100943 drv_remove_interface(local, sdata);
100944 err_stop:
100945- if (!local->open_count)
100946+ if (!local_read(&local->open_count))
100947 drv_stop(local);
100948 err_del_bss:
100949 sdata->bss = NULL;
100950@@ -874,7 +874,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
100951 }
100952
100953 if (going_down)
100954- local->open_count--;
100955+ local_dec(&local->open_count);
100956
100957 switch (sdata->vif.type) {
100958 case NL80211_IFTYPE_AP_VLAN:
100959@@ -933,7 +933,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
100960 }
100961 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
100962
100963- if (local->open_count == 0)
100964+ if (local_read(&local->open_count) == 0)
100965 ieee80211_clear_tx_pending(local);
100966
100967 /*
100968@@ -973,7 +973,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
100969
100970 ieee80211_recalc_ps(local, -1);
100971
100972- if (local->open_count == 0) {
100973+ if (local_read(&local->open_count) == 0) {
100974 ieee80211_stop_device(local);
100975
100976 /* no reconfiguring after stop! */
100977@@ -984,7 +984,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
100978 ieee80211_configure_filter(local);
100979 ieee80211_hw_config(local, hw_reconf_flags);
100980
100981- if (local->monitors == local->open_count)
100982+ if (local->monitors == local_read(&local->open_count))
100983 ieee80211_add_virtual_monitor(local);
100984 }
100985
100986diff --git a/net/mac80211/main.c b/net/mac80211/main.c
100987index c7a7a86..a74f57b 100644
100988--- a/net/mac80211/main.c
100989+++ b/net/mac80211/main.c
100990@@ -174,7 +174,7 @@ int ieee80211_hw_config(struct ieee80211_local *local, u32 changed)
100991 changed &= ~(IEEE80211_CONF_CHANGE_CHANNEL |
100992 IEEE80211_CONF_CHANGE_POWER);
100993
100994- if (changed && local->open_count) {
100995+ if (changed && local_read(&local->open_count)) {
100996 ret = drv_config(local, changed);
100997 /*
100998 * Goal:
100999diff --git a/net/mac80211/pm.c b/net/mac80211/pm.c
101000index d478b88..8c8d157 100644
101001--- a/net/mac80211/pm.c
101002+++ b/net/mac80211/pm.c
101003@@ -12,7 +12,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
101004 struct ieee80211_sub_if_data *sdata;
101005 struct sta_info *sta;
101006
101007- if (!local->open_count)
101008+ if (!local_read(&local->open_count))
101009 goto suspend;
101010
101011 ieee80211_scan_cancel(local);
101012@@ -58,7 +58,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
101013 cancel_work_sync(&local->dynamic_ps_enable_work);
101014 del_timer_sync(&local->dynamic_ps_timer);
101015
101016- local->wowlan = wowlan && local->open_count;
101017+ local->wowlan = wowlan && local_read(&local->open_count);
101018 if (local->wowlan) {
101019 int err = drv_suspend(local, wowlan);
101020 if (err < 0) {
101021@@ -123,7 +123,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
101022 WARN_ON(!list_empty(&local->chanctx_list));
101023
101024 /* stop hardware - this must stop RX */
101025- if (local->open_count)
101026+ if (local_read(&local->open_count))
101027 ieee80211_stop_device(local);
101028
101029 suspend:
101030diff --git a/net/mac80211/rate.c b/net/mac80211/rate.c
101031index 22b223f..ab70070 100644
101032--- a/net/mac80211/rate.c
101033+++ b/net/mac80211/rate.c
101034@@ -734,7 +734,7 @@ int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
101035
101036 ASSERT_RTNL();
101037
101038- if (local->open_count)
101039+ if (local_read(&local->open_count))
101040 return -EBUSY;
101041
101042 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
101043diff --git a/net/mac80211/rc80211_pid_debugfs.c b/net/mac80211/rc80211_pid_debugfs.c
101044index 6ff1346..936ca9a 100644
101045--- a/net/mac80211/rc80211_pid_debugfs.c
101046+++ b/net/mac80211/rc80211_pid_debugfs.c
101047@@ -193,7 +193,7 @@ static ssize_t rate_control_pid_events_read(struct file *file, char __user *buf,
101048
101049 spin_unlock_irqrestore(&events->lock, status);
101050
101051- if (copy_to_user(buf, pb, p))
101052+ if (p > sizeof(pb) || copy_to_user(buf, pb, p))
101053 return -EFAULT;
101054
101055 return p;
101056diff --git a/net/mac80211/util.c b/net/mac80211/util.c
101057index b8700d4..89086d5 100644
101058--- a/net/mac80211/util.c
101059+++ b/net/mac80211/util.c
101060@@ -1483,7 +1483,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
101061 }
101062 #endif
101063 /* everything else happens only if HW was up & running */
101064- if (!local->open_count)
101065+ if (!local_read(&local->open_count))
101066 goto wake_up;
101067
101068 /*
101069@@ -1708,7 +1708,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
101070 local->in_reconfig = false;
101071 barrier();
101072
101073- if (local->monitors == local->open_count && local->monitors > 0)
101074+ if (local->monitors == local_read(&local->open_count) && local->monitors > 0)
101075 ieee80211_add_virtual_monitor(local);
101076
101077 /*
101078diff --git a/net/netfilter/Kconfig b/net/netfilter/Kconfig
101079index e9410d1..77b6378 100644
101080--- a/net/netfilter/Kconfig
101081+++ b/net/netfilter/Kconfig
101082@@ -1081,6 +1081,16 @@ config NETFILTER_XT_MATCH_ESP
101083
101084 To compile it as a module, choose M here. If unsure, say N.
101085
101086+config NETFILTER_XT_MATCH_GRADM
101087+ tristate '"gradm" match support'
101088+ depends on NETFILTER_XTABLES && NETFILTER_ADVANCED
101089+ depends on GRKERNSEC && !GRKERNSEC_NO_RBAC
101090+ ---help---
101091+ The gradm match allows to match on grsecurity RBAC being enabled.
101092+ It is useful when iptables rules are applied early on bootup to
101093+ prevent connections to the machine (except from a trusted host)
101094+ while the RBAC system is disabled.
101095+
101096 config NETFILTER_XT_MATCH_HASHLIMIT
101097 tristate '"hashlimit" match support'
101098 depends on (IP6_NF_IPTABLES || IP6_NF_IPTABLES=n)
101099diff --git a/net/netfilter/Makefile b/net/netfilter/Makefile
101100index bffdad7..f9317d1 100644
101101--- a/net/netfilter/Makefile
101102+++ b/net/netfilter/Makefile
101103@@ -133,6 +133,7 @@ obj-$(CONFIG_NETFILTER_XT_MATCH_DEVGROUP) += xt_devgroup.o
101104 obj-$(CONFIG_NETFILTER_XT_MATCH_DSCP) += xt_dscp.o
101105 obj-$(CONFIG_NETFILTER_XT_MATCH_ECN) += xt_ecn.o
101106 obj-$(CONFIG_NETFILTER_XT_MATCH_ESP) += xt_esp.o
101107+obj-$(CONFIG_NETFILTER_XT_MATCH_GRADM) += xt_gradm.o
101108 obj-$(CONFIG_NETFILTER_XT_MATCH_HASHLIMIT) += xt_hashlimit.o
101109 obj-$(CONFIG_NETFILTER_XT_MATCH_HELPER) += xt_helper.o
101110 obj-$(CONFIG_NETFILTER_XT_MATCH_HL) += xt_hl.o
101111diff --git a/net/netfilter/ipset/ip_set_core.c b/net/netfilter/ipset/ip_set_core.c
101112index de770ec..3fc49d2 100644
101113--- a/net/netfilter/ipset/ip_set_core.c
101114+++ b/net/netfilter/ipset/ip_set_core.c
101115@@ -1922,7 +1922,7 @@ done:
101116 return ret;
101117 }
101118
101119-static struct nf_sockopt_ops so_set __read_mostly = {
101120+static struct nf_sockopt_ops so_set = {
101121 .pf = PF_INET,
101122 .get_optmin = SO_IP_SET,
101123 .get_optmax = SO_IP_SET + 1,
101124diff --git a/net/netfilter/ipvs/ip_vs_conn.c b/net/netfilter/ipvs/ip_vs_conn.c
101125index a8eb0a8..86f2de4 100644
101126--- a/net/netfilter/ipvs/ip_vs_conn.c
101127+++ b/net/netfilter/ipvs/ip_vs_conn.c
101128@@ -556,7 +556,7 @@ ip_vs_bind_dest(struct ip_vs_conn *cp, struct ip_vs_dest *dest)
101129 /* Increase the refcnt counter of the dest */
101130 ip_vs_dest_hold(dest);
101131
101132- conn_flags = atomic_read(&dest->conn_flags);
101133+ conn_flags = atomic_read_unchecked(&dest->conn_flags);
101134 if (cp->protocol != IPPROTO_UDP)
101135 conn_flags &= ~IP_VS_CONN_F_ONE_PACKET;
101136 flags = cp->flags;
101137@@ -900,7 +900,7 @@ ip_vs_conn_new(const struct ip_vs_conn_param *p,
101138
101139 cp->control = NULL;
101140 atomic_set(&cp->n_control, 0);
101141- atomic_set(&cp->in_pkts, 0);
101142+ atomic_set_unchecked(&cp->in_pkts, 0);
101143
101144 cp->packet_xmit = NULL;
101145 cp->app = NULL;
101146@@ -1188,7 +1188,7 @@ static inline int todrop_entry(struct ip_vs_conn *cp)
101147
101148 /* Don't drop the entry if its number of incoming packets is not
101149 located in [0, 8] */
101150- i = atomic_read(&cp->in_pkts);
101151+ i = atomic_read_unchecked(&cp->in_pkts);
101152 if (i > 8 || i < 0) return 0;
101153
101154 if (!todrop_rate[i]) return 0;
101155diff --git a/net/netfilter/ipvs/ip_vs_core.c b/net/netfilter/ipvs/ip_vs_core.c
101156index 4f26ee4..6a9d7c3 100644
101157--- a/net/netfilter/ipvs/ip_vs_core.c
101158+++ b/net/netfilter/ipvs/ip_vs_core.c
101159@@ -567,7 +567,7 @@ int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
101160 ret = cp->packet_xmit(skb, cp, pd->pp, iph);
101161 /* do not touch skb anymore */
101162
101163- atomic_inc(&cp->in_pkts);
101164+ atomic_inc_unchecked(&cp->in_pkts);
101165 ip_vs_conn_put(cp);
101166 return ret;
101167 }
101168@@ -1706,7 +1706,7 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af)
101169 if (cp->flags & IP_VS_CONN_F_ONE_PACKET)
101170 pkts = sysctl_sync_threshold(ipvs);
101171 else
101172- pkts = atomic_add_return(1, &cp->in_pkts);
101173+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
101174
101175 if (ipvs->sync_state & IP_VS_STATE_MASTER)
101176 ip_vs_sync_conn(net, cp, pkts);
101177diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c
101178index 35be035..50f8834 100644
101179--- a/net/netfilter/ipvs/ip_vs_ctl.c
101180+++ b/net/netfilter/ipvs/ip_vs_ctl.c
101181@@ -794,7 +794,7 @@ __ip_vs_update_dest(struct ip_vs_service *svc, struct ip_vs_dest *dest,
101182 */
101183 ip_vs_rs_hash(ipvs, dest);
101184 }
101185- atomic_set(&dest->conn_flags, conn_flags);
101186+ atomic_set_unchecked(&dest->conn_flags, conn_flags);
101187
101188 /* bind the service */
101189 old_svc = rcu_dereference_protected(dest->svc, 1);
101190@@ -1654,7 +1654,7 @@ proc_do_sync_ports(struct ctl_table *table, int write,
101191 * align with netns init in ip_vs_control_net_init()
101192 */
101193
101194-static struct ctl_table vs_vars[] = {
101195+static ctl_table_no_const vs_vars[] __read_only = {
101196 {
101197 .procname = "amemthresh",
101198 .maxlen = sizeof(int),
101199@@ -2075,7 +2075,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
101200 " %-7s %-6d %-10d %-10d\n",
101201 &dest->addr.in6,
101202 ntohs(dest->port),
101203- ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
101204+ ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
101205 atomic_read(&dest->weight),
101206 atomic_read(&dest->activeconns),
101207 atomic_read(&dest->inactconns));
101208@@ -2086,7 +2086,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
101209 "%-7s %-6d %-10d %-10d\n",
101210 ntohl(dest->addr.ip),
101211 ntohs(dest->port),
101212- ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
101213+ ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
101214 atomic_read(&dest->weight),
101215 atomic_read(&dest->activeconns),
101216 atomic_read(&dest->inactconns));
101217@@ -2564,7 +2564,7 @@ __ip_vs_get_dest_entries(struct net *net, const struct ip_vs_get_dests *get,
101218
101219 entry.addr = dest->addr.ip;
101220 entry.port = dest->port;
101221- entry.conn_flags = atomic_read(&dest->conn_flags);
101222+ entry.conn_flags = atomic_read_unchecked(&dest->conn_flags);
101223 entry.weight = atomic_read(&dest->weight);
101224 entry.u_threshold = dest->u_threshold;
101225 entry.l_threshold = dest->l_threshold;
101226@@ -3107,7 +3107,7 @@ static int ip_vs_genl_fill_dest(struct sk_buff *skb, struct ip_vs_dest *dest)
101227 if (nla_put(skb, IPVS_DEST_ATTR_ADDR, sizeof(dest->addr), &dest->addr) ||
101228 nla_put_be16(skb, IPVS_DEST_ATTR_PORT, dest->port) ||
101229 nla_put_u32(skb, IPVS_DEST_ATTR_FWD_METHOD,
101230- (atomic_read(&dest->conn_flags) &
101231+ (atomic_read_unchecked(&dest->conn_flags) &
101232 IP_VS_CONN_F_FWD_MASK)) ||
101233 nla_put_u32(skb, IPVS_DEST_ATTR_WEIGHT,
101234 atomic_read(&dest->weight)) ||
101235@@ -3580,7 +3580,7 @@ out:
101236 }
101237
101238
101239-static const struct genl_ops ip_vs_genl_ops[] __read_mostly = {
101240+static const struct genl_ops ip_vs_genl_ops[] = {
101241 {
101242 .cmd = IPVS_CMD_NEW_SERVICE,
101243 .flags = GENL_ADMIN_PERM,
101244@@ -3697,7 +3697,7 @@ static int __net_init ip_vs_control_net_init_sysctl(struct net *net)
101245 {
101246 int idx;
101247 struct netns_ipvs *ipvs = net_ipvs(net);
101248- struct ctl_table *tbl;
101249+ ctl_table_no_const *tbl;
101250
101251 atomic_set(&ipvs->dropentry, 0);
101252 spin_lock_init(&ipvs->dropentry_lock);
101253diff --git a/net/netfilter/ipvs/ip_vs_lblc.c b/net/netfilter/ipvs/ip_vs_lblc.c
101254index ca056a3..9cf01ef 100644
101255--- a/net/netfilter/ipvs/ip_vs_lblc.c
101256+++ b/net/netfilter/ipvs/ip_vs_lblc.c
101257@@ -118,7 +118,7 @@ struct ip_vs_lblc_table {
101258 * IPVS LBLC sysctl table
101259 */
101260 #ifdef CONFIG_SYSCTL
101261-static struct ctl_table vs_vars_table[] = {
101262+static ctl_table_no_const vs_vars_table[] __read_only = {
101263 {
101264 .procname = "lblc_expiration",
101265 .data = NULL,
101266diff --git a/net/netfilter/ipvs/ip_vs_lblcr.c b/net/netfilter/ipvs/ip_vs_lblcr.c
101267index 3f21a2f..a112e85 100644
101268--- a/net/netfilter/ipvs/ip_vs_lblcr.c
101269+++ b/net/netfilter/ipvs/ip_vs_lblcr.c
101270@@ -289,7 +289,7 @@ struct ip_vs_lblcr_table {
101271 * IPVS LBLCR sysctl table
101272 */
101273
101274-static struct ctl_table vs_vars_table[] = {
101275+static ctl_table_no_const vs_vars_table[] __read_only = {
101276 {
101277 .procname = "lblcr_expiration",
101278 .data = NULL,
101279diff --git a/net/netfilter/ipvs/ip_vs_sync.c b/net/netfilter/ipvs/ip_vs_sync.c
101280index db80126..ef7110e 100644
101281--- a/net/netfilter/ipvs/ip_vs_sync.c
101282+++ b/net/netfilter/ipvs/ip_vs_sync.c
101283@@ -609,7 +609,7 @@ static void ip_vs_sync_conn_v0(struct net *net, struct ip_vs_conn *cp,
101284 cp = cp->control;
101285 if (cp) {
101286 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
101287- pkts = atomic_add_return(1, &cp->in_pkts);
101288+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
101289 else
101290 pkts = sysctl_sync_threshold(ipvs);
101291 ip_vs_sync_conn(net, cp->control, pkts);
101292@@ -771,7 +771,7 @@ control:
101293 if (!cp)
101294 return;
101295 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
101296- pkts = atomic_add_return(1, &cp->in_pkts);
101297+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
101298 else
101299 pkts = sysctl_sync_threshold(ipvs);
101300 goto sloop;
101301@@ -895,7 +895,7 @@ static void ip_vs_proc_conn(struct net *net, struct ip_vs_conn_param *param,
101302
101303 if (opt)
101304 memcpy(&cp->in_seq, opt, sizeof(*opt));
101305- atomic_set(&cp->in_pkts, sysctl_sync_threshold(ipvs));
101306+ atomic_set_unchecked(&cp->in_pkts, sysctl_sync_threshold(ipvs));
101307 cp->state = state;
101308 cp->old_state = cp->state;
101309 /*
101310diff --git a/net/netfilter/ipvs/ip_vs_xmit.c b/net/netfilter/ipvs/ip_vs_xmit.c
101311index c47444e..b0961c6 100644
101312--- a/net/netfilter/ipvs/ip_vs_xmit.c
101313+++ b/net/netfilter/ipvs/ip_vs_xmit.c
101314@@ -1102,7 +1102,7 @@ ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
101315 else
101316 rc = NF_ACCEPT;
101317 /* do not touch skb anymore */
101318- atomic_inc(&cp->in_pkts);
101319+ atomic_inc_unchecked(&cp->in_pkts);
101320 goto out;
101321 }
101322
101323@@ -1194,7 +1194,7 @@ ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
101324 else
101325 rc = NF_ACCEPT;
101326 /* do not touch skb anymore */
101327- atomic_inc(&cp->in_pkts);
101328+ atomic_inc_unchecked(&cp->in_pkts);
101329 goto out;
101330 }
101331
101332diff --git a/net/netfilter/nf_conntrack_acct.c b/net/netfilter/nf_conntrack_acct.c
101333index a4b5e2a..13b1de3 100644
101334--- a/net/netfilter/nf_conntrack_acct.c
101335+++ b/net/netfilter/nf_conntrack_acct.c
101336@@ -62,7 +62,7 @@ static struct nf_ct_ext_type acct_extend __read_mostly = {
101337 #ifdef CONFIG_SYSCTL
101338 static int nf_conntrack_acct_init_sysctl(struct net *net)
101339 {
101340- struct ctl_table *table;
101341+ ctl_table_no_const *table;
101342
101343 table = kmemdup(acct_sysctl_table, sizeof(acct_sysctl_table),
101344 GFP_KERNEL);
101345diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c
101346index 356bef5..99932cb 100644
101347--- a/net/netfilter/nf_conntrack_core.c
101348+++ b/net/netfilter/nf_conntrack_core.c
101349@@ -1627,6 +1627,10 @@ void nf_conntrack_init_end(void)
101350 #define DYING_NULLS_VAL ((1<<30)+1)
101351 #define TEMPLATE_NULLS_VAL ((1<<30)+2)
101352
101353+#ifdef CONFIG_GRKERNSEC_HIDESYM
101354+static atomic_unchecked_t conntrack_cache_id = ATOMIC_INIT(0);
101355+#endif
101356+
101357 int nf_conntrack_init_net(struct net *net)
101358 {
101359 int ret;
101360@@ -1641,7 +1645,11 @@ int nf_conntrack_init_net(struct net *net)
101361 goto err_stat;
101362 }
101363
101364+#ifdef CONFIG_GRKERNSEC_HIDESYM
101365+ net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%08lx", atomic_inc_return_unchecked(&conntrack_cache_id));
101366+#else
101367 net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%p", net);
101368+#endif
101369 if (!net->ct.slabname) {
101370 ret = -ENOMEM;
101371 goto err_slabname;
101372diff --git a/net/netfilter/nf_conntrack_ecache.c b/net/netfilter/nf_conntrack_ecache.c
101373index 1df1761..ce8b88a 100644
101374--- a/net/netfilter/nf_conntrack_ecache.c
101375+++ b/net/netfilter/nf_conntrack_ecache.c
101376@@ -188,7 +188,7 @@ static struct nf_ct_ext_type event_extend __read_mostly = {
101377 #ifdef CONFIG_SYSCTL
101378 static int nf_conntrack_event_init_sysctl(struct net *net)
101379 {
101380- struct ctl_table *table;
101381+ ctl_table_no_const *table;
101382
101383 table = kmemdup(event_sysctl_table, sizeof(event_sysctl_table),
101384 GFP_KERNEL);
101385diff --git a/net/netfilter/nf_conntrack_helper.c b/net/netfilter/nf_conntrack_helper.c
101386index 974a2a4..52cc6ff 100644
101387--- a/net/netfilter/nf_conntrack_helper.c
101388+++ b/net/netfilter/nf_conntrack_helper.c
101389@@ -57,7 +57,7 @@ static struct ctl_table helper_sysctl_table[] = {
101390
101391 static int nf_conntrack_helper_init_sysctl(struct net *net)
101392 {
101393- struct ctl_table *table;
101394+ ctl_table_no_const *table;
101395
101396 table = kmemdup(helper_sysctl_table, sizeof(helper_sysctl_table),
101397 GFP_KERNEL);
101398diff --git a/net/netfilter/nf_conntrack_proto.c b/net/netfilter/nf_conntrack_proto.c
101399index b65d586..beec902 100644
101400--- a/net/netfilter/nf_conntrack_proto.c
101401+++ b/net/netfilter/nf_conntrack_proto.c
101402@@ -52,7 +52,7 @@ nf_ct_register_sysctl(struct net *net,
101403
101404 static void
101405 nf_ct_unregister_sysctl(struct ctl_table_header **header,
101406- struct ctl_table **table,
101407+ ctl_table_no_const **table,
101408 unsigned int users)
101409 {
101410 if (users > 0)
101411diff --git a/net/netfilter/nf_conntrack_standalone.c b/net/netfilter/nf_conntrack_standalone.c
101412index f641751..d3c5b51 100644
101413--- a/net/netfilter/nf_conntrack_standalone.c
101414+++ b/net/netfilter/nf_conntrack_standalone.c
101415@@ -471,7 +471,7 @@ static struct ctl_table nf_ct_netfilter_table[] = {
101416
101417 static int nf_conntrack_standalone_init_sysctl(struct net *net)
101418 {
101419- struct ctl_table *table;
101420+ ctl_table_no_const *table;
101421
101422 table = kmemdup(nf_ct_sysctl_table, sizeof(nf_ct_sysctl_table),
101423 GFP_KERNEL);
101424diff --git a/net/netfilter/nf_conntrack_timestamp.c b/net/netfilter/nf_conntrack_timestamp.c
101425index 7a394df..bd91a8a 100644
101426--- a/net/netfilter/nf_conntrack_timestamp.c
101427+++ b/net/netfilter/nf_conntrack_timestamp.c
101428@@ -42,7 +42,7 @@ static struct nf_ct_ext_type tstamp_extend __read_mostly = {
101429 #ifdef CONFIG_SYSCTL
101430 static int nf_conntrack_tstamp_init_sysctl(struct net *net)
101431 {
101432- struct ctl_table *table;
101433+ ctl_table_no_const *table;
101434
101435 table = kmemdup(tstamp_sysctl_table, sizeof(tstamp_sysctl_table),
101436 GFP_KERNEL);
101437diff --git a/net/netfilter/nf_log.c b/net/netfilter/nf_log.c
101438index 85296d4..8becdec 100644
101439--- a/net/netfilter/nf_log.c
101440+++ b/net/netfilter/nf_log.c
101441@@ -243,7 +243,7 @@ static const struct file_operations nflog_file_ops = {
101442
101443 #ifdef CONFIG_SYSCTL
101444 static char nf_log_sysctl_fnames[NFPROTO_NUMPROTO-NFPROTO_UNSPEC][3];
101445-static struct ctl_table nf_log_sysctl_table[NFPROTO_NUMPROTO+1];
101446+static ctl_table_no_const nf_log_sysctl_table[NFPROTO_NUMPROTO+1] __read_only;
101447
101448 static int nf_log_proc_dostring(struct ctl_table *table, int write,
101449 void __user *buffer, size_t *lenp, loff_t *ppos)
101450@@ -274,14 +274,16 @@ static int nf_log_proc_dostring(struct ctl_table *table, int write,
101451 rcu_assign_pointer(net->nf.nf_loggers[tindex], logger);
101452 mutex_unlock(&nf_log_mutex);
101453 } else {
101454+ ctl_table_no_const nf_log_table = *table;
101455+
101456 mutex_lock(&nf_log_mutex);
101457 logger = rcu_dereference_protected(net->nf.nf_loggers[tindex],
101458 lockdep_is_held(&nf_log_mutex));
101459 if (!logger)
101460- table->data = "NONE";
101461+ nf_log_table.data = "NONE";
101462 else
101463- table->data = logger->name;
101464- r = proc_dostring(table, write, buffer, lenp, ppos);
101465+ nf_log_table.data = logger->name;
101466+ r = proc_dostring(&nf_log_table, write, buffer, lenp, ppos);
101467 mutex_unlock(&nf_log_mutex);
101468 }
101469
101470diff --git a/net/netfilter/nf_sockopt.c b/net/netfilter/nf_sockopt.c
101471index f042ae5..30ea486 100644
101472--- a/net/netfilter/nf_sockopt.c
101473+++ b/net/netfilter/nf_sockopt.c
101474@@ -45,7 +45,7 @@ int nf_register_sockopt(struct nf_sockopt_ops *reg)
101475 }
101476 }
101477
101478- list_add(&reg->list, &nf_sockopts);
101479+ pax_list_add((struct list_head *)&reg->list, &nf_sockopts);
101480 out:
101481 mutex_unlock(&nf_sockopt_mutex);
101482 return ret;
101483@@ -55,7 +55,7 @@ EXPORT_SYMBOL(nf_register_sockopt);
101484 void nf_unregister_sockopt(struct nf_sockopt_ops *reg)
101485 {
101486 mutex_lock(&nf_sockopt_mutex);
101487- list_del(&reg->list);
101488+ pax_list_del((struct list_head *)&reg->list);
101489 mutex_unlock(&nf_sockopt_mutex);
101490 }
101491 EXPORT_SYMBOL(nf_unregister_sockopt);
101492diff --git a/net/netfilter/nf_tables_api.c b/net/netfilter/nf_tables_api.c
101493index adce01e..8d52d50 100644
101494--- a/net/netfilter/nf_tables_api.c
101495+++ b/net/netfilter/nf_tables_api.c
101496@@ -152,8 +152,8 @@ nf_tables_chain_type_lookup(const struct nft_af_info *afi,
101497 #ifdef CONFIG_MODULES
101498 if (autoload) {
101499 nfnl_unlock(NFNL_SUBSYS_NFTABLES);
101500- request_module("nft-chain-%u-%*.s", afi->family,
101501- nla_len(nla)-1, (const char *)nla_data(nla));
101502+ request_module("nft-chain-%u-%.*s", afi->family,
101503+ nla_len(nla), (const char *)nla_data(nla));
101504 nfnl_lock(NFNL_SUBSYS_NFTABLES);
101505 type = __nf_tables_chain_type_lookup(afi->family, nla);
101506 if (type != NULL)
101507@@ -1934,7 +1934,8 @@ static const struct nft_set_ops *nft_select_set_ops(const struct nlattr * const
101508
101509 static const struct nla_policy nft_set_policy[NFTA_SET_MAX + 1] = {
101510 [NFTA_SET_TABLE] = { .type = NLA_STRING },
101511- [NFTA_SET_NAME] = { .type = NLA_STRING },
101512+ [NFTA_SET_NAME] = { .type = NLA_STRING,
101513+ .len = IFNAMSIZ - 1 },
101514 [NFTA_SET_FLAGS] = { .type = NLA_U32 },
101515 [NFTA_SET_KEY_TYPE] = { .type = NLA_U32 },
101516 [NFTA_SET_KEY_LEN] = { .type = NLA_U32 },
101517diff --git a/net/netfilter/nfnetlink_log.c b/net/netfilter/nfnetlink_log.c
101518index a155d19..726b0f2 100644
101519--- a/net/netfilter/nfnetlink_log.c
101520+++ b/net/netfilter/nfnetlink_log.c
101521@@ -82,7 +82,7 @@ static int nfnl_log_net_id __read_mostly;
101522 struct nfnl_log_net {
101523 spinlock_t instances_lock;
101524 struct hlist_head instance_table[INSTANCE_BUCKETS];
101525- atomic_t global_seq;
101526+ atomic_unchecked_t global_seq;
101527 };
101528
101529 static struct nfnl_log_net *nfnl_log_pernet(struct net *net)
101530@@ -564,7 +564,7 @@ __build_packet_message(struct nfnl_log_net *log,
101531 /* global sequence number */
101532 if ((inst->flags & NFULNL_CFG_F_SEQ_GLOBAL) &&
101533 nla_put_be32(inst->skb, NFULA_SEQ_GLOBAL,
101534- htonl(atomic_inc_return(&log->global_seq))))
101535+ htonl(atomic_inc_return_unchecked(&log->global_seq))))
101536 goto nla_put_failure;
101537
101538 if (data_len) {
101539diff --git a/net/netfilter/nft_compat.c b/net/netfilter/nft_compat.c
101540index 82cb823..5685dd5 100644
101541--- a/net/netfilter/nft_compat.c
101542+++ b/net/netfilter/nft_compat.c
101543@@ -216,7 +216,7 @@ target_dump_info(struct sk_buff *skb, const struct xt_target *t, const void *in)
101544 /* We want to reuse existing compat_to_user */
101545 old_fs = get_fs();
101546 set_fs(KERNEL_DS);
101547- t->compat_to_user(out, in);
101548+ t->compat_to_user((void __force_user *)out, in);
101549 set_fs(old_fs);
101550 ret = nla_put(skb, NFTA_TARGET_INFO, XT_ALIGN(t->targetsize), out);
101551 kfree(out);
101552@@ -403,7 +403,7 @@ match_dump_info(struct sk_buff *skb, const struct xt_match *m, const void *in)
101553 /* We want to reuse existing compat_to_user */
101554 old_fs = get_fs();
101555 set_fs(KERNEL_DS);
101556- m->compat_to_user(out, in);
101557+ m->compat_to_user((void __force_user *)out, in);
101558 set_fs(old_fs);
101559 ret = nla_put(skb, NFTA_MATCH_INFO, XT_ALIGN(m->matchsize), out);
101560 kfree(out);
101561diff --git a/net/netfilter/xt_gradm.c b/net/netfilter/xt_gradm.c
101562new file mode 100644
101563index 0000000..c566332
101564--- /dev/null
101565+++ b/net/netfilter/xt_gradm.c
101566@@ -0,0 +1,51 @@
101567+/*
101568+ * gradm match for netfilter
101569